source: LMDZ6/trunk/create_make_gcm @ 5528

Last change on this file since 5528 was 5528, checked in by fhourdin, 29 hours ago

Rephasage makelmdz/create_make_gcm

  • 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:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1#!/bin/bash
2#
3# $Id: create_make_gcm 5528 2025-02-09 17:48:58Z fhourdin $
4#
5#set -xv
6
7machine=`hostname`
8os=`uname`
9gcm=`pwd`
10logfile=$gcm/create_make_gcm.log
11rm -f $logfile ; touch -f $logfile
12libf=$gcm/libf
13libo=$gcm/libo
14
15# arguments given to create_make_gcm are the directories to scan
16src_dirs=""
17for d in $* ; do if [ -d $libf/$d ] ; then src_dirs="$src_dirs $d" ; fi ; done
18
19echo '# List of scanned directories :' $src_dirs
20
21# Pour l'inclusion des modules dans dynphy_lonlat/phy*
22# TBD : integrer la gestion dans create_make_gcm des options pour l'instant gérées dans makelmdz
23for d in $src_dirs ; do if [ ${d:0:3} = phy -a $d != phy_common ] ; then phys=$( echo $d | cut -d/ -f1 ) ; fi ; done
24#for d in $src_dirs ; do echo hm $d ; done
25
26
27
28
29CRAY=0
30if [ "$machine" = "atlas" -o "$machine" = "etoile" -o "$machine" = "axis" ] ; then
31  CRAY=1
32fi
33XNEC=0
34if [ "$machine" = "rhodes" ] ; then
35  XNEC=1
36fi
37X6NEC=0
38if [ "$machine" = "mercure" ] ; then
39  X6NEC=1
40fi
41X8BRODIE=0
42if [ "$machine" = "brodie" ] ; then
43  X8BRODIE=1
44fi
45VPP=0
46if [ "$machine" = "nymphea0" ] ; then
47  VPP=1
48fi
49#
50echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
51echo "# Definitions de Macros pour Make"
52echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
53echo
54echo "# Repertoires :"
55echo
56echo "GCM     = "$gcm
57echo 'LIBF    = $(GCM)/libf'
58if [ "$CRAY" = '0' ] ; then
59   echo 'LIBO    = $(LIBOGCM)/$(MACHINE)'
60else
61   echo 'LIBO    = $(GCM)/libo'
62fi
63echo "LOCAL_DIR=`echo $localdir`"
64echo 'MISC    = $(LIBF)/misc'
65echo "FILTRE   = filtre"
66echo "PHYS  = "
67echo 'LIBPHY = $(LIBO)/libphy$(PHYS).a'
68echo 'LIBPHY_COMMON= $(LIBO)/libphy_common.a'
69echo 'LIBDYN_PHY = $(LIBO)/libdynlmdz_phy$(PHYS).a'
70echo 'DIRMAIN=dyn$(DIM)d$(FLAG_PARA)'
71echo 'RM=rm'
72echo
73echo "OPLINK = "
74echo
75echo '# Les differentes librairies pour l"edition des liens:'
76echo 'L_DYN      = -ldyn$(DIM)d$(FLAG_PARA) -ldyn3d_common -lgrid'
77echo 'L_FILTRE   = -l$(FILTRE)'
78echo 'L_DYN_PHY = -ldynlmdz_phy$(PHYS) '
79echo 'L_PHY = -lphy$(PHYS) -lphy_common'
80echo 'L_MISC    = -lmisc'
81echo 'L_ADJNT    ='
82
83echo
84echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
85echo "# Option de compilation FORTRAN"
86echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
87echo
88   echo 'COMPILE = $(F77) $(OPTIM) $(INCLUDE) -c'
89   echo 'COMPILE90 = $(F90) $(OPTIM90) $(INCLUDE) -c'
90   echo 'COMPTRU90 = $(F90) $(OPTIMTRU90) $(INCLUDE) -c'
91   echo 'LINK    = $(LINK)'
92   echo 'AR      = $(AR)'
93   echo 'ARFLAGS   = $(ARFLAGS)'
94echo
95echo
96echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
97echo "# Creation des differents executables"
98echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
99echo
100echo "# Executables:"
101echo "# ------------"
102echo
103echo "PROG = code"
104echo 'DYN  = dyn$(DIM)d'
105echo
106#echo 'main : chimie $(DYN) misc phys $(OPTION_DEP) '
107echo 'main : $(DYN) misc phys phy_common dyn_phy $(OPTION_DEP) '
108echo '  cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\'
109echo '  cd $(LOCAL_DIR); \'
110echo '  $(COMPILE90) $(LIBF)/$(DIRMAIN)/$(SOURCE) -o $(PROG).o ; \'
111echo '  $(LINK) $(PROG).o -L$(LIBO) $(L_DYN) $(L_DYN_PHY) $(L_ADJNT) $(L_PHY) $(L_DYN) $(L_DYN3D_COMMON) $(L_MISC) $(L_DYN3D_COMMON) $(L_PHY) $(L_DYN_PHY) $(L_DYN) $(L_FILTRE) $(OPLINK) $(OPTION_LINK) -o $(LOCAL_DIR)/$(PROG).e ; $(RM) $(PROG).o '
112echo
113echo 'phys : $(LIBPHY)'
114echo 'phy_common : $(LIBPHY_COMMON)'
115echo 'dyn3d : $(LIBO)/libdyn$(DIM)d$(FLAG_PARA).a $(LIBO)/lib$(FILTRE).a $(LIBO)/libdyn3d_common.a'
116echo 'dyn2d : $(LIBO)/libdyn2d.a'
117echo 'dyn1d :'
118echo
119echo 'dyn_phy: $(LIBDYN_PHYS)'
120echo
121#echo 'chimie : $(LIBO)/libchimie.a'
122echo
123echo 'misc : $(LIBO)/libmisc.a'
124echo
125echo 'adjnt : $(LIBO)/libadjnt.a'
126echo
127echo '$(FILTRE)3d : $(LIBO)/lib$(FILTRE).a'
128echo
129echo '$(FILTRE)2d :'
130echo
131echo '$(FILTRE)1d :'
132echo
133echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
134echo "# Contenu des differentes bibliotheques"
135echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
136echo
137echo
138cd $libf >/dev/null 2>&1
139
140for diri in $src_dirs ; do
141
142   if [ -d $diri ] ; then
143   if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.[fF]90`" != "" ]  ; then 
144#      cd $diri >/dev/null 2>&1
145      echo
146      listlib=""
147# Liste des fichiers .F et .F90 n'etant pas des programmes principaux
148      for fili in `ls $diri/*.[fF]` ; do
149         # Check if file is a routine or main program
150         # i.e: look for the "program" keword preceeded by leading spaces
151         test=` (  head -20 $fili | grep -i '^ *program' ) `
152         # if it is not a main program, add it to the list
153         if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi
154      done
155      for fili in `ls $diri/*.[fF]90` ; do
156         # Check if file is a routine or main program
157         # i.e. look for "program" keyword (with possibly some leading spaces)
158         test=` (  head -20 $fili | grep -i '^ \{0,\}program' ) `
159         # if it is not a main program, add it to the list
160         if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi 
161      done
162      echo
163      echo $listlib >> $logfile
164      echo
165      # topdiri contains main dir name (without trailing "/blabla" for subdirs)
166      topdiri=${diri%/*}
167      echo "#=================================================================="
168      echo "# Contenu de la bibliotheque correspondant au Directory "$diri
169      echo "#=================================================================="
170      echo
171      for trufile in $listlib ; do
172         fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1`
173         echo '$(LIBO)/lib'$topdiri".a : " '$(LIBO)/lib'$topdiri".a("$fili".o)"
174         echo
175      done
176      echo '.PRECIOUS   : $(LIBO)/lib'$topdiri'.a'
177      echo
178      echo
179      echo "# Compilation of elements in $diri of library lib"$topdiri".a"
180      echo
181      for trufile in $listlib ; do
182         fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1`
183         F90=0 ; egrep -i '^ *use ' $trufile > /dev/null 2>&1 && F90=1
184                 egrep -i '^ *module ' $trufile > /dev/null 2>&1 && F90=1
185                 egrep -i '#include*.inc ' $trufile > /dev/null 2>&1 && F90=1
186         str1='$(LIBO)/lib'$topdiri'.a('$fili'.o) : $(LIBF)/'$trufile
187         [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F
188
189##########################################################################
190# TRAITEMENT DES DEPENDANCES
191# Differents cas de dependance correspondant a des include ou des
192# use module.
193# soit dans le repertoire local soit dans un autre.
194# Pour dyn3d, il faudrait remplacer la chaine de caractere par $DYN
195# ou quelque chose du genre.
196##########################################################################
197dirs_inc=""
198for d in $phys/dyn1d dynphy_lonlat/$phys $src_dirs ; do if [ -d $d ] ; then dirs_inc="$dirs_inc $d" ; fi ; done
199echo '# List of scanned directories for include files and modules :' $dirs_inc
200
201         for stri in ` ( sed -e '/^[cC\!]/d' $trufile | sed -e "/\#include /s/\#include /XXnclude /" -e "/include /s/include /XXnclude /" -e "/INCLUDE /s/INCLUDE /XXnclude /" | sed -n "/XXnclude /s/XXnclude//p" | sed 's/\"//g' | sort | uniq ; sed -e '/^[cC\!]/d' $trufile | egrep -i '^ *use ' | sed -e 's/,/ /' | awk ' { print $2 } ' | sort | uniq ) ` ; do
202            echo $trufile $fili $stri >> $logfile
203            strj=`echo $stri | tr [A-Z] [a-z]`
204            str2=""
205            #echo $dirs_inc
206            for dirinc in $dirs_inc ; do
207# Recherche dans l'ordre hierarchique inverse car seule la derniere
208# ligne est conservee
209#               if [ $dirinc = phydev ] ; then
210#                   dirstr='$(PHYS)'
211#                   libstr='phy$(PHYS)'
212#               else
213                   dirstr=$dirinc
214                   libstr=$dirinc
215#               fi
216               echo dirinc $dirinc >> $logfile
217               if [ -f $dirinc/$stri ] ; then
218                  str2='$(LIBF)/'$dirstr/$stri
219               elif [ -f $dirinc/$strj ] ; then
220                  str2='$(LIBF)/'$dirstr/$stri
221               elif [ -f $dirinc/$strj.[fF]90 ]  || [ -f $dirinc/$strj.[fF] ]  ; then 
222                  strlib=`echo $libstr | awk -F/ ' { print $1 } '`
223                  str2='$(LIBO)/lib'$strlib'.a('$strj'.o)'
224               elif [ -f $dirinc/$stri.[fF]90 ]  || [ -f $dirinc/$stri.[fF] ]  ; then 
225                  strlib=`echo $libstr | awk -F/ ' { print $1 } '`
226                  str2='$(LIBO)/lib'$strlib'.a('$stri'.o)'
227               fi
228               echo stri $stri  >> $logfile
229               echo str2 $str2  >> $logfile
230            done
231               echo dernier str2 $str2  >> $logfile
232            if [ "$str2" = "" ] ; then
233                if [ "$stri" = "YOMCST" ] ; then
234                  str2='$(LIBO)/libphylmd.a(yomcst_mod_h.o)' 
235                  echo $str1 \\
236                  str1=$str2
237                else
238                  echo Warn: Include $diri $trufile $fili $stri pas trouve >> $logfile
239                fi
240            elif [ "$str2" = "$str1" ] ; then
241               echo Warn: Include $diri $trufile $fili $stri $str1 trouve 2x >> $logfile
242            else
243               echo $str1 \\
244               str1=$str2
245            fi
246         done # Fin de la boucle sur les dependances et ecriture de la derniere
247         echo $str1
248         # Compile in LIBO directory; and before compiling, remove
249         # object from library
250         echo ' cd $(LIBO); \'
251         echo ' $(AR) -d $(LIBO)/lib'$topdiri'.a '$fili'.o ; \'
252         if [ "$F90" -eq '0' ] ; then
253         ## Fixed Form Fortran 77
254           echo '       $(COMPILE) $(LIBF)/'$trufile' ; \'
255         else
256         ## Fortran 90
257           if [ `echo $trufile | cut -d. -f2` = F90 ] ; then
258              ## Free Form
259              echo '    $(COMPTRU90) $(LIBF)/'$trufile' ; \'
260           else
261              echo '    $(COMPILE90) $(LIBF)/'$trufile' ; \'
262           fi
263         fi
264         # Put generated object in library
265         echo ' $(AR) $(ARFLAGS) $(LIBO)/lib'$topdiri'.a '$fili'.o ; $(RM) '$fili'.o ; \'
266         echo
267      done
268#       
269      echo
270   cd $libf
271   fi
272   fi
273done
Note: See TracBrowser for help on using the repository browser.