source: CPL/oasis3/trunk/util/compile/frames/include_moon/COMP_libs.moon @ 1991

Last change on this file since 1991 was 1677, checked in by aclsce, 10 years ago

Imported oasis3 (tag ipslcm5a) from cvs server to svn server (igcmg project).

File size: 13.5 KB
Line 
1#! /bin/ksh
2
3
4################################################################################
5#
6#     C O M P I L E  -  script for maintaining PRISM libraries.
7#                                                                       
8#     File       : ~/util/COMP_libs
9#
10#     This script is used to compile or clean any PRISM library.
11#     This include libraries used exclusively in any of the models
12#     or those used by the coupler only, or those shared by the models.
13#     
14#     When needed, different versions of the libraries are created.
15#     At the moment these are MPI1/MPI2 libraries. 
16#     
17#     This script is called directly by the administrator or SMS
18#     or by the model's compile scripts (on scripting level).
19#     When called by the model's compile scripts it checks and updates
20#     the libraries needed to compile the models and only those.
21#     
22################################################################################
23#
24#     4 positional parameters are possible:
25#                               $1=make_target       (optional)
26#                               $2=list_of_libraries (optional)
27#                               $3=message_passing   (optional)
28#                               $4=calling_model     (optional)
29#
30#     Usage : COMP_libs        ["make_target" ["list_of_libraries" \
31#                              ["message_passing"  \
32#                              ["calling_model"]]]]
33#
34#     If called with no parameters, the defaults given below
35#     are used. If parameter n is specified; the parameter 1,...n-1
36#     must be specified as well.
37#     Note: parameter 4 is not used on the scripting level.
38#
39################################################################################
40
41set -e
42
43################### Start of user specifications (defaults) ####################
44#
45
46# message_passing                       : NONE   /  MPI 2/1
47
48message_passing=MPI1
49
50# coupler                               : oasis3
51# use_key_noIO                          : whether mpp_io will be used for I/O
52# 
53coupler=oasis3
54use_key_noIO=no
55
56# list_of_libraries  : any list of PRISM libraries possible
57# compile mode       : default/opt/..
58
59#compile_mode=default
60compile_mode=debug
61
62use_NetCDF=yes
63
64list_of_libraries=" anaisg anaism clim fscint mpp_io psmile scrip"
65
66# make_target                           : clean/all/tar/lib
67make_target=all
68
69######################## Command line parameter  ###############################
70# 
71# Help function
72#
73if [ "$1" = "--" ] || [ "$1" = "help" ] || [ "$1" = "--help" ] ; then
74  echo
75  echo '----------- Usage -----------------------------------------------'
76  echo ' $1=make_target       (all/tar/clean; optional)'
77  echo ' $2=list_of_libraries (anaisg/anaism/clim/etc.; optional)'
78  echo ' $3=message_passing   (NONE/MPI1/MPI2; optional)'
79  echo ' '
80  echo ' Default active values are:'
81  echo ' make_target       : '${make_target}
82  echo ' list_of_libraries : '${list_of_libraries}
83  echo ' message_passing   : '${message_passing}
84  echo '-----------------------------------------------------------------'
85  exit 1
86fi
87
88# Overwrite with command line parameter if specified
89
90[ "$1" = "" ] || make_target=$1
91[ "$3" = "" ] || message_passing=$3
92#
93# if no message passing is specified, only compile the interpolation libraries
94#
95
96if [ ${message_passing} = "NONE" ]; then
97  list_of_libraries=" anaisg anaism fscint scrip"
98fi
99
100[ "$2" = "" ] || list_of_libraries=$2
101
102set -u
103
104
105######################## Input checks : all  ########################
106# 
107#
108
109if [ "${make_target}" != "clean" ] && \
110   [ "${make_target}" != "all" ]   && \
111   [ "${make_target}" != "lib" ]   && \
112   [ "${make_target}" != "tar" ];       then 
113  echo " Invalid target : "${make_target}
114  echo " The task is stopped!"
115  exit 1
116fi
117
118if [ "${message_passing}" != "MPI2" ] && \
119   [ "${message_passing}" != "MPI1" ] && \
120   [ "${message_passing}" != "NONE" ];     then 
121  echo " Invalid option for message passing : "${message_passing}
122  echo " The task is stopped!"
123  exit 1
124fi
125
126######################## Input checks : libraries only  ########################
127# 
128
129for library in ${list_of_libraries}; do
130  if [ "${library}" != "anaisg" ]   && \
131     [ "${library}" != "anaism" ]   && \
132     [ "${library}" != "blas" ]     && \
133     [ "${library}" != "clim" ]     && \
134     [ "${library}" != "fscint" ]   && \
135     [ "${library}" != "ioipsl" ]   && \
136     [ "${library}" != "lapack" ]   && \
137     [ "${library}" != "linpack" ]   && \
138     [ "${library}" != "mpp_io" ]   && \
139     [ "${library}" != "netcdf90" ] && \
140     [ "${library}" != "psmile" ]   && \
141     [ "${library}" != "scrip" ]    && \
142     [ "${library}" != "libV4" ]    && \
143     [ "${library}" != "svipc" ]    && \
144     [ "${library}" != "support" ];       then 
145    echo " Invalid library : "${library}
146    echo " The task is stopped!"
147    exit 1
148  fi
149done
150
151
152######################## Set and print input parameter: all  ###################
153# 
154
155export COUPLER=${coupler}
156
157export MAKETARGET=${make_target}
158echo " "
159echo "Make target : "$MAKETARGET
160
161export CHAN=${message_passing}
162
163######################## Set and print input parameters: libs  #################
164# 
165
166export srclibs=${list_of_libraries}
167echo " "
168if [ "$MAKETARGET" = "all" ]; then
169  echo "Libraries which will be updated :" 
170  echo $srclibs
171elif [ "$MAKETARGET" = "clean" ]; then
172  echo "Libraries which will be cleaned :" 
173  echo $srclibs
174elif [ "$MAKETARGET" = "tar" ]; then
175  echo "A tar-file of libraries will be created with:"
176  echo $srclibs
177fi
178
179################################################################################
180# 
181# Libraries for all models
182#
183
184TARFILE_DIRS=""
185for srclib in $srclibs; do
186 TARFILE_DIRS=${TARFILE_DIRS}" src/lib/${srclib}"
187done
188export TARFILE_DIRS
189
190
191
192scriptdir=`dirname $0`
193cd $scriptdir
194export SCRIPTDIR=`pwd`
195node=`uname -n`
196node1_7=`echo ${node} | cut -c1-7`
197if [ ${node1_7} = platine ]; then node=${node1_7}; fi
198
199################################# Prolog  #######################################
200#
201# 'Prolog' : Node name and operating system etc.
202#
203
204export NODE=$node
205
206echo ' '
207echo 'This script runs on node ' $NODE'.'
208
209cd $SCRIPTDIR
210
211cd ..
212export SRCROOT=`pwd`
213# echo 'PRISM top source root directory is '$SRCROOT
214export TARFILE=libs_`date +%y%m%d`.tar
215
216############### Site and OS dependent specifications ###########################
217#
218#                moon :  part of name of header file
219#                NODE   : where the model is compiled
220
221  if   [ ${NODE} != moon ]; then
222  if   [ ${NODE} != moon2 ]; then
223    echo ' The OS/Site dependent specifications are not for this machine.'
224    echo ' Node name of this machine:' ${NODE}
225    echo ' Script setup is for use on a moon node (cross compiling for ES)'
226  if [ "$MAKETARGET" != "tar" ]; then
227    echo ' The task is stopped!'
228    exit 1
229  fi
230  fi
231  fi
232
233  if [ "$MAKETARGET" = "lib" ]; then
234    echo ' '
235    echo 'No executable will be created. '
236  fi
237  export ARCH=ES                                                                 
238  export BLDROOT=$SRCROOT/$ARCH
239
240  set +u
241  if [[ -z "$LD_LIBRARY_PATH0" ]]; then
242    LD_LIBRARY_PATH0=""
243  fi
244  set -u
245
246  export MPI_INCLUDE=./
247
248  export NETCDFROOT=/S/home010/c0010/ES
249  export NETCDF_LIB="-L${NETCDFROOT}/lib -lnetcdf"
250  export NETCDF_INCLUDE=${NETCDFROOT}/include
251
252  export LIB1=" -L/ES/opt/mathkeisan/inst/lib0 -llapack -lblas "
253
254  export SYS_INCLUDE=./
255
256  if [ "$MAKETARGET" = "all" ] || [ "$MAKETARGET" = "lib" ]; then
257    echo ' '
258    echo 'Compiler revision :'
259    echo ` esf90 -V ` 
260  fi
261
262  export F90com=esmpif90
263  export f90com=${F90com}
264  export Fcom=${F90com}
265  export fcom=${F90com}
266
267  export cc=esmpic++
268  export ar=esar
269  export as="esas"
270  export cp=cp
271
272  PATH=$SRCROOT/util:$PATH
273
274  alias make="gmake"
275
276# Compile modes (specified by user): libraries on mercure
277#
278#     Note : - all libraries are compiled with -Pstack
279#            - the models use their own (stack/static) option
280#           
281  if [ $compile_mode = default ];   then
282    optc=" "
283    optl=" "
284    optf=" -Wf,-pvctl noassume "
285    optf77=" -Wf,-pvctl noassume "
286  elif [ $compile_mode = debug ];   then
287    optc=" "
288    optf=" -Wf,-pvctl noassume -ftrace"
289    optf77=" -Wf,-pvctl noassume -ftrace"
290    optl=" -ftrace"
291  elif [ $compile_mode = profile ]; then
292    echo "not yet possible"
293    exit 1
294  elif [ $compile_mode = opt ];     then
295    optc="-Chopt"
296    optf="-Chopt"
297    optf77="-Chopt"
298    optl=" -Wl,-Z 1000000 -pi line=1000"
299  elif [ $compile_mode = ad_hoc ];  then
300    echo "with this option the options are set through GUI input"
301    exit 1
302  else
303    echo "Invalid compile mode"
304    exit 1
305  fi
306
307# Other compile options
308
309  optdbl="-dw -Wf,-A idbl4"
310  optnh=""
311  lstflags="-Wf,-L fmtlist transform"
312#
313# All models should use cpp flag __SX for activation of platform dependent
314#     source code on SUPER-SX machines !
315#
316# `uname -n` : moon (cross compiling only) 
317# `uname -s` : HP-UX
318# `uname -m` : 
319#
320
321  export CPPFLAG="-D__SX -DSX"
322
323  export CPPFLAGF90start=" "
324  export CPPFLAGSEP=" "
325
326  export F90FLAG="-EP ${optf} ${optdbl} ${optnh} ${lstflags}"   
327  export FFLAG="-EP ${optf77} ${optdbl} ${optnh} ${lstflags}"
328  export f90FLAG=${F90FLAG}
329  export fFLAG=${FFLAG}
330
331  export LDFLAG="-Pstack ${optl} ${optdbl} ${optnh}"
332
333  export CCFLAG=${optc}
334
335  export AFLAG="-h float0  -m"
336
337  export ARFLAG="-rv"
338
339  export MPPFLAG=" "
340
341  export I4mods="I"
342
343
344
345################################################################################
346#
347# Libraries CPP flags not depending on site or OS
348#
349
350  CPPFLAG=$CPPFLAG" -Duse_comm_${CHAN} -Duse_libMPI"
351
352  if [ ${use_key_noIO} = yes ]; then 
353    CPPFLAG=$CPPFLAG" -Dkey_noIO"
354  fi
355  if [ ${use_NetCDF} = yes ]; then
356    CPPFLAG=$CPPFLAG" -Duse_netCDF"
357  fi
358
359  CPPFLAG=$CPPFLAG" -DNC_DOUBLE"
360
361export CPPFLAGCC=$CPPFLAG
362
363CPPFLAGF90=""
364for flag in $CPPFLAG ; do
365 CPPFLAGF90=$CPPFLAGF90$CPPFLAGSEP$flag
366done
367if [ "$CPPFLAGF90" != "" ]; then 
368  CPPFLAGF90=$CPPFLAGF90start$CPPFLAGF90
369fi
370export CPPFLAGF90
371
372if [ "$MAKETARGET" = "all" ] || [ "$MAKETARGET" = "lib" ]; then
373  echo ' '
374  echo "CPP flags used with the cc command: "
375  echo $CPPFLAGCC
376  echo ' '
377  echo "CPP flags used with the f90 command: "
378  echo $CPPFLAGF90
379fi
380
381
382################################# Directories   ################################
383# 
384# Container 'Build the build' : make build directories if needed
385#
386
387libs=${BLDROOT}/lib
388[ -d $libs ] || mkdir -p $libs
389
390lib=${BLDROOT}/build/lib
391
392BLDLIBS=" "
393bldlib=""
394for library in $srclibs; do
395  if [ $library = psmile ] || \
396     [ $library = clim   ]       ; then 
397    bldlib=${library}.${CHAN}
398  else
399    bldlib=${library}
400  fi 
401  if [ ! -d ${lib}/$bldlib  ]; then
402    echo 'Making build directory '${lib}/$bldlib' ...'
403    mkdir -p ${lib}/$bldlib
404  fi
405  ${cp} -p ${SRCROOT}/src/lib/$library/src/Makefile ${lib}/$bldlib
406  BLDLIBS=${BLDLIBS}" "$bldlib
407done
408export BLDLIBS
409
410cd ${lib}/$bldlib
411
412
413################################################################################
414#
415# Create the top level Makefile
416#
417
418cat > Top_Makefile_$$ <<'EOF1'
419
420export
421
422SHELL = /bin/ksh
423 
424builddir = ./
425
426prefix = ../../../..
427
428includedir = ${prefix}/include
429
430configdir = ${prefix}/config
431
432exec_prefix = ../../..
433
434top_builddir = $(exec_prefix)/build
435
436bindir = $(exec_prefix)/bin
437
438libdir = $(exec_prefix)/lib
439 
440INCLUDES = -I$(NETCDF_INCLUDE) -I$(MPI_INCLUDE) -I$(SYS_INCLUDE)
441
442F90      = ${F90com}
443f90      = ${f90com}
444F        = ${Fcom}
445f        = ${fcom}
446CC       = $(cc)
447CPP      = ${cc} -E
448AR       = ${ar}
449AS       = ${as}
450
451AFLAGS   = $(AFLAG)
452
453ARFLAGS   = $(ARFLAG)
454
455CCFLAGS  = -I$(configdir) -I$(SYS_INCLUDE) $(CCFLAG) $(CPPFLAGCC)
456
457F90FLAGS = $(F90FLAG) $(INCLUDES) $(CPPFLAGF90)
458
459FFLAGS = $(FFLAG) $(INCLUDES) $(CPPFLAGF90)
460
461f90FLAGS = $(f90FLAG) $(INCLUDES) $(CPPFLAGF90)
462
463fFLAGS = $(fFLAG) $(INCLUDES) $(CPPFLAGF90)
464
465COUPLE = ${COUPLER}
466
467MPPFLAGS = $(MPPFLAG)
468
469LIBDIRS  = ${BLDLIBS}
470
471all:
472        @for DIR in $(LIBDIRS) ;\
473          do \
474            back=`pwd`; \
475            echo ' ' ; \
476            cd ../../lib/$$DIR ;\
477            $(MAKE) -Makefile $(MAKETARGET); status=$$? ; \
478            echo $$DIR ':' $$status >> $(BLDROOT)/lib.status ; \
479            if [ $$status != 0 ] ; then \
480              echo "Exit status from make was $$status" ; \
481            fi ; \
482            cd $$back ; \
483          done
484clean:
485        @for DIR in $(LIBDIRS) ;\
486          do \
487            back=`pwd`; \
488            echo ' ' ; \
489            cd ../../lib/$$DIR ;\
490            $(MAKE) -Makefile $(MAKETARGET); status=$$? ; \
491            echo $$DIR ':' $$status >> $(BLDROOT)/lib.status ; \
492            if [ $$status != 0 ] ; then \
493              echo "Exit status from make was $$status"  ; \
494            fi ; \
495            cd $$back ; \
496          done
497tar:
498        cd $(prefix) ; \
499        tar -cvf ${TARFILE} \
500        ${TARFILE_DIRS} \
501        util/compile
502EOF1
503
504#       util/COMP_libs.moon  \
505
506stdout=$SCRIPTDIR/COMP_libs.log
507stderr=$SCRIPTDIR/COMP_libs.err
508
509if [ -f $BLDROOT/lib.status ]; then rm $BLDROOT/lib.status; fi
510
511################################################################################
512#
513# Execute makefile  :   -p : listing of all default rules
514#                       -d : debug
515#                       -k : dont stop when error occurs
516# 
517
518mv Top_Makefile_$$ ../Top_Makefile_$$
519
520if [ -f ${stdout} ] ; then
521   rm -f ${stdout}
522fi
523if [ -f ${stderr} ] ; then
524   rm -f ${stderr}
525fi
526
527make -f ../Top_Makefile_$$ $MAKETARGET -k
528
529rm ../Top_Makefile_$$
530
531# 
532# Print compilation status
533# 
534
535if [ $MAKETARGET != "tar" ] ; then
536  echo ' '
537  cat $BLDROOT/lib.status
538  set +e
539  grep -v ': 0' $BLDROOT/lib.status
540  if [ $? != 0 ]; then
541    echo 'Libraries ...'
542    echo $srclibs
543    if [ $MAKETARGET = all   ]; then echo '... are up-to-date!' ; fi
544    if [ $MAKETARGET = clean ]; then echo '... are cleaned!'    ; fi
545    echo ' '
546  else
547   if [ $MAKETARGET = all   ]; then  echo 'Updating libraries '$srclibs' failed !'; fi
548   if [ $MAKETARGET = clean ]; then  echo 'Cleaning libraries '$srclibs' failed !'; fi
549    echo 'Compilation is stopped!'
550    exit 1
551  fi
552  set -e
553fi
554echo ' '
555
556#
557################################################################################
558
559
560
561exit
Note: See TracBrowser for help on using the repository browser.