source: LMDZ5/trunk/makelmdz @ 2744

Last change on this file since 2744 was 2743, checked in by Ehouarn Millour, 9 years ago

Adapted makelmdz_fcm to be able to source an arch-*.env file, and also added option -arch_path to specify path to directory where arch files can be found.
Likewise adapted makelmdz with these options.
EM

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:executable set to *
File size: 23.5 KB
Line 
1#!/bin/bash
2#
3# $Id$
4#
5#
6########################################################################
7# for debug, uncomment line below
8#set -xv
9########################################################################
10# options par defaut pour la commande make
11########################################################################
12dim="96x72x19"
13physique=lmd
14code=gcm
15filtre=filtrez
16grille=reg
17couple=false
18veget=false
19chimie=false
20parallel=none
21paramem="par"
22compil_mod=prod
23io=ioipsl
24LIBPREFIX=""
25fcm_path=none
26cosp=false
27sisvat=false
28rrtm=false
29rrtm=false
30dust=false
31strataer=false
32full=""
33
34arch_defined="FALSE"
35arch_path="arch"
36arch_default_path="arch"
37
38# guess a default 'arch'
39arch="local" # start with assuming we're on a local machine with local arch file
40## try to recognise machine and infer arch from it
41machine=`hostname`
42if [[ "${machine:0:3}" == "ada" ]]
43then
44  arch="X64_ADA"
45fi
46if [[ "${machine:0:7}" == "platine" ]]
47then
48  arch="IA64_PLATINE"
49fi
50if [[ "${machine:0:6}" == "titane" ]]
51then
52  arch="X64_TITANE"
53fi
54if [[ "${machine:0:8}" == "mercure1" ]]
55then
56  arch="SX8_MERCURE"
57fi
58if [[ "${machine:0:8}" == "mercure2" ]]
59then
60  arch="SX9_MERCURE"
61fi
62
63LMDGCM=`pwd -P`
64LIBFGCM=$LMDGCM/libf
65LIBOGCM=$LMDGCM/libo
66if [[ ! -d $LIBOGCM ]]
67then
68  # create the directory
69  mkdir $LIBOGCM
70  if [[ ! $? ]]
71  then
72  echo "Failed to create directory $LIBOGCM"
73  exit
74  fi
75fi
76COSP_PATH=$LMDGCM/.void_dir
77
78
79
80localdir=`pwd -P`
81########################################################################
82#  Quelques initialisations de variables du shell.
83########################################################################
84
85CPP_KEY="" 
86INCLUDE='-I$(LIBF)/grid -I$(LIBF)/misc -I$(LIBF)/filtrez -I. '
87LIB=""
88adjnt=""
89##COMPIL_FFLAGS="%PROD_FFLAGS"
90PARA_FFLAGS=""
91PARA_LD=""
92EXT_SRC=""
93#src_dirs: directories containing source files
94src_dirs="grid misc" 
95########################################################################
96# lecture des options
97########################################################################
98
99while (($# > 0))
100  do
101  case $1 in
102      "-h") cat <<fin
103Usage :
104makelmdz [options] -arch nom_arch exec
105[-h]                       : brief help
106[-d [[IMx]JMx]LM]          : IM, JM, LM are the dimensions in x, y, z (default: $dim)
107[-p PHYS]                  : set of physical parametrizations (in libf/phyPHYS), (default: lmd)
108[-prod / -dev / -debug]    : compilation mode production (default) / developement / debug
109[-c false/MPI1/MPI2]       : coupling with ocean model : MPI1/MPI2/false (default: false)
110[-v false/orchidee2.0/orchidee1.9/true] : version of the vegetation model to include (default: false)
111          false       : no vegetation model
112          orchidee2.0 : compile using ORCHIDEE 2.0 (or more recent version)
113          orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
114          true        : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6
115[-chimie INCA/false]       : with INCA chemistry model or without (default: false)
116[-cosp true/false]    : compile with/without cosp package (default: false)
117[-sisvat true/false]  : compile with/without sisvat package (default: false)
118[-rrtm true/false]    : compile with/without rrtm package (default: false)
119[-dust true/false]    : compile with/without the dust package from Boucher et al. (default: false)
120[-strataer true/false]    : compile with/without the strat aer package from Boucher et al. (default: false)
121[-parallel none/mpi/omp/mpi_omp] : parallelism (default: none) : mpi, openmp or mixted mpi_openmp
122[-g GRI]                   : grid configuration in dyn3d/GRI_xy.h  (default: reg, inclues a zoom)
123[-io ioipsl/mix/xios]                   : Input/Output library (default: ioipsl)
124[-include INCLUDES]        : extra include path to add
125[-cpp CPP_KEY]             : additional preprocessing definitions
126[-adjnt]                   : adjoint model, not operational ...
127[-mem]                     : reduced memory dynamics (if in parallel mode)
128[-filtre NOMFILTRE]        : use filtre from libf/NOMFILTRE (default: filtrez)
129[-full]                    : Full (re)compilation (from scratch)
130[-link LINKS]              : additional links with other libraries
131[-fcm_path path]           : path to the fcm tool (default: tools/fcm/bin)
132[-ext_src path]            : path to an additional set of routines to compile with the model
133[-arch_path path]          : path to architecture files (default: $arch_default_path)
134 -arch nom_arch            : target architecture
135 exec                      : executable to build
136fin
137          exit;;
138      "-d")
139          dim=$2 ; shift ; shift ;;
140     
141      "-p")
142          physique="$2" ;  shift ; shift ;;
143
144      "-g")
145          grille="$2" ; shift ; shift ;;
146
147      "-c")
148          couple="$2" ; shift ; shift ;;
149
150      "-prod")
151          compil_mod="prod" ; shift ;;
152
153      "-dev")
154          compil_mod="dev" ; shift ;;
155
156      "-debug")
157          compil_mod="debug" ; shift ;;
158
159      "-io")
160          io="$2" ; shift ; shift ;;
161
162      "-v")
163          veget="$2" ; shift ; shift ;;
164
165      "-chimie")
166          chimie="$2" ; shift ; shift ;;
167
168      "-parallel")
169          parallel="$2" ; shift ; shift ;;
170     
171      "-include")
172          INCLUDE="$INCLUDE -I$2" ; shift ; shift ;;
173
174      "-cpp")
175          CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
176
177      "-cosp")
178          cosp="$2" ; shift ; shift ;;
179     
180      "-sisvat")
181          sisvat="$2" ; shift ; shift ;;
182     
183      "-rrtm")
184          rrtm="$2" ; shift ; shift ;;
185
186      "-dust")
187          dust="$2" ; shift ; shift ;;
188     
189      "-strataer")
190          strataer="$2" ; shift ; shift ;;
191     
192      "-mem")
193          paramem="mem" ; shift ;;
194
195      "-filtre")
196          filtre=$2 ; shift ; shift ;;
197
198      "-full")
199      full="full" ; shift ;;
200
201      "-link")
202          LIB="$LIB $2" ; shift ; shift ;;
203
204      "-fcm_path")
205          fcm_path=$2 ; shift ; shift ;;
206
207      "-ext_src")
208          EXT_SRC=$2 ; src_dirs="$src_dirs $EXT_SRC" ; shift ; shift ;;
209
210      "-arch")
211          arch=$2 ; arch_defined="TRUE" ; shift ; shift ;;
212
213      "-arch_path")
214          arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;;
215
216      *)
217          code="$1" ; shift ;;
218  esac
219done
220
221###############################################################
222# lecture des chemins propres \`a l'architecture de la machine #
223###############################################################
224rm -f .void_file
225echo > .void_file
226rm -rf .void_dir
227mkdir .void_dir
228
229if [[ "$arch_defined" == "TRUE" ]]
230then
231  rm -f arch.path
232  rm -f arch.fcm
233  rm -f arch.env
234
235  if test -f $arch_path/arch-${arch}.path
236  then
237    ln -s $arch_path/arch-${arch}.path arch.path
238  elif test -f $arch_default_path/arch-${arch}.path
239  then
240    ln -s $arch_default_path/arch-${arch}.path arch.path
241  fi
242       
243  if test -f $arch_path/arch-${arch}.fcm
244  then
245    ln -s $arch_path/arch-${arch}.fcm arch.fcm
246  elif test -f $arch_default_path/arch-${arch}.fcm
247  then
248    ln -s $arch_default_path/arch-${arch}.fcm arch.fcm
249  fi
250
251  if test -f $arch_path/arch-${arch}.env
252  then
253    ln -s $arch_path/arch-${arch}.env arch.env
254  elif test -f $arch_default_path/arch-${arch}.env
255  then
256    ln -s $arch_default_path/arch-${arch}.env arch.env
257  else
258    ln -s .void_file arch.env
259  fi
260  # source architecture PATH and ENV files
261  source arch.env
262  source arch.path
263else
264  echo "You must define a target architecture"
265  exit 1
266fi
267
268########################################################################
269# Definition des clefs CPP, des chemins des includes et modules
270#  et des libraries
271########################################################################
272
273# basic compile flags from arch.fcm file
274archfileline=$( grep -i '^%BASE_FFLAGS' arch.fcm )
275COMPIL_FFLAGS=$( echo ${archfileline##%BASE_FFLAGS} )
276
277# other compile flags, depending on compilation mode
278if [[ "$compil_mod" == "prod" ]]
279then
280## read COMPIL_FFLAGS from arch.fcm file
281  archfileline=$( grep -i '^%PROD_FFLAGS' arch.fcm )
282  archfileopt=$( echo ${archfileline##%PROD_FFLAGS} )
283  COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}"
284elif [[ "$compil_mod" == "dev" ]]
285then
286## read %DEV_FFLAGS from arch.fcm file
287  archfileline=$( grep -i '^%DEV_FFLAGS' arch.fcm )
288  archfileopt=$( echo ${archfileline##%DEV_FFLAGS} )
289  COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}"
290elif [[ "$compil_mod" == "debug" ]]
291then
292## read %DEBUG_FFLAGS from arch.fcm file
293  archfileline=$( grep -i '^%DEBUG_FFLAGS' arch.fcm )
294  archfileopt=$( echo ${archfileline##%DEBUG_FFLAGS} )
295  COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}"
296fi
297
298# add CPP_KEY defined in arch.fcm file
299archfileline=$( grep -i '^%FPP_DEF' arch.fcm )
300archfileopt=$( echo ${archfileline##%FPP_DEF} )
301CPP_KEY="$CPP_KEY ${archfileopt}"
302
303# get compiler name from arch.fcm file
304archfileline=$( grep -i '^%COMPILER' arch.fcm )
305fcompiler=$( echo ${archfileline##%COMPILER} )
306
307# get linker name from arch.fcm file
308archfileline=$( grep -i '^%LINK' arch.fcm )
309linker=$( echo ${archfileline##%LINK} )
310
311# get ar command from arch.fcm file
312archfileline=$( grep -i '^%AR' arch.fcm )
313arcommand=$( echo ${archfileline##%AR} )
314
315# get make utility from arch.fcm file
316archfileline=$( grep -i '^%MAKE' arch.fcm )
317makecommand=$( echo ${archfileline##%MAKE} )
318
319# get basic libraries to link with arch.fcm file
320archfileline=$( grep -i '^%BASE_LD' arch.fcm )
321archfileopt=$( echo ${archfileline##%BASE_LD} )
322LIB="$LIB  ${archfileopt}"
323
324# add Include files defined in arch.fcm file for pre-processing
325archfileline=$( grep -i '^%FPP_FLAGS' arch.fcm )
326for inc in $archfileline ; do INCLUDE="$INCLUDE `echo $inc | grep '\-I'`" ; done
327
328phys_root=$physique
329if [[ "${physique:0:3}" == "lmd" ]] ; then phys_root=lmd ; fi
330if [[ "${physique:0:4}" == "mars" ]] ; then phys_root=mars ; fi
331if [[ "${physique:0:3}" == "std" ]] ; then phys_root=std ; fi
332if [[ "${physique:0:5}" == "venus" ]] ; then phys_root=venus ; fi
333if [[ "${physique:0:5}" == "titan" ]] ; then phys_root=titan ; fi
334if [[ "${physique:0:3}" == "mar" ]] ; then phys_root=mar ; fi
335if [[ "${physique:0:3}" == "dev" ]] ; then phys_root=dev ; fi
336
337if [[ "$physique" != "nophys" ]]
338then
339   #We'll use some physics
340   src_dirs="$src_dirs phy_common phy$physique"
341   LIBPHY='$(LIBO)/libphy'"$physique"'.a'
342   LIBPHY_COMMON='$(LIBO)/libphy_common.a'
343   lib_phy='-lphy'"$physique"' -lphy_common'
344   CPP_KEY="$CPP_KEY CPP_PHYS"
345   if [[ $phys_root == "lmd" ]]
346      then
347      #For lmd physics, default planet type is Earth
348      CPP_KEY="$CPP_KEY CPP_EARTH"
349   fi
350fi
351
352if [[ "$chimie" == "INCA" ]]
353then
354   CPP_KEY="$CPP_KEY INCA"
355   INCLUDE="$INCLUDE -I${INCA_INCDIR}"
356   LIB="$LIB -L${INCA_LIBDIR} -lchimie"
357   libchimie=" -L${INCA_LIBDIR} -lchimie"
358fi
359
360if [[ "$couple" != "false" ]]
361then
362   CPP_KEY="$CPP_KEY CPP_COUPLE"
363   INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
364   LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.${couple} -lmpp_io"
365fi
366
367if [[ "$parallel" == "none" ]]
368then
369  FLAG_PARA=''
370else
371  FLAG_PARA="$paramem"
372  if [[ $paramem == par ]]
373  then
374      echo "The version of the dynamics in dyn3dpar is no longer updated."
375      echo "You should use option \"-mem\"."
376      exit 1
377  fi
378fi
379
380if [[ "$parallel" == "mpi" ]]
381then
382   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI"
383  # MPI additional compilation options
384  archfileline=$( grep -i '^%MPI_FFLAGS' arch.fcm )
385  PARA_FFLAGS=$( echo ${archfileline##%MPI_FFLAGS} )
386  # MPI additional links
387  archfileline=$( grep -i '^%MPI_LD' arch.fcm )
388  PARA_LD=$( echo ${archfileline##%MPI_LD} )
389elif [[ "$parallel" == "omp" ]]
390then
391   CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP"
392  # OMP additional compilation options
393  archfileline=$( grep -i '^%OMP_FFLAGS' arch.fcm )
394  PARA_FFLAGS=$( echo ${archfileline##%OMP_FFLAGS} )
395  # OMP additional links
396  archfileline=$( grep -i '^%OMP_LD' arch.fcm )
397  PARA_LD=$( echo ${archfileline##%OMP_LD} )
398elif [[ "$parallel" == "mpi_omp" ]]
399then
400   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP"
401  # MPI additional compilation options
402  archfileline=$( grep -i '^%MPI_FFLAGS' arch.fcm )
403  PARA_FFLAGS=$( echo ${archfileline##%MPI_FFLAGS} )
404  # OMP additional compilation options
405  archfileline=$( grep -i '^%OMP_FFLAGS' arch.fcm )
406  PARA_FFLAGS="${PARA_FFLAGS} "$( echo $archfileopt ${archfileline##%OMP_FFLAGS} )
407  # MPI additional links
408  archfileline=$( grep -i '^%MPI_LD' arch.fcm )
409  PARA_LD=$( echo ${archfileline##%MPI_LD} )
410  # OMP additional links
411  archfileline=$( grep -i '^%OMP_LD' arch.fcm )
412  PARA_LD="${PARA_LD} "$( echo $archfileopt ${archfileline##%OMP_LD} )
413fi
414
415if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \
416   && "$compil_mod" == "debug" ]]
417then
418    echo "Usually, parallelization with OpenMP requires some optimization."
419    echo "We suggest switching to \"-dev\"."
420fi
421
422
423#==============================================================================
424if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" ]
425then
426
427   INCLUDE="${INCLUDE} -I${ORCH_INCDIR}"
428   CPP_KEY="$CPP_KEY CPP_VEGET"
429# temporary, for Orchidee versions 1.9.* (before openmp activation)
430   if [[ "$veget" == "orchidee1.9" ]] ; then
431      CPP_KEY="$CPP_KEY ORCHIDEE_NOOPENMP"
432   fi
433   if [[ "$veget" == "orchidee2.0" ]] ; then
434      orch_libs="sechiba parameters stomate parallel orglob orchidee"
435   else
436      orch_libs="sechiba parameters stomate parallel orglob"
437   fi
438   LIB="${LIB} -L${ORCH_LIBDIR}"
439   for lib in ${orch_libs} ; do
440      if [ -f ${ORCH_LIBDIR}/lib${LIBPREFIX}$lib.a ] ; then
441         LIB="${LIB} -l${LIBPREFIX}$lib "
442      fi
443   done
444elif [[ "$veget" != "false" ]] ; then
445   echo "Option -v $veget does not exist"
446   echo "Use ./makelmdz -h for more information"
447   exit 
448fi
449
450#===============================================================================
451if [[ $io == ioipsl ]]
452then
453   CPP_KEY="$CPP_KEY CPP_IOIPSL"
454   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}"
455   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl"
456elif [[ $io == mix ]]
457then
458   # For now, xios implies also using ioipsl
459   CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS"
460   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
461   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios"
462elif [[ $io == xios ]]
463then
464   # For now, xios implies also using ioipsl
465   CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS CPP_IOIPSL_NO_OUTPUT"
466   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
467   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios"
468fi
469
470if [[ "$cosp" == "true" ]]
471then
472   CPP_KEY="$CPP_KEY CPP_COSP"
473   COSP_PATH="$LIBFGCM/phylmd/cosp"
474   src_dirs="$src_dirs cosp"
475#   LIB="${LIB} -l${LIBPREFIX}cosp"
476   opt_dep="$opt_dep cosp"
477   lcosp="-l${LIBPREFIX}cosp"
478   INCLUDE="$INCLUDE"' -I$(LIBF)/cosp'
479fi
480
481if [[ "$sisvat" == "true" ]]
482then
483   CPP_KEY="$CPP_KEY CPP_SISVAT"
484   src_dirs="$src_dirs phy${physique}/sisvat"
485fi
486
487if [[ "$rrtm" == "true" ]]
488then
489   CPP_KEY="$CPP_KEY CPP_RRTM"
490   src_dirs="$src_dirs phy${physique}/rrtm"
491fi
492
493if [[ "$dust" == "true" ]]
494then
495   CPP_KEY="$CPP_KEY CPP_Dust"
496   src_dirs="$src_dirs phy${physique}/Dust"
497fi
498
499if [[ "$strataer" == "true" ]]
500then
501   CPP_KEY="$CPP_KEY CPP_StratAer"
502   src_dirs="$src_dirs phy${physique}/StratAer"
503fi
504
505
506INCLUDE="$INCLUDE ${NETCDF_INCDIR}"
507LIB="$LIB ${NETCDF_LIBDIR}"
508
509########################################################################
510# calcul du nombre de dimensions
511########################################################################
512
513
514dim_full=$dim
515dim=`echo $dim | sed -e 's/[^0-9]/ /g'` 
516set $dim
517dimc=$#
518echo calcul de la dimension
519echo dim $dim
520echo dimc $dimc
521
522########################################################################
523# Gestion des dimensions du modele.
524# on cree ou remplace le fichier des dimensions
525########################################################################
526
527cd $LIBFGCM/grid
528if [[ -f dimensions.h ]]
529then
530  echo 'ATTENTION: vous etes sans doute en train de compiler le modele par ailleurs'
531  echo "Attendez que la premiere compilation soit terminee pour relancer la suivante."
532  echo "Si vous etes sur que vous ne compilez pas le modele par ailleurs,"
533  echo  vous pouvez continuer en repondant oui.
534  echo "Voulez-vous vraiment continuer?"
535  echo ""
536  echo "WARNING: you are probably already compiling the model somewhere else."
537  echo "Wait until the first compilation is finished before launching this one."
538  echo "If you are sure that you are not compiling elsewhere, just answer "
539  echo "yes (or 'oui') to the question below to proceed."
540  echo "Do you wish to continue?"
541  read reponse
542  if [[ $reponse == "oui" || $reponse == "yes" ]]
543  then
544    \rm -f $LIBFGCM/grid/dimensions.h
545  else
546    exit
547  fi
548fi
549
550cd $LIBFGCM/grid/dimension
551./makdim $dim
552if (($? != 0))
553then
554    exit 1
555fi
556
557cat $LIBFGCM/grid/dimensions.h
558cd $LMDGCM
559
560########################################################################
561# Differentes dynamiques (3d, 2d, 1d)
562########################################################################
563
564if (( $dimc == 3 )) ; then
565   src_dirs="$src_dirs $filtre dyn3d_common dyn3d${FLAG_PARA}"
566   if [[ $physique != "nophys" ]] ; then
567     src_dirs="$src_dirs dynphy_lonlat dynphy_lonlat/phy${phys_root}"
568     libdyn_phy="-ldynphy_lonlat"
569     LIBDYN_PHYS='$(LIBO)/libdynphy_lonlat.a'
570     INCLUDE="$INCLUDE "'-I$(LIBF)/dynphy_lonlat'
571     INCLUDE="$INCLUDE "'-I$(LIBF)/dynphy_lonlat/'"phy${phys_root}"
572   fi
573   cd $LIBFGCM/grid
574   \rm fxyprim.h
575   cp -p fxy_${grille}.h fxyprim.h
576   filtre="FILTRE=$filtre"
577   INCLUDE="$INCLUDE "'-I$(LIBF)/dyn3d${FLAG_PARA} -I$(LIBF)/dyn3d_common '
578elif (( $dimc == 2 )) ; then
579   src_dirs="$src_dirs dyn2d"
580   filtre="FILTRE= L_FILTRE= "
581   INCLUDE="$INCLUDE "'-I$(LIBF)/dyn2d'
582elif (( $dimc == 1 )) ; then
583   #src_dirs="$src_dirs dyn3d dyn3d_common filtrez"
584   src_dirs="$src_dirs phy${physique}/dyn1d"
585   CPP_KEY="$CPP_KEY CPP_1D"
586   filtre="L_DYN= DYN= FILTRE= L_FILTRE= "
587   #INCLUDE="$INCLUDE "'-I$(LIBF)/dyn3d -I$(LIBF)/dyn3d_common ' # Pas tres propre
588   INCLUDE="$INCLUDE "' -I$(LIBF)/phy'"$physique"'/dyn1d'
589else
590   echo Dimension dimc=$dimc pas prevu ; exit
591fi
592
593cd $LMDGCM
594
595########################################################################
596# library directory name:
597########################################################################
598
599nomlib=`echo ${arch}_${physique}_${dim_full}_${grille}_${compil_mod}_parall${parallel}_${CPP_KEY}_${FLAG_PARA} | sed -e 's/ //g' -e 's/-//g ' | sed -e 's/CPP_//g'`
600echo "Path to library: "$nomlib
601
602########################################################################
603#  Cleanup for a full recompilation, if requested
604########################################################################
605
606if [[ $full == "full" ]]
607then
608# remove makefile and librairies
609  echo "-full option: recompiling from scratch"
610  \rm -f makefile
611  \rm -rf "${LIBOGCM}/${nomlib}"
612fi
613
614########################################################################
615#  Avant de lancer le make, on recree le makefile si necessaire
616########################################################################
617########################################################################
618# c'est a dire dans 3 cas:
619# 1. si la liste des fichiers .F et .h a ete modifiee depuis la
620#    derniere creation du makefile
621# 2. si le fichier contenant cette liste "liste_des_sources"
622#    n'existe pas.
623# 3. Si le makefile n'existe pas.
624########################################################################
625cd $LMDGCM
626
627
628if [[ -r .makelmdz ]]
629then
630old_lmdz_configuration=$(cat .makelmdz )
631else
632old_lmdz_configuration=""
633fi
634lmdz_configuration="$src_dirs"
635if [[ "$lmdz_configuration" != "$old_lmdz_configuration" ]]
636then
637  configuration_change="true"
638else
639  configuration_change="false"
640fi
641
642mkdir -p make_dir
643suf_make=`echo $src_dirs | sed -e 's/\//_/g' -e 's/ /_/g'`
644echo suf_make $suf_make
645
646\rm tmp77 tmp90
647for dir in $src_dirs ; do
648find libf/$dir -name '*.[Fh]' -print | sort >> tmp77
649find libf/$dir -name '*.F90' -print | sort >> tmp90
650done
651
652liste77=make_dir/liste_des_sources_f77_$suf_make
653liste90=make_dir/liste_des_sources_f90_$suf_make
654makefile=make_dir/makefile_$suf_make
655
656if [[ $configuration_change == "true" || ! ( -r $makefile ) || ! ( -r $liste90 ) || ! ( -r $liste77 ) || ` diff tmp77 $liste77 | wc -w ` -ne 0 || ` diff tmp90 $liste90 | wc -w ` -ne 0 ]]
657then
658  echo "les fichiers suivants ont ete crees ou detruits"
659  echo "ou les fichiers suivants sont passes ou ne sont plus en Fortran 90"
660  diff $liste77 tmp77
661  diff $liste90 tmp90
662  \cp -f tmp77 $liste77
663  \cp -f tmp90 $liste90
664  echo "Recreating the makefile"
665  echo "src_dirs: $src_dirs"
666  ./create_make_gcm $src_dirs > tmp
667  \mv -f tmp $makefile
668  echo "New makefile created"
669fi
670
671ln -sf $makefile makefile
672
673#Create a .makelmdz file containing main compilation option for later comparisons
674echo "$lmdz_configuration" > .makelmdz
675
676#################################################################
677# Preparation de l'execution de la comande make
678#################################################################
679
680source_code=${code}.F
681dirmain=dyn${dimc}d${FLAG_PARA}
682if [[ -r $LMDGCM/libf/dyn${dimc}d${FLAG_PARA}/${code}.F90 ]]
683then
684  source_code=${code}.F90
685elif [[ -r $LMDGCM/libf/phy$physique/${code}.F90 ]] ; then
686  dirmain=phy$physique
687  source_code=${code}.F90
688elif [[ -r $LMDGCM/libf/dynphy_lonlat/phy$phys_root/${code}.F90 ]] ; then
689  dirmain="dynphy_lonlat/phy${phys_root}"
690  source_code=${code}.F90
691elif [[ -r $LMDGCM/libf/phy$physique/dyn1d/${code}.F90 ]] ; then
692  dirmain=phy$physique/dyn1d
693  source_code=${code}.F90
694fi
695
696if [[ ! -d "${LIBOGCM}/${nomlib}" ]]
697then
698  mkdir ${LIBOGCM}/${nomlib}
699  # check we indeed managed to create the directory
700  if [[ ! $? ]]
701  then
702    echo "Error: could not create directory ${LIBOGCM}/${nomlib}"
703    exit
704  fi
705fi
706
707# where module files are created
708mod_loc_dir=$localdir
709
710if [[ "$physique" != "nophys" ]]
711then
712  INCLUDE="$INCLUDE"' -I$(LIBF)/phy'"$physique"
713fi
714INCLUDE="$INCLUDE"' -I'${LIBOGCM}/${nomlib}
715
716# ranlib utility (check it exists or else default to ls)
717if [[ `which ranlib > /dev/null 2>&1 ; echo $?` -eq 0 ]]
718then
719  ranlib="ranlib"
720else
721  ranlib="ls"
722fi
723
724# add CPP keys to COMPIL_FLAGS
725# (but first add -D before all CPP_KEY items)
726cpp_definitions=`echo $CPP_KEY | sed -e 's/[A-Za-z_=0-9]*/-D&/g'`
727# (but add a -WF,-D before all CPP_KEY items) => for xlf on Vargas
728if [[ "${fcompiler:0:3}" == "xlf" ]]
729then
730cpp_definitions=`echo $CPP_KEY | sed -e 's/[A-Za-z_=0-9]*/-WF,-D&/g'`
731fi
732COMPIL_FFLAGS="${COMPIL_FFLAGS} ${cpp_definitions}"
733
734#################################################################
735# Execution du make
736#################################################################
737echo $makecommand RANLIB=$ranlib -f $LMDGCM/makefile \
738OPTION_DEP="$opt_dep" OPTION_LINK="$LIB ${PARA_LD}" \
739OPTIM90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
740OPTIMTRU90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
741OPTIM="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
742INCLUDE="$INCLUDE" \
743$filtre \
744LIBO=${LIBOGCM}/${nomlib} \
745"PHYS=$physique" \
746LIBPHY=${LIBPHY} \
747LIBPHY_COMMON=${LIBPHY_COMMON} \
748LIBDYN_PHYS=${LIBDYN_PHYS} \
749DIM=$dimc \
750FLAG_PARA=$FLAG_PARA \
751L_PHY="$lib_phy" \
752L_DYN_PHY="$libdyn_phy" \
753L_ADJNT=$adjnt \
754L_COSP="$lcosp" \
755L_CHIMIE="$libchimie" \
756LOCAL_DIR="$localdir"  \
757F77="$fcompiler" \
758F90="$fcompiler" \
759OPLINK="$LIB" \
760LINK="$linker" \
761GCM="$LMDGCM" \
762MOD_LOC_DIR=$mod_loc_dir \
763MOD_SUFFIX="mod" \
764AR=$arcommand \
765DIRMAIN=$dirmain \
766SOURCE=$source_code \
767PROG=$code
768
769$makecommand RANLIB=$ranlib -f $LMDGCM/makefile \
770OPTION_DEP="$opt_dep" OPTION_LINK="$LIB ${PARA_LD}" \
771OPTIM90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
772OPTIMTRU90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
773OPTIM="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
774INCLUDE="$INCLUDE" \
775$filtre \
776LIBO=${LIBOGCM}/${nomlib} \
777"PHYS=$physique" \
778LIBPHY=${LIBPHY} \
779LIBPHY_COMMON=${LIBPHY_COMMON} \
780LIBDYN_PHYS=${LIBDYN_PHYS} \
781DIM=$dimc \
782FLAG_PARA=$FLAG_PARA \
783L_PHY="$lib_phy" \
784L_DYN_PHY="$libdyn_phy" \
785L_ADJNT=$adjnt \
786L_COSP="$lcosp" \
787L_CHIMIE="$libchimie" \
788LOCAL_DIR="$localdir"  \
789F77="$fcompiler" \
790F90="$fcompiler" \
791OPLINK="$LIB" \
792LINK="$linker" \
793GCM="$LMDGCM" \
794MOD_LOC_DIR=$mod_loc_dir \
795MOD_SUFFIX="mod" \
796AR=$arcommand \
797DIRMAIN=$dirmain \
798SOURCE=$source_code \
799PROG=$code
800
801
802if [[ -r $LIBFGCM/grid/dimensions.h ]]
803then
804  # Cleanup: remove dimension.h file
805  \rm -f $LIBFGCM/grid/dimensions.h
806fi
Note: See TracBrowser for help on using the repository browser.