[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 | |
---|
| 79 | #- Local variables --- |
---|
| 80 | b_n=$(basename ${0}) |
---|
[2359] | 81 | OPTIND=1 |
---|
| 82 | MAIN_DIR=$(cd $(dirname "$0"); pwd) |
---|
| 83 | MAIN_DIR=${MAIN_DIR%/SETTE*} |
---|
| 84 | MAIN_DIR=${MAIN_DIR%/TOOLS*} |
---|
| 85 | MAIN_DIR=${MAIN_DIR%/CONFIG*} |
---|
| 86 | export MAIN_DIR |
---|
[2354] | 87 | # |
---|
[2359] | 88 | export CONFIG_DIR=${MAIN_DIR}/CONFIG |
---|
| 89 | export TOOLS_DIR=${MAIN_DIR}/TOOLS |
---|
| 90 | export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE |
---|
| 91 | export NEMO_DIR=${MAIN_DIR}/NEMO |
---|
| 92 | export AGRIFUSE=10 |
---|
[2263] | 93 | |
---|
[2359] | 94 | declare -a TAB |
---|
[2248] | 95 | #- |
---|
| 96 | #- FCM and functions location --- |
---|
[2359] | 97 | export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH |
---|
[2248] | 98 | |
---|
| 99 | #- |
---|
| 100 | #- Choice of the options --- |
---|
[2359] | 101 | x_d=""; |
---|
[3173] | 102 | x_h=""; |
---|
[2359] | 103 | x_n=""; |
---|
| 104 | x_r=""; |
---|
| 105 | x_m=""; |
---|
| 106 | x_t=""; |
---|
| 107 | x_c=""; |
---|
| 108 | x_j=1; |
---|
| 109 | while getopts :hd:n:r:m:j:t: V |
---|
| 110 | do |
---|
| 111 | case $V in |
---|
[3173] | 112 | (h) x_h=${OPTARG}; |
---|
| 113 | echo "Usage : "${b_n} \ |
---|
[2359] | 114 | " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-j No]"; |
---|
[3173] | 115 | echo " -h : help"; |
---|
| 116 | echo " -h institute : specific help for consortium members"; |
---|
| 117 | echo " -n name : config name, [-n help] to list existing configurations"; |
---|
| 118 | echo " -m arch : choose compiler, [-m help] to list existing compilers"; |
---|
| 119 | echo " -d dir : choose NEMO sub-directories"; |
---|
| 120 | echo " -r conf : choose reference configuration"; |
---|
| 121 | echo " -j No : number of processes used to compile (0=nocompilation)"; |
---|
| 122 | echo " -t dir : temporary directory for compilation" |
---|
[2359] | 123 | echo ""; |
---|
| 124 | echo "Example to install a new configuration MY_CONFIG"; |
---|
| 125 | echo "with OPA_SRC and LIM_SRC_2 "; |
---|
| 126 | echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\""; |
---|
| 127 | echo ""; |
---|
| 128 | echo "Available configurations :"; cat ${COMPIL_DIR}/cfg.txt; |
---|
| 129 | echo ""; |
---|
| 130 | echo "Example to remove bad configuration "; |
---|
| 131 | echo "./makenemo -n MY_CONFIG clean_config"; |
---|
| 132 | echo ""; |
---|
| 133 | echo "Example to clean "; |
---|
| 134 | echo "./makenemo clean"; |
---|
| 135 | echo ""; |
---|
| 136 | echo "Example to add and remove keys"; |
---|
| 137 | echo "./makenemo add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" "; |
---|
| 138 | echo ""; |
---|
| 139 | echo "Example to add and remove keys for a new configuration, and do not compile"; |
---|
| 140 | echo "./makenemo -n MY_CONFIG -j0 add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" "; |
---|
| 141 | echo ""; |
---|
[3173] | 142 | . ${COMPIL_DIR}/Flist_archfile.sh ${x_h} ; |
---|
[2359] | 143 | echo ""; |
---|
| 144 | echo "Default : previous configuration and compiler"; |
---|
| 145 | exit 0;; |
---|
| 146 | (d) x_d=${OPTARG};; |
---|
| 147 | (n) x_n=${OPTARG};; |
---|
| 148 | (r) x_r=${OPTARG};; |
---|
| 149 | (m) x_m=${OPTARG};; |
---|
| 150 | (j) x_j=${OPTARG};; |
---|
| 151 | (t) x_t=${OPTARG};; |
---|
| 152 | (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; |
---|
| 153 | exit 2;; |
---|
| 154 | (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; |
---|
| 155 | exit 2;; |
---|
| 156 | esac |
---|
[2354] | 157 | done |
---|
[2248] | 158 | shift $(($OPTIND-1)); |
---|
| 159 | |
---|
[2301] | 160 | while [ ${#1} -gt 0 ] # Get clean, clean_config options |
---|
| 161 | do |
---|
[2359] | 162 | case "$1" in |
---|
| 163 | clean) |
---|
| 164 | x_c="--$1" |
---|
| 165 | ;; |
---|
| 166 | clean_config) |
---|
| 167 | . ${COMPIL_DIR}/Fclean_config.sh |
---|
| 168 | exit |
---|
| 169 | ;; |
---|
| 170 | add_key) |
---|
| 171 | list_add_key=$2 |
---|
| 172 | export ${list_add_key} |
---|
| 173 | shift |
---|
| 174 | ;; |
---|
| 175 | del_key) |
---|
| 176 | list_del_key=$2 |
---|
| 177 | export ${list_del_key} |
---|
| 178 | shift |
---|
| 179 | ;; |
---|
| 180 | *) |
---|
| 181 | echo " \"$1\" BAD OPTION" |
---|
| 182 | exit |
---|
| 183 | ;; |
---|
| 184 | |
---|
| 185 | esac |
---|
| 186 | shift |
---|
[2301] | 187 | done |
---|
| 188 | |
---|
[2302] | 189 | |
---|
[2248] | 190 | #- |
---|
| 191 | #- Go to NEMOGCM/config directory --- |
---|
| 192 | cd ${CONFIG_DIR} |
---|
| 193 | |
---|
| 194 | #- |
---|
| 195 | #- Initialisation from input --- |
---|
| 196 | export NEW_CONF=${x_n} |
---|
| 197 | NBR_PRC=${x_j} |
---|
| 198 | CMP_NAM=${x_m} |
---|
| 199 | NEM_SUBDIR=${x_d} |
---|
| 200 | REF_CONF=${x_r} |
---|
| 201 | NEMO_TDIR=${x_t:-$NEMO_TDIR} |
---|
| 202 | export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR} |
---|
| 203 | |
---|
| 204 | #- Check if the tool or the compiler exist or list it |
---|
| 205 | if [ "${NEW_CONF}" == help ] ; then |
---|
[2359] | 206 | echo "Available configurations :" |
---|
| 207 | cat ${COMPIL_DIR}/cfg.txt |
---|
| 208 | exit |
---|
[2248] | 209 | fi |
---|
[3173] | 210 | [ "${CMP_NAM}" == help ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit |
---|
[2248] | 211 | |
---|
| 212 | #- When used for the first time, choose a compiler --- |
---|
| 213 | . ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm ${CMP_NAM} || exit |
---|
| 214 | |
---|
| 215 | #- |
---|
| 216 | #- Choose a default configuration if needed --- |
---|
| 217 | #- ORCA2_LIM or last one used --- |
---|
| 218 | . ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit |
---|
| 219 | |
---|
[2354] | 220 | |
---|
[2248] | 221 | if [ ${#NEW_CONF} -eq 0 ] ; then |
---|
[2359] | 222 | if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then |
---|
[2354] | 223 | echo "You are installing a new configuration" |
---|
[2359] | 224 | ind=0 |
---|
| 225 | . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC YES |
---|
| 226 | . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2 YES |
---|
| 227 | . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3 NO |
---|
| 228 | . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC NO |
---|
| 229 | . ${COMPIL_DIR}/Fread_dir.sh NST_SRC YES |
---|
| 230 | . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC NO |
---|
[2354] | 231 | REF_CONF=ORCA2_LIM |
---|
[2359] | 232 | elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then |
---|
| 233 | echo "You are installing a new configuration" |
---|
| 234 | TAB=( ${NEM_SUBDIR} ) |
---|
| 235 | REF_CONF=ORCA2_LIM |
---|
| 236 | elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then |
---|
[2354] | 237 | echo "You are installing a new configuration based on ${REF_CONF}" |
---|
| 238 | . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} |
---|
[2359] | 239 | fi |
---|
| 240 | NEW_CONF=${x_n} |
---|
| 241 | . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF} |
---|
| 242 | else |
---|
| 243 | sed -e "/${NEW_CONF} /d" ${COMPIL_DIR}/cfg.txt > ${COMPIL_DIR}/cfg.tmp |
---|
| 244 | \mv ${COMPIL_DIR}/cfg.tmp ${COMPIL_DIR}/cfg.txt |
---|
| 245 | fi |
---|
[2248] | 246 | |
---|
| 247 | #- |
---|
| 248 | #- Save new configuration and directories names --- |
---|
[2359] | 249 | echo ${NEW_CONF} ${TAB[*]} >> ${COMPIL_DIR}/cfg.txt |
---|
[2248] | 250 | |
---|
| 251 | #- |
---|
| 252 | #- Create the WORK --- |
---|
| 253 | #- Clean links and librairies --- |
---|
| 254 | #- Creating the good links, at first on OPA_SRC --- |
---|
[2359] | 255 | . ${COMPIL_DIR}/Fmake_WORK.sh ${NEW_CONF} ${TAB[*]} || exit |
---|
[2248] | 256 | |
---|
[2359] | 257 | . ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
[2248] | 258 | |
---|
[2302] | 259 | #- At this stage new configuration has been added, |
---|
| 260 | #- We add or remove keys |
---|
[2359] | 261 | if [ ${#list_add_key} -ne 0 ] ; then |
---|
| 262 | . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key} |
---|
| 263 | fi |
---|
[2302] | 264 | |
---|
[2359] | 265 | if [ ${#list_del_key} -ne 0 ] ; then |
---|
| 266 | . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key} |
---|
| 267 | fi |
---|
[2302] | 268 | |
---|
[2248] | 269 | #- At this stage the configuration has beeen chosen |
---|
[2731] | 270 | #- We coose the default light file |
---|
| 271 | export USEBLD=bldxioxag.cfg |
---|
| 272 | |
---|
[2248] | 273 | #- We look after agrif |
---|
[2731] | 274 | grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/} |
---|
[2359] | 275 | . ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
[2248] | 276 | |
---|
[2301] | 277 | #- and test whether we need to build the ioserver |
---|
[2731] | 278 | grep key_iomput ${COMPIL_DIR}/cpp.fcm && export USEBLD=${USEBLD/xio/} |
---|
[2301] | 279 | |
---|
[2248] | 280 | #- |
---|
| 281 | #_ END OF CONFIGURATION PHASE |
---|
| 282 | #_ |
---|
| 283 | |
---|
| 284 | #- |
---|
| 285 | #- Compile --- |
---|
| 286 | |
---|
[2359] | 287 | if [ "${NBR_PRC}" -gt 0 ]; then |
---|
| 288 | cd ${NEMO_TDIR}/${NEW_CONF} || cd - |
---|
[2437] | 289 | |
---|
| 290 | #if AGRIF we do a first preprocessing |
---|
[2359] | 291 | if [ ${#x_c} -eq 0 ]; then |
---|
[2437] | 292 | [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${COMPIL_DIR}/$USEBLD |
---|
| 293 | [ "$AGRIFUSE" == 1 ] && rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD/* |
---|
[2359] | 294 | fi |
---|
[2437] | 295 | fcm build ${x_c} --ignore-lock -v 1 -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd - |
---|
| 296 | [ -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 |
---|
| 297 | [ -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 |
---|
| 298 | |
---|
| 299 | #add remove for clean option |
---|
| 300 | if [ ${#x_c} -ne 0 ]; then |
---|
| 301 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK |
---|
| 302 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD |
---|
| 303 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa |
---|
| 304 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/server.exe |
---|
| 305 | echo "cleaning ${NEW_CONF} WORK, BLD" |
---|
| 306 | fi |
---|
| 307 | |
---|
[2248] | 308 | fi |
---|
| 309 | |
---|
| 310 | #- Come back to original directory --- |
---|
| 311 | cd - |
---|
| 312 | |
---|
| 313 | #- |
---|
| 314 | #- Unset variables |
---|
| 315 | ${COMPIL_DIR}/Fclean_var.sh |
---|
| 316 | |
---|
| 317 | |
---|