-
Notifications
You must be signed in to change notification settings - Fork 1
/
bbuild
executable file
·325 lines (276 loc) · 8.21 KB
/
bbuild
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/bash -i
# Force correct shell
export SHELL=/bin/bash
# For debugging
# set -v
# Print bash commands before they are executed
# set -x
# Prints entire command trace before each command
# Define a trap to catch errors
# Currently this does not work since we have *many* errors
# This needs to be fixed
#set -eE -o functrace
function _bbuild_failure() {
local source="$1"
local lineno="$2"
local msg="$3"
echo "Failed in source: [$source] at line: $lineno with error: $msg"
}
#trap '_bbuild_failure "${BASH_SOURCE[@]}" "$BASH_LINENO" "$BASH_COMMAND"' ERR
# Set the umask 022 means read and execute
# This should be the default for our installation
umask 022
_top_dir=`pwd`
source ~/.bashrc
module purge 1>/dev/null 2>/dev/null
# Ensure that there is not multiple threads running
export OMP_NUM_THREADS=1
# On thul and interactive nodes, sourching leads to going back
cd $_top_dir
# We have here the installation of all the stuff for gray....
source src/init.bash
# Default prefix installation
_prefix=/opt
_signal_default=1
# Default python version installed
_python_version=3
# Default MPI version
declare -l _mpi_version=openmpi
# Default name for build which builds the generic
# packages.
_b_name_generic=generic
_b_name_default=generic
_post_run=this-directory-should-never-exist
while [ $# -gt 0 ]; do
trim_em opt $1
case $opt in
-*)
shift
;;
esac
case $opt in
-prefix)
_prefix=$1
touch $_prefix/.bash-build-test-file
if [[ $? -ne 0 ]]; then
doerr "Prefix" "cannot write to installation directory, please chmod"
exit 1
else
rm $_prefix/.bash-build-test-file
fi
;;
-gnu-version)
gnu_version=$1
;;
-gen-gnu-version)
gen_gnu_version=$1
;;
# Basic options for every kind of
# build customization...
-python-version|-pv)
_python_version=$1
case $_python_version in
2|3)
;; # fine
*)
doerr "option parsing" "Python version does not exist [2|3]"
;;
esac
shift ;;
-mpi)
_mpi_version=$1
case $_mpi_version in
openmpi|mpich|mvapich)
noop
;; # fine
ompi)
_mpi_version=openmpi
;;
*)
doerr "option parsing" "MPI version does not exist [OpenMPI|MPICH|MVAPICH]"
;;
esac
shift ;;
-tcl|-env-mod)
_mod_format=$_mod_format_ENVMOD
;;
-lua|-lmod)
_mod_format=$_mod_format_LMOD
;;
-generic)
_b_name_generic=$1
shift ;;
-default|-d)
_b_name_default=$1
shift ;;
-list)
export PACK_LIST=1
;;
-n)
set_procs $1
shift
;;
-only)
pack_only $1
shift ;;
-only-file)
pack_only -file $1
shift ;;
-post-run)
_post_run=$1
shift ;;
-help|-h)
help_
exit 0
;;
-build)
opt=$1
;& # go through
*)
# We consider empty stuff to be builds
if [ ! -e $opt ]; then
doerr "option parsing" "Build source $opt does not exist!"
fi
_signal_default=0
source $opt
shift
;;
esac
done
# If the user have not specified any build-instructions
# we will commense our own default build
if [[ $_signal_default -eq 1 ]]; then
source src/default_build.bash
fi
# We should now have populated all builds
# Check if the _b_name_generic exists
tmp=$(get_index -hash-array "_b_index" $_b_name_generic)
if [ -z "$tmp" ]; then
doerr "option parsing" "Unrecognized build $_b_name_generic, create it first"
else
build_set -default-build $_b_name_generic
msg_install -message "The default build for the generic packages is: $_b_name_generic"
source $(build_get -source)
fi
tmp=$(get_index -hash-array "_b_index" $_b_name_default)
if [ -z "$tmp" ]; then
doerr "option parsing" "Unrecognized build $_b_name_default, create it first"
else
msg_install -message "The default build for packages is: $_b_name_default"
fi
# Notify the user about which module files will be generated
msg_install -message "Will create $_mod_format compliant module files"
msg_install -message "Will build with $_n_procs processors"
tmp=0
while [ $tmp -lt $_N_b ]; do
if [ -z "$(build_get -installation-path[$tmp])" ]; then
msg_install -message "The installation path for ${_b_name[$tmp]} has not been set."
echo "I do not dare to guess where to place packages!"
echo "Please set it in your source file."
exit 1
fi
if [ -z "$(build_get -module-path[$tmp])" ]; then
msg_install -message "The module path for ${_b_name[$tmp]} has not been set."
msg_install -message "Will set it to: $(build_get -installation-path[$tmp])/modules"
build_set -module-path "$(build_get -installation-path[$tmp])/modules"
fi
# DEBUG
#build_print $tmp
let tmp++
done
# Begin installation of various packages
# List of archives
# The order is the installation order
# We can always set the env-variable of LMOD
export LMOD_IGNORE_CACHE=1
# Far more often than not, we need Modules to be installed before
source_pack helpers/modules.bash
# Check that modules was installed previously, and if
# that isn't the case, error out and denote the user should
# rerun the script..
if [[ $_has_module_cmd -eq 0 ]]; then
msg_install -message "Please rerun the script and add $(pack_get -prefix modules) to your path (for correct environment variable)"
msg_install -message "For environment modules, add this to your .bashrc: 'source $(pack_get -prefix modules)/$(pack_get -version modules)/init/bash'"
exit 1
fi
# Now check that all module-paths are actually used
_has_module_path=1
for ib in `seq 0 $_N_b` ; do
path=$(build_get -module-path[$ib])
if [[ $(check_modulepath $path) -eq 0 ]]; then
msg_install -message "Module path: '$path' is not in env(MODULEPATH)"
msg_install -message "Add this to your .bashrc: 'module use --append $path'"
_has_module_path=0
fi
done
path=$(build_get -module-path[$_b_name_default])-apps
if [[ $(check_modulepath $path) -eq 0 ]]; then
module use -p $path
fi
if [[ $(check_modulepath $path) -eq 0 ]]; then
msg_install -message "Module path: '$path' is not in env(MODULEPATH)"
msg_install -message "Add this to your .bashrc: 'module use --append $path'"
_has_module_path=0
fi
if [[ $_has_module_path -eq 0 ]]; then
msg_install -message "Please correct your environment, the module path is not consistent with your build."
exit 1
fi
# Vendor libraries do not depend on anything...
source vendor.bash
# Install the helper
source helpers.bash
# Install the lua-libraries
source lua/install.bash
# Install helper scripts
# These should _never_ have any dependencies.
# However, the Lmod switch requires LMOD (for usage, not for installation)
source scripts.bash
# Set the future correct default build as
# requested by the user.
build_set -default-build $_b_name_default
# We need to update the module requirements for the
# build (for instance if gnu-X.X.X has not been expanded)
build_set -reset-module \
$(list -prefix "-default-module " \
$(build_get -default-module))
# Do the same for the debug build
build_set -reset-module[debug] \
$(list -prefix '-default-module[debug] ' \
$(build_get -default-module))
# Source the compiler specifications to ensure the correct
# versions has been set etc.
source $(build_get -source)
# Install all libraries
source libs.bash
# These are "parent" installations...
source python${_python_version}.bash
source R.bash
source julia.bash
source nim.bash
# We have installed all libraries needed for doing application installs
source apps.bash
# Add the default modules
source default.bash
# Add the latest modules
source latest.bash
msg_install -message "Finished installing all applications..."
# When dealing with additional sets of instructions spec files
# can come in handy.
# For instance to add an include directory to all cpp files do
# gcc -dumpspecs > specs
# Edit specs in line *cpp:
# and add -I<folder>
# Per default will gcc read specs in the folder of generic libraries:
# gcc -print-libgcc-file-name (dir)
if [[ -d $_post_run ]]; then
msg_install -message "Running post-directory installations..."
pushd $_post_run 1> /dev/null
# List files and add them one-at a time
for never_used in $(ls -pL | grep -v '/' | sort)
do
source_pack $never_used
done
popd 2>/dev/null
msg_install -message "Done running post-directory installations!"
fi