source: CONFIG_DEVT/IPSLCM6.5_work_ENSEMBLES/oasis3-mct/util/make_dir/TopMakefileOasis3 @ 5725

Last change on this file since 5725 was 5725, checked in by aclsce, 3 years ago

Added new oasis3-MCT version to be used to handle ensembles simulations with XIOS.

  • Property svn:executable set to *
File size: 13.4 KB
Line 
1##############################################################################
2
3# This is the top makefile for compiling OASIS3-MCT coupling library including
4#   static and shared versions of mct/mpeu, scrip, psmile
5#   (i.e. interpolation and communication), and c-bindings
6# Platform dependent settings, compiler options, cpp keys,
7#   paths has to be set in an include file indicated in make.inc.
8# Extra targets and paths are defined in the automatically included make.common
9
10# for basic help:
11# gmake -f TopMakefileOasis3 help
12
13########################################################################################
14
15include make.inc
16include make.common
17
18########################################################################################
19
20SHELL = /bin/sh
21ifeq ($(MAKE),gmake)
22MAKEf = $(MAKE) --no-print-directory -f TopMakefileOasis3
23else
24MAKEf = $(MAKE) -f TopMakefileOasis3
25endif
26
27# Defining path for FORTRAN and C sources
28LIBSRC  = $(COUPLE)/lib
29
30# Log and error files for compiling
31LOGSTATIC = $(COUPLE)/util/make_dir/COMP.log
32ERRSTATIC = $(COUPLE)/util/make_dir/COMP.err
33# Log and error files for compiling the shared libraries
34LOGSHARED = $(COUPLE)/util/make_dir/COMP-shared.log
35ERRSHARED = $(COUPLE)/util/make_dir/COMP-shared.err
36# Log and error files for installing PyOasis
37LOGPYO = $(COUPLE)/util/make_dir/COMP-pyoasis.log
38ERRPYO = $(COUPLE)/util/make_dir/COMP-pyoasis.err
39
40########################################################################################
41# For backwards compatibility
42
43default: static-libs-fortran
44
45oasis3_psmile: static-libs-fortran
46
47oasis3-psmile: static-libs-fortran
48
49makedirs: makedirs-static
50
51makemct: makemct-static
52
53makelibs: makescrip-static
54
55makepsmile: makepsmile-static
56
57cleanlibs: clean-static
58
59########################################################################################
60
61.DEFAULT:
62        @echo " "
63        @echo "make: *** No rule to make target \`$@\`.  Stop."
64        @$(MAKEf) help
65
66help:
67        @echo " "
68        @echo "TopMakefileOasis3 recommended targets:"
69        @echo "  static-libs         = static oasis libraries including fortran and c-bindings"
70        @echo "  shared-libs         = shared (dynamic) oasis libraries including fortran and c-bindings"
71        @echo "  pyoasis             = builds and installs shared-libs plus higher and intermediate python classes"
72        @echo "  realclean           = cleans and resets the build"
73        @echo "TopMakefileOasis3 alternative targets:"
74        @echo "  oasis3-psmile       = static-libs-fortran (for backwards compatibility)"
75        @echo "  static-libs-fortran = static oasis libraries for fortran only"
76        @echo "  shared-libs-fortran = shared (dynamic) oasis libraries for fortran only"
77        @echo " "
78
79########################################################################################
80
81static-and-shared-libs-fortran: static-libs-fortran shared-libs-fortran
82
83static-libs-fortran: check-vars
84        @echo ""
85        @echo "Compilation of the OASIS3-MCT static libraries"
86        @echo "Build output to $(LOGSTATIC)"
87        @echo "Build errors to $(ERRSTATIC)"
88        @rm -f $(LOGSTATIC) $(ERRSTATIC)
89        $(call check_defined, AR, static lib. archiver command)
90        $(call check_defined, ARFLAGS, static lib. archiver options)
91        @$(MAKEf) makedirs-static
92        @$(MAKEf) makemct-static
93        @$(MAKEf) makescrip-static
94        @$(MAKEf) makepsmile-static
95        @(echo "DONE" ; echo "")
96
97shared-libs-fortran: check-vars
98        @echo ""
99        @echo "Compilation of the OASIS3-MCT shared libraries"
100        @echo "Build output to $(LOGSHARED)"
101        @echo "Build errors to $(ERRSHARED)"
102        @rm -f $(LOGSHARED) $(ERRSHARED)
103        $(call check_defined, DYNOPT LDDYNOPT, shared lib. compilation options)
104        @$(MAKEf) makedirs-shared
105        @$(MAKEf) makemct-shared
106        @$(MAKEf) makescrip-shared
107        @$(MAKEf) makepsmile-shared
108        @(echo "DONE" ; echo "")
109
110static-libs: static-libs-fortran
111        @echo "Compilation of the OASIS3-MCT C bindings static libraries"
112        @echo "Build output to $(LOGSTATIC)"
113        @echo "Build errors to $(ERRSTATIC)"
114        @$(MAKEf) makecbindings-static
115        @(echo "DONE" ; echo "")
116
117shared-libs: shared-libs-fortran
118        @echo "Compilation of the OASIS3-MCT C bindings shared libraries"
119        @echo "Build output to $(LOGSHARED)"
120        @echo "Build errors to $(ERRSHARED)"
121        @$(MAKEf) makecbindings-shared
122        @(echo "DONE" ; echo "")
123
124pyoasis: shared-libs
125        @echo "Installation of PyOasis"
126        @echo "Build output to $(LOGPYO)"
127        @echo "Build errors to $(ERRPYO)"
128        @rm -f $(LOGPYO) $(ERRPYO)
129        $(call check_defined, MPIRUN, mpi launcher mnemonic helper)
130        @$(MAKEf) makedirs-py
131        @$(MAKEf) makepyoasis
132        @(echo "DONE" ; echo "")
133
134realclean: check-vars
135        $(MAKEf) clean-static clean-shared clean-pyoasis
136
137########################################################################################
138# Rules for creating build and library directories
139
140makedirs-static:
141        @echo "=> Creating directories for compiling the static libraries"
142        @echo "   in $(LIBBUILD)"
143        @mkdir -p $(LIBBUILD)/scrip
144        @mkdir -p $(LIBBUILD)/mctdir
145        @mkdir -p $(LIBBUILD)/mct
146        @mkdir -p $(LIBBUILD)/psmile.$(CHAN)
147        @mkdir -p $(LIBBUILD)/cbindings
148        @mkdir -p $(ARCHDIR)/include
149        @mkdir -p $(ARCHDIR)/lib
150
151makedirs-shared:
152        @echo "=> Creating directories for compiling the shared libraries"
153        @echo "   in $(LIBBUILDSHARED)"
154        @mkdir -p $(LIBBUILDSHARED)/scrip
155        @mkdir -p $(LIBBUILDSHARED)/mctdir
156        @mkdir -p $(LIBBUILDSHARED)/mct
157        @mkdir -p $(LIBBUILDSHARED)/psmile.$(CHAN)
158        @mkdir -p $(LIBBUILDSHARED)/cbindings
159        @mkdir -p $(ARCHDIR)/include
160        @mkdir -p $(ARCHDIR)/lib
161
162makedirs-py:
163        @echo "=> Creating pyoasis installation path"
164        @mkdir -p $(ARCHDIR)/python/pyoasis
165
166########################################################################################
167# Rules for cleaning
168
169clean-static:
170        @echo cleaning oasis3-mct static libraries
171        rm -r -f $(LIBBUILD)/scrip
172        rm -r -f $(LIBBUILD)/mct
173        rm -r -f $(LIBBUILD)/mctdir
174        rm -r -f $(LIBBUILD)/psmile.$(CHAN)
175        rm -r -f $(ARCHDIR)/include
176        rm -r -f $(LIBBUILD)/cbindings
177        rm -f $(ARCHDIR)/lib/libscrip.a
178        rm -f $(ARCHDIR)/lib/libmct.a
179        rm -f $(ARCHDIR)/lib/libmpeu.a
180        rm -f $(ARCHDIR)/lib/libpsmile.$(CHAN).a
181        rm -f $(ARCHDIR)/lib/liboasis.cbind.a
182
183clean-shared:
184        @echo cleaning oasis3-mct shared libraries
185        rm -r -f $(LIBBUILDSHARED)/scrip
186        rm -r -f $(LIBBUILDSHARED)/mct
187        rm -r -f $(LIBBUILDSHARED)/mctdir
188        rm -r -f $(LIBBUILDSHARED)/psmile.$(CHAN)
189        rm -r -f $(LIBBUILDSHARED)/cbindings
190        rm -r -f $(ARCHDIR)/include
191        rm -f $(ARCHDIR)/lib/libscrip.so
192        rm -f $(ARCHDIR)/lib/libmct.so
193        rm -f $(ARCHDIR)/lib/libmpeu.so
194        rm -f $(ARCHDIR)/lib/libpsmile.$(CHAN).so
195        rm -f $(ARCHDIR)/lib/liboasis.cbind.so
196
197clean-pyoasis:
198        @echo cleaning pyoasis
199        rm -r -f $(ARCHDIR)/python
200
201########################################################################################
202# Rules for compiling mpeu/mct library
203
204makemct-static:
205        @echo "=> Configuring libraries mpeu and mct"
206        @(cd $(LIBBUILD)/mctdir; cp -f -r -p $(LIBSRC)/mct/* .;\
207         ./configure MPIFC="$(F90)" FC="$(F90)" CC="$(CC)" \
208         1>> $(LOGSTATIC) 2>> $(ERRSTATIC) ;)
209        @echo "=> Compiling libraries mpeu and mct"
210        @(cd $(LIBBUILD)/mctdir; \
211         $(MAKE) 1>> $(LOGSTATIC) 2>> $(ERRSTATIC) ;)
212        @echo "=> Installing libraries mpeu and mct"
213        @(cd $(LIBBUILD)/mctdir; \
214         cp -f ./*/lib*.a   $(ARCHDIR)/lib/; \
215         cp -f ./*/*.o    $(LIBBUILD)/mct/; \
216         cp -f ./*/*.mod  $(LIBBUILD)/mct/; \
217         cp -f ./*/*.mod  $(ARCHDIR)/include/;)
218
219makemct-shared:
220        @echo "=> Configuring shared libraries mpeu and mct"
221        @(cd $(LIBBUILDSHARED)/mctdir; cp -f -r -p $(LIBSRC)/mct/* .;\
222         ./configure MPIFC="$(F90) $(DYNOPT)" FC="$(F90) $(DYNOPT)" CC="$(CC) $(DYNOPT)" \
223         1>> $(LOGSHARED) 2>> $(ERRSHARED) ;)
224        @echo "=> Compiling shared libraries mpeu and mct"
225        @(cd $(LIBBUILDSHARED)/mctdir; \
226         $(MAKE) 1>> $(LOGSHARED) 2>> $(ERRSHARED) ; )
227        @echo "=> Creating shared library libmpeu.so"
228        @(cd $(LIBBUILDSHARED)/mctdir ; \
229         $(F90) $(DYNOPT) $(LDFLAGS) $(LDDYNOPT) \
230         -o $(ARCHDIR)/lib/libmpeu.so ./mpeu/*.o $(NETCDF_LIBRARY); )
231        @echo "=> Creating shared library libmct.so"
232        @(cd $(LIBBUILDSHARED)/mctdir ; \
233         $(F90) $(DYNOPT) $(LDFLAGS) $(LDDYNOPT) \
234         -o $(ARCHDIR)/lib/libmct.so ./mct/*.o -L$(ARCHDIR)/lib -lmpeu $(NETCDF_LIBRARY); )
235        @echo "=> Installing shared libraries mpeu and mct"
236        @(cd $(LIBBUILDSHARED)/mctdir ; \
237         cp -f ./*/*.o    $(LIBBUILDSHARED)/mct/; \
238         cp -f ./*/*.mod  $(LIBBUILDSHARED)/mct/; \
239         cp -f ./*/*.mod  $(ARCHDIR)/include/;)
240
241########################################################################################
242# Rules for compiling the libraries scrip
243
244makescrip-static:
245        @echo "=> Compiling library scrip"
246        @(cd $(LIBBUILD)/scrip; cp -f $(LIBSRC)/scrip/src/Makefile .;\
247         $(modifmakefile) ; $(MAKE) all 1>> $(LOGSTATIC) 2>> $(ERRSTATIC) )
248        @echo "=> Installing scrip modules"
249        @(cd $(LIBBUILD)/scrip ; \
250         cp -f *.mod  $(ARCHDIR)/include/;)
251
252makescrip-shared:
253        @echo "=> Compiling shared library scrip"
254        @(cd $(LIBBUILDSHARED)/scrip; cp -f $(LIBSRC)/scrip/src/Makefile .;\
255         $(modifmakefile) ; $(MAKE) shared 1>> $(LOGSHARED) 2>> $(ERRSHARED) )
256        @echo "=> Installing scrip modules"
257        @(cd $(LIBBUILDSHARED)/scrip ; \
258         cp -f *.mod  $(ARCHDIR)/include/;)
259
260########################################################################################
261# Rules for compiling the libraries psmile
262
263makepsmile-static:
264        @echo "=> Compiling library psmile"
265        @(cd $(LIBBUILD)/psmile.$(CHAN) ; \
266         cp -f $(LIBSRC)/psmile/src/Makefile . ; $(modifmakefile) ; \
267         $(MAKE) all 1>> $(LOGSTATIC) 2>> $(ERRSTATIC) ; )
268        @echo "=> Installing library psmile"
269        @(cd $(LIBBUILD)/psmile.$(CHAN) ; \
270         cp -f *.mod $(ARCHDIR)/include ; )
271
272makepsmile-shared:
273        @echo "=> Compiling shared library psmile"
274        @(cd $(LIBBUILDSHARED)/psmile.$(CHAN) ; \
275         cp -f $(LIBSRC)/psmile/src/Makefile . ; $(modifmakefile) ; \
276         $(MAKE) shared 1>> $(LOGSHARED) 2>> $(ERRSHARED) ; )
277        @echo "=> Installing shared library psmile"
278        @(cd $(LIBBUILDSHARED)/psmile.$(CHAN) ; \
279         cp -f *.mod $(ARCHDIR)/include ; )
280
281########################################################################################
282# Rules for compiling the oasis C bindings
283
284makecbindings-static:
285        @echo "=> Compiling the C bindings static"
286        @(cd $(LIBBUILD)/cbindings ; \
287         cp -f -r -p $(LIBSRC)/cbindings/Makefile .; $(modifmakefile) ; \
288         $(MAKE) libstatic 1>> $(LOGSTATIC) 2>> $(ERRSTATIC) )
289        @echo "=> Installing cbindings modules"
290        @(cd $(LIBBUILD)/cbindings ; \
291         cp -f *.mod  $(ARCHDIR)/include/;)
292
293makecbindings-shared:
294        @echo "=> Compiling the C bindings shared"
295        @(cd $(LIBBUILDSHARED)/cbindings ; \
296         cp -f -r -p $(LIBSRC)/cbindings/Makefile .; $(modifmakefile) ; \
297         $(MAKE) libshared 1>> $(LOGSHARED) 2>> $(ERRSHARED) )
298        @echo "=> Installing cbindings modules"
299        @(cd $(LIBBUILDSHARED)/cbindings ; \
300         cp -f *.mod  $(ARCHDIR)/include/;)
301
302########################################################################################
303# Rules for installing the PyOasis python modules
304
305makepyoasis:
306        @echo "=> Installing the PyOasis Modules"
307        @(cp -f -r -p $(COUPLE)/pyoasis/src/* $(ARCHDIR)/python/pyoasis \
308          1>> $(LOGPYO) 2>> $(ERRPYO) )
309        @echo export PYOASIS_ROOT=${ARCHDIR} > ${ARCHDIR}/python/init.sh
310        @echo setenv PYOASIS_ROOT ${ARCHDIR} > ${ARCHDIR}/python/init.csh
311        @echo export LD_LIBRARY_PATH=\$${PYOASIS_ROOT}/lib:\$${LD_LIBRARY_PATH} >> ${ARCHDIR}/python/init.sh
312        @echo setenv LD_LIBRARY_PATH \$${PYOASIS_ROOT}/lib:\$${LD_LIBRARY_PATH} >> ${ARCHDIR}/python/init.csh
313        @echo export PYTHONPATH=\$${PYOASIS_ROOT}/python:\$${PYTHONPATH} >> ${ARCHDIR}/python/init.sh
314        @echo setenv PYTHONPATH \$${PYOASIS_ROOT}/python:\$${PYTHONPATH} >> ${ARCHDIR}/python/init.csh
315        @echo export MPIRUN4PY=\"${MPIRUN}\" >> ${ARCHDIR}/python/init.sh
316        @echo setenv MPIRUN4PY \"${MPIRUN}\" >> ${ARCHDIR}/python/init.csh
317        @echo
318        @echo =====================================================================
319        @echo The following lines have been put in the file
320        @echo \"${ARCHDIR}/python/init.sh\"
321        @echo
322        @cat ${ARCHDIR}/python/init.sh
323        @echo
324        @echo The following lines have been put in the file
325        @echo \"${ARCHDIR}/python/init.csh\"
326        @echo
327        @cat ${ARCHDIR}/python/init.csh
328        @echo
329        @echo Before using pyOASIS issue the command:
330        @echo \"source ${ARCHDIR}/python/init.sh\"
331        @echo    or
332        @echo \"source ${ARCHDIR}/python/init.csh\"
333        @echo Alternatively, these lines could be added to your \"\~/.bashrc\" or \"\~/.cshrc\" file.
334        @echo =====================================================================
335        @echo
336
337########################################################################################
338# Rules for checks
339
340check-vars:
341        $(call check_defined, COUPLE, Root of the source directory)
342        $(call check_defined, ARCHDIR, Root of the installation path)
343        $(call check_defined, CHAN, MPI flavour MPI1/MPI2)
344        $(call check_defined, MAKE, the make command make/gmake)
345        $(call check_defined, F90 F f90 f CC, compiler command)
346        $(call check_defined, F90FLAGS f90FLAGS FFLAGS fFLAGS CCFLAGS, \
347                              compilation options)
348
349# Params:
350#   1. Variable name(s) to test.
351#   2. (optional) Error message to print.
352check_defined = \
353    $(strip $(foreach 1,$1, \
354        $(call __check_defined,$1,$(strip $(value 2)))))
355__check_defined = \
356    $(if $(value $1),, \
357      $(error Undefined $1$(if $2, ($2))))
358
359########################################################################################
360# Some rules to modify/add variables in makefiles
361
362modifmakefile = ( echo 'include $(COUPLE)/util/make_dir/make.inc'  > infile;\
363                  echo 'include $(COUPLE)/util/make_dir/make.common' >> infile;\
364                  cat Makefile >> infile ; \
365                  cp -f infile Makefile )
366
367########################################################################################
Note: See TracBrowser for help on using the repository browser.