source: LMDZ6/trunk/create_make_gcm @ 3982

Last change on this file since 3982 was 3232, checked in by fhourdin, 6 years ago

Modifications pour compiler avec makelmdz et cosp

  • 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.9 KB
Line 
1#!/bin/sh
2#
3# $Id: create_make_gcm 3232 2018-02-27 09:18:32Z fairhead $
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 'MISC    = $(LIBF)/misc'
53echo "FILTRE   = filtre"
54echo "PHYS  = "
55echo 'LIBPHY = $(LIBO)/libphy$(PHYS).a'
56echo 'LIBPHY_COMMON= $(LIBO)/libphy_common.a'
57echo 'LIBDYN_PHY = $(LIBO)/libdynlmdz_phy$(PHYS).a'
58echo 'DIRMAIN=dyn$(DIM)d$(FLAG_PARA)'
59echo 'RM=rm'
60echo
61echo "OPLINK = "
62echo
63echo '# Les differentes librairies pour l"edition des liens:'
64echo 'L_DYN      = -ldyn$(DIM)d$(FLAG_PARA) -ldyn3d_common'
65echo 'L_FILTRE   = -l$(FILTRE)'
66echo 'L_DYN_PHY = -ldynlmdz_phy$(PHYS) '
67echo 'L_PHY = -lphy$(PHYS) -lphy_common'
68echo 'L_MISC    = -lmisc'
69echo 'L_ADJNT    ='
70
71echo
72echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
73echo "# Option de compilation FORTRAN"
74echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
75echo
76   echo 'COMPILE = $(F77) $(OPTIM) $(INCLUDE) -c'
77   echo 'COMPILE90 = $(F90) $(OPTIM90) $(INCLUDE) -c'
78   echo 'COMPTRU90 = $(F90) $(OPTIMTRU90) $(INCLUDE) -c'
79   echo 'LINK    = $(LINK)'
80   echo 'AR      = $(AR)'
81   echo 'ARFLAGS   = $(ARFLAGS)'
82echo
83echo
84echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
85echo "# Creation des differents executables"
86echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
87echo
88echo "# Executables:"
89echo "# ------------"
90echo
91echo "PROG = code"
92echo 'DYN  = dyn$(DIM)d'
93echo
94#echo 'main : chimie $(DYN) misc phys $(OPTION_DEP) '
95echo 'main : $(DYN) misc phys phy_common dyn_phy $(OPTION_DEP) '
96echo '  cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\'
97echo '  cd $(LOCAL_DIR); \'
98echo '  $(COMPILE90) $(LIBF)/$(DIRMAIN)/$(SOURCE) -o $(PROG).o ; \'
99echo '  $(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 '
100echo
101echo 'phys : $(LIBPHY)'
102echo 'phy_common : $(LIBPHY_COMMON)'
103echo 'dyn3d : $(LIBO)/libdyn$(DIM)d$(FLAG_PARA).a $(LIBO)/lib$(FILTRE).a $(LIBO)/libdyn3d_common.a'
104echo 'dyn2d : $(LIBO)/libdyn2d.a'
105echo 'dyn1d :'
106echo
107echo 'dyn_phy: $(LIBDYN_PHYS)'
108echo
109#echo 'chimie : $(LIBO)/libchimie.a'
110echo
111echo 'misc : $(LIBO)/libmisc.a'
112echo
113echo 'adjnt : $(LIBO)/libadjnt.a'
114echo
115echo '$(FILTRE)3d : $(LIBO)/lib$(FILTRE).a'
116echo
117echo '$(FILTRE)2d :'
118echo
119echo '$(FILTRE)1d :'
120echo
121echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
122echo "# Contenu des differentes bibliotheques"
123echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
124echo
125echo
126cd $libf >/dev/null 2>&1
127
128for diri in $src_dirs ; do
129
130   if [ -d $diri ] ; then
131   if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.[fF]90`" != "" ]  ; then 
132#      cd $diri >/dev/null 2>&1
133      echo
134      listlib=""
135# Liste des fichiers .F et .F90 n'etant pas des programmes principaux
136      for fili in `ls $diri/*.[fF]` ; do
137         # Check if file is a routine or main program
138         # i.e: look for the "program" keword preceeded by leading spaces
139         test=` (  head $fili | grep -i '^ *program' ) `
140         # if it is not a main program, add it to the list
141         if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi
142      done
143      for fili in `ls $diri/*.[fF]90` ; do
144         # Check if file is a routine or main program
145         # i.e. look for "program" keyword (with possibly some leading spaces)
146         test=` (  head $fili | grep -i '^ \{0,\}program' ) `
147         # if it is not a main program, add it to the list
148         if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi 
149      done
150      echo
151      echo $listlib >> $logfile
152      echo
153      # topdiri contains main dir name (without trailing "/blabla" for subdirs)
154      topdiri=${diri%/*}
155      echo "#=================================================================="
156      echo "# Contenu de la bibliotheque correspondant au Directory "$diri
157      echo "#=================================================================="
158      echo
159      for trufile in $listlib ; do
160         fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1`
161         echo '$(LIBO)/lib'$topdiri".a : " '$(LIBO)/lib'$topdiri".a("$fili".o)"
162         echo
163      done
164      echo '.PRECIOUS   : $(LIBO)/lib'$topdiri'.a'
165      echo
166      echo
167      echo "# Compilation of elements in $diri of library lib"$topdiri".a"
168      echo
169      for trufile in $listlib ; do
170         fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1`
171         F90=0 ; egrep -i '^ *use ' $trufile > /dev/null 2>&1 && F90=1
172                 egrep -i '^ *module ' $trufile > /dev/null 2>&1 && F90=1
173                 egrep -i '#include*.inc ' $trufile > /dev/null 2>&1 && F90=1
174         str1='$(LIBO)/lib'$topdiri'.a('$fili'.o) : $(LIBF)/'$trufile
175         [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F
176
177##########################################################################
178# TRAITEMENT DES DEPENDANCES
179# Differents cas de dependance correspondant a des include ou des
180# use module.
181# soit dans le repertoire local soit dans un autre.
182# Pour dyn3d, il faudrait remplacer la chaine de caractere par $DYN
183# ou quelque chose du genre.
184##########################################################################
185
186         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
187            echo $trufile $fili $stri >> $logfile
188            strj=`echo $stri | tr [A-Z] [a-z]`
189            str2=""
190            for dirinc in $src_dirs ; do
191# Recherche dans l'ordre hierarchique inverse car seule la derniere
192# ligne est conservee
193#               if [ $dirinc = phydev ] ; then
194#                   dirstr='$(PHYS)'
195#                   libstr='phy$(PHYS)'
196#               else
197                   dirstr=$dirinc
198                   libstr=$dirinc
199#               fi
200               echo dirinc $dirinc >> $logfile
201               if [ -f $dirinc/$stri ] ; then
202                  str2='$(LIBF)/'$dirstr/$stri
203               elif [ -f $dirinc/$strj ] ; then
204                  str2='$(LIBF)/'$dirstr/$stri
205               elif [ -f $dirinc/$strj.[fF]90 ]  || [ -f $dirinc/$strj.[fF] ]  ; then 
206                  strlib=`echo $libstr | awk -F/ ' { print $1 } '`
207                  str2='$(LIBO)/lib'$strlib'.a('$strj'.o)'
208               elif [ -f $dirinc/$stri.[fF]90 ]  || [ -f $dirinc/$stri.[fF] ]  ; then 
209                  strlib=`echo $libstr | awk -F/ ' { print $1 } '`
210                  str2='$(LIBO)/lib'$strlib'.a('$stri'.o)'
211               fi
212               echo stri $stri  >> $logfile
213               echo str2 $str2  >> $logfile
214            done
215               echo dernier str2 $str2  >> $logfile
216            if [ "$str2" = "" ] ; then
217               echo Warn: Include $diri $trufile $fili $stri pas trouve >> $logfile
218            elif [ "$str2" = "$str1" ] ; then
219               echo Warn: Include $diri $trufile $fili $stri $str1 trouve 2x >> $logfile
220            else
221               echo $str1 \\
222               str1=$str2
223            fi
224         done # Fin de la boucle sur les dependances et ecriture de la derniere
225         echo $str1
226         # Compile in LIBO directory; and before compiling, remove
227         # object from library
228         echo ' cd $(LIBO); \'
229         echo ' $(AR) -d $(LIBO)/lib'$topdiri'.a '$fili'.o ; \'
230         if [ "$F90" -eq '0' ] ; then
231         ## Fixed Form Fortran 77
232           echo '       $(COMPILE) $(LIBF)/'$trufile' ; \'
233         else
234         ## Fortran 90
235           if [ `echo $trufile | cut -d. -f2` = F90 ] ; then
236              ## Free Form
237              echo '    $(COMPTRU90) $(LIBF)/'$trufile' ; \'
238           else
239              echo '    $(COMPILE90) $(LIBF)/'$trufile' ; \'
240           fi
241         fi
242         # Put generated object in library
243         echo ' $(AR) $(ARFLAGS) $(LIBO)/lib'$topdiri'.a '$fili'.o ; $(RM) '$fili'.o ; \'
244         echo
245      done
246#       
247      echo
248   cd $libf
249   fi
250   fi
251done
Note: See TracBrowser for help on using the repository browser.