forked from NASA-LIS/NASA-Land-Coupler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·193 lines (178 loc) · 5.9 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
#!/bin/bash
#-----------------------BEGIN NOTICE -- DO NOT EDIT-----------------------------
# NASA Goddard Space Flight Center
# NASA Land Coupler (NLC)
# Version 0.5
#
# Copyright (c) 2022 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# Licensed under Apache License 2.0.
#-------------------------END NOTICE -- DO NOT EDIT-----------------------------
# usage instructions
usage () {
printf "Usage: $0 [OPTIONS]...\n"
printf "\n"
printf "OPTIONS\n"
printf " --system=SYSTEM\n"
printf " name of machine (e.g. 'discover', 'cheyenne'\n"
printf " --compiler=COMPILER\n"
printf " compiler to use; valid options are 'intel.X.Y.Z', \n"
printf " 'gnu.X.Y.Z'; default is system dependent.\n"
printf " --components=\"COMPONENT1,COMPONENT2...\"\n"
printf " components to include in build; delimited with ','\n"
printf " --continue\n"
printf " continue with existing build\n"
printf " --clean\n"
printf " removes existing build; will override --continue\n"
printf " --build-dir=BUILD_DIR\n"
printf " build directory\n"
printf " --build-type=BUILD_TYPE\n"
printf " build type; valid options are 'debug', 'release',\n"
printf " 'relWithDebInfo'\n"
printf " --install-dir=INSTALL_DIR\n"
printf " installation prefix\n"
printf " --verbose, -v\n"
printf " build with verbose output\n"
printf "\n"
}
# print settings
settings () {
printf "Settings:\n"
printf "\n"
printf " NLC_DIR=${NLC_DIR}\n"
printf " BUILD_DIR=${BUILD_DIR}\n"
printf " INSTALL_DIR=${INSTALL_DIR}\n"
printf " SYSTEM=${SYSTEM}\n"
printf " COMPILER=${MYCOMPILER}\n"
if [ ! -z "${COMPONENTS}" ]; then printf " COMPONENTS=${COMPONENTS}\n"; fi
printf " CLEAN=${CLEAN}\n"
printf " CONTINUE=${CONTINUE}\n"
printf " BUILD_TYPE=${BUILD_TYPE}\n"
printf " VERBOSE=${VERBOSE}\n"
printf "\n"
}
# find system name
find_system () {
local sysname=`hostname`
sysname="${sysname//[[:digit:]]/}"
echo "$sysname"
}
# default settings
NLC_DIR=$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)
BUILD_DIR=${NLC_DIR}/build
INSTALL_DIR=${NLC_DIR}/src/driver
SYSTEM=""
MYCOMPILER=""
COMPONENTS=""
BUILD_TYPE="release"
CLEAN=false
CONTINUE=false
VERBOSE=false
# required arguments
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
usage
exit 0
fi
# process arguments
while :; do
case $1 in
--help|-h) usage; exit 0 ;;
--system=?*) SYSTEM=${1#*=} ;;
--system) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--system=) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--compiler=?*) MYCOMPILER=${1#*=} ;;
--compiler) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--compiler=) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--components=?*) COMPONENTS=${1#*=} ;;
--components) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--components=) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--build-dir=?*) BUILD_DIR=${1#*=} ;;
--build-dir) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--build-dir=) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--install-dir=?*) INSTALL_DIR=${1#*=} ;;
--install-dir) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--install-dir=) printf "ERROR: $1 requires an argument.\n"; usage; exit 1 ;;
--clean) CLEAN=true ;;
--clean=?*) printf "ERROR: $1 argument ignored.\n"; usage; exit 1 ;;
--clean=) printf "ERROR: $1 argument ignored.\n"; usage; exit 1 ;;
--continue) CONTINUE=true ;;
--continue=?*) printf "ERROR: $1 argument ignored.\n"; usage; exit 1 ;;
--continue=) printf "ERROR: $1 argument ignored.\n"; usage; exit 1 ;;
--verbose|-v) VERBOSE=true ;;
--verbose=?*) printf "ERROR: $1 argument ignored.\n"; usage; exit 1 ;;
--verbose=) printf "ERROR: $1 argument ignored.\n"; usage; exit 1 ;;
-?*) printf "ERROR: Unknown option $1\n"; usage; exit 1 ;;
*) break
esac
shift
done
set -eu
# automatically determine system
if [ -z "${SYSTEM}" ] ; then
SYSTEM=$(find_system)
fi
# automatically determine compiler
if [ -z "${MYCOMPILER}" ] ; then
if [ "${SYSTEM}" = "discover" ]; then
MYCOMPILER="intel.19.1.3"
elif [ "${SYSTEM}" = "cheyenne" ]; then
MYCOMPILER="intel.19.1.1"
else
printf "ERROR: no default compiler for ${SYSTEM}\n"
printf "\n"
exit 1
fi
fi
# print settings
if [ "${VERBOSE}" = true ] ; then
settings
fi
# load environment for this system/compiler combination
ENVFILE="${NLC_DIR}/env/${SYSTEM}.${MYCOMPILER}"
if [ ! -f "${ENVFILE}" ]; then
printf "ERROR: environment file does not exist for ${SYSTEM}.${MYCOMPILER}\n"
printf "Please select one of the following configurations\n"
for f in "${NLC_DIR}/env"/*
do
printf " $(basename $f)\n"
done
printf "\n"
exit 1
fi
source ${ENVFILE}
# if build directory already exists then exist
if [ "${CLEAN}" = true ]; then
printf "Remove build directory\n"
printf " BUILD_DIR=${BUILD_DIR}\n"
printf "\n"
rm -rf ${BUILD_DIR}
elif [ "${CONTINUE}" = true ]; then
printf "Continue build in directory\n"
printf " BUILD_DIR=${BUILD_DIR}\n"
printf "\n"
else
if [ -d "${BUILD_DIR}" ]; then
printf "ERROR: Build directory exists\n"
printf " use option --continue to continue existing build\n"
printf " use option --clean to remove existing build\n"
exit 1
fi
fi
mkdir -p ${BUILD_DIR}
# cmake settings
CMAKE_SETTINGS="-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
if [ ! -z "${COMPONENTS}" ]; then
CMAKE_SETTINGS="${CMAKE_SETTINGS} -DINCLUDE_COMPONENTS=${COMPONENTS}"
fi
# make settings
MAKE_SETTINGS=""
if [ "${VERBOSE}" = true ]; then
MAKE_SETTINGS="VERBOSE=1"
fi
# build the code
cd ${BUILD_DIR}
cmake ${NLC_DIR} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} ${CMAKE_SETTINGS}
make -j ${BUILD_JOBS:-4} ${MAKE_SETTINGS}
make install
exit 0