maketools 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/bin/bash
  2. #set -x
  3. set -o posix
  4. #set -u
  5. #set -e
  6. #+
  7. #
  8. # ===============
  9. # maketools
  10. # ===============
  11. #
  12. # --------------------------
  13. # Compile NEMO
  14. # --------------------------
  15. #
  16. # SYNOPSIS
  17. # ========
  18. #
  19. # ::
  20. #
  21. # $ maketools
  22. #
  23. #
  24. # DESCRIPTION
  25. # ===========
  26. #
  27. #
  28. # This script aims :
  29. #
  30. # - to choose a tool to compile
  31. # - to choose compiler options
  32. # - to compile this tool
  33. #
  34. # Variables used :
  35. #
  36. # From user input
  37. #
  38. # - NEW_CONF : configuration to be created
  39. # - CMP_NAM : compiler name
  40. # - NBR_PRC : number of processes used to compile
  41. #
  42. # Locally defined :
  43. #
  44. # - MAIN_DIR : self explaining
  45. # - MODELES_DIR : " " "
  46. # - TOOLS_DIR : " " "
  47. # - NEMO_DIR : " " "
  48. #
  49. # EXAMPLES
  50. # ========
  51. #
  52. # ::
  53. #
  54. # $ ./maketools -t ifort_osx - j3 -n NESTING
  55. #
  56. #
  57. # TODO
  58. # ====
  59. #
  60. # option debug
  61. #
  62. #
  63. # EVOLUTIONS
  64. # ==========
  65. #
  66. # $Id: maketools 4363 2014-01-22 11:11:47Z rfurner $
  67. #
  68. #
  69. #
  70. # * creation
  71. #
  72. #-
  73. #- Local variables ---
  74. b_n=$(basename ${0})
  75. export MAIN_DIR=${PWD%/TOOLS*}
  76. export TOOLS_DIR=${MAIN_DIR}/TOOLS
  77. export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE
  78. export NEMO_DIR=${MAIN_DIR}/NEMO
  79. #-
  80. #- FCM and functions location ---
  81. export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH
  82. #-
  83. #- Choice of the options ---
  84. x_h="";
  85. x_n="";
  86. x_m="";
  87. x_t="";
  88. x_c="";
  89. x_j=1;
  90. while getopts :hm:n:r:j:t: V
  91. do
  92. case $V in
  93. (h) x_h=${OPTARG};
  94. echo "Usage : "${b_n} \
  95. " [-h] [-n name] [-m arch] [-j No] [-t tmpdir]";
  96. echo " -h : help";
  97. echo " -h institute : specific help for consortium members";
  98. echo " -n name : tool name, [-n help] to list existing tools";
  99. echo " -m arch : choose compiler, [-m help] to list exiting compilers";
  100. echo " -j No : number of processes used to compile (0=nocompilation)";
  101. echo " -t dir : remporary directory for compilation"
  102. echo "";
  103. echo "Example to compile Agrif Nesting tools";
  104. echo "maketools -n NESTING" ;
  105. echo "";
  106. printf "%s\n" "Available tools :" `ls ${TOOLS_DIR}|grep -v COMPILE | grep -v maketools`;
  107. echo "";
  108. . ${COMPIL_DIR}/Flist_archfile.sh ${x_h};
  109. echo "";
  110. echo "Default : previous tool and compiler";
  111. exit 0;;
  112. (n) x_n=${OPTARG};;
  113. (m) x_m=${OPTARG};;
  114. (j) x_j=${OPTARG};;
  115. (t) x_t=${OPTARG};;
  116. (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
  117. exit 2;;
  118. (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
  119. exit 2;;
  120. esac
  121. done
  122. shift $(($OPTIND-1));
  123. #-
  124. #- Get the clean option
  125. [[ "${#@}" -ne 0 && "${@}" != clean ]] && echo "Invalid option "$@" " && exit
  126. [ "${#@}" -ne 0 ] && x_c="--$@"
  127. #-
  128. #- Go to NEMOGCM/TOOLS directory ---
  129. cd ${TOOLS_DIR}
  130. #-
  131. #- Initialisation from input ---
  132. export NEW_CONF=${x_n}
  133. NBR_PRC=${x_j}
  134. CMP_NAM=${x_m}
  135. NEMO_TDIR=${x_t:-$NEMO_TDIR}
  136. export NEMO_TDIR=${NEMO_TDIR:-$TOOLS_DIR}
  137. #- Check if the tool or the compiler exist or list it
  138. [ "${NEW_CONF}" == help ] && printf "%s\n" "Available tools :" `ls ${TOOLS_DIR}|grep -v COMPILE | grep -v maketools` && exit
  139. [ "${CMP_NAM}" == help ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit
  140. #- When used for the first time, choose a compiler ---
  141. . ${COMPIL_DIR}/Fcheck_archfile.sh arch_tools.fcm cpp.fcm ${CMP_NAM} || exit
  142. #- Choose a default tool if needed ---
  143. #- REBUILD or last one used ---
  144. . ${COMPIL_DIR}/Fcheck_config.sh tools.txt ${NEW_CONF} || exit
  145. #- Save new configuration ---
  146. echo "${NEW_CONF} " > ${COMPIL_DIR}/tools.txt
  147. #- Make the building directory
  148. . ${COMPIL_DIR}/Fmake_bld.sh ${TOOLS_DIR} ${NEW_CONF} ${NEMO_TDIR} || exit
  149. #-
  150. #_ END OF CONFIGURATION PHASE
  151. #_
  152. #-
  153. #- Compile ---
  154. if [ "${NBR_PRC}" -gt 0 ]; then
  155. cd ${NEMO_TDIR}/${NEW_CONF} || cd -
  156. fcm build ${x_c} --ignore-lock -v 1 -j ${NBR_PRC} ${COMPIL_DIR}/bld_tools.cfg || cd -
  157. if [ -n "$(ls ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/*.exe)" ]; then
  158. for i in `ls ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/*.exe`
  159. do
  160. ln -sf ${i} ${TOOLS_DIR}/${NEW_CONF}/.
  161. done
  162. fi
  163. fi
  164. #-
  165. #- Come back to original directory ---
  166. cd -
  167. #-
  168. #- Unset variables
  169. ${COMPIL_DIR}/Fclean_var.sh
  170. exit 0;