| 1 | #!/bin/bash |
|---|
| 2 | export PATH=$PWD/tools/FCM/bin:$PATH |
|---|
| 3 | |
|---|
| 4 | export ROOT=$PWD |
|---|
| 5 | #set -x |
|---|
| 6 | echo $0 $* > rebuild_all |
|---|
| 7 | chmod a+x rebuild_all |
|---|
| 8 | |
|---|
| 9 | compil_mode_defined="FALSE" |
|---|
| 10 | compil_mode="prod" |
|---|
| 11 | |
|---|
| 12 | job=1 |
|---|
| 13 | full_defined="FALSE" |
|---|
| 14 | with_xios_defined="TRUE" |
|---|
| 15 | with_orchidee_defined="FALSE" |
|---|
| 16 | arch_defined="FALSE" |
|---|
| 17 | parallel_defined="FALSE" |
|---|
| 18 | arch_path="../ARCH" |
|---|
| 19 | arch_default_path="arch" |
|---|
| 20 | parallel="none" |
|---|
| 21 | physics="none" |
|---|
| 22 | build_deps="TRUE" |
|---|
| 23 | CPP_KEY="CPP_NONE" |
|---|
| 24 | ICOSA_LIB="" |
|---|
| 25 | |
|---|
| 26 | while (($# > 0)) |
|---|
| 27 | do |
|---|
| 28 | case $1 in |
|---|
| 29 | "-h") cat <<fin |
|---|
| 30 | Usage : |
|---|
| 31 | make_icosa_lmdz [options] -arch arch_name -p phys |
|---|
| 32 | [-h] : help |
|---|
| 33 | [-prod / -dev / -debug] : compilation mode: production (default) / developpement / debug . |
|---|
| 34 | [-full] : recompile all code from scratch |
|---|
| 35 | [-nodeps] : do not build dependencies (XIOS and IOIPSL libraries) |
|---|
| 36 | -arch arch_name : target architecture |
|---|
| 37 | [-arch_path path] : relative PATH to directory containing multi-model |
|---|
| 38 | path and environment arch files |
|---|
| 39 | -p phys : physics package (e.g. std , venus , mars, ...) |
|---|
| 40 | [-p_opt "options"] : additional options for physics package |
|---|
| 41 | [-parallel type] : parallelism (none|mpi|omp|mpi_omp) |
|---|
| 42 | [-with_xios] : compile and link with XIOS (default) |
|---|
| 43 | [-job num] : speed up compilation by using num simulateneous |
|---|
| 44 | compilation steps (when possible) |
|---|
| 45 | fin |
|---|
| 46 | exit;; |
|---|
| 47 | |
|---|
| 48 | "-p") |
|---|
| 49 | phys=$2 ; shift ; shift ;; |
|---|
| 50 | |
|---|
| 51 | "-p_opt") |
|---|
| 52 | phys_opt=$2 ; shift ; shift ;; |
|---|
| 53 | |
|---|
| 54 | "-prod") |
|---|
| 55 | compil_mode="prod" ; shift ;; |
|---|
| 56 | |
|---|
| 57 | "-dev") |
|---|
| 58 | compil_mode="dev" ; shift ;; |
|---|
| 59 | |
|---|
| 60 | "-debug") |
|---|
| 61 | compil_mode="debug" ; shift ;; |
|---|
| 62 | |
|---|
| 63 | "-arch") |
|---|
| 64 | arch=$2 ; arch_defined="TRUE"; shift ; shift ;; |
|---|
| 65 | |
|---|
| 66 | "-arch_path") |
|---|
| 67 | arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;; |
|---|
| 68 | |
|---|
| 69 | "-parallel") |
|---|
| 70 | parallel=$2 ; parallel_defined="TRUE"; shift ; shift ;; |
|---|
| 71 | |
|---|
| 72 | "-job") |
|---|
| 73 | job=$2 ; shift ; shift;; |
|---|
| 74 | |
|---|
| 75 | "-full") |
|---|
| 76 | full_defined="TRUE" ; shift ;; |
|---|
| 77 | |
|---|
| 78 | "-nodeps") |
|---|
| 79 | build_deps="FALSE" ; shift ;; |
|---|
| 80 | |
|---|
| 81 | "-with_xios") |
|---|
| 82 | with_xios_defined="TRUE" ; shift ;; |
|---|
| 83 | |
|---|
| 84 | "-with_orchidee") |
|---|
| 85 | with_orchidee_defined="TRUE" ; shift ;; |
|---|
| 86 | |
|---|
| 87 | *) |
|---|
| 88 | code="$1" ; shift ;; |
|---|
| 89 | esac |
|---|
| 90 | done |
|---|
| 91 | |
|---|
| 92 | rm -f .void_file |
|---|
| 93 | echo > .void_file |
|---|
| 94 | rm -rf .void_dir |
|---|
| 95 | mkdir .void_dir |
|---|
| 96 | |
|---|
| 97 | if [[ "$arch_defined" == "TRUE" ]] |
|---|
| 98 | then |
|---|
| 99 | rm -f arch.path |
|---|
| 100 | rm -f arch.fcm |
|---|
| 101 | rm -f arch.env |
|---|
| 102 | |
|---|
| 103 | if test -f $arch_path/arch-${arch}.path |
|---|
| 104 | then |
|---|
| 105 | ln -s $arch_path/arch-${arch}.path arch.path |
|---|
| 106 | elif test -f $arch_default_path/arch-${arch}.path |
|---|
| 107 | then |
|---|
| 108 | ln -s $arch_default_path/arch-${arch}.path arch.path |
|---|
| 109 | fi |
|---|
| 110 | |
|---|
| 111 | if test -f $arch_path/arch-${arch}.fcm |
|---|
| 112 | then |
|---|
| 113 | ln -s $arch_path/arch-${arch}.fcm arch.fcm |
|---|
| 114 | elif test -f $arch_default_path/arch-${arch}.fcm |
|---|
| 115 | then |
|---|
| 116 | ln -s $arch_default_path/arch-${arch}.fcm arch.fcm |
|---|
| 117 | fi |
|---|
| 118 | |
|---|
| 119 | if test -f $arch_path/arch-${arch}.env |
|---|
| 120 | then |
|---|
| 121 | ln -s $arch_path/arch-${arch}.env arch.env |
|---|
| 122 | elif test -f $arch_default_path/arch-${arch}.env |
|---|
| 123 | then |
|---|
| 124 | ln -s $arch_default_path/arch-${arch}.env arch.env |
|---|
| 125 | else |
|---|
| 126 | ln -s .void_file arch.env |
|---|
| 127 | fi |
|---|
| 128 | source arch.env |
|---|
| 129 | source arch.path |
|---|
| 130 | else |
|---|
| 131 | echo "Please define a target architecture" |
|---|
| 132 | exit 1 |
|---|
| 133 | fi |
|---|
| 134 | |
|---|
| 135 | LD_FLAGS="%BASE_LD" |
|---|
| 136 | |
|---|
| 137 | if [[ "$compil_mode" == "prod" ]] |
|---|
| 138 | then |
|---|
| 139 | COMPIL_FFLAGS="%PROD_FFLAGS" |
|---|
| 140 | elif [[ "$compil_mode" == "dev" ]] |
|---|
| 141 | then |
|---|
| 142 | COMPIL_FFLAGS="%DEV_FFLAGS" |
|---|
| 143 | elif [[ "$compil_mode" == "debug" ]] |
|---|
| 144 | then |
|---|
| 145 | COMPIL_FFLAGS="%DEBUG_FFLAGS" |
|---|
| 146 | fi |
|---|
| 147 | |
|---|
| 148 | if [[ "$parallel" == "mpi" ]] |
|---|
| 149 | then |
|---|
| 150 | CPP_KEY="$CPP_KEY CPP_USING_MPI" |
|---|
| 151 | elif [[ "$parallel" == "omp" ]] |
|---|
| 152 | then |
|---|
| 153 | CPP_KEY="$CPP_KEY CPP_USING_OMP" |
|---|
| 154 | COMPIL_FFLAGS="$COMPIL_FFLAGS %OMP_FFLAGS" |
|---|
| 155 | LD_FLAGS="$LD_FLAGS %OMP_LD" |
|---|
| 156 | elif [[ "$parallel" == "mpi_omp" ]] |
|---|
| 157 | then |
|---|
| 158 | CPP_KEY="$CPP_KEY CPP_USING_MPI CPP_USING_OMP" |
|---|
| 159 | COMPIL_FFLAGS="$COMPIL_FFLAGS %OMP_FFLAGS" |
|---|
| 160 | LD_FLAGS="$LD_FLAGS %OMP_LD" |
|---|
| 161 | elif [[ "$parallel" == "none" ]] |
|---|
| 162 | then |
|---|
| 163 | parallel="none" |
|---|
| 164 | else |
|---|
| 165 | echo "-parallel value $parallel is invalid, only permited <none>, <mpi>, <omp> or <mpi_omp>" |
|---|
| 166 | exit 1 |
|---|
| 167 | fi |
|---|
| 168 | |
|---|
| 169 | if [[ "$with_orchidee_defined" == "TRUE" ]] |
|---|
| 170 | then |
|---|
| 171 | ICOSA_LIB="$ICOSA_LIB $ORCHIDEE_LIBDIR $ORCHIDEE_LIB" |
|---|
| 172 | fi |
|---|
| 173 | |
|---|
| 174 | if [[ "$with_xios_defined" == "TRUE" ]] |
|---|
| 175 | then |
|---|
| 176 | CPP_KEY="$CPP_KEY CPP_USING_XIOS" |
|---|
| 177 | COMPIL_FFLAGS="$COMPIL_FFLAGS $XIOS_INCDIR" |
|---|
| 178 | ICOSA_LIB="$ICOSA_LIB $XIOS_LIBDIR $XIOS_LIB" |
|---|
| 179 | fi |
|---|
| 180 | |
|---|
| 181 | ICOSA_LIB="$ICOSA_LIB $IOIPSL_LIBDIR $IOIPSL_LIB $NETCDF_LIBDIR $NETCDF_LIB $HDF5_LIBDIR $HDF5_LIB" |
|---|
| 182 | |
|---|
| 183 | rm bin/* |
|---|
| 184 | |
|---|
| 185 | if [[ "$full_defined" == "TRUE" ]] |
|---|
| 186 | then |
|---|
| 187 | full_flag="-full" |
|---|
| 188 | full_flag2="--full" |
|---|
| 189 | else |
|---|
| 190 | full_flag="" |
|---|
| 191 | full_flag2="" |
|---|
| 192 | fi |
|---|
| 193 | |
|---|
| 194 | rm -f config.fcm |
|---|
| 195 | |
|---|
| 196 | echo "%COMPIL_FFLAGS $COMPIL_FFLAGS $NETCDF_INCDIR" >> config.fcm |
|---|
| 197 | echo "%LD_FLAGS $LD_FLAGS" >> config.fcm |
|---|
| 198 | echo "%CPP_KEY $CPP_KEY" >> config.fcm |
|---|
| 199 | echo "%PHYS phy$phys" >> config.fcm |
|---|
| 200 | echo "%LIB $ICOSA_LIB">> config.fcm |
|---|
| 201 | |
|---|
| 202 | function compile_module { |
|---|
| 203 | ## function to compile each module. |
|---|
| 204 | dir=$1 # module folder |
|---|
| 205 | shift |
|---|
| 206 | cmd=$@ # command line to compile |
|---|
| 207 | if [[ -d ../$dir ]] ; then |
|---|
| 208 | cd ../$dir |
|---|
| 209 | echo "-- Compiling $dir with:" |
|---|
| 210 | echo $cmd |
|---|
| 211 | $cmd |
|---|
| 212 | if [ $? != 0 ]; then # check if fcm command worked |
|---|
| 213 | echo "In ../$dir, the following command failed:" |
|---|
| 214 | echo "$cmd" |
|---|
| 215 | exit 1 |
|---|
| 216 | fi |
|---|
| 217 | |
|---|
| 218 | cd - |
|---|
| 219 | else |
|---|
| 220 | echo "Error: cannot find ../$dir directory" |
|---|
| 221 | exit 1 |
|---|
| 222 | fi |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | if [[ "$build_deps" == "TRUE" ]] |
|---|
| 226 | then |
|---|
| 227 | compile_module IOIPSL ./makeioipsl_fcm -parallel -arch $arch -arch_path $arch_path -j $job $full_flag |
|---|
| 228 | compile_module XIOS ./make_xios --arch $arch --arch_path $arch_path --job $job $full_flag2 |
|---|
| 229 | fi # of if [[ "$build_deps" == "TRUE" ]] |
|---|
| 230 | |
|---|
| 231 | compile_module LMDZ.COMMON ./makelmdz_fcm -p $phys $phys_opt -$compil_mode -parallel $parallel -libphy -io xios -arch $arch -arch_path $arch_path -j $job $full_flag |
|---|
| 232 | |
|---|
| 233 | compile_module ICOSAGCM ./make_icosa -$compil_mode -parallel $parallel -external_ioipsl -with_xios -arch $arch -arch_path $arch_path -job $job $full_flag |
|---|
| 234 | |
|---|
| 235 | # compile interface and link |
|---|
| 236 | ./build --job $job $full_flag2 |
|---|