1 | #!/bin/bash |
---|
2 | #set -x |
---|
3 | set -o posix |
---|
4 | #set -u |
---|
5 | #set -e |
---|
6 | #+ |
---|
7 | # |
---|
8 | # =============== |
---|
9 | # makenemo |
---|
10 | # =============== |
---|
11 | # |
---|
12 | # -------------------------- |
---|
13 | # Compile NEMO |
---|
14 | # -------------------------- |
---|
15 | # |
---|
16 | # SYNOPSIS |
---|
17 | # ======== |
---|
18 | # |
---|
19 | # :: |
---|
20 | # |
---|
21 | # $ makenemo |
---|
22 | # |
---|
23 | # |
---|
24 | # DESCRIPTION |
---|
25 | # =========== |
---|
26 | # |
---|
27 | # |
---|
28 | # This script aims : |
---|
29 | # |
---|
30 | # - to choose MYCONFIG |
---|
31 | # - to choose compiler options |
---|
32 | # - to create the CONFIG/MYCONFIG/WORK directory |
---|
33 | # - to compile this configuration |
---|
34 | # |
---|
35 | # Variables used : |
---|
36 | # |
---|
37 | # From user input |
---|
38 | # |
---|
39 | # - NEW_CONF : configuration to be created |
---|
40 | # - REF_CONF : reference configuration to build the new one |
---|
41 | # - CMP_NAM : compiler name |
---|
42 | # - NBR_PRC : number of processes used to compile |
---|
43 | # - NEM_SUBDIR : NEMO subdirectory used (specified) |
---|
44 | # |
---|
45 | # Locally defined : |
---|
46 | # |
---|
47 | # - TAB : NEMO subdirectory used (read) |
---|
48 | # - MAIN_DIR : self explaining |
---|
49 | # - CONFIG_DIR : " " " |
---|
50 | # - MODELES_DIR : " " " |
---|
51 | # - TOOLS_DIR : " " " |
---|
52 | # - NEMO_DIR : " " " |
---|
53 | # |
---|
54 | # EXAMPLES |
---|
55 | # ======== |
---|
56 | # |
---|
57 | # :: |
---|
58 | # |
---|
59 | # $ ./makenemo -m ifort_osx - j3 -n ORCA2_LIM |
---|
60 | # |
---|
61 | # |
---|
62 | # TODO |
---|
63 | # ==== |
---|
64 | # |
---|
65 | # option debug |
---|
66 | # |
---|
67 | # |
---|
68 | # EVOLUTIONS |
---|
69 | # ========== |
---|
70 | # |
---|
71 | # $Id$ |
---|
72 | # |
---|
73 | # |
---|
74 | # |
---|
75 | # * creation |
---|
76 | # |
---|
77 | #- |
---|
78 | |
---|
79 | #- |
---|
80 | #- Initialization of the options --- |
---|
81 | x_d=""; |
---|
82 | x_h=""; |
---|
83 | x_n=""; |
---|
84 | x_r=""; |
---|
85 | x_m=""; |
---|
86 | x_t=""; |
---|
87 | x_c=""; |
---|
88 | x_j=1; |
---|
89 | x_e="none"; |
---|
90 | x_s=NEMO; |
---|
91 | x_v=1; |
---|
92 | |
---|
93 | #- Local variables --- |
---|
94 | b_n=$(basename ${0}) |
---|
95 | OPTIND=1 |
---|
96 | MAIN_DIR=$(cd $(dirname "$0"); pwd) |
---|
97 | MAIN_DIR=${MAIN_DIR%/SETTE*} |
---|
98 | MAIN_DIR=${MAIN_DIR%/TOOLS*} |
---|
99 | MAIN_DIR=${MAIN_DIR%/CONFIG*} |
---|
100 | export MAIN_DIR |
---|
101 | # |
---|
102 | export CONFIG_DIR=${MAIN_DIR}/CONFIG |
---|
103 | export TOOLS_DIR=${MAIN_DIR}/TOOLS |
---|
104 | export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE |
---|
105 | export NEMO_DIR=${MAIN_DIR}/${x_s} |
---|
106 | export AGRIFUSE=10 |
---|
107 | declare -a TAB |
---|
108 | #- |
---|
109 | #- FCM and functions location --- |
---|
110 | export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH |
---|
111 | |
---|
112 | #- |
---|
113 | #- Choice of the options --- |
---|
114 | while getopts :hd:n:r:m:j:e:s:v:t: V |
---|
115 | do |
---|
116 | case $V in |
---|
117 | (h) x_h=${OPTARG}; |
---|
118 | echo "Usage : "${b_n} \ |
---|
119 | " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-s Path] [-e Path] [-j No] [-v No]"; |
---|
120 | echo " -h : help"; |
---|
121 | echo " -h institute : specific help for consortium members"; |
---|
122 | echo " -n name : config name, [-n help] to list existing configurations"; |
---|
123 | echo " -m arch : choose compiler, [-m help] to list existing compilers"; |
---|
124 | echo " -d dir : choose NEMO sub-directories"; |
---|
125 | echo " -r conf : choose reference configuration"; |
---|
126 | echo " -s Path : choose alternative location for NEMO main directory"; |
---|
127 | echo " -e Path : choose alternative location for MY_SRC directory"; |
---|
128 | echo " -j No : number of processes used to compile (0=nocompilation)"; |
---|
129 | echo " -v No : set verbosity level for compilation [0-3]"; |
---|
130 | echo " -t dir : temporary directory for compilation" |
---|
131 | echo ""; |
---|
132 | echo "Example to install a new configuration MY_CONFIG"; |
---|
133 | echo "with OPA_SRC and LIM_SRC_2 "; |
---|
134 | echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\""; |
---|
135 | echo ""; |
---|
136 | echo "Available configurations :"; cat ${CONFIG_DIR}/cfg.txt; |
---|
137 | echo ""; |
---|
138 | echo "Example to remove bad configuration "; |
---|
139 | echo "./makenemo -n MY_CONFIG clean_config"; |
---|
140 | echo ""; |
---|
141 | echo "Example to clean "; |
---|
142 | echo "./makenemo clean"; |
---|
143 | echo ""; |
---|
144 | echo "Example to add and remove keys"; |
---|
145 | echo "./makenemo add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" "; |
---|
146 | echo ""; |
---|
147 | echo "Example to add and remove keys for a new configuration, and do not compile"; |
---|
148 | echo "./makenemo -n MY_CONFIG -j0 add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" "; |
---|
149 | echo ""; |
---|
150 | . ${COMPIL_DIR}/Flist_archfile.sh ${x_h} ; |
---|
151 | echo ""; |
---|
152 | echo "Default : previous configuration and compiler"; |
---|
153 | exit 0;; |
---|
154 | (d) x_d=${OPTARG};; |
---|
155 | (n) x_n=${OPTARG};; |
---|
156 | (r) x_r=${OPTARG};; |
---|
157 | (m) x_m=${OPTARG};; |
---|
158 | (j) x_j=${OPTARG};; |
---|
159 | (t) x_t=${OPTARG};; |
---|
160 | (e) x_e=${OPTARG};; |
---|
161 | (s) x_s=${OPTARG};; |
---|
162 | (v) x_v=${OPTARG};; |
---|
163 | (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; |
---|
164 | exit 2;; |
---|
165 | (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; |
---|
166 | exit 2;; |
---|
167 | esac |
---|
168 | done |
---|
169 | shift $(($OPTIND-1)); |
---|
170 | |
---|
171 | while [ ${#1} -gt 0 ] # Get clean, clean_config options |
---|
172 | do |
---|
173 | case "$1" in |
---|
174 | clean) |
---|
175 | x_c="--$1" |
---|
176 | ;; |
---|
177 | clean_config) |
---|
178 | . ${COMPIL_DIR}/Fclean_config.sh |
---|
179 | exit |
---|
180 | ;; |
---|
181 | add_key) |
---|
182 | list_add_key=$2 |
---|
183 | export ${list_add_key} |
---|
184 | shift |
---|
185 | ;; |
---|
186 | del_key) |
---|
187 | list_del_key=$2 |
---|
188 | export ${list_del_key} |
---|
189 | shift |
---|
190 | ;; |
---|
191 | *) |
---|
192 | echo " \"$1\" BAD OPTION" |
---|
193 | exit |
---|
194 | ;; |
---|
195 | |
---|
196 | esac |
---|
197 | shift |
---|
198 | done |
---|
199 | |
---|
200 | |
---|
201 | #- |
---|
202 | #- Go to NEMOGCM/config directory --- |
---|
203 | cd ${CONFIG_DIR} |
---|
204 | |
---|
205 | #- |
---|
206 | #- Initialisation from input --- |
---|
207 | export NEW_CONF=${x_n} |
---|
208 | NBR_PRC=${x_j} |
---|
209 | CMP_NAM=${x_m} |
---|
210 | NEM_SUBDIR=${x_d} |
---|
211 | REF_CONF=${x_r} |
---|
212 | NEMO_TDIR=${x_t:-$NEMO_TDIR} |
---|
213 | export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR} |
---|
214 | export NEMO_DIR=${MAIN_DIR}/${x_s} |
---|
215 | |
---|
216 | #- Check if the tool or the compiler exist or list it |
---|
217 | if [ "${NEW_CONF}" == help ] ; then |
---|
218 | echo "Available configurations :" |
---|
219 | cat ${CONFIG_DIR}/cfg.txt |
---|
220 | exit |
---|
221 | fi |
---|
222 | [ "${CMP_NAM}" == help ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit |
---|
223 | |
---|
224 | #- When used for the first time, choose a compiler --- |
---|
225 | . ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm ${CMP_NAM} || exit |
---|
226 | |
---|
227 | #- |
---|
228 | #- Choose a default configuration if needed --- |
---|
229 | #- ORCA2_LIM or last one used --- |
---|
230 | . ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit |
---|
231 | |
---|
232 | |
---|
233 | if [ ${#NEW_CONF} -eq 0 ] ; then |
---|
234 | if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then |
---|
235 | echo "You are installing a new configuration" |
---|
236 | ind=0 |
---|
237 | . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC YES |
---|
238 | . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2 YES |
---|
239 | . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3 NO |
---|
240 | . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC NO |
---|
241 | . ${COMPIL_DIR}/Fread_dir.sh NST_SRC YES |
---|
242 | . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC NO |
---|
243 | REF_CONF=ORCA2_LIM |
---|
244 | elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then |
---|
245 | echo "You are installing a new configuration" |
---|
246 | TAB=( ${NEM_SUBDIR} ) |
---|
247 | REF_CONF=ORCA2_LIM |
---|
248 | elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then |
---|
249 | echo "You are installing a new configuration based on ${REF_CONF}" |
---|
250 | . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} |
---|
251 | fi |
---|
252 | NEW_CONF=${x_n} |
---|
253 | . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF} |
---|
254 | else |
---|
255 | sed -e "/${NEW_CONF} /d" ${CONFIG_DIR}/cfg.txt > ${COMPIL_DIR}/cfg.tmp |
---|
256 | \mv ${COMPIL_DIR}/cfg.tmp ${CONFIG_DIR}/cfg.txt |
---|
257 | fi |
---|
258 | |
---|
259 | #- |
---|
260 | #- Save new configuration and directories names --- |
---|
261 | echo ${NEW_CONF} ${TAB[*]} >> ${CONFIG_DIR}/cfg.txt |
---|
262 | |
---|
263 | #- |
---|
264 | #- Create the WORK --- |
---|
265 | #- Clean links and librairies --- |
---|
266 | #- Creating the good links, at first on OPA_SRC --- |
---|
267 | . ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${TAB[*]} || exit |
---|
268 | |
---|
269 | . ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
270 | |
---|
271 | #- At this stage new configuration has been added, |
---|
272 | #- We add or remove keys |
---|
273 | if [ ${#list_add_key} -ne 0 ] ; then |
---|
274 | . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key} |
---|
275 | fi |
---|
276 | |
---|
277 | if [ ${#list_del_key} -ne 0 ] ; then |
---|
278 | . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key} |
---|
279 | fi |
---|
280 | |
---|
281 | #- At this stage the configuration has beeen chosen |
---|
282 | #- We coose the default light file |
---|
283 | export USEBLD=bldxioxag.cfg |
---|
284 | |
---|
285 | #- We look after agrif |
---|
286 | grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/} |
---|
287 | . ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
288 | |
---|
289 | #- and test whether we need to build the ioserver |
---|
290 | grep key_iomput ${COMPIL_DIR}/cpp.fcm && export USEBLD=${USEBLD/xio/} |
---|
291 | |
---|
292 | #- |
---|
293 | #_ END OF CONFIGURATION PHASE |
---|
294 | #_ |
---|
295 | |
---|
296 | #- |
---|
297 | #- Compile --- |
---|
298 | |
---|
299 | #IO server first as a library |
---|
300 | cd $MAIN_DIR/EXTERNAL/XIOS |
---|
301 | fcm build -j 1 --ignore-lock || exit |
---|
302 | cd - |
---|
303 | |
---|
304 | |
---|
305 | |
---|
306 | if [ "${NBR_PRC}" -gt 0 ]; then |
---|
307 | cd ${NEMO_TDIR}/${NEW_CONF} || cd - |
---|
308 | |
---|
309 | #if AGRIF we do a first preprocessing |
---|
310 | if [ ${#x_c} -eq 0 ]; then |
---|
311 | [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${COMPIL_DIR}/$USEBLD |
---|
312 | [ "$AGRIFUSE" == 1 ] && rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD/* |
---|
313 | fi |
---|
314 | fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd - |
---|
315 | [ -f ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe ] && ln -sf ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe ${CONFIG_DIR}/${NEW_CONF}/EXP00/opa |
---|
316 | [ -f $MAIN_DIR/EXTERNAL/XIOS/bin/xios_server.exe ] && ln -sf $MAIN_DIR/EXTERNAL/XIOS/bin/xios_server.exe ${CONFIG_DIR}/${NEW_CONF}/EXP00/xios_server.exe |
---|
317 | |
---|
318 | #add remove for clean option |
---|
319 | if [ ${#x_c} -ne 0 ]; then |
---|
320 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK |
---|
321 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD |
---|
322 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa |
---|
323 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/server.exe |
---|
324 | echo "cleaning ${NEW_CONF} WORK, BLD" |
---|
325 | fi |
---|
326 | |
---|
327 | fi |
---|
328 | |
---|
329 | #- Come back to original directory --- |
---|
330 | cd - |
---|
331 | |
---|
332 | #- |
---|
333 | #- Unset variables |
---|
334 | ${COMPIL_DIR}/Fclean_var.sh |
---|
335 | |
---|
336 | |
---|