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 from |
---|
41 | # - CMP_NAM : compiler name |
---|
42 | # - NBR_PRC : number of processes used to compile |
---|
43 | # - RMT_CONF : unsupported (external) configuration to build the new one from |
---|
44 | # - NEM_SUBDIR : NEMO subdirectory used (specified) |
---|
45 | # |
---|
46 | # Locally defined : |
---|
47 | # |
---|
48 | # - TAB : NEMO subdirectory used (read) |
---|
49 | # - MAIN_DIR : self explaining |
---|
50 | # - CONFIG_DIR : " " " |
---|
51 | # - MODELES_DIR : " " " |
---|
52 | # - TOOLS_DIR : " " " |
---|
53 | # - NEMO_DIR : " " " |
---|
54 | # - REMOTE_CTL : URL link to a remote resource list for an external configuration |
---|
55 | # which is not part of the reference suite |
---|
56 | # - LOCAL_REF : Nearest reference configuration to an external configuration |
---|
57 | # which is not part of the reference suite |
---|
58 | # (used to populate work directories if remote access is not available) |
---|
59 | # |
---|
60 | # EXAMPLES |
---|
61 | # ======== |
---|
62 | # |
---|
63 | # :: |
---|
64 | # |
---|
65 | # $ ./makenemo -m ifort_osx - j3 -n ORCA2_SI3_PISCES |
---|
66 | # |
---|
67 | # |
---|
68 | # TODO |
---|
69 | # ==== |
---|
70 | # |
---|
71 | # option debug |
---|
72 | # |
---|
73 | # |
---|
74 | # EVOLUTIONS |
---|
75 | # ========== |
---|
76 | # |
---|
77 | # $Id$ |
---|
78 | # |
---|
79 | # |
---|
80 | # |
---|
81 | # * creation |
---|
82 | # |
---|
83 | #- |
---|
84 | |
---|
85 | #- |
---|
86 | ##- Initialization of the options --- |
---|
87 | x_d=''; x_h=''; x_n=''; x_r=''; |
---|
88 | x_u=''; x_a=''; x_m=''; x_t=''; |
---|
89 | x_c=''; |
---|
90 | x_j='1'; x_e='none'; x_s='src'; x_v='1' |
---|
91 | |
---|
92 | ##- Local variables --- |
---|
93 | b_n=$(basename ${0}) |
---|
94 | OPTIND='1' |
---|
95 | MAIN_DIR=$(cd $(dirname "$0"); pwd) |
---|
96 | MAIN_DIR=${MAIN_DIR%/sette*} |
---|
97 | MAIN_DIR=${MAIN_DIR%/tools*} |
---|
98 | MAIN_DIR=${MAIN_DIR%/cfgs*} |
---|
99 | export MAIN_DIR |
---|
100 | # |
---|
101 | export CONFIG_DIR=${MAIN_DIR}/cfgs |
---|
102 | export TOOLS_DIR=${MAIN_DIR}/tools |
---|
103 | export COMPIL_DIR=${MAIN_DIR}/mk |
---|
104 | export NEMO_DIR=${MAIN_DIR}/${x_s} |
---|
105 | export AGRIFUSE='10' |
---|
106 | list_key='0'; chk_key='1' |
---|
107 | list_add_key=''; list_del_key=''; |
---|
108 | conf_file=ref_cfgs.txt |
---|
109 | #- |
---|
110 | #- FCM and functions location --- |
---|
111 | export PATH=${MAIN_DIR}/ext/FCM/bin:$PATH |
---|
112 | |
---|
113 | #- |
---|
114 | #- Choice of the options --- |
---|
115 | while getopts :hd:n:r:u:a:m:j:e:s:v:t:k: option; do |
---|
116 | |
---|
117 | case $option in |
---|
118 | ('h') cat <<EOF |
---|
119 | Usage: |
---|
120 | ------ |
---|
121 | ./makenemo -[adru] ... -m ... [-h] [-[dejntv] ...] [{list_key,clean,clean_config}] [{add_key,del_key} ...] |
---|
122 | |
---|
123 | The previous build is reused by default if no given options |
---|
124 | |
---|
125 | Mandatory: 'all' to list available arguments by option |
---|
126 | -a Demonstration case (./tests) |
---|
127 | -m Computing architecture (./arch) |
---|
128 | -r Reference configuration (./cfgs) |
---|
129 | -u Scripted remote configuration (./tests/rmt_cfgs.txt) |
---|
130 | |
---|
131 | Optional: |
---|
132 | -d Set of new sub-components (space separated list from ./src directory) |
---|
133 | -e Path for alternative patch location (default: 'MY_SRC' in configuration folder) |
---|
134 | -j Number of processes to compile (0: no build) |
---|
135 | -n Name for new configuration |
---|
136 | -s Path for alternative source location (default: 'src' root directory) |
---|
137 | -t Path for alternative build location (default: 'BLD' in configuration folder) |
---|
138 | -v Level of verbosity ([0-3]) |
---|
139 | |
---|
140 | Examples: |
---|
141 | ¤ Configuration build |
---|
142 | Creation : ./makenemo -[adru] ... -m ... [...] |
---|
143 | Duplication : ./makenemo -r ... -n ... [...] |
---|
144 | ¤ Configuration management |
---|
145 | List CPP keys : ./makenemo [...] list_key |
---|
146 | Add-Remove keys: ./makenemo [...] add_key '...' del_key '...' |
---|
147 | Fresh start : ./makenemo [...] clean |
---|
148 | Erasure : ./makenemo [...] clean_config |
---|
149 | |
---|
150 | EOF |
---|
151 | exit 0 ;; |
---|
152 | ('d') x_d=${OPTARG};; ('n') x_n=${OPTARG};; ('r') x_r=${OPTARG};; ('u') x_u=${OPTARG};; |
---|
153 | ('a') x_a=${OPTARG};; ('m') x_m=${OPTARG};; ('j') x_j=${OPTARG};; ('t') x_t=${OPTARG};; |
---|
154 | ('e') x_e=${OPTARG};; ('s') x_s=${OPTARG};; ('v') x_v=${OPTARG} ;; |
---|
155 | ('k') chk_key=${OPTARG} ;; |
---|
156 | (':') echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; exit 2 ;; |
---|
157 | ('?') echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; exit 2 ;; |
---|
158 | esac |
---|
159 | |
---|
160 | done |
---|
161 | |
---|
162 | shift $(($OPTIND-1)); |
---|
163 | |
---|
164 | ## Get clean, clean_config options |
---|
165 | while [ ${#1} -gt 0 ]; do |
---|
166 | |
---|
167 | case "$1" in |
---|
168 | 'clean' ) x_c="--$1" ;; |
---|
169 | 'clean_config') . ${COMPIL_DIR}/Fclean_config.sh; exit ;; |
---|
170 | ## Checking if argument has anything other than whitespace |
---|
171 | 'add_key' ) [[ ! "$2" =~ ^\ +$ ]] && list_add_key=$2; shift;; |
---|
172 | 'del_key' ) [[ ! "$2" =~ ^\ +$ ]] && list_del_key=$2; shift;; |
---|
173 | 'list_key' ) list_key='1' ;; |
---|
174 | '*' ) echo " \"$1\" BAD OPTION"; exit 2 ;; |
---|
175 | esac |
---|
176 | |
---|
177 | shift |
---|
178 | done |
---|
179 | |
---|
180 | |
---|
181 | export NEW_CONF=${x_n} |
---|
182 | NBR_PRC=${x_j} |
---|
183 | CMP_NAM=${x_m} |
---|
184 | NEM_SUBDIR=${x_d} |
---|
185 | REF_CONF=${x_r} |
---|
186 | DEMO_CONF=${x_a} |
---|
187 | RMT_CONF=${x_u} |
---|
188 | TML_CONF=${REF_CONF} |
---|
189 | export NEMO_DIR=${MAIN_DIR}/${x_s} |
---|
190 | |
---|
191 | [ "${CMP_NAM}" == 'all' ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit |
---|
192 | |
---|
193 | |
---|
194 | ## No ref. cfg, demo case, nor remote cfg selected |
---|
195 | if [[ -z "${REF_CONF}" && -z "${DEMO_CONF}" && -z "${RMT_CONF}" ]]; then |
---|
196 | |
---|
197 | ## Reuse last configuration compiled if any (existing 'work_cfgs.txt') |
---|
198 | if [[ $( find ./cfgs ./tests -name work_cfgs.txt ) ]]; then |
---|
199 | CONFIG_DIR=${MAIN_DIR}/$( ls -rt */work_cfgs.txt | awk -F/ 'END{ print $1}' ) |
---|
200 | TML_CONF=$( tail -1 ${CONFIG_DIR}/work_cfgs.txt | awk '{ print $1 }' ) |
---|
201 | else |
---|
202 | ## No ${REF_CONF}, ${DEMO_CONF}, ${RMT_CONF} nor ${NEM_SUBDIR} and 1st compilation => exit |
---|
203 | echo -e "\033[0;33m\nNo previous build found!" |
---|
204 | echo -e "\033[0;31m\nAt least a reference configuration ('-r'), a demonstration case ('-a'), " |
---|
205 | echo -e "a remote configuration ('-u') or a set of NEMO sub-components ('-d') " |
---|
206 | echo -e "has to be choose!!!\033[0m" |
---|
207 | ${COMPIL_DIR}/Flist_cfgs.sh |
---|
208 | exit 2 |
---|
209 | fi |
---|
210 | |
---|
211 | ## At least one config has been requested |
---|
212 | else |
---|
213 | |
---|
214 | ## Argument 'all': list all available configurations |
---|
215 | if [[ "${REF_CONF}" == 'all' || "${DEMO_CONF}" == 'all' || "${RMT_CONF}" == 'all' ]]; then |
---|
216 | ${COMPIL_DIR}/Flist_cfgs.sh |
---|
217 | exit 2 |
---|
218 | elif [[ -n "${REF_CONF}" && -n "${DEMO_CONF}" ]]; then |
---|
219 | echo -e "\033[0;31m\nYou have to choose whether you work with:" |
---|
220 | echo -e " - Supported reference configurations in ./cfgs ('-r') or" |
---|
221 | echo -e " - Unsupported demonstration cases in ./tests ('-a')\033[0m\n" |
---|
222 | exit 2 |
---|
223 | fi |
---|
224 | |
---|
225 | ## Remote cfg |
---|
226 | if [ -n "${RMT_CONF}" ]; then |
---|
227 | conf_file=rmt_cfgs.txt; CONFIG_DIR=${MAIN_DIR}/tests; |
---|
228 | |
---|
229 | if [[ ! $( grep ${RMT_CONF} ${CONFIG_DIR}/${conf_file} ) ]]; then |
---|
230 | echo -e "\033[0;31m\nThe reference configuration ('-r'), demonstration case ('-a') or " |
---|
231 | echo -e "remote configuration ('-u') selected is not available!!!" |
---|
232 | echo -e "Check if you use the good option and the available items in txt files\033[0m" |
---|
233 | ${COMPIL_DIR}/Flist_cfgs.sh |
---|
234 | exit 2 |
---|
235 | fi |
---|
236 | |
---|
237 | ## Little tricky this one |
---|
238 | for word in $( grep ${RMT_CONF} ${CONFIG_DIR}/${conf_file} ); do |
---|
239 | words[${#words[@]}]=$word |
---|
240 | done |
---|
241 | |
---|
242 | TML_CONF=${words[2]}; NEM_SUBDIR=${words[4]}; URL=${words[6]} |
---|
243 | |
---|
244 | ## Demo case |
---|
245 | elif [ -n "${DEMO_CONF}" ]; then |
---|
246 | conf_file=demo_cfgs.txt; CONFIG_DIR=${MAIN_DIR}/tests; TML_CONF=${DEMO_CONF} |
---|
247 | fi |
---|
248 | |
---|
249 | fi |
---|
250 | |
---|
251 | ## Test if ref. cfg or demo case does exist |
---|
252 | if [[ ! $( grep "${TML_CONF} " ${CONFIG_DIR}/*_cfgs.txt ) ]]; then |
---|
253 | echo -e "\033[0;31m\nThe reference configuration ('-r'), demonstration case ('-a') or " |
---|
254 | echo -e "remote configuration ('-u') selected is not available!!!" |
---|
255 | echo -e "Check if you use the good option and the available items in txt files\033[0m" |
---|
256 | ${COMPIL_DIR}/Flist_cfgs.sh |
---|
257 | exit 2 |
---|
258 | |
---|
259 | else |
---|
260 | |
---|
261 | if [[ -f ${CONFIG_DIR}/work_cfgs.txt && $( grep "${TML_CONF} " ${CONFIG_DIR}/work_cfgs.txt ) ]]; then |
---|
262 | conf_file=work_cfgs.txt |
---|
263 | fi |
---|
264 | |
---|
265 | [ -z "${NEW_CONF}" ] && NEW_CONF=${TML_CONF} |
---|
266 | |
---|
267 | ## Update sub-comps if needed |
---|
268 | if [ -z "${NEM_SUBDIR}" ]; then |
---|
269 | NEM_SUBDIR=$( grep "${TML_CONF} " ${CONFIG_DIR}/${conf_file} | awk '{$1 = ""; print $0}' ) |
---|
270 | fi |
---|
271 | |
---|
272 | fi |
---|
273 | |
---|
274 | export NEMO_TDIR=${x_t:-$CONFIG_DIR} |
---|
275 | |
---|
276 | ## Save new configuration with sub-components set in work_cfgs.txt |
---|
277 | [ -f ${CONFIG_DIR}/work_cfgs.txt ] && sed -i "/${NEW_CONF} /d" ${CONFIG_DIR}/work_cfgs.txt |
---|
278 | echo ${NEW_CONF} "${NEM_SUBDIR}" \ |
---|
279 | >> ${CONFIG_DIR}/work_cfgs.txt |
---|
280 | |
---|
281 | cd ${CONFIG_DIR} |
---|
282 | |
---|
283 | printf "\nYou are installing a new configuration %s from %s " ${NEW_CONF} ${TML_CONF} |
---|
284 | printf "with sub-components: %s\n" "${NEM_SUBDIR}" |
---|
285 | |
---|
286 | ## Build a copy of a tmp cfg |
---|
287 | [ ! -d ${NEW_CONF} ] && ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${TML_CONF} |
---|
288 | |
---|
289 | ## Get online script file for remote cfg |
---|
290 | [ -n "${RMT_CONF}" ] && ${COMPIL_DIR}/Ffetch_extdir.sh ${NEW_CONF} $URL |
---|
291 | |
---|
292 | #- Create the WORK --- |
---|
293 | #- Clean links and librairies --- |
---|
294 | #- Creating the good links, at first on OCE --- |
---|
295 | . ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${NEM_SUBDIR} || exit 3 |
---|
296 | |
---|
297 | . ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF} ${NEMO_TDIR} || exit 3 |
---|
298 | |
---|
299 | # build the complete list of the cpp keys of this configuration |
---|
300 | if [ ${chk_key} -eq 1 ] ; then |
---|
301 | |
---|
302 | for i in $( grep "^ *#.* key_" ${NEW_CONF}/WORK/* ); do |
---|
303 | echo $i | grep key_ | sed -e "s/=.*//" |
---|
304 | done \ |
---|
305 | | sort -d | uniq > ${COMPIL_DIR}/full_key_list.txt |
---|
306 | |
---|
307 | [ ${list_key} -eq 1 ] && cat ${COMPIL_DIR}/full_key_list.txt && exit 0 |
---|
308 | |
---|
309 | fi |
---|
310 | |
---|
311 | #- At this stage new configuration has been added, we add or remove keys |
---|
312 | [ ! -z "${list_add_key}" ] && { . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key}; } |
---|
313 | [ ! -z "${list_del_key}" ] && { . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key}; } |
---|
314 | |
---|
315 | #- check that all keys are really existing... |
---|
316 | if [ $chk_key -eq 1 ] ; then |
---|
317 | |
---|
318 | for kk in $( cat ${NEW_CONF}/cpp_${NEW_CONF}.fcm ); do |
---|
319 | |
---|
320 | if [ "$( echo $kk | cut -c 1-4 )" == "key_" ]; then |
---|
321 | kk=${kk/=*/} |
---|
322 | |
---|
323 | if [ ! $( grep $kk ${COMPIL_DIR}/full_key_list.txt ) ]; then |
---|
324 | echo |
---|
325 | echo "E R R O R : key "$kk" is not found in ${NEW_CONF}/WORK routines..." |
---|
326 | echo "we stop..." |
---|
327 | echo |
---|
328 | exit 1 |
---|
329 | fi |
---|
330 | |
---|
331 | fi |
---|
332 | |
---|
333 | done |
---|
334 | |
---|
335 | fi |
---|
336 | |
---|
337 | #- At this stage cpp keys have been updated. we can check the arch file |
---|
338 | #- When used for the first time, choose a compiler --- |
---|
339 | . ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm cpp.fcm ${CMP_NAM} || exit 3 |
---|
340 | |
---|
341 | #- At this stage the configuration has beeen chosen |
---|
342 | #- We coose the default light file |
---|
343 | export USEBLD=bldxag.cfg |
---|
344 | |
---|
345 | #- We look after agrif |
---|
346 | grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/} |
---|
347 | . ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit 3 |
---|
348 | |
---|
349 | #- |
---|
350 | #_ END OF CONFIGURATION PHASE |
---|
351 | #_ |
---|
352 | |
---|
353 | #- |
---|
354 | #- Compile --- |
---|
355 | |
---|
356 | if [ "${NBR_PRC}" -gt 0 ]; then |
---|
357 | cd ${NEMO_TDIR}/${NEW_CONF} || cd - |
---|
358 | |
---|
359 | ## if AGRIF we do a first preprocessing |
---|
360 | if [[ ${#x_c} -eq 0 && "$AGRIFUSE" -eq 1 ]]; then |
---|
361 | fcm build --ignore-lock -j 1 ${COMPIL_DIR}/bld_preproagr.cfg ||{ cd - ; exit 1 ;} |
---|
362 | echo '' |
---|
363 | echo "---------------------------------" |
---|
364 | echo "CONV preprocessing successfull !!" |
---|
365 | echo "---------------------------------" |
---|
366 | echo '' |
---|
367 | fi |
---|
368 | |
---|
369 | fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD ||{ cd - ; exit 1 ;} |
---|
370 | |
---|
371 | if [ -f ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe ]; then |
---|
372 | ln -sf ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe ${CONFIG_DIR}/${NEW_CONF}/EXP00/nemo |
---|
373 | fi |
---|
374 | |
---|
375 | ## add remove for clean option |
---|
376 | if [ ${#x_c} -ne 0 ]; then |
---|
377 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/NEMOFILES |
---|
378 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK |
---|
379 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD |
---|
380 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/nemo |
---|
381 | rm -f ${COMPIL_DIR}/*history ${COMPIL_DIR}/*fcm ${COMPIL_DIR}/*txt |
---|
382 | echo "cleaning ${NEW_CONF} WORK, BLD" |
---|
383 | fi |
---|
384 | |
---|
385 | fi |
---|
386 | |
---|
387 | #- Come back to original directory --- |
---|
388 | cd - |
---|
389 | |
---|
390 | #- |
---|
391 | #- Unset variables |
---|
392 | ${COMPIL_DIR}/Fclean_var.sh |
---|