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