-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
executable file
·265 lines (238 loc) · 7.25 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
#!/bin/bash
# usage instructions
usage () {
cat << EOF_USAGE
Usage: $0 --platform=PLATFORM [OPTIONS] ... [TARGETS]
OPTIONS
-a, --app=APPLICATION
weather model application to build; for example, CSTLS for DATM+SCHISM
--bin-dir=BIN_DIR
installation binary directory name ("bin" by default; any name is available)
-b, --build-dir=BUILD_DIR
build directory
--build-jobs=BUILD_JOBS
number of build jobs; defaults to 4
--build-type=BUILD_TYPE
build type; defaults to RELEASE
(e.g. DEBUG | RELEASE | RELWITHDEBINFO)
--clean
does a "make clean"
-c, --compiler=COMPILER
compiler to use; default depends on platform
(e.g. intel | gnu)
-h, --help
show this help guide
-i, --install-dir=INSTALL_DIR
installation prefix
-p, --platform=PLATFORM
name of machine you are building on
(e.g. cheyenne | hera | jet | orion | wcoss2)
--remove
removes existing build
-v, --verbose
build with verbose output
NOTE: See User's Guide for detailed build instructions
EOF_USAGE
}
# print usage error and exit
usage_error () {
printf "ERROR: $1\n" >&2
usage >&2
exit 1
}
# helper to try and load module
function load_module() {
set +e
MODF="$1${PLATFORM}.${COMPILER}"
printf "Loading module ${MODF} ...\n"
module is-avail ${MODF}
if [ $? -eq 0 ]; then
module load ${MODF}
return
fi
}
# print settings
settings () {
cat << EOF_SETTINGS
Settings:
APP=${APPLICATION}
APP_DIR=${APP_DIR}
BIN_DIR=${BIN_DIR}
BUILD_DIR=${BUILD_DIR}
BUILD_JOBS=${BUILD_JOBS}
BUILD_TYPE=${BUILD_TYPE}
CLEAN=${CLEAN}
COMPILER=${COMPILER}
INSTALL_DIR=${INSTALL_DIR}
PLATFORM=${PLATFORM}
REMOVE=${REMOVE}
VERBOSE=${VERBOSE}
EOF_SETTINGS
}
# process required arguments
if [[ ("$1" == "--help") || ("$1" == "-h") ]]; then
usage
exit 0
fi
# default settings
APP_DIR=$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)
BIN_DIR=${BIN_DIR:-${APP_DIR}/install/bin}
BUILD_DIR="${BUILD_DIR:-${APP_DIR}/build}"
BUILD_JOBS=4
BUILD_TYPE="RELEASE"
CLEAN=false
CMAKE_SETTINGS=""
INSTALL_DIR=${INSTALL_DIR:-${APP_DIR}/install}
REMOVE=false
VERBOSE=false
# process optional arguments
while :; do
case $1 in
--app=?*|-a=?*) APPLICATION=${1#*=} ;;
--app|--app=|-a|-a=) usage_error "$1 requires argument." ;;
--bin-dir=?*) BIN_DIR=${1#*=} ;;
--bin-dir|--bin-dir=) usage_error "$1 requires argument." ;;
--build-dir=?*|-b=?*) BUILD_DIR=${1#*=} ;;
--build-dir|--build-dir=|-b|-b=) usage_error "$1 requires argument." ;;
--build-type=?*) BUILD_TYPE=${1#*=} ;;
--build-type|--build-type=) usage_error "$1 requires argument." ;;
--build-jobs=?*) BUILD_JOBS=$((${1#*=})) ;;
--build-jobs|--build-jobs=) usage_error "$1 requires argument." ;;
--clean) CLEAN=true ;;
--compiler=?*|-c=?*) COMPILER=${1#*=} ;;
--compiler|--compiler=|-c|-c=) usage_error "$1 requires argument." ;;
--help|-h) usage; exit 0 ;;
--install-dir=?*|-i=?*) INSTALL_DIR=${1#*=} ;;
--install-dir|--install-dir=|-i|-i=) usage_error "$1 requires argument." ;;
--platform=?*|-p=?*) PLATFORM=${1#*=} ;;
--platform|--platform=|-p|-p=) usage_error "$1 requires argument." ;;
--remove) REMOVE=true ;;
--remove=?*|--remove=) usage_error "$1 argument ignored." ;;
--verbose|-v) VERBOSE=true ;;
--verbose=?*|--verbose=) usage_error "$1 argument ignored." ;;
# unknown
-?*|?*) usage_error "Unknown option $1" ;;
*) break
esac
shift
done
# ensure uppercase/lowercase
APPLICATION=$(echo ${APPLICATION} | tr '[a-z]' '[A-Z]')
PLATFORM=$(echo ${PLATFORM} | tr '[A-Z]' '[a-z]')
COMPILER=$(echo ${COMPILER} | tr '[A-Z]' '[a-z]')
# check if PLATFORM is set
if [ -z $PLATFORM ] ; then
printf "\nERROR: Please set PLATFORM.\n\n"
usage
exit 0
fi
# set PLATFORM (MACHINE)
MACHINE="${PLATFORM}"
set -eu
# automatically determine compiler
if [ -z "${COMPILER}" ] ; then
case ${PLATFORM} in
jet|hera|gaea|gaea-c5) COMPILER=intel ;;
orion) COMPILER=intel ;;
wcoss2) COMPILER=intel ;;
cheyenne) COMPILER=intel ;;
macos|singularity) COMPILER=gnu ;;
odin|noaacloud) COMPILER=intel ;;
*)
COMPILER=intel
printf "WARNING: Setting default COMPILER=intel for new platform ${PLATFORM}\n" >&2;
;;
esac
fi
# cmake settings
CMAKE_SETTINGS="\
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}\
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}\
-DCMAKE_INSTALL_BINDIR=${BIN_DIR}"
if [ ! -z "${APPLICATION}" ]; then
CMAKE_SETTINGS="${CMAKE_SETTINGS} -DAPP=${APPLICATION}"
# application specific cmake settings
# adcirc
if [ "${APPLICATION}" == "CSTLA" ]; then
CMAKE_SETTINGS="${CMAKE_SETTINGS} -DADCIRC_CONFIG=PADCIRC -DBUILD_ADCPREP=ON -DCOUPLED=ON"
# fvcom
elif [ "${APPLICATION}" == "CSTLF" ]; then
CMAKE_SETTINGS="${CMAKE_SETTINGS} -DCOORDINATE_TYPE=SPHERICAL -DWET_DRY=ON"
# roms
elif [ "${APPLICATION}" == "CSTLR" ]; then
CMAKE_SETTINGS="${CMAKE_SETTINGS} -DMY_CPP_FLAGS=BULK_FLUXES"
# schism
elif [ "${APPLICATION}" == "CSTLS" ]; then
CMAKE_SETTINGS="${CMAKE_SETTINGS} -DUSE_ATMOS=ON -DNO_PARMETIS=OFF -DOLDIO=ON -DBUILD_UTILS=ON"
fi
fi
# make settings
MAKE_SETTINGS="-j ${BUILD_JOBS}"
if [ "${VERBOSE}" = true ]; then
MAKE_SETTINGS="${MAKE_SETTINGS} VERBOSE=1"
fi
# print settings
if [ "${VERBOSE}" = true ] ; then
settings
fi
# load modules
module purge
module use ${APP_DIR}/sorc/ufs-weather-model/modulefiles
load_module "ufs_"
module li
# if build directory already exists then exit
if [ "${REMOVE}" = true ]; then
# Clean build, install and executable directories
if [ -d "${BUILD_DIR}" ]; then
printf "Build directory already exists! Removing ${BUILD_DIR} ...\n"
rm -rf ${BUILD_DIR}
fi
if [ -d "${INSTALL_DIR}" ]; then
printf "Install directory already exists! Removing ${INSTALL_DIR} ...\n"
rm -rf ${INSTALL_DIR}
fi
# Create new build directory
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
else
# The build directory exists
if [ -d "${BUILD_DIR}" ]; then
# Check which application is build
if [ -f ${BUILD_DIR}/CMakeCache.txt ]; then
# Query existing app
APP_BUILD=`cat ${BUILD_DIR}/CMakeCache.txt | grep "APP:BOOL=" | awk -F= '{print $2}'`
# Check with the requested one
if [ "${APPLICATION}" != "${APP_BUILD}" ]; then
printf "Build directory already exists and used to build -DAPP=${APP_BUILD} but the requested application is -DAPP=${APPLICATION}\n" >&2
printf "Please clean existing build with --remove option and build again. Exiting ...\n" >&2
exit
else
cd ${BUILD_DIR}
fi
fi
# There is no build directory. Just create it
else
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
fi
fi
# configure model
printf "Generate CMAKE configuration ...\n" >&2
cmake ${APP_DIR} ${CMAKE_SETTINGS} 2>&1 | tee log.cmake
# build/clean model
if [ "${CLEAN}" = true ]; then
if [ -f $PWD/Makefile ]; then
printf "Clean executables ...\n"
make ${MAKE_SETTINGS} clean 2>&1 | tee log.make
fi
else
printf "Build and create executables ...\n"
make ${MAKE_SETTINGS} install 2>&1 | tee log.make
fi
# move executables
if [ -f "${BUILD_DIR}/sorc/ufs-weather-model/ufs_model" ]; then
printf "Moving executables to final locations ...\n"
mkdir -p ${BIN_DIR}
mv ${BUILD_DIR}/sorc/ufs-weather-model/ufs_model ${BIN_DIR}/.
mv ${BUILD_DIR}/bin/* ${BIN_DIR}/.
fi