make_xios 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. #!/bin/bash
  2. install_dir=$PWD
  3. compil_full="false"
  4. use_oasis="false"
  5. oasis="oasis3_mct"
  6. build_path="./"
  7. build_dir="./"
  8. build_suffixed="false"
  9. use_extern_boost="false"
  10. use_extern_blitz="false"
  11. use_memtrack="false"
  12. job="1"
  13. netcdf_lib="netcdf4_par"
  14. compil_mode="prod"
  15. arch_path=$PWD/"arch"
  16. arch_default_path=$PWD/"arch"
  17. arch_defined="FALSE"
  18. arch_path_defined="FALSE"
  19. # Traitement de la ligne de commande
  20. while (($# > 0))
  21. do
  22. case $1 in
  23. "-h"|"--help"|"-help")
  24. echo "make_xios - installs XIOS on your architecture"
  25. echo "make_xios [options]"
  26. echo "options :"
  27. echo " [--prod] : compilation in production mode (default)"
  28. echo " [--dev] : compilation in development mode"
  29. echo " [--debug] : compilation in debug mode"
  30. echo " --arch arch : to choose target architecture"
  31. echo " [--avail] : to know available target architectures "
  32. echo " [--full] : to generate dependencies and recompile from scratch"
  33. echo " [--use_oasis 'oasis3' 'oasis3_mct' : default oasis3_mct] : to use Oasis coupler"
  34. echo " [--build_path : absolute path to the build directory"
  35. echo " [--build_dir : name of the build directory"
  36. echo " [--build_suffixed : generate automatically suffixed name of the build directory (e.g. config_X64_CURIE_prod)"
  37. echo " [--use_extern_boost : to use external boost library"
  38. echo " [--use_extern_blitz : to use external blitz library"
  39. echo " [--doc] : to generate Doxygen documentation (not available yet)"
  40. echo " [--job ntasks] : to use parallel compilation with ntasks"
  41. echo " [--netcdf_lib 'netcdf4_par'/'netcdf4_seq'/'netcdf4_internal' : default netcdf4_par] : choice of netcdf library"
  42. echo " [--memtrack] : tracking memory leak - developper only"
  43. echo "Example : ./make_xios --prod --arch PW6_VARGAS"
  44. echo "Example : ./make_xios --avail"
  45. exit;;
  46. "--prod") compil_mode="prod" ; shift ;;
  47. "--dev") compil_mode="dev" ; shift ;;
  48. "--debug") compil_mode="debug" ; shift ;;
  49. "--arch") arch=$2 ; arch_defined="TRUE"; shift ; shift ;;
  50. "--arch_path") arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;;
  51. "--avail") ls arch/*.fcm | cut -d"-" -f2 | cut -d"." -f1 ; exit ;;
  52. "--full") compil_full="true" ; shift ;;
  53. "--use_oasis") use_oasis="true" oasis=$2 ; shift ; shift ;;
  54. "--build_path") build_path=$2 ; shift ; shift ;;
  55. "--build_dir") build_dir=$2 ; shift ; shift ;;
  56. "--build_suffixed") build_suffixed="true" ; shift ;;
  57. "--use_extern_boost") use_extern_boost="true" ; shift ;;
  58. "--use_extern_blitz") use_extern_blitz="true" ; shift ;;
  59. "--doc") doc="true" ; shift ;;
  60. "--job") job=$2 ; shift ; shift ;;
  61. "--netcdf_lib") netcdf_lib=$2 ; shift ; shift ;;
  62. "--memtrack") use_memtrack="true" memtrack=$2 ; shift ; shift ;;
  63. *) code="$1" ; shift ;;
  64. esac
  65. done
  66. # Installation des sources
  67. nb_files_gz=`ls $install_dir/tools/archive | grep tar.gz | wc -l`
  68. if [ ${nb_files_gz} -ne 0 ]
  69. then
  70. echo -e "- uncompress archives ..."
  71. for tarname in `ls $install_dir/tools/archive/*.tar.gz` ; do
  72. if ( [[ ${tarname} == "${install_dir}/tools/archive/boost.tar.gz" ]] && [[ "$use_extern_boost" == "true" ]] ) || ( [[ ${tarname} == "${install_dir}/tools/archive/blitz.tar.gz" ]] && [[ "$use_extern_blitz" == "true" ]] )
  73. then
  74. continue
  75. fi
  76. gunzip -f "$tarname"
  77. tar -xf ${tarname%.gz}
  78. done
  79. fi
  80. # Definition of the root directory of the build
  81. if [[ "$build_path" == "./" ]]; then
  82. install_dir=$PWD
  83. else
  84. install_dir=${build_path}
  85. fi
  86. if [[ "$build_suffixed" == "true" ]]; then
  87. install_dir="${install_dir}/config_${arch}_${compil_mode}"
  88. else
  89. install_dir="${install_dir}/${build_dir}"
  90. fi
  91. mkdir -p $install_dir
  92. rm -f ${PWD}/bld_dir.cfg
  93. echo "inc ${install_dir}/arch.fcm" >> ${PWD}/bld_dir.cfg
  94. echo "inc ${install_dir}/config.fcm" >> ${PWD}/bld_dir.cfg
  95. echo "dir::root ${install_dir}" >> ${PWD}/bld_dir.cfg
  96. # Vérification de la présence d'un identifiant d'architecture.
  97. ###############################################################
  98. # lecture des chemins propres a l'architecture de la machine #
  99. # et configuration de l'environnement #
  100. ###############################################################
  101. rm -f .void_file
  102. echo > .void_file
  103. rm -rf .void_dir
  104. mkdir .void_dir
  105. if [[ "$arch_defined" == "TRUE" ]]
  106. then
  107. rm -f ${install_dir}/arch.path
  108. rm -f ${install_dir}/arch.fcm
  109. rm -f ${install_dir}/arch.env
  110. if test -f $arch_path/arch-${arch}.path
  111. then
  112. ln -s $arch_path/arch-${arch}.path ${install_dir}/arch.path
  113. elif test -f $arch_default_path/arch-${arch}.path
  114. then
  115. ln -s $arch_default_path/arch-${arch}.path ${install_dir}/arch.path
  116. fi
  117. if test -f $arch_path/arch-${arch}.fcm
  118. then
  119. ln -s $arch_path/arch-${arch}.fcm ${install_dir}/arch.fcm
  120. elif test -f $arch_default_path/arch-${arch}.fcm
  121. then
  122. ln -s $arch_default_path/arch-${arch}.fcm ${install_dir}/arch.fcm
  123. fi
  124. if test -f $arch_path/arch-${arch}.env
  125. then
  126. ln -s $arch_path/arch-${arch}.env ${install_dir}/arch.env
  127. elif test -f $arch_default_path/arch-${arch}.env
  128. then
  129. ln -s $arch_default_path/arch-${arch}.env ${install_dir}/arch.env
  130. else
  131. ln -s .void_file ${install_dir}/arch.env
  132. fi
  133. source ${install_dir}/arch.env
  134. source ${install_dir}/arch.path
  135. else
  136. echo "Please choose a target achitecture --> list all available architecture using make_xios --avail!"
  137. exit 1
  138. fi
  139. # Vérification de la présence d'un mode de compilation.
  140. if [[ "$compil_mode" == "prod" ]]
  141. then
  142. COMPIL_CFLAGS="%PROD_CFLAGS"
  143. COMPIL_FFLAGS="%PROD_FFLAGS"
  144. elif [[ "$compil_mode" == "dev" ]]
  145. then
  146. COMPIL_CFLAGS="%DEV_CFLAGS"
  147. COMPIL_FFLAGS="%DEV_FFLAGS"
  148. elif [[ "$compil_mode" == "debug" ]]
  149. then
  150. COMPIL_CFLAGS="%DEBUG_CFLAGS"
  151. COMPIL_FFLAGS="%DEBUG_FFLAGS"
  152. fi
  153. rm -r $PWD/extern/netcdf4
  154. if [[ "$netcdf_lib" == "netcdf4_par" ]]
  155. then
  156. ln -s $PWD/.void_dir $PWD/extern/netcdf4
  157. XIOS_CPPKEY="$XIOS_CPPKEY USING_NETCDF_PAR"
  158. elif [[ "$netcdf_lib" == "netcdf4_seq" ]]
  159. then
  160. ln -s $PWD/.void_dir $PWD/extern/netcdf4
  161. elif [[ "$netcdf_lib" == "netcdf4_internal" ]]
  162. then
  163. ln -s $PWD/extern/src_netcdf4 $PWD/extern/netcdf4
  164. XIOS_CPPKEY="$XIOS_CPPKEY USING_NETCDF_PAR USING_NETCDF_INTERNAL"
  165. export NETCDF_INCDIR="-I${PWD}/extern/netcdf4"
  166. export NETCDF_LIBDIR=""
  167. export NETCDF_LIB=""
  168. else
  169. echo "Bad choice for --netcdf_lib argument : choose between 'netcdf4_par','netcdf4_seq' or 'netcdf4_internal'"
  170. exit
  171. fi
  172. if [[ "$use_oasis" == "true" ]]
  173. then
  174. if [[ "$oasis" == "oasis3_mct" ]]
  175. then
  176. XIOS_CPPKEY="$XIOS_CPPKEY USE_OMCT"
  177. elif [[ "$oasis" == "oasis3" ]]
  178. then
  179. XIOS_CPPKEY="$XIOS_CPPKEY USE_OASIS"
  180. OASIS_INCDIR="-I$PWD/../../prism/X64/build/lib/psmile.MPI1"
  181. OASIS_LIBDIR="-L$PWD/../../prism/X64/lib"
  182. OASIS_LIB="-lpsmile.MPI1 -lmpp_io"
  183. else
  184. echo "Bad choice for --use_oasis argument : choose between 'oasis3','oasis3_mct'"
  185. exit
  186. fi
  187. NETCDF_LIB="-lnetcdff -lnetcdf"
  188. XIOS_FINCDIR="$OASIS_INCDIR $XIOS_FINCDIR"
  189. XIOS_LIB="$OASIS_LIBDIR $OASIS_LIB $XIOS_LIB"
  190. fi
  191. # Setting path for boost
  192. if [[ "$use_extern_boost" == "true" ]]
  193. then
  194. rm -r $PWD/extern/boost
  195. ln -s $PWD/.void_dir $PWD/extern/boost
  196. else
  197. export BOOST_INCDIR="-I${PWD}/extern/boost"
  198. export BOOST_LIBDIR=""
  199. export BOOST_LIB=""
  200. fi
  201. # Setting path for blitz
  202. if [[ "$use_extern_blitz" == "true" ]]
  203. then
  204. rm -r $PWD/extern/blitz
  205. ln -s $PWD/.void_dir $PWD/extern/blitz
  206. else
  207. echo "src::blitz $PWD/extern/blitz/src" >> ${PWD}/bld_dir.cfg
  208. export BLITZ_INCDIR="-I${PWD}/extern/blitz"
  209. export BLITZ_LIBDIR=""
  210. export BLITZ_LIB=""
  211. fi
  212. if [[ "$use_memtrack" == "true" ]]
  213. then
  214. XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK"
  215. if [[ "$memtrack" == "light" ]]
  216. then
  217. XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK_LIGHT"
  218. elif [[ "$memtrack" == "FULL" ]]
  219. then
  220. XIOS_LIB="$ADDR2LINE_LIBDIR $ADDR2LINE_LIB $XIOS_LIB"
  221. XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK_FULL"
  222. else
  223. echo "Bad choice for --memtrack argument : choose between 'light','full'"
  224. exit
  225. fi
  226. fi
  227. XIOS_CINCDIR="$NETCDF_INCDIR $HDF5_INCDIR $MPI_INCDIR $BOOST_INCDIR $BLITZ_INCDIR"
  228. XIOS_FINCDIR="$NETCDF_INCDIR $XIOS_FINCDIR $MPI_INCDIR $BOOST_INCDIR $BLITZ_INCDIR"
  229. XIOS_LIB="$XIOS_LIB $NETCDF_LIBDIR $HDF5_LIBDIR $MPI_LIBDIR $NETCDF_LIB $HDF5_LIB $MPI_LIB"
  230. rm -f ${install_dir}/config.fcm
  231. echo "%COMPIL_CFLAGS $COMPIL_CFLAGS" >> ${install_dir}/config.fcm
  232. echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> ${install_dir}/config.fcm
  233. echo "%CPP_KEY $XIOS_CPPKEY" >> ${install_dir}/config.fcm
  234. echo "%CBASE_INC $XIOS_CINCDIR" >> ${install_dir}/config.fcm
  235. echo "%FBASE_INC $XIOS_FINCDIR" >> ${install_dir}/config.fcm
  236. echo "%ARCH_LD $XIOS_LIB" >> ${install_dir}/config.fcm
  237. echo "=> Using "$compil_mode" mode for compiling under architecture \""$arch"\" !"
  238. # Création de la documentation doxygen.
  239. if [[ !(-z $doc) ]]
  240. then
  241. echo -e "- Create Doxygen documentation (disabled)..."
  242. #doxygen -s
  243. fi
  244. make_dir=$PWD
  245. export PATH=$PWD/tools/FCM/bin:$PATH
  246. if [[ "$compil_full" == "true" ]]
  247. then
  248. fcm build --clean --ignore-lock
  249. fcm build -f --ignore-lock -j $job
  250. else
  251. fcm build --ignore-lock -j $job
  252. fi
  253. build_exit_status=$?
  254. if [[ $build_exit_status == 0 ]]
  255. then
  256. set nothing
  257. # cd $WORKDIR/XIOS_NEMO_COUPLE/modeles/NEMO/WORK
  258. # cd $WORKDIR/XIOS_NEMO/modeles/NEMO/WORK
  259. # make
  260. fi
  261. exit $build_exit_status