New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
makenemo in utils/build – NEMO

source: utils/build/makenemo @ 12489

Last change on this file since 12489 was 12415, checked in by smueller, 4 years ago

Reintegration of 2019 development branch /utils/build_MERGE_2019 into the build directory (/utils/build)

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