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 | if [[ "$build_deps" == "TRUE" ]] |
---|
203 | then |
---|
204 | |
---|
205 | if [[ -d ../IOIPSL ]] ; then |
---|
206 | cd ../IOIPSL |
---|
207 | ./makeioipsl_fcm -parallel -arch $arch -arch_path $arch_path -j $job $full_flag || exit 1 |
---|
208 | cd - |
---|
209 | else |
---|
210 | echo "Error: cannot find ../IOIPSL directory" |
---|
211 | exit |
---|
212 | fi |
---|
213 | |
---|
214 | if [[ -d ../XIOS ]] ; then |
---|
215 | cd ../XIOS |
---|
216 | ./make_xios --arch $arch --arch_path $arch_path --job $job $full_flag2 || exit 1 |
---|
217 | cd - |
---|
218 | else |
---|
219 | echo "Error: cannot find ../XIOS directory" |
---|
220 | exit |
---|
221 | fi |
---|
222 | |
---|
223 | fi # of if [[ "$build_deps" == "TRUE" ]] |
---|
224 | |
---|
225 | if [[ -d ../LMDZ.COMMON ]] ; then |
---|
226 | cd ../LMDZ.COMMON |
---|
227 | echo "Compiling LMDZ.COMMON with:" |
---|
228 | cmd="./makelmdz_fcm -p $phys $phys_opt -$compil_mode -parallel $parallel -libphy -io xios -arch $arch -arch_path $arch_path -j $job $full_flag" |
---|
229 | echo $cmd |
---|
230 | $cmd || (echo "Failed compilation of LMDZ.COMMON. Command line was:" && echo $cmd && exit 1) |
---|
231 | cd - |
---|
232 | else |
---|
233 | echo "Error: cannot find ../LMDZ.COMMON directory" |
---|
234 | exit |
---|
235 | fi |
---|
236 | |
---|
237 | if [[ -d ../ICOSAGCM ]] ; then |
---|
238 | cd ../ICOSAGCM |
---|
239 | # from now on, compile using fcm2 |
---|
240 | echo "Compiling ICOSAGCM with:" |
---|
241 | cmd="./make_icosa -$compil_mode -parallel $parallel -external_ioipsl -with_xios -arch $arch -arch_path $arch_path -job $job $full_flag" |
---|
242 | echo "$cmd" |
---|
243 | $cmd || (echo "Failed compilation of ICOSAGCM. Command line was:" && echo $cmd && exit 1) |
---|
244 | cd - |
---|
245 | else |
---|
246 | echo "Error: cannot find ../ICOSAGCM directory" |
---|
247 | exit |
---|
248 | fi |
---|
249 | |
---|
250 | # compile interface and link |
---|
251 | ./build --job $job $full_flag2 |
---|