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 trunk/NEMOGCM/CONFIG – NEMO

source: trunk/NEMOGCM/CONFIG/makenemo @ 4345

Last change on this file since 4345 was 3937, checked in by smasson, 11 years ago

trunk:compilation enhancements, bugfix of changeset r3922, see ticket #1117

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 9.3 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
[3764]40# - REF_CONF    : reference configuration to build the new one
41# - CMP_NAM     : compiler name
42# - NBR_PRC     : number of processes used to compile
[2248]43# - NEM_SUBDIR  : NEMO subdirectory used (specified)
44#
45#  Locally defined :
46#
[3764]47# - TAB         : NEMO subdirectory used (read)
[2301]48# - MAIN_DIR    : self explaining
[3764]49# - CONFIG_DIR  :   "    "    "
50# - MODELES_DIR :   "    "    "
51# - TOOLS_DIR   :   "    "    "
[2248]52# - NEMO_DIR    :   "    "    "
53#
54# EXAMPLES
55# ========
56#
57# ::
58#
[2252]59#  $ ./makenemo -m ifort_osx - j3 -n ORCA2_LIM
[2248]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
[3294]79#-
80#- Initialization of the options ---
81x_d="";
82x_h="";
83x_n="";
84x_r="";
85x_m="";
86x_t="";
87x_c="";
88x_j=1;
89x_e="none";
90x_s=NEMO;
91x_v=1;
92
[2248]93#- Local variables ---
94b_n=$(basename ${0})
[2359]95OPTIND=1
96MAIN_DIR=$(cd $(dirname "$0"); pwd)
97MAIN_DIR=${MAIN_DIR%/SETTE*}
98MAIN_DIR=${MAIN_DIR%/TOOLS*}
99MAIN_DIR=${MAIN_DIR%/CONFIG*}
100export MAIN_DIR
[2354]101#
[2359]102export CONFIG_DIR=${MAIN_DIR}/CONFIG
103export TOOLS_DIR=${MAIN_DIR}/TOOLS
104export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE
[3294]105export NEMO_DIR=${MAIN_DIR}/${x_s}
[2359]106export AGRIFUSE=10
107declare -a TAB
[3937]108list_key=0
109chk_key=1
[2248]110#-
111#- FCM and functions location ---
[2359]112export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH
[2248]113
114#-
115#- Choice of the options ---
[3937]116while getopts :hd:n:r:m:j:e:s:v:t:k: V
[2359]117do
118    case $V in
[3294]119   (h) x_h=${OPTARG};
120        echo "Usage   : "${b_n} \
[3937]121       " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-s Path] [-e Path] [-j No] [-v No] [-k 0/1]";
[3294]122   echo " -h           : help";
123   echo " -h institute : specific help for consortium members";
124   echo " -n name      : config name, [-n help] to list existing configurations";
125   echo " -m arch      : choose compiler, [-m help] to list existing compilers";
126   echo " -d dir       : choose NEMO sub-directories";
127   echo " -r conf      : choose reference configuration";
128        echo " -s Path      : choose alternative location for NEMO main directory";
129        echo " -e Path      : choose alternative location for MY_SRC directory";
130        echo " -j No        : number of processes used to compile (0=nocompilation)";
131        echo " -v No        : set verbosity level for compilation [0-3]";
[3937]132        echo " -k 0/1       : used cpp keys check (default = 1 -> check activated)";
[3294]133   echo " -t dir       : temporary directory for compilation"
[2359]134   echo "";
135   echo "Example to install a new configuration MY_CONFIG";
136   echo "with OPA_SRC and LIM_SRC_2 ";
137   echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\"";
138   echo "";
[3764]139   echo "Available configurations :"; cat ${CONFIG_DIR}/cfg.txt;
[2359]140   echo "";
141   echo "Example to remove bad configuration ";
142   echo "./makenemo -n MY_CONFIG clean_config";
143   echo "";
144   echo "Example to clean ";
145   echo "./makenemo clean";
146   echo "";
[3922]147   echo "Example to list the available keys of a CONFIG ";
148   echo "./makenemo list_key";
149   echo "";
[2359]150   echo "Example to add and remove keys";
151   echo "./makenemo add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" ";
152   echo "";
153   echo "Example to add and remove keys for a new configuration, and do not compile";
154   echo "./makenemo -n MY_CONFIG -j0 add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" ";
155   echo "";
[3294]156   . ${COMPIL_DIR}/Flist_archfile.sh ${x_h}  ;
[2359]157   echo "";
158   echo "Default : previous configuration and compiler";
159   exit 0;;
160   (d)  x_d=${OPTARG};;
161   (n)  x_n=${OPTARG};;
162   (r)  x_r=${OPTARG};;
163   (m)  x_m=${OPTARG};;
164   (j)  x_j=${OPTARG};;
165   (t)  x_t=${OPTARG};;
[3922]166   (e)  x_e=${OPTARG};;
167   (s)  x_s=${OPTARG};;
168   (v)  x_v=${OPTARG};;
[3937]169   (k)  chk_key=${OPTARG};;
[2359]170   (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
171   exit 2;;
172   (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
173   exit 2;;
174    esac
[2354]175done
[2248]176shift $(($OPTIND-1));
177
[2301]178while [ ${#1} -gt 0 ]   # Get clean, clean_config options
179do
[2359]180    case "$1" in
181   clean)
182       x_c="--$1"
183       ;;
184   clean_config)
185       . ${COMPIL_DIR}/Fclean_config.sh
186       exit
187       ;;
188   add_key)
189       list_add_key=$2
190       export ${list_add_key}
191       shift
192       ;;
193   del_key)
194       list_del_key=$2
195       export ${list_del_key}
196       shift
197       ;;
[3922]198   list_key)
199       list_key=1
200       ;;
[2359]201   *)
[3764]202       echo " \"$1\" BAD OPTION"
[2359]203       exit
204       ;;
[3764]205
[2359]206    esac
207    shift
[2301]208done
209
[2302]210
[2248]211#-
212#- Go to NEMOGCM/config directory ---
213cd ${CONFIG_DIR}
214
215#-
216#- Initialisation from input ---
217export NEW_CONF=${x_n}
218NBR_PRC=${x_j}
219CMP_NAM=${x_m}
220NEM_SUBDIR=${x_d}
221REF_CONF=${x_r}
222NEMO_TDIR=${x_t:-$NEMO_TDIR}
223export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR}
[3294]224export NEMO_DIR=${MAIN_DIR}/${x_s}
[2248]225
226#- Check if the tool or the compiler exist or list it
227if [ "${NEW_CONF}" == help ] ; then
[3764]228    echo "Available configurations :"
[3294]229    cat ${CONFIG_DIR}/cfg.txt
[2359]230    exit
[2248]231fi
[3294]232[ "${CMP_NAM}" ==  help ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit
[2248]233
234#-
235#- Choose a default configuration if needed ---
236#- ORCA2_LIM or last one used ---
[3764]237. ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit
[2248]238
239if [ ${#NEW_CONF} -eq 0 ] ; then
[2359]240    if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then
[2354]241   echo "You are  installing a new configuration"
[2359]242   ind=0
[3764]243   . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC    YES
244   . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2   YES
245   . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3   NO
246   . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC    NO
247   . ${COMPIL_DIR}/Fread_dir.sh NST_SRC    YES
248   . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC    NO
[2354]249   REF_CONF=ORCA2_LIM
[2359]250    elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then
251   echo "You are  installing a new configuration"
252   TAB=( ${NEM_SUBDIR} )
253   REF_CONF=ORCA2_LIM
254    elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then
[2354]255   echo "You are  installing a new configuration based on ${REF_CONF}"
[3764]256   . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF}
[2359]257    fi
258    NEW_CONF=${x_n}
259    . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF}
260else
[3294]261    sed -e "/${NEW_CONF} /d"  ${CONFIG_DIR}/cfg.txt >  ${COMPIL_DIR}/cfg.tmp
262    \m${COMPIL_DIR}/cfg.tmp  ${CONFIG_DIR}/cfg.txt
[2359]263fi
[2248]264
265#-
266#- Save new configuration and directories names ---
[3294]267echo ${NEW_CONF} ${TAB[*]} >> ${CONFIG_DIR}/cfg.txt
[2248]268
269#-
270#- Create the WORK ---
271#- Clean links and librairies ---
272#- Creating the good links, at first on OPA_SRC ---
[3294]273. ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${TAB[*]} || exit
[2248]274
[2359]275. ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF}  ${NEMO_TDIR} || exit
[2248]276
[3922]277# build the complete list of the cpp keys of this configuration
[3937]278if [ $chk_key -eq 1 ] ; then
279    for i in $( grep "^ *#.* key_" ${NEW_CONF}/WORK/* ) 
280    do
281   echo $i | grep key_ | sed -e "s/=.*//"
282    done | sort -d | uniq > ${COMPIL_DIR}/full_key_list.txt
283    if [ $list_key -eq 1 ]; then
284   cat ${COMPIL_DIR}/full_key_list.txt
285   exit 0
286    fi
[3922]287fi
288
[2302]289#- At this stage new configuration has been added,
290#- We add or remove keys
[2359]291if [ ${#list_add_key} -ne 0 ] ; then
[3764]292    . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key}
[2359]293fi
[2302]294
[2359]295if [ ${#list_del_key} -ne 0 ] ; then
296    . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key}
297fi
[2302]298
[3937]299#- check that all keys are really existing...
300if [ $chk_key -eq 1 ] ; then
301    for kk in $( cat ${NEW_CONF}/cpp_${NEW_CONF}.fcm )
302    do
303   if [ "$( echo $kk | cut -c 1-4 )" == "key_" ]; then
304       kk=${kk/=*/}
305       nb=$( grep -c $kk ${COMPIL_DIR}/full_key_list.txt )
306       if [ $nb -eq 0 ]; then
307      echo
308      echo "E R R O R : key "$kk" is not found in ${NEW_CONF}/WORK routines..."
309      echo "we stop..."
310      echo
311      exit 1
312       fi
[3922]313   fi
[3937]314    done
315fi
[3922]316
317#- At this stage cpp keys have been updated. we can check the arch file
318#- When used for the first time, choose a compiler ---
319. ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm cpp.fcm ${CMP_NAM} || exit
320
[2248]321#- At this stage the configuration has beeen chosen
[2731]322#- We coose the default light file
[3695]323export USEBLD=bldxag.cfg
[2731]324
[2248]325#- We look after agrif
[2731]326grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/}
[2359]327. ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit
[2248]328
329#-
330#_ END OF CONFIGURATION PHASE
331#_
332
333#-
334#- Compile ---
335
[2359]336if [ "${NBR_PRC}" -gt 0 ]; then
337    cd ${NEMO_TDIR}/${NEW_CONF} || cd -
[2437]338
339#if AGRIF we do a first preprocessing
[2359]340    if [ ${#x_c} -eq 0 ]; then
[3680]341       if [ "$AGRIFUSE" == 1 ]; then
342          fcm build --ignore-lock  -j 1 ${COMPIL_DIR}/bld_preproagr.cfg ||{ cd - ; exit ;}
343          echo ""
344          echo "---------------------------------"
345          echo "CONV preprocessing successfull !!"
346          echo "---------------------------------"
347          echo ""
348       fi
[2359]349    fi
[3294]350    fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd -
[2437]351    [ -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
352
353#add remove for clean option
354    if  [ ${#x_c} -ne 0 ]; then
[3680]355        rm -rf ${NEMO_TDIR}/${NEW_CONF}/OPAFILES
[2437]356        rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK
357        rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD
358        rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa
[3937]359        rm -f ${COMPIL_DIR}/*history ${COMPIL_DIR}/*fcm ${COMPIL_DIR}/*txt
[2437]360        echo "cleaning ${NEW_CONF} WORK, BLD"
361    fi
362
[2248]363fi
364
365#- Come back to original directory ---
366cd -
367
368#-
369#- Unset variables
370${COMPIL_DIR}/Fclean_var.sh
371
372
Note: See TracBrowser for help on using the repository browser.