-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·148 lines (130 loc) · 4.17 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# ##############################################################################
# Utility
# ##############################################################################
expandPath() {
local path
local -a pathElements resultPathElements
IFS=':' read -r -a pathElements <<<"$1"
: "${pathElements[@]}"
for path in "${pathElements[@]}"; do
: "$path"
case $path in
"~+"/*)
path=$PWD/${path#"~+/"}
;;
"~-"/*)
path=$OLDPWD/${path#"~-/"}
;;
"~"/*)
path=$HOME/${path#"~/"}
;;
"~"*)
username=${path%%/*}
username=${username#"~"}
IFS=: read -r _ _ _ _ _ homedir _ < <(getent passwd "$username")
if [[ $path = */* ]]; then
path=${homedir}/${path#*/}
else
path=$homedir
fi
;;
esac
resultPathElements+=("$path")
done
local result
printf -v result '%s:' "${resultPathElements[@]}"
printf '%s\n' "${result%:}"
}
usage_msg="Build script for setting up the DiFfRG library and its dependencies.
For configuration of build flags, please edit the config file.
Usage: build.sh [options]
Options:
-f Perform a full build and install of everything without confirmations.
-c Use CUDA when building the DiFfRG library.
-i <directory> Set the installation directory for the library.
-j <threads> Set the number of threads passed to make and git fetch.
--help Display this information.
"
# ##############################################################################
# Script setup
# ##############################################################################
threads='1'
full_inst='n'
install_dir=''
cuda_flag=''
config_file='config'
config_flag=''
while getopts :i:j:fcd flag; do
case "${flag}" in
d)
config_file="config_docker"
config_flag="-d"
;;
i) install_dir=${OPTARG} ;;
j) threads=${OPTARG} ;;
f) full_inst='y' ;;
c) cuda_flag="-c" ;;
?)
printf "${usage_msg}"
exit 2
;;
esac
done
# Get the path where this script is located
SCRIPTPATH="$(
cd -- "$(dirname "$0")" >/dev/null 2>&1
pwd -P
)"
SOURCEPATH=${SCRIPTPATH}/DiFfRG
BUILDPATH=${SCRIPTPATH}/DiFfRG_build
LOGPATH=${SCRIPTPATH}/logs
mkdir -p ${LOGPATH}
# Obtain possibly user-defined configuration
source ${SCRIPTPATH}/${config_file}
# ##############################################################################
# Build bundled libraries
# ##############################################################################
git submodule update --init --recursive --jobs ${threads}
if [[ -z ${install_dir} ]]; then
echo
read -p "Install DiFfRG library globally to /opt/DiFfRG? [y/N/path] " install_dir
install_dir=${install_dir:-N}
fi
if [[ ${install_dir} == "y" ]]; then
install_dir="/opt/DiFfRG"
fi
if [[ ${install_dir} != "n" ]] && [[ ${install_dir} != "N" ]]; then
cd ${SCRIPTPATH}
# Make sure the install directory is absolute
idir=$(expandPath ${install_dir})
#idir=$(readlink --canonicalize ${idir})
echo "DiFfRG library will be installed in ${idir}"
# Install dependencies
start=$(date +%s)
cd ${SCRIPTPATH}/external
echo "Installing dependencies..."
bash ./install.sh -i ${idir}/bundled -j ${threads} ${cuda_flag} 2>&1 | tee ${LOGPATH}/DiFfRG_dependencies_install.log
end=$(date +%s)
runtime=$((end - start))
elapsed="Elapsed: $(($runtime / 3600))hrs $((($runtime / 60) % 60))min $(($runtime % 60))sec"
echo " Done. (${elapsed})"
echo
fi
# ##############################################################################
# Setup and build library
# ##############################################################################
if [[ "$full_inst" == "y" ]] && [[ "$install_dir" != "" ]]; then
bash ${SCRIPTPATH}/update_DiFfRG.sh -j ${threads} -m ${cuda_flag} ${config_flag} -i ${install_dir}
else
if [[ "$full_inst" == "y" ]]; then
bash ${SCRIPTPATH}/update_DiFfRG.sh -j ${threads} -m ${cuda_flag} ${config_flag}
else
bash ${SCRIPTPATH}/update_DiFfRG.sh -j ${threads} ${config_flag}
fi
fi
# ##############################################################################
# Finish
# ##############################################################################
echo "DiFfRG setup complete."
echo