-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·340 lines (288 loc) · 8.14 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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/bin/bash
# ================
# === Usage ===
# ================
function print_usage_info {
echo
echo
echo "Usage: ${0##*/} <CONFIG> [OPTIONS]"
echo "- Only when <CONFIG>=all: Compile all engines that are not CMaked yet in the traditional way"
echo "- Create directory 'build_<CONFIG>'"
echo " Delete it when it already existed"
echo "- Execute '. src/setenv.sh' to load modules"
echo "- Execute 'CMake <CONFIG>' to create makefile inside 'build_<CONFIG>'"
echo "- Execute 'make VERBOSE=1 install'"
echo "- Only when <CONFIG>=all: Combine all binaries in 'build_<CONFIG>\lnx64'"
echo
echo "<CONFIG>:"
echo "- If <CONFIG> is missing, this usage will be print"
echo "- all: All CMaked projects, currently D-Flow FM, DWAQ and DIMR"
echo "- dflowfm"
echo "- dwaq"
echo "- dwaves"
echo "- dimr"
echo "- tests"
echo "- swan"
echo "- delft3d4"
echo "- flow2d3d"
echo
echo "Options:"
echo "-p, --prepareonly"
echo " Only CMake, no make"
echo
echo "--debug"
echo " Compile in debug mode"
echo
echo "More info : https://oss.deltares.nl/web/delft3d/source-code"
echo "About CMake: https://git.deltares.nl/oss/delft3d/-/tree/main/src/cmake/README"
echo
exit 1
}
# =========================
# === CheckUtils ===
# =========================
function CheckUtils () {
if ! command -v patchelf &> /dev/null; then
echo "'patchelf' is not found."
fi
if ! command -v svnversion &> /dev/null; then
echo "'svnversion' is not found."
fi
}
# =========================
# === CreateCMakedir ===
# =========================
function CreateCMakedir () {
echo
echo "Create CMake dir for $1$2 ..."
cd $root
rm -rf $root/build_$1$2
mkdir $root/build_$1$2
return
}
# ==================
# === DoCMake ===
# ==================
function DoCMake () {
echo
echo "Executing CMake for $1 ..."
cd $root/build_$1$2
echo "cmake ../src/cmake -G "$generator" -B "." -D CONFIGURATION_TYPE="$1" -D CMAKE_BUILD_TYPE=${buildtype}"
cmake ../src/cmake -G "$generator" -B "." -D CONFIGURATION_TYPE="$1" -D CMAKE_BUILD_TYPE=${buildtype}
if [ $? -ne 0 ]; then
echo "CMake configure resulted in an error. Check log files."
exit 1
fi
return
}
# =====================
# === BuildCMake ===
# =====================
function BuildCMake () {
echo
echo "Building (make) based on CMake preparations for $1 ..."
cd $root/build_$1$2
echo "make -j VERBOSE=1 install"
make -j VERBOSE=1 install
if [ $? -ne 0 ]; then
echo "CMake build resulted in an error. Check log files."
exit 1
fi
return
}
# =========================
# === InstallAll ===
# =========================
function InstallAll () {
if [ ${1} = "all" ]; then
echo
echo "Installing in build_$1$2 ..."
cd $root
rm -rf $root/build_$1$2/lnx64
mkdir -p $root/build_$1$2/lnx64/bin
mkdir -p $root/build_$1$2/lnx64/lib
mkdir -p $root/build_$1$2/lnx64/share/delft3d/esmf/lnx64/bin
mkdir -p $root/build_$1$2/lnx64/share/delft3d/esmf/lnx64/bin_COS7
# CMaked stuff
cp -rf $root/build_$1$2/install/* $root/build_$1$2/lnx64/ &>/dev/null
# Additional step to copy ESMF stuff needed by D-WAVES
cp -rf $root/src/third_party_open/esmf/lnx64/bin/ESMF_RegridWeightGen $root/build_$1$2/lnx64/bin &>/dev/null
cp -rf $root/src/third_party_open/esmf/lnx64/scripts/ESMF_RegridWeightGen_in_Delft3D-WAVE.sh $root/build_$1$2/lnx64/bin &>/dev/null
cp -rf $root/src/third_party_open/esmf/lnx64/bin/lib* $root/build_$1$2/lnx64/share/delft3d/esmf/lnx64/bin &>/dev/null
cp -rf $root/src/third_party_open/esmf/lnx64/bin_COS7/lib* $root/build_$1$2/lnx64/share/delft3d/esmf/lnx64/bin_COS7 &>/dev/null
fi
return
}
# =========================
# === InstallDwaq ===
# =========================
function InstallDwaq () {
if [ ${1} = "dwaq" ]; then
echo
echo "Installing in build_$1$2 ..."
cd $root
rm -rf $root/build_$1$2/lnx64
mkdir -p $root/build_$1$2/lnx64/bin
mkdir -p $root/build_$1$2/lnx64/lib
# CMaked stuff
cp -rf $root/build_$1$2/install/* $root/build_$1$2/lnx64/ &>/dev/null
fi
return
}
# =========================
# === InstallDimr ===
# =========================
function InstallDimr () {
if [ ${1} = "dimr" ]; then
echo
echo "Installing in build_$1$2 ..."
cd $root
rm -rf $root/build_$1$2/lnx64
mkdir -p $root/build_$1$2/lnx64/bin
mkdir -p $root/build_$1$2/lnx64/lib
# CMaked stuff
cp -rf $root/build_$1$2/install/* $root/build_$1$2/lnx64/ &>/dev/null
fi
return
}
# ============
# === MAIN ===
# ============
#
## Defaults
prepareonly=0
mode=quiet
config="dflowfm"
generator="Unix Makefiles"
compiler=intel21
buildtype=debug
buildDirExtension="_debug"
## check if Deltares system
isdeltares=$([ -f "/opt/apps/deltares/.nl" ] && echo "yes" || echo "no")
#
## Start processing command line options:
while [[ $# -ge 1 ]]
do
key="$1"
case $key in
-c|--compiler)
shift
compiler="$1"
shift
;;
-p|--prepareonly)
prepareonly=1
shift
;;
-h|--help)
print_usage_info
;;
all)
config="all"
shift
;;
dflowfm)
config="dflowfm"
shift
;;
dwaq)
config="dwaq"
shift
;;
dwaves)
config="dwaves"
shift
;;
dimr)
config="dimr"
shift
;;
tests)
config="tests"
shift
;;
swan)
config="swan"
shift
;;
delft3d4)
config="delft3d4"
shift
;;
flow2d3d)
config="flow2d3d"
shift
;;
--debug)
buildtype=Debug
buildDirExtension="_debug"
shift
;;
*)
echo ERROR: Unknown command line argument $key
exit 1
;;
esac
done
#
# Check config parameter
if [ -z $config ]; then
print_usage_info
fi
scriptdirname=`readlink \-f \$0`
scriptdir=`dirname $scriptdirname`
root=$scriptdir
if [ "$isdeltares" = "yes" ]; then
# On Deltares systems only
echo
echo " config : $config" "${buildtype}"
echo " deltares system : $isdeltares"
echo " compiler : $compiler"
echo " prepareonly : $prepareonly"
echo
# Check if modules exist
module list > /dev/null
if [ $? -ne 0 ]; then
# No, modules do not exist: "Dot" setenv.sh version without modules
echo ". $root/src/setenv.sh $compiler"
. $root/src/setenv.sh $compiler
else
# Yes, modules do exist: "Dot" setenv.sh to load the modules needed
echo ". $root/src/setenv.sh $compiler"
. $root/src/setenv.sh $compiler
fi
if [ $? -ne 0 ]; then
echo "Setenv.sh resulted in an error. Check log files."
exit 1
fi
else
# On other systems
echo
echo " config : $config" "${buildtype}"
echo " prepareonly : $prepareonly"
echo ". $root/src/setenv.sh $compiler"
. $root/src/setenv.sh $compiler
fi
# check required utilities
chkutils=$(CheckUtils)
if [ ! -z "$chkutils" ]; then
echo "$chkutils"
echo "Install missing programs and retry."
exit 1
fi
CreateCMakedir ${config} ${buildDirExtension}
DoCMake ${config} ${buildDirExtension}
if [ "$prepareonly" = "1" ]; then
echo Finished with preparations only
exit 0
fi
BuildCMake ${config} ${buildDirExtension}
InstallAll ${config} ${buildDirExtension}
InstallDwaq ${config} ${buildDirExtension}
InstallDimr ${config} ${buildDirExtension}
echo "Copying over BMI shared libraries and driver test to BMI_build directory"
# Now copy over bmi shared libraries and
# driver script to the "BMI_Build" directory
cp -r $root/build_dflowfm${buildDirExtension}/dflowfm_bmi_lib/*.so $root/BMI_build
cp -r $root/build_dflowfm${buildDirExtension}/dflowfm_bmi_driver_test/dflowfm_bmi_driver_test $root/BMI_build
echo Finished