[12] | 1 | #!/bin/bash |
---|
| 2 | |
---|
[730] | 3 | # resolve symlinks and '..' in $PWD to avoid useless re-compilation |
---|
| 4 | cd -P $PWD |
---|
| 5 | |
---|
[279] | 6 | echo ./make_icosa $* > rebuild |
---|
| 7 | chmod a+x rebuild |
---|
| 8 | |
---|
[12] | 9 | compil_mode_defined="FALSE" |
---|
| 10 | compil_mode="prod" |
---|
| 11 | |
---|
[89] | 12 | job=1 |
---|
| 13 | full_defined="FALSE" |
---|
[171] | 14 | with_xios_defined="FALSE" |
---|
[12] | 15 | arch_defined="FALSE" |
---|
[28] | 16 | parallel_defined="FALSE" |
---|
[497] | 17 | arch_default_path="arch" |
---|
[332] | 18 | arch_path="arch" |
---|
[28] | 19 | parallel="none" |
---|
[327] | 20 | physics="none" |
---|
[347] | 21 | external_ioipsl="FALSE" |
---|
| 22 | external_physics="FALSE" |
---|
[488] | 23 | no_io_defined="FALSE" |
---|
[347] | 24 | |
---|
[28] | 25 | CPP_KEY="CPP_NONE" |
---|
[171] | 26 | ICOSA_LIB="" |
---|
[12] | 27 | |
---|
| 28 | while (($# > 0)) |
---|
| 29 | do |
---|
| 30 | case $1 in |
---|
| 31 | "-h") cat <<fin |
---|
| 32 | Usage : |
---|
| 33 | makegcm [options] -m arch exec |
---|
| 34 | [-h] : help |
---|
| 35 | [-prod / -dev / -debug] : compilation en mode production (default) / developpement / debug . |
---|
[535] | 36 | -arch nom_arch : target architecture, use paths and compilation options from arch files arch/arch-NAME.* |
---|
| 37 | -arch_path PATH : use arch files PATH/arch-ARCH.* |
---|
| 38 | -parallel mpi|mpi_omp : pure MPI or hybrid MPI/OpenMP parallelism |
---|
| 39 | -job N : parallel compilation as with make -j N |
---|
| 40 | -full : full compilation |
---|
| 41 | -with_xios : use XIOS for I/O (default is NetCDF-CF on native grid) |
---|
| 42 | -no_io : disable I/O altogether |
---|
| 43 | -external_ioipsl PATH : use IOIPSL from PATH rather than tools/ioipsl |
---|
| 44 | -physics lmdz_generic : use LMDZ generic physics (planets) |
---|
| 45 | -external_physics : allows external physics |
---|
[744] | 46 | -mixed_prec : compiles unstructured dynamics in single precision (float32) |
---|
[12] | 47 | fin |
---|
| 48 | exit;; |
---|
| 49 | |
---|
| 50 | "-prod") |
---|
| 51 | compil_mode="prod" ; shift ;; |
---|
| 52 | |
---|
| 53 | "-dev") |
---|
| 54 | compil_mode="dev" ; shift ;; |
---|
| 55 | |
---|
| 56 | "-debug") |
---|
| 57 | compil_mode="debug" ; shift ;; |
---|
| 58 | |
---|
| 59 | "-arch") |
---|
| 60 | arch=$2 ; arch_defined="TRUE"; shift ; shift ;; |
---|
[332] | 61 | |
---|
| 62 | "-arch_path") |
---|
| 63 | arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;; |
---|
[12] | 64 | |
---|
[28] | 65 | "-parallel") |
---|
| 66 | parallel=$2 ; parallel_defined="TRUE"; shift ; shift ;; |
---|
| 67 | |
---|
[327] | 68 | "-physics") |
---|
| 69 | physics=$2 ; physics_defined="TRUE"; shift ; shift ;; |
---|
| 70 | |
---|
[89] | 71 | "-job") |
---|
[103] | 72 | job=$2 ; shift ; shift;; |
---|
[89] | 73 | |
---|
| 74 | "-full") |
---|
[103] | 75 | full_defined="TRUE" ; shift ;; |
---|
[89] | 76 | |
---|
[171] | 77 | "-with_xios") |
---|
| 78 | with_xios_defined="TRUE" ; shift ;; |
---|
[488] | 79 | |
---|
[535] | 80 | "-no_io") |
---|
[488] | 81 | no_io_defined="TRUE" ; shift ;; |
---|
| 82 | |
---|
[347] | 83 | "-external_ioipsl") |
---|
| 84 | external_ioipsl="TRUE" ; shift ;; |
---|
| 85 | |
---|
| 86 | "-external_physics") |
---|
| 87 | external_physics="TRUE" ; shift ;; |
---|
| 88 | |
---|
[744] | 89 | "-mixed_prec") |
---|
| 90 | mixed_prec="TRUE" ; shift ;; |
---|
[12] | 91 | *) |
---|
| 92 | code="$1" ; shift ;; |
---|
| 93 | esac |
---|
| 94 | done |
---|
| 95 | |
---|
[28] | 96 | rm -f .void_file |
---|
| 97 | echo > .void_file |
---|
| 98 | rm -rf .void_dir |
---|
| 99 | mkdir .void_dir |
---|
| 100 | |
---|
[738] | 101 | function link_if_exists() |
---|
| 102 | { |
---|
| 103 | suffix=$1 |
---|
[743] | 104 | rm -f arch.$suffix |
---|
[738] | 105 | if test -f $arch_path/arch-${arch}.${suffix} |
---|
| 106 | then |
---|
| 107 | ln -s $arch_path/arch-${arch}.${suffix} arch.${suffix} |
---|
| 108 | elif test -f $arch_default_path/arch-${arch}.${suffix} |
---|
| 109 | then |
---|
| 110 | ln -s $arch_default_path/arch-${arch}.${suffix} arch.${suffix} |
---|
[743] | 111 | else |
---|
| 112 | ln -sf .void_file arch.$suffix |
---|
| 113 | fi |
---|
[738] | 114 | } |
---|
| 115 | |
---|
[12] | 116 | if [[ "$arch_defined" == "TRUE" ]] |
---|
| 117 | then |
---|
[738] | 118 | for suffix in env path fcm opt ; do link_if_exists $suffix ; done |
---|
[497] | 119 | |
---|
[28] | 120 | source arch.env |
---|
[12] | 121 | source arch.path |
---|
[738] | 122 | |
---|
[12] | 123 | else |
---|
| 124 | echo "Veuillez definir une architecture cible" |
---|
| 125 | exit 1 |
---|
| 126 | fi |
---|
| 127 | |
---|
[152] | 128 | LD_FLAGS="%BASE_LD" |
---|
[738] | 129 | COMPIL_FFLAGS="" |
---|
[152] | 130 | |
---|
[28] | 131 | if [[ "$parallel" == "mpi" ]] |
---|
| 132 | then |
---|
| 133 | CPP_KEY="$CPP_KEY CPP_USING_MPI" |
---|
[152] | 134 | elif [[ "$parallel" == "omp" ]] |
---|
| 135 | then |
---|
| 136 | CPP_KEY="$CPP_KEY CPP_USING_OMP" |
---|
| 137 | COMPIL_FFLAGS="$COMPIL_FFLAGS %OMP_FFLAGS" |
---|
| 138 | LD_FLAGS="$LD_FLAGS %OMP_LD" |
---|
| 139 | elif [[ "$parallel" == "mpi_omp" ]] |
---|
| 140 | then |
---|
| 141 | CPP_KEY="$CPP_KEY CPP_USING_MPI CPP_USING_OMP" |
---|
[189] | 142 | COMPIL_FFLAGS="$COMPIL_FFLAGS %OMP_FFLAGS" |
---|
[152] | 143 | LD_FLAGS="$LD_FLAGS %OMP_LD" |
---|
[28] | 144 | elif [[ "$parallel" == "none" ]] |
---|
| 145 | then |
---|
| 146 | parallel="none" |
---|
| 147 | else |
---|
[152] | 148 | echo "-parallel value $parallel is invalid, only permited <none>, <mpi>, <omp> or <mpi_omp>" |
---|
[28] | 149 | exit 1 |
---|
| 150 | fi |
---|
| 151 | |
---|
[327] | 152 | if [[ "$physics" == "lmdz_generic" ]] |
---|
| 153 | then |
---|
| 154 | CPP_KEY="$CPP_KEY CPP_PHYSICS_LMDZ_GENERIC" |
---|
| 155 | COMPIL_FFLAGS="$COMPIL_FFLAGS $PHYSICS_INCDIR" |
---|
| 156 | ICOSA_LIB="$ICOSA_LIB $PHYSICS_LIBDIR $PHYSICS_LIB" |
---|
| 157 | fi |
---|
| 158 | |
---|
[488] | 159 | if [[ "$no_io_defined" == "TRUE" ]] |
---|
| 160 | then |
---|
| 161 | CPP_KEY="$CPP_KEY CPP_NO_IO" |
---|
| 162 | with_xios_defined="FALSE" |
---|
| 163 | fi |
---|
| 164 | |
---|
[171] | 165 | if [[ "$with_xios_defined" == "TRUE" ]] |
---|
| 166 | then |
---|
| 167 | CPP_KEY="$CPP_KEY CPP_USING_XIOS" |
---|
| 168 | COMPIL_FFLAGS="$COMPIL_FFLAGS $XIOS_INCDIR" |
---|
| 169 | ICOSA_LIB="$ICOSA_LIB $XIOS_LIBDIR $XIOS_LIB" |
---|
| 170 | fi |
---|
[28] | 171 | |
---|
[347] | 172 | if [[ "$external_ioipsl" == "TRUE" ]] |
---|
| 173 | then |
---|
| 174 | ioipsl_path=".void_dir" |
---|
| 175 | use_ioipsl="use::ioipsl" |
---|
| 176 | COMPIL_FFLAGS="$COMPIL_FFLAGS $IOIPSL_INCDIR" |
---|
| 177 | ICOSA_LIB="$ICOSA_LIB $IOIPSL_LIBDIR $IOIPSL_LIB" |
---|
| 178 | else |
---|
| 179 | ioipsl_path="tools/ioipsl" |
---|
| 180 | use_ioipsl="" |
---|
| 181 | fi |
---|
| 182 | |
---|
| 183 | if [[ "$external_physics" == "TRUE" ]] |
---|
| 184 | then |
---|
| 185 | CPP_KEY="$CPP_KEY CPP_USING_EXTERNAL_PHYSICS" |
---|
| 186 | fi |
---|
| 187 | |
---|
[744] | 188 | if [[ "$mixed_prec" == "TRUE" ]] |
---|
| 189 | then |
---|
| 190 | CPP_KEY="$CPP_KEY CPP_MIXED_PREC" |
---|
| 191 | fi |
---|
| 192 | |
---|
[488] | 193 | if [[ "$no_io_defined" == "FALSE" ]] |
---|
| 194 | then |
---|
| 195 | ICOSA_LIB="$ICOSA_LIB $NETCDF_LIBDIR $NETCDF_LIB $HDF5_LIBDIR $HDF5_LIB" |
---|
| 196 | COMPIL_FFLAGS="$COMPIL_FFLAGS $NETCDF_INCDIR" |
---|
| 197 | fi |
---|
[171] | 198 | |
---|
[738] | 199 | if [[ "$compil_mode" == "prod" ]] |
---|
| 200 | then |
---|
| 201 | HOPT_FFLAGS="%FAST_FFLAGS $COMPIL_FFLAGS" |
---|
| 202 | COMPIL_FFLAGS="%PROD_FFLAGS $COMPIL_FFLAGS" |
---|
| 203 | elif [[ "$compil_mode" == "dev" ]] |
---|
| 204 | then |
---|
| 205 | COMPIL_FFLAGS="%DEV_FFLAGS $COMPIL_FFLAGS" |
---|
| 206 | HOPT_FFLAGS=$COMPIL_FFLAGS |
---|
| 207 | elif [[ "$compil_mode" == "debug" ]] |
---|
| 208 | then |
---|
| 209 | COMPIL_FFLAGS="%DEBUG_FFLAGS $COMPIL_FFLAGS" |
---|
| 210 | HOPT_FFLAGS=$COMPIL_FFLAGS |
---|
| 211 | fi |
---|
| 212 | |
---|
[12] | 213 | rm -f config.fcm |
---|
| 214 | |
---|
[488] | 215 | echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> config.fcm |
---|
[828] | 216 | echo "%HOPT_FFLAGS %BASE_FFLAGS $HOPT_FFLAGS" >> config.fcm |
---|
[152] | 217 | echo "%LD_FLAGS $LD_FLAGS" >> config.fcm |
---|
[28] | 218 | echo "%CPP_KEY $CPP_KEY" >> config.fcm |
---|
| 219 | echo "%LIB $ICOSA_LIB">> config.fcm |
---|
[347] | 220 | echo "%IOIPSL_PATH $ioipsl_path">> config.fcm |
---|
| 221 | echo "%USE_IOIPSL $use_ioipsl">> config.fcm |
---|
[12] | 222 | |
---|
[835] | 223 | # generate signature |
---|
| 224 | function signature() |
---|
| 225 | { |
---|
| 226 | cat <<EOF |
---|
[1009] | 227 | ! Signature file generated by make_icosa. |
---|
| 228 | ! Please do NOT track with svn. |
---|
[835] | 229 | MODULE signature_mod |
---|
| 230 | IMPLICIT NONE |
---|
| 231 | CONTAINS |
---|
| 232 | SUBROUTINE print_signature |
---|
| 233 | EOF |
---|
| 234 | (cd -P src ; svn info .. ; svn status -q) | (while read line ; do echo " PRINT *, '$line' " ; done) |
---|
| 235 | cat <<EOF |
---|
| 236 | END SUBROUTINE print_signature |
---|
| 237 | END MODULE signature_mod |
---|
| 238 | EOF |
---|
| 239 | } |
---|
| 240 | |
---|
[841] | 241 | signature > signature.f90 |
---|
| 242 | diff -q signature.f90 src/base/signature.f90 || cp -f signature.f90 src/base/ |
---|
| 243 | rm -f signature.f90 |
---|
[835] | 244 | |
---|
[89] | 245 | if [[ "$full_defined" == "TRUE" ]] |
---|
| 246 | then |
---|
| 247 | ./build --job $job --full |
---|
| 248 | else |
---|
| 249 | ./build --job $job |
---|
| 250 | fi |
---|
[747] | 251 | |
---|
| 252 | # force recompilation of cython modules |
---|
[981] | 253 | touch Python/*/*.pyx |
---|