[2248] | 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) |
---|
[2301] | 48 | # - MAIN_DIR : self explaining |
---|
[2248] | 49 | # - CONFIG_DIR : " " " |
---|
| 50 | # - MODELES_DIR : " " " |
---|
| 51 | # - TOOLS_DIR : " " " |
---|
| 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 | |
---|
[3201] | 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 | |
---|
[2248] | 93 | #- Local variables --- |
---|
| 94 | b_n=$(basename ${0}) |
---|
[2359] | 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 |
---|
[2354] | 101 | # |
---|
[2359] | 102 | export CONFIG_DIR=${MAIN_DIR}/CONFIG |
---|
| 103 | export TOOLS_DIR=${MAIN_DIR}/TOOLS |
---|
| 104 | export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE |
---|
[3198] | 105 | export NEMO_DIR=${MAIN_DIR}/${x_s} |
---|
[2359] | 106 | export AGRIFUSE=10 |
---|
| 107 | declare -a TAB |
---|
[2248] | 108 | #- |
---|
| 109 | #- FCM and functions location --- |
---|
[2359] | 110 | export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH |
---|
[2248] | 111 | |
---|
| 112 | #- |
---|
| 113 | #- Choice of the options --- |
---|
[3198] | 114 | while getopts :hd:n:r:m:j:e:s:v:t: V |
---|
[2359] | 115 | do |
---|
| 116 | case $V in |
---|
[3198] | 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"; |
---|
[3201] | 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]"; |
---|
[3198] | 130 | echo " -t dir : temporary directory for compilation" |
---|
[2359] | 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 ""; |
---|
[3213] | 136 | echo "Available configurations :"; cat ${CONFIG_DIR}/cfg.txt; |
---|
[2359] | 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 ""; |
---|
[3198] | 150 | . ${COMPIL_DIR}/Flist_archfile.sh ${x_h} ; |
---|
[2359] | 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};; |
---|
[3198] | 160 | (e) x_e=${OPTARG};; |
---|
| 161 | (s) x_s=${OPTARG};; |
---|
| 162 | (v) x_v=${OPTARG};; |
---|
[2359] | 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 |
---|
[2354] | 168 | done |
---|
[2248] | 169 | shift $(($OPTIND-1)); |
---|
| 170 | |
---|
[2301] | 171 | while [ ${#1} -gt 0 ] # Get clean, clean_config options |
---|
| 172 | do |
---|
[2359] | 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 |
---|
[2301] | 198 | done |
---|
| 199 | |
---|
[2302] | 200 | |
---|
[2248] | 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} |
---|
[3219] | 214 | export NEMO_DIR=${MAIN_DIR}/${x_s} |
---|
[2248] | 215 | |
---|
| 216 | #- Check if the tool or the compiler exist or list it |
---|
| 217 | if [ "${NEW_CONF}" == help ] ; then |
---|
[2359] | 218 | echo "Available configurations :" |
---|
[3213] | 219 | cat ${CONFIG_DIR}/cfg.txt |
---|
[2359] | 220 | exit |
---|
[2248] | 221 | fi |
---|
[3198] | 222 | [ "${CMP_NAM}" == help ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit |
---|
[2248] | 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 | |
---|
[2354] | 232 | |
---|
[2248] | 233 | if [ ${#NEW_CONF} -eq 0 ] ; then |
---|
[2359] | 234 | if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then |
---|
[2354] | 235 | echo "You are installing a new configuration" |
---|
[2359] | 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 |
---|
[2354] | 243 | REF_CONF=ORCA2_LIM |
---|
[2359] | 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 |
---|
[2354] | 249 | echo "You are installing a new configuration based on ${REF_CONF}" |
---|
| 250 | . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} |
---|
[2359] | 251 | fi |
---|
| 252 | NEW_CONF=${x_n} |
---|
| 253 | . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF} |
---|
| 254 | else |
---|
[3213] | 255 | sed -e "/${NEW_CONF} /d" ${CONFIG_DIR}/cfg.txt > ${COMPIL_DIR}/cfg.tmp |
---|
| 256 | \mv ${COMPIL_DIR}/cfg.tmp ${CONFIG_DIR}/cfg.txt |
---|
[2359] | 257 | fi |
---|
[2248] | 258 | |
---|
| 259 | #- |
---|
| 260 | #- Save new configuration and directories names --- |
---|
[3213] | 261 | echo ${NEW_CONF} ${TAB[*]} >> ${CONFIG_DIR}/cfg.txt |
---|
[2248] | 262 | |
---|
| 263 | #- |
---|
| 264 | #- Create the WORK --- |
---|
| 265 | #- Clean links and librairies --- |
---|
| 266 | #- Creating the good links, at first on OPA_SRC --- |
---|
[3198] | 267 | . ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${TAB[*]} || exit |
---|
[2248] | 268 | |
---|
[2359] | 269 | . ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
[2248] | 270 | |
---|
[2302] | 271 | #- At this stage new configuration has been added, |
---|
| 272 | #- We add or remove keys |
---|
[2359] | 273 | if [ ${#list_add_key} -ne 0 ] ; then |
---|
| 274 | . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key} |
---|
| 275 | fi |
---|
[2302] | 276 | |
---|
[2359] | 277 | if [ ${#list_del_key} -ne 0 ] ; then |
---|
| 278 | . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key} |
---|
| 279 | fi |
---|
[2302] | 280 | |
---|
[2248] | 281 | #- At this stage the configuration has beeen chosen |
---|
[2731] | 282 | #- We coose the default light file |
---|
| 283 | export USEBLD=bldxioxag.cfg |
---|
| 284 | |
---|
[2248] | 285 | #- We look after agrif |
---|
[2731] | 286 | grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/} |
---|
[2359] | 287 | . ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
[2248] | 288 | |
---|
[2301] | 289 | #- and test whether we need to build the ioserver |
---|
[2731] | 290 | grep key_iomput ${COMPIL_DIR}/cpp.fcm && export USEBLD=${USEBLD/xio/} |
---|
[2301] | 291 | |
---|
[2248] | 292 | #- |
---|
| 293 | #_ END OF CONFIGURATION PHASE |
---|
| 294 | #_ |
---|
| 295 | |
---|
| 296 | #- |
---|
| 297 | #- Compile --- |
---|
| 298 | |
---|
[2359] | 299 | if [ "${NBR_PRC}" -gt 0 ]; then |
---|
| 300 | cd ${NEMO_TDIR}/${NEW_CONF} || cd - |
---|
[2437] | 301 | |
---|
| 302 | #if AGRIF we do a first preprocessing |
---|
[2359] | 303 | if [ ${#x_c} -eq 0 ]; then |
---|
[2437] | 304 | [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${COMPIL_DIR}/$USEBLD |
---|
| 305 | [ "$AGRIFUSE" == 1 ] && rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD/* |
---|
[2359] | 306 | fi |
---|
[3198] | 307 | fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd - |
---|
[2437] | 308 | [ -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 |
---|
| 309 | [ -f ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/server.exe ] && ln -sf ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/server.exe ${CONFIG_DIR}/${NEW_CONF}/EXP00/server.exe |
---|
| 310 | |
---|
| 311 | #add remove for clean option |
---|
| 312 | if [ ${#x_c} -ne 0 ]; then |
---|
| 313 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK |
---|
| 314 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD |
---|
| 315 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa |
---|
| 316 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/server.exe |
---|
| 317 | echo "cleaning ${NEW_CONF} WORK, BLD" |
---|
| 318 | fi |
---|
| 319 | |
---|
[2248] | 320 | fi |
---|
| 321 | |
---|
| 322 | #- Come back to original directory --- |
---|
| 323 | cd - |
---|
| 324 | |
---|
| 325 | #- |
---|
| 326 | #- Unset variables |
---|
| 327 | ${COMPIL_DIR}/Fclean_var.sh |
---|
| 328 | |
---|
| 329 | |
---|