makenemo 11 KB

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