[248] | 1 | #!/bin/bash |
---|
| 2 | install_dir=$PWD |
---|
[287] | 3 | compil_full="false" |
---|
| 4 | use_oasis="false" |
---|
[475] | 5 | oasis="oasis3_mct" |
---|
[1497] | 6 | build_path="./" |
---|
| 7 | build_dir="./" |
---|
| 8 | build_suffixed="false" |
---|
[1453] | 9 | use_extern_blitz="false" |
---|
[402] | 10 | use_memtrack="false" |
---|
[313] | 11 | job="1" |
---|
[381] | 12 | netcdf_lib="netcdf4_par" |
---|
| 13 | compil_mode="prod" |
---|
[1497] | 14 | arch_path=$PWD/"arch" |
---|
| 15 | arch_default_path=$PWD/"arch" |
---|
[1450] | 16 | arch_defined="FALSE" |
---|
| 17 | arch_path_defined="FALSE" |
---|
[2166] | 18 | fcm_version=new |
---|
[248] | 19 | |
---|
| 20 | # Traitement de la ligne de commande |
---|
| 21 | while (($# > 0)) |
---|
| 22 | do |
---|
| 23 | case $1 in |
---|
[383] | 24 | "-h"|"--help"|"-help") |
---|
[374] | 25 | echo "make_xios - installs XIOS on your architecture" |
---|
| 26 | echo "make_xios [options]" |
---|
| 27 | echo "options :" |
---|
[381] | 28 | echo " [--prod] : compilation in production mode (default)" |
---|
[374] | 29 | echo " [--dev] : compilation in development mode" |
---|
| 30 | echo " [--debug] : compilation in debug mode" |
---|
| 31 | echo " --arch arch : to choose target architecture" |
---|
| 32 | echo " [--avail] : to know available target architectures " |
---|
| 33 | echo " [--full] : to generate dependencies and recompile from scratch" |
---|
[1497] | 34 | echo " [--use_oasis 'oasis3' 'oasis3_mct' : default oasis3_mct] : to use Oasis coupler" |
---|
[2166] | 35 | echo " [--build_path : absolute path to the build directory" |
---|
| 36 | echo " [--build_dir : name of the build directory" |
---|
| 37 | echo " [--build_suffixed : generate automatically suffixed name of the build directory (e.g. config_X64_CURIE_prod)" |
---|
| 38 | echo " [--use_extern_blitz : to use external blitz library" |
---|
[374] | 39 | echo " [--doc] : to generate Doxygen documentation (not available yet)" |
---|
| 40 | echo " [--job ntasks] : to use parallel compilation with ntasks" |
---|
[410] | 41 | echo " [--netcdf_lib 'netcdf4_par'/'netcdf4_seq'/'netcdf4_internal' : default netcdf4_par] : choice of netcdf library" |
---|
[2213] | 42 | echo " [--memtrack full/light] : tracking memory leak - developper only" |
---|
[2166] | 43 | echo " [--fcm] : fcm version compatibility : 'new'/'old'" |
---|
[374] | 44 | echo "Example : ./make_xios --prod --arch PW6_VARGAS" |
---|
| 45 | echo "Example : ./make_xios --avail" |
---|
[248] | 46 | exit;; |
---|
| 47 | "--prod") compil_mode="prod" ; shift ;; |
---|
| 48 | "--dev") compil_mode="dev" ; shift ;; |
---|
| 49 | "--debug") compil_mode="debug" ; shift ;; |
---|
[1450] | 50 | "--arch") arch=$2 ; arch_defined="TRUE"; shift ; shift ;; |
---|
| 51 | "--arch_path") arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;; |
---|
[383] | 52 | "--avail") ls arch/*.fcm | cut -d"-" -f2 | cut -d"." -f1 ; exit ;; |
---|
[313] | 53 | "--full") compil_full="true" ; shift ;; |
---|
[475] | 54 | "--use_oasis") use_oasis="true" oasis=$2 ; shift ; shift ;; |
---|
[1497] | 55 | "--build_path") build_path=$2 ; shift ; shift ;; |
---|
| 56 | "--build_dir") build_dir=$2 ; shift ; shift ;; |
---|
| 57 | "--build_suffixed") build_suffixed="true" ; shift ;; |
---|
[1453] | 58 | "--use_extern_blitz") use_extern_blitz="true" ; shift ;; |
---|
[248] | 59 | "--doc") doc="true" ; shift ;; |
---|
[313] | 60 | "--job") job=$2 ; shift ; shift ;; |
---|
[381] | 61 | "--netcdf_lib") netcdf_lib=$2 ; shift ; shift ;; |
---|
[1450] | 62 | "--memtrack") use_memtrack="true" memtrack=$2 ; shift ; shift ;; |
---|
[2166] | 63 | "--fcm") fcm_version=$2 ; shift ; shift ;; |
---|
[248] | 64 | *) code="$1" ; shift ;; |
---|
| 65 | esac |
---|
| 66 | done |
---|
| 67 | |
---|
[374] | 68 | # Installation des sources |
---|
[377] | 69 | nb_files_gz=`ls $install_dir/tools/archive | grep tar.gz | wc -l` |
---|
| 70 | if [ ${nb_files_gz} -ne 0 ] |
---|
[376] | 71 | then |
---|
[377] | 72 | echo -e "- uncompress archives ..." |
---|
[376] | 73 | for tarname in `ls $install_dir/tools/archive/*.tar.gz` ; do |
---|
[2629] | 74 | if ( [[ ${tarname} == "${install_dir}/tools/archive/blitz.tar.gz" ]] && [[ "$use_extern_blitz" == "true" ]] ) |
---|
[1458] | 75 | then |
---|
| 76 | continue |
---|
| 77 | fi |
---|
[376] | 78 | gunzip -f "$tarname" |
---|
| 79 | tar -xf ${tarname%.gz} |
---|
| 80 | done |
---|
| 81 | fi |
---|
[374] | 82 | |
---|
[1498] | 83 | # Definition of the root directory of the build |
---|
| 84 | |
---|
| 85 | if [[ "$build_path" == "./" ]]; then |
---|
| 86 | install_dir=$PWD |
---|
| 87 | else |
---|
| 88 | install_dir=${build_path} |
---|
| 89 | fi |
---|
| 90 | |
---|
[1497] | 91 | if [[ "$build_suffixed" == "true" ]]; then |
---|
[1498] | 92 | install_dir="${install_dir}/config_${arch}_${compil_mode}" |
---|
[1497] | 93 | else |
---|
[1498] | 94 | install_dir="${install_dir}/${build_dir}" |
---|
[1497] | 95 | fi |
---|
[1498] | 96 | |
---|
[1497] | 97 | mkdir -p $install_dir |
---|
| 98 | |
---|
| 99 | rm -f ${PWD}/bld_dir.cfg |
---|
| 100 | echo "inc ${install_dir}/arch.fcm" >> ${PWD}/bld_dir.cfg |
---|
| 101 | echo "inc ${install_dir}/config.fcm" >> ${PWD}/bld_dir.cfg |
---|
| 102 | echo "dir::root ${install_dir}" >> ${PWD}/bld_dir.cfg |
---|
| 103 | |
---|
[248] | 104 | # Vérification de la présence d'un identifiant d'architecture. |
---|
| 105 | |
---|
[281] | 106 | ############################################################### |
---|
[374] | 107 | # lecture des chemins propres a l'architecture de la machine # |
---|
[281] | 108 | # et configuration de l'environnement # |
---|
| 109 | ############################################################### |
---|
| 110 | |
---|
| 111 | rm -f .void_file |
---|
| 112 | echo > .void_file |
---|
| 113 | rm -rf .void_dir |
---|
| 114 | mkdir .void_dir |
---|
| 115 | |
---|
[1450] | 116 | if [[ "$arch_defined" == "TRUE" ]] |
---|
| 117 | then |
---|
[1497] | 118 | rm -f ${install_dir}/arch.path |
---|
| 119 | rm -f ${install_dir}/arch.fcm |
---|
| 120 | rm -f ${install_dir}/arch.env |
---|
[281] | 121 | |
---|
[1450] | 122 | if test -f $arch_path/arch-${arch}.path |
---|
| 123 | then |
---|
[1497] | 124 | ln -s $arch_path/arch-${arch}.path ${install_dir}/arch.path |
---|
[1450] | 125 | elif test -f $arch_default_path/arch-${arch}.path |
---|
| 126 | then |
---|
[1497] | 127 | ln -s $arch_default_path/arch-${arch}.path ${install_dir}/arch.path |
---|
[1450] | 128 | fi |
---|
| 129 | |
---|
| 130 | if test -f $arch_path/arch-${arch}.fcm |
---|
| 131 | then |
---|
[1497] | 132 | ln -s $arch_path/arch-${arch}.fcm ${install_dir}/arch.fcm |
---|
[1450] | 133 | elif test -f $arch_default_path/arch-${arch}.fcm |
---|
| 134 | then |
---|
[1497] | 135 | ln -s $arch_default_path/arch-${arch}.fcm ${install_dir}/arch.fcm |
---|
[1450] | 136 | fi |
---|
[281] | 137 | |
---|
[1450] | 138 | if test -f $arch_path/arch-${arch}.env |
---|
| 139 | then |
---|
[1497] | 140 | ln -s $arch_path/arch-${arch}.env ${install_dir}/arch.env |
---|
[1450] | 141 | elif test -f $arch_default_path/arch-${arch}.env |
---|
| 142 | then |
---|
[1497] | 143 | ln -s $arch_default_path/arch-${arch}.env ${install_dir}/arch.env |
---|
[281] | 144 | else |
---|
[1497] | 145 | ln -s .void_file ${install_dir}/arch.env |
---|
[1450] | 146 | fi |
---|
[1497] | 147 | source ${install_dir}/arch.env |
---|
| 148 | source ${install_dir}/arch.path |
---|
[1450] | 149 | else |
---|
[381] | 150 | echo "Please choose a target achitecture --> list all available architecture using make_xios --avail!" |
---|
[248] | 151 | exit 1 |
---|
| 152 | fi |
---|
| 153 | |
---|
| 154 | # Vérification de la présence d'un mode de compilation. |
---|
| 155 | |
---|
| 156 | if [[ "$compil_mode" == "prod" ]] |
---|
| 157 | then |
---|
| 158 | COMPIL_CFLAGS="%PROD_CFLAGS" |
---|
| 159 | COMPIL_FFLAGS="%PROD_FFLAGS" |
---|
| 160 | elif [[ "$compil_mode" == "dev" ]] |
---|
| 161 | then |
---|
| 162 | COMPIL_CFLAGS="%DEV_CFLAGS" |
---|
| 163 | COMPIL_FFLAGS="%DEV_FFLAGS" |
---|
| 164 | elif [[ "$compil_mode" == "debug" ]] |
---|
| 165 | then |
---|
| 166 | COMPIL_CFLAGS="%DEBUG_CFLAGS" |
---|
| 167 | COMPIL_FFLAGS="%DEBUG_FFLAGS" |
---|
| 168 | fi |
---|
| 169 | |
---|
[410] | 170 | rm -r $PWD/extern/netcdf4 |
---|
| 171 | |
---|
[381] | 172 | if [[ "$netcdf_lib" == "netcdf4_par" ]] |
---|
| 173 | then |
---|
[410] | 174 | ln -s $PWD/.void_dir $PWD/extern/netcdf4 |
---|
[591] | 175 | XIOS_CPPKEY="$XIOS_CPPKEY USING_NETCDF_PAR" |
---|
[381] | 176 | elif [[ "$netcdf_lib" == "netcdf4_seq" ]] |
---|
| 177 | then |
---|
[410] | 178 | ln -s $PWD/.void_dir $PWD/extern/netcdf4 |
---|
| 179 | elif [[ "$netcdf_lib" == "netcdf4_internal" ]] |
---|
| 180 | then |
---|
| 181 | ln -s $PWD/extern/src_netcdf4 $PWD/extern/netcdf4 |
---|
[591] | 182 | XIOS_CPPKEY="$XIOS_CPPKEY USING_NETCDF_PAR USING_NETCDF_INTERNAL" |
---|
[410] | 183 | export NETCDF_INCDIR="-I${PWD}/extern/netcdf4" |
---|
| 184 | export NETCDF_LIBDIR="" |
---|
| 185 | export NETCDF_LIB="" |
---|
[381] | 186 | else |
---|
[410] | 187 | echo "Bad choice for --netcdf_lib argument : choose between 'netcdf4_par','netcdf4_seq' or 'netcdf4_internal'" |
---|
[381] | 188 | exit |
---|
| 189 | fi |
---|
| 190 | |
---|
[287] | 191 | if [[ "$use_oasis" == "true" ]] |
---|
| 192 | then |
---|
[475] | 193 | if [[ "$oasis" == "oasis3_mct" ]] |
---|
| 194 | then |
---|
[591] | 195 | XIOS_CPPKEY="$XIOS_CPPKEY USE_OMCT" |
---|
[475] | 196 | elif [[ "$oasis" == "oasis3" ]] |
---|
| 197 | then |
---|
[591] | 198 | XIOS_CPPKEY="$XIOS_CPPKEY USE_OASIS" |
---|
[475] | 199 | OASIS_INCDIR="-I$PWD/../../prism/X64/build/lib/psmile.MPI1" |
---|
| 200 | OASIS_LIBDIR="-L$PWD/../../prism/X64/lib" |
---|
| 201 | OASIS_LIB="-lpsmile.MPI1 -lmpp_io" |
---|
| 202 | else |
---|
| 203 | echo "Bad choice for --use_oasis argument : choose between 'oasis3','oasis3_mct'" |
---|
| 204 | exit |
---|
| 205 | fi |
---|
| 206 | NETCDF_LIB="-lnetcdff -lnetcdf" |
---|
[591] | 207 | XIOS_FINCDIR="$OASIS_INCDIR $XIOS_FINCDIR" |
---|
| 208 | XIOS_LIB="$OASIS_LIBDIR $OASIS_LIB $XIOS_LIB" |
---|
[1450] | 209 | fi |
---|
[362] | 210 | |
---|
[2529] | 211 | |
---|
| 212 | # Detecting if parallel compression is available : |
---|
| 213 | # - NetCDF is HDF5 based and >= 4.7.4 ? |
---|
| 214 | # - HDF5 is parallel and >= 1.10.3 ? |
---|
| 215 | USE_HDF5=0 |
---|
| 216 | if [[ ! -z $NETCDF_INCDIR ]] |
---|
| 217 | then |
---|
| 218 | NETCDF_LOOKUP=`echo ${NETCDF_INCDIR} | sed 's/\-I/\ /g'` |
---|
| 219 | netcdf_meta_file=`find $NETCDF_LOOKUP -name netcdf_meta.h 2> /dev/null` |
---|
| 220 | else |
---|
| 221 | for dir in `echo $CPATH | sed 's/\:/\ /g'` ; do |
---|
| 222 | if [ -f "$dir/netcdf_meta.h" ] |
---|
| 223 | then |
---|
| 224 | netcdf_meta_file=$dir/netcdf_meta.h |
---|
| 225 | break |
---|
| 226 | fi |
---|
| 227 | done |
---|
| 228 | fi |
---|
| 229 | if [[ ! -z $netcdf_meta_file ]] |
---|
| 230 | then |
---|
| 231 | NC_MAJOR=`grep "NC_VERSION_MAJOR" $netcdf_meta_file | awk '{ print $3 }'` |
---|
| 232 | NC_MINOR=`grep "NC_VERSION_MINOR" $netcdf_meta_file | awk '{ print $3 }'` |
---|
| 233 | NC_PATCH=`grep "NC_VERSION_PATCH" $netcdf_meta_file | awk '{ print $3 }'` |
---|
| 234 | if ( [[ "$NC_MAJOR" -ge 5 || ( "$NC_MAJOR" -eq 4 && "$NC_MINOR" -ge 8 )|| ( "$NC_MAJOR" -eq 4 && "$NC_MINOR" -eq 7 && "$NC_PATCH" -ge 4 ) ]] ) |
---|
| 235 | then |
---|
| 236 | USE_HDF5=`grep NC_HAS_HDF5 $netcdf_meta_file | awk '{ print $3 }'` |
---|
| 237 | fi |
---|
| 238 | fi |
---|
| 239 | |
---|
| 240 | if [ "$USE_HDF5" == "1" ] |
---|
| 241 | then |
---|
| 242 | # https://forum.hdfgroup.org/t/parallel-compression-support-detection/5398 |
---|
| 243 | if [[ ! -z $HDF5_LIBDIR ]] |
---|
| 244 | then |
---|
| 245 | HDF5_LOOKUP=`echo ${HDF5_LIBDIR} | sed 's/\-L/\ /g'` |
---|
| 246 | hdf5_settings_file=`find $HDF5_LOOKUP -name libhdf5.settings 2> /dev/null` |
---|
| 247 | else |
---|
| 248 | for dir in `echo $LD_LIBRARY_PATH | sed 's/\:/\ /g'` ; do |
---|
| 249 | if [ -f "$dir/libhdf5.settings" ] |
---|
| 250 | then |
---|
| 251 | hdf5_settings_file=$dir/libhdf5.settings |
---|
| 252 | break |
---|
| 253 | fi |
---|
| 254 | done |
---|
| 255 | fi |
---|
[2608] | 256 | if [[ ! -z $hdf5_settings_file ]] |
---|
[2529] | 257 | then |
---|
[2608] | 258 | HDF5_VERSION=`grep "HDF5 Version" $hdf5_settings_file | awk -F ':' '{ print $2 }'` |
---|
| 259 | HDF5_MAJOR_VERSION=`echo $HDF5_VERSION | awk -F '.' '{ print $2 }'` |
---|
| 260 | HDF5_MINOR_VERSION=`echo $HDF5_VERSION | awk -F '.' '{ print $3 }'` |
---|
| 261 | HDF5_PARALLEL=`grep "Parallel HDF5" $hdf5_settings_file | awk -F ':' '{ print $2 }'` |
---|
| 262 | HDF5_DEFLATE=`grep "I/O filters (external)" $hdf5_settings_file | awk -F ':' '{ print $2 }'` |
---|
| 263 | if ( [[ "$HDF5_MAJOR_VERSION" -ge 11 || ( "$HDF5_MAJOR_VERSION" -eq 10 && "$HDF5_MINOR_VERSION" -ge 3 ) ]] ) |
---|
| 264 | then |
---|
| 265 | if [[ "$HDF5_PARALLEL" =~ "yes" && "$HDF5_DEFLATE" =~ "zlib" ]] |
---|
| 266 | then |
---|
| 267 | XIOS_CPPKEY="$XIOS_CPPKEY PARALLEL_COMPRESSION" |
---|
| 268 | fi |
---|
| 269 | fi |
---|
| 270 | fi # hdf5_settings_file |
---|
[2529] | 271 | fi |
---|
| 272 | if [[ "$XIOS_CPPKEY" =~ "PARALLEL_COMPRESSION" ]] |
---|
| 273 | then |
---|
| 274 | echo "->Parallel compression is available" |
---|
| 275 | else |
---|
| 276 | echo "->Parallel compression is NOT available" |
---|
| 277 | fi |
---|
| 278 | # End "Detecting if parallel compression is available" |
---|
| 279 | |
---|
[1449] | 280 | # Setting path for boost |
---|
[2629] | 281 | export BOOST_INCDIR="-I${PWD}/extern/boost_extraction/include" |
---|
[1449] | 282 | |
---|
[1453] | 283 | # Setting path for blitz |
---|
| 284 | if [[ "$use_extern_blitz" == "true" ]] |
---|
| 285 | then |
---|
[1458] | 286 | rm -r $PWD/extern/blitz |
---|
[1453] | 287 | ln -s $PWD/.void_dir $PWD/extern/blitz |
---|
| 288 | else |
---|
[1510] | 289 | echo "src::blitz $PWD/extern/blitz/src" >> ${PWD}/bld_dir.cfg |
---|
[1453] | 290 | export BLITZ_INCDIR="-I${PWD}/extern/blitz" |
---|
| 291 | export BLITZ_LIBDIR="" |
---|
| 292 | export BLITZ_LIB="" |
---|
| 293 | fi |
---|
| 294 | |
---|
| 295 | |
---|
[402] | 296 | if [[ "$use_memtrack" == "true" ]] |
---|
| 297 | then |
---|
[591] | 298 | XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK" |
---|
[1450] | 299 | |
---|
| 300 | if [[ "$memtrack" == "light" ]] |
---|
| 301 | then |
---|
| 302 | XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK_LIGHT" |
---|
[2213] | 303 | elif [[ "$memtrack" == "full" ]] |
---|
[1450] | 304 | then |
---|
| 305 | XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK_FULL" |
---|
| 306 | else |
---|
| 307 | echo "Bad choice for --memtrack argument : choose between 'light','full'" |
---|
| 308 | exit |
---|
| 309 | fi |
---|
[402] | 310 | fi |
---|
| 311 | |
---|
[1453] | 312 | XIOS_CINCDIR="$NETCDF_INCDIR $HDF5_INCDIR $MPI_INCDIR $BOOST_INCDIR $BLITZ_INCDIR" |
---|
| 313 | XIOS_FINCDIR="$NETCDF_INCDIR $XIOS_FINCDIR $MPI_INCDIR $BOOST_INCDIR $BLITZ_INCDIR" |
---|
[248] | 314 | |
---|
[591] | 315 | XIOS_LIB="$XIOS_LIB $NETCDF_LIBDIR $HDF5_LIBDIR $MPI_LIBDIR $NETCDF_LIB $HDF5_LIB $MPI_LIB" |
---|
[248] | 316 | |
---|
[1497] | 317 | rm -f ${install_dir}/config.fcm |
---|
| 318 | echo "%COMPIL_CFLAGS $COMPIL_CFLAGS" >> ${install_dir}/config.fcm |
---|
| 319 | echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> ${install_dir}/config.fcm |
---|
| 320 | echo "%CPP_KEY $XIOS_CPPKEY" >> ${install_dir}/config.fcm |
---|
[248] | 321 | |
---|
[1497] | 322 | echo "%CBASE_INC $XIOS_CINCDIR" >> ${install_dir}/config.fcm |
---|
| 323 | echo "%FBASE_INC $XIOS_FINCDIR" >> ${install_dir}/config.fcm |
---|
| 324 | echo "%ARCH_LD $XIOS_LIB" >> ${install_dir}/config.fcm |
---|
[248] | 325 | |
---|
[381] | 326 | echo "=> Using "$compil_mode" mode for compiling under architecture \""$arch"\" !" |
---|
[248] | 327 | |
---|
| 328 | # Création de la documentation doxygen. |
---|
| 329 | if [[ !(-z $doc) ]] |
---|
| 330 | then |
---|
[381] | 331 | echo -e "- Create Doxygen documentation (disabled)..." |
---|
[248] | 332 | #doxygen -s |
---|
| 333 | fi |
---|
| 334 | |
---|
| 335 | make_dir=$PWD |
---|
| 336 | |
---|
[2166] | 337 | if [[ "$fcm_version" == "new" ]] |
---|
| 338 | then |
---|
| 339 | export PATH=$PWD/tools/FCM_NEW/bin:$PATH |
---|
| 340 | elif [[ "$fcm_version" == "old" ]] |
---|
| 341 | then |
---|
| 342 | export PATH=$PWD/tools/FCM_OLD/bin:$PATH |
---|
| 343 | else |
---|
| 344 | echo "=> Bad option for --fcm flag : "$fcm_version" , only 'new' or 'old' permitted" |
---|
| 345 | fi |
---|
| 346 | |
---|
[287] | 347 | if [[ "$compil_full" == "true" ]] |
---|
| 348 | then |
---|
[395] | 349 | fcm build --clean --ignore-lock |
---|
| 350 | fcm build -f --ignore-lock -j $job |
---|
[287] | 351 | else |
---|
[395] | 352 | fcm build --ignore-lock -j $job |
---|
[287] | 353 | fi |
---|
[248] | 354 | |
---|
[601] | 355 | build_exit_status=$? |
---|
[287] | 356 | |
---|
[601] | 357 | if [[ $build_exit_status == 0 ]] |
---|
[287] | 358 | then |
---|
[366] | 359 | set nothing |
---|
[591] | 360 | # cd $WORKDIR/XIOS_NEMO_COUPLE/modeles/NEMO/WORK |
---|
| 361 | # cd $WORKDIR/XIOS_NEMO/modeles/NEMO/WORK |
---|
[301] | 362 | # make |
---|
[287] | 363 | fi |
---|
[601] | 364 | |
---|
| 365 | exit $build_exit_status |
---|