[1972] | 1 | #!/bin/bash |
---|
| 2 | #set -x |
---|
| 3 | set -o posix |
---|
| 4 | #set -u |
---|
| 5 | #set -e |
---|
| 6 | #+ |
---|
| 7 | # |
---|
| 8 | # =============== |
---|
[2136] | 9 | # makenemo |
---|
[1972] | 10 | # =============== |
---|
| 11 | # |
---|
| 12 | # -------------------------- |
---|
| 13 | # Compile NEMO |
---|
| 14 | # -------------------------- |
---|
| 15 | # |
---|
| 16 | # SYNOPSIS |
---|
| 17 | # ======== |
---|
| 18 | # |
---|
| 19 | # :: |
---|
| 20 | # |
---|
[2136] | 21 | # $ makenemo |
---|
[1972] | 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) |
---|
| 48 | # - MAIN_DIR : self explaining |
---|
| 49 | # - CONFIG_DIR : " " " |
---|
| 50 | # - MODELES_DIR : " " " |
---|
| 51 | # - TOOLS_DIR : " " " |
---|
| 52 | # - NEMO_DIR : " " " |
---|
| 53 | # |
---|
| 54 | # EXAMPLES |
---|
| 55 | # ======== |
---|
| 56 | # |
---|
| 57 | # :: |
---|
| 58 | # |
---|
[2292] | 59 | # $ ./makenemo -m ifort_osx - j3 -n ORCA2_LIM |
---|
[1972] | 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}) |
---|
[2292] | 81 | export MAIN_DIR=${PWD%/CONFIG*} |
---|
[1972] | 82 | export CONFIG_DIR=${MAIN_DIR}/CONFIG |
---|
| 83 | export TOOLS_DIR=${MAIN_DIR}/TOOLS |
---|
[2136] | 84 | export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE |
---|
[1972] | 85 | export NEMO_DIR=${MAIN_DIR}/NEMO |
---|
[2010] | 86 | export AGRIFUSE=10 |
---|
[2292] | 87 | |
---|
[1972] | 88 | declare -a TAB |
---|
| 89 | #- |
---|
| 90 | #- FCM and functions location --- |
---|
[1985] | 91 | export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH |
---|
[1972] | 92 | |
---|
| 93 | #- |
---|
| 94 | #- Choice of the options --- |
---|
| 95 | x_d=""; |
---|
| 96 | x_n=""; |
---|
| 97 | x_r=""; |
---|
| 98 | x_m=""; |
---|
| 99 | x_t=""; |
---|
[2143] | 100 | x_c=""; |
---|
[1972] | 101 | x_j=1; |
---|
[2143] | 102 | while getopts :hd:n:r:m:j:t: V |
---|
[1972] | 103 | do |
---|
| 104 | case $V in |
---|
| 105 | (h) echo "Usage : "${b_n} \ |
---|
[2143] | 106 | " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-j No]"; |
---|
[2136] | 107 | echo " -h : help"; |
---|
[2143] | 108 | echo " -n name : config name, [-n help] to list existing configurations"; |
---|
| 109 | echo " -m arch : choose compiler, [-m help] to list exiting compilers"; |
---|
[1972] | 110 | echo " -d dir : choose NEMO sub-directories"; |
---|
| 111 | echo " -r conf : choose reference configuration"; |
---|
| 112 | echo " -j No : number of processes used to compile (0=nocompilation)"; |
---|
| 113 | echo " -t dir : remporary directory for compilation" |
---|
| 114 | echo ""; |
---|
| 115 | echo "Example to install a new configuration MY_CONFIG"; |
---|
| 116 | echo "with OPA_SRC and LIM_SRC_2 "; |
---|
[2136] | 117 | echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\""; |
---|
[1972] | 118 | echo ""; |
---|
[2143] | 119 | echo "Available configurations :"; cat ${COMPIL_DIR}/cfg.txt; |
---|
[1972] | 120 | echo ""; |
---|
[2143] | 121 | . ${COMPIL_DIR}/Flist_archfile.sh ; |
---|
| 122 | echo ""; |
---|
| 123 | echo "Default : previous configuration and compiler"; |
---|
[1972] | 124 | exit 0;; |
---|
| 125 | (d) x_d=${OPTARG};; |
---|
| 126 | (n) x_n=${OPTARG};; |
---|
| 127 | (r) x_r=${OPTARG};; |
---|
| 128 | (m) x_m=${OPTARG};; |
---|
| 129 | (j) x_j=${OPTARG};; |
---|
| 130 | (t) x_t=${OPTARG};; |
---|
| 131 | (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; |
---|
| 132 | exit 2;; |
---|
| 133 | (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; |
---|
| 134 | exit 2;; |
---|
| 135 | esac |
---|
| 136 | done |
---|
| 137 | shift $(($OPTIND-1)); |
---|
| 138 | |
---|
| 139 | #- |
---|
[2143] | 140 | #- Get the clean option |
---|
| 141 | [[ "${#@}" -ne 0 && "${@}" != clean ]] && echo "Invalid option "$@" " && exit |
---|
| 142 | [ "${#@}" -ne 0 ] && x_c="--$@" |
---|
| 143 | |
---|
| 144 | #- |
---|
[1972] | 145 | #- Go to NEMOGCM/config directory --- |
---|
| 146 | cd ${CONFIG_DIR} |
---|
| 147 | |
---|
| 148 | #- |
---|
| 149 | #- Initialisation from input --- |
---|
| 150 | export NEW_CONF=${x_n} |
---|
| 151 | NBR_PRC=${x_j} |
---|
| 152 | CMP_NAM=${x_m} |
---|
| 153 | NEM_SUBDIR=${x_d} |
---|
| 154 | REF_CONF=${x_r} |
---|
| 155 | NEMO_TDIR=${x_t:-$NEMO_TDIR} |
---|
| 156 | export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR} |
---|
| 157 | |
---|
[2143] | 158 | #- Check if the tool or the compiler exist or list it |
---|
| 159 | if [ "${NEW_CONF}" == help ] ; then |
---|
| 160 | echo "Available configurations :" |
---|
| 161 | cat ${COMPIL_DIR}/cfg.txt |
---|
| 162 | exit |
---|
| 163 | fi |
---|
| 164 | [ "${CMP_NAM}" == help ] && . ${COMPIL_DIR}/Flist_archfile.sh && exit |
---|
| 165 | |
---|
[1972] | 166 | #- When used for the first time, choose a compiler --- |
---|
[2136] | 167 | . ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm ${CMP_NAM} || exit |
---|
[1972] | 168 | |
---|
| 169 | #- |
---|
| 170 | #- Choose a default configuration if needed --- |
---|
| 171 | #- ORCA2_LIM or last one used --- |
---|
[2158] | 172 | . ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit |
---|
[1972] | 173 | |
---|
| 174 | if [ ${#NEW_CONF} -eq 0 ] ; then |
---|
| 175 | if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then |
---|
| 176 | echo "You are installing a new configuration" |
---|
| 177 | ind=0 |
---|
[2136] | 178 | . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC YES |
---|
| 179 | . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2 YES |
---|
| 180 | . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3 NO |
---|
| 181 | . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC NO |
---|
| 182 | . ${COMPIL_DIR}/Fread_dir.sh C1D_SRC YES |
---|
| 183 | . ${COMPIL_DIR}/Fread_dir.sh NST_SRC YES |
---|
| 184 | . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC NO |
---|
[1972] | 185 | REF_CONF=ORCA2_LIM |
---|
| 186 | elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then |
---|
| 187 | echo "You are installing a new configuration" |
---|
| 188 | TAB=( ${NEM_SUBDIR} ) |
---|
| 189 | REF_CONF=ORCA2_LIM |
---|
| 190 | elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then |
---|
| 191 | echo "You are installing a new configuration based on ${REF_CONF}" |
---|
[2136] | 192 | . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} |
---|
[1972] | 193 | fi |
---|
| 194 | NEW_CONF=${x_n} |
---|
[2136] | 195 | . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF} |
---|
[1972] | 196 | else |
---|
[2136] | 197 | sed -e "/${NEW_CONF} /d" ${COMPIL_DIR}/cfg.txt > ${COMPIL_DIR}/cfg.tmp |
---|
| 198 | \mv ${COMPIL_DIR}/cfg.tmp ${COMPIL_DIR}/cfg.txt |
---|
[1972] | 199 | fi |
---|
| 200 | |
---|
| 201 | #- |
---|
| 202 | #- Save new configuration and directories names --- |
---|
[2136] | 203 | echo ${NEW_CONF} ${TAB[*]} >> ${COMPIL_DIR}/cfg.txt |
---|
[1972] | 204 | |
---|
| 205 | #- |
---|
| 206 | #- Create the WORK --- |
---|
| 207 | #- Clean links and librairies --- |
---|
| 208 | #- Creating the good links, at first on OPA_SRC --- |
---|
[2136] | 209 | . ${COMPIL_DIR}/Fmake_WORK.sh ${NEW_CONF} ${TAB[*]} || exit |
---|
[1972] | 210 | |
---|
[2136] | 211 | . ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
[1972] | 212 | |
---|
| 213 | #- At this stage the configuration has beeen chosen |
---|
| 214 | #- We look after agrif |
---|
[2136] | 215 | grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 |
---|
| 216 | . ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
[1972] | 217 | |
---|
| 218 | #- |
---|
| 219 | #_ END OF CONFIGURATION PHASE |
---|
| 220 | #_ |
---|
| 221 | |
---|
| 222 | #- |
---|
| 223 | #- Compile --- |
---|
| 224 | |
---|
| 225 | if [ "${NBR_PRC}" -gt 0 ]; then |
---|
[2158] | 226 | cd ${NEMO_TDIR}/${NEW_CONF} || cd - |
---|
[1972] | 227 | |
---|
[2158] | 228 | #if AGRIF we do a first preprocessing |
---|
| 229 | if [ ${#x_c} -eq 0 ]; then |
---|
| 230 | [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${COMPIL_DIR}/bld.cfg |
---|
| 231 | [ "$AGRIFUSE" == 1 ] && rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD/* |
---|
| 232 | fi |
---|
| 233 | fcm build ${x_c} --ignore-lock -v 1 -j ${NBR_PRC} ${COMPIL_DIR}/bld.cfg || cd - |
---|
| 234 | [ -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 |
---|
| 235 | [ -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 |
---|
[2143] | 236 | fi |
---|
[1972] | 237 | |
---|
| 238 | #- |
---|
| 239 | #- Come back to original directory --- |
---|
| 240 | cd - |
---|
| 241 | |
---|
| 242 | #- |
---|
| 243 | #- Unset variables |
---|
[2136] | 244 | ${COMPIL_DIR}/Fclean_var.sh |
---|
[1972] | 245 | |
---|
| 246 | |
---|
| 247 | exit 0; |
---|