source: LMDZ5/trunk/create_make_gcm @ 2238

Last change on this file since 2238 was 2238, checked in by Ehouarn Millour, 10 years ago

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