1 | #!/bin/sh |
---|
2 | # |
---|
3 | # $Id: create_make_gcm 1461 2010-12-03 11:12:25Z emillour $ |
---|
4 | # |
---|
5 | #set -xv |
---|
6 | |
---|
7 | # arguments given to create_make_gcm are the directories to scan |
---|
8 | src_dirs=$* |
---|
9 | |
---|
10 | machine=`hostname` |
---|
11 | os=`uname` |
---|
12 | gcm=`pwd` |
---|
13 | logfile=$gcm/create_make_gcm.log |
---|
14 | rm -f $logfile ; touch -f $logfile |
---|
15 | libf=$gcm/libf |
---|
16 | libo=$gcm/libo |
---|
17 | CRAY=0 |
---|
18 | if [ "$machine" = "atlas" -o "$machine" = "etoile" -o "$machine" = "axis" ] ; then |
---|
19 | CRAY=1 |
---|
20 | fi |
---|
21 | XNEC=0 |
---|
22 | if [ "$machine" = "rhodes" ] ; then |
---|
23 | XNEC=1 |
---|
24 | fi |
---|
25 | X6NEC=0 |
---|
26 | if [ "$machine" = "mercure" ] ; then |
---|
27 | X6NEC=1 |
---|
28 | fi |
---|
29 | X8BRODIE=0 |
---|
30 | if [ "$machine" = "brodie" ] ; then |
---|
31 | X8BRODIE=1 |
---|
32 | fi |
---|
33 | VPP=0 |
---|
34 | if [ "$machine" = "nymphea0" ] ; then |
---|
35 | VPP=1 |
---|
36 | fi |
---|
37 | # |
---|
38 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
39 | echo "# Definitions de Macros pour Make" |
---|
40 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
41 | echo |
---|
42 | echo "# Repertoires :" |
---|
43 | echo |
---|
44 | echo "GCM = "$gcm |
---|
45 | echo 'LIBF = $(GCM)/libf' |
---|
46 | if [ "$CRAY" = '0' ] ; then |
---|
47 | echo 'LIBO = $(LIBOGCM)/$(MACHINE)' |
---|
48 | else |
---|
49 | echo 'LIBO = $(GCM)/libo' |
---|
50 | fi |
---|
51 | echo "LOCAL_DIR=`echo $localdir`" |
---|
52 | echo 'MISC = $(LIBF)/misc' |
---|
53 | #echo 'DYN3D_COMMON = $(LIBF)/dyn3d_common' |
---|
54 | echo "FILTRE = filtre" |
---|
55 | echo "PHYS = " |
---|
56 | echo 'LIBPHY = $(LIBO)/libphy$(PHYS).a' |
---|
57 | echo 'LIBDYN_PHY = $(LIBO)/libdynlmdz_phy$(PHYS).a' |
---|
58 | echo 'DIRMAIN=dyn$(DIM)d$(FLAG_PARA)' |
---|
59 | echo 'RM=rm' |
---|
60 | echo |
---|
61 | echo "OPLINK = " |
---|
62 | echo |
---|
63 | echo '# Les differentes librairies pour l"edition des liens:' |
---|
64 | echo 'L_DYN = -ldyn$(DIM)d$(FLAG_PARA) -ldyn3d_common' |
---|
65 | echo 'L_FILTRE = -l$(FILTRE)' |
---|
66 | echo 'L_DYN_PHY = -ldynlmdz_phy$(PHYS) ' |
---|
67 | echo 'L_PHY = -lphy$(PHYS) -lphy_common' |
---|
68 | echo 'L_MISC = -lmisc' |
---|
69 | echo 'L_ADJNT =' |
---|
70 | echo 'L_COSP = -lcosp' |
---|
71 | echo 'L_AERONOMARS = -laeronomars' |
---|
72 | echo 'L_AERONOSTD = -laeronostd' |
---|
73 | |
---|
74 | echo |
---|
75 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
76 | echo "# Option de compilation FORTRAN" |
---|
77 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
78 | echo |
---|
79 | echo 'COMPILE = $(F77) $(OPTIM) $(INCLUDE) -c' |
---|
80 | echo 'COMPILE90 = $(F90) $(OPTIM90) $(INCLUDE) -c' |
---|
81 | echo 'COMPTRU90 = $(F90) $(OPTIMTRU90) $(INCLUDE) -c' |
---|
82 | echo "LINK = $LINK" |
---|
83 | echo "AR = $AR" |
---|
84 | echo |
---|
85 | echo |
---|
86 | echo '#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' |
---|
87 | echo '# Option de compilation C' |
---|
88 | echo '#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' |
---|
89 | echo |
---|
90 | echo 'COMPILEC = $(CCC) $(OPTIMC) $(INCLUDEC) -c' |
---|
91 | echo |
---|
92 | echo |
---|
93 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
94 | echo "# Creation des differents executables" |
---|
95 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
96 | echo |
---|
97 | echo "# Executables:" |
---|
98 | echo "# ------------" |
---|
99 | echo |
---|
100 | echo "PROG = code" |
---|
101 | echo 'DYN = dyn$(DIM)d' |
---|
102 | echo |
---|
103 | #echo 'main : chimie $(DYN) bibio phys $(OPTION_DEP) ' |
---|
104 | echo 'main : $(DYN) misc phys phy_common dyn_phy $(OPTION_DEP) ' |
---|
105 | echo ' cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\' |
---|
106 | echo ' cd $(LOCAL_DIR); \' |
---|
107 | echo ' $(COMPILE90) $(LIBF)/$(DIRMAIN)/$(SOURCE) -o $(PROG).o ; \' |
---|
108 | echo ' $(LINK) $(PROG).o -L$(LIBO) $(L_DYN) $(L_DYN_PHY) $(L_ADJNT) $(L_COSP) $(L_AERONOMARS) $(L_AERONOSTD) $(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 ' |
---|
109 | echo |
---|
110 | echo 'phys : $(LIBPHY)' |
---|
111 | echo 'phy_common : $(LIBPHY_COMMON)' |
---|
112 | echo 'dyn3d : $(LIBO)/libdyn$(DIM)d$(FLAG_PARA).a $(LIBO)/lib$(FILTRE).a $(LIBO)/libdyn3d_common.a' |
---|
113 | echo 'dyn2d : $(LIBO)/libdyn2d.a' |
---|
114 | echo 'dyn1d :' |
---|
115 | echo |
---|
116 | echo 'dyn_phy: $(LIBDYN_PHYS)' |
---|
117 | echo |
---|
118 | #echo 'chimie : $(LIBO)/libchimie.a' |
---|
119 | echo |
---|
120 | echo 'misc : $(LIBO)/libmisc.a' |
---|
121 | echo |
---|
122 | echo 'adjnt : $(LIBO)/libadjnt.a' |
---|
123 | echo |
---|
124 | echo 'cosp : $(LIBO)/libcosp.a' |
---|
125 | echo |
---|
126 | echo 'chimtitan : $(LIBO)/libchimtitan.a' |
---|
127 | echo |
---|
128 | echo 'aeronomars : $(LIBO)/libaeronomars.a' |
---|
129 | echo |
---|
130 | echo 'aeronostd : $(LIBO)/libaeronostd.a' |
---|
131 | echo |
---|
132 | echo '$(FILTRE)3d : $(LIBO)/lib$(FILTRE).a' |
---|
133 | echo |
---|
134 | echo '$(FILTRE)2d :' |
---|
135 | echo |
---|
136 | echo '$(FILTRE)1d :' |
---|
137 | echo |
---|
138 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
139 | echo "# Contenu des differentes bibliotheques" |
---|
140 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
141 | echo |
---|
142 | echo |
---|
143 | cd $libf >/dev/null 2>&1 |
---|
144 | |
---|
145 | for diri in $src_dirs ; do |
---|
146 | |
---|
147 | if [ -d $diri ] ; then |
---|
148 | if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.[fF]90`" != "" ] ; then |
---|
149 | # cd $diri >/dev/null 2>&1 |
---|
150 | echo |
---|
151 | listlib="" |
---|
152 | # Liste des fichiers .F et .F90 n'etant pas des programmes principaux |
---|
153 | for fili in `ls $diri/*.[fF]` ; do |
---|
154 | # Check if file is a routine or main program |
---|
155 | # i.e: look for the "program" keword preceeded by leading spaces |
---|
156 | test=` ( head $fili | grep -i '^ *program' ) ` |
---|
157 | if [ "$test" = "" ] ; then |
---|
158 | # if it is not a main program, add it to the list |
---|
159 | listlib=$listlib" "$fili |
---|
160 | fi |
---|
161 | done |
---|
162 | for fili in `ls $diri/*.[fF]90` ; do |
---|
163 | # Check if file is a routine or main program |
---|
164 | # i.e. look for "program" keyword (with possibly some leading spaces) |
---|
165 | test=` ( head $fili | grep -i '^ \{0,\}program' ) ` |
---|
166 | if [ "$test" = "" ] ; then |
---|
167 | # if it is not a main program, add it to the list |
---|
168 | listlib=$listlib" "$fili |
---|
169 | fi |
---|
170 | done |
---|
171 | # |
---|
172 | echo |
---|
173 | echo $listlib >> $logfile |
---|
174 | echo |
---|
175 | # topdiri contains main dir name (without trailing "/blabla" for subdirs) |
---|
176 | topdiri=${diri%/*} |
---|
177 | echo "#=======================================================================" |
---|
178 | echo "# Contenu de la bibliotheque correspondant au Directory "$diri |
---|
179 | echo "#=======================================================================" |
---|
180 | echo |
---|
181 | for trufile in $listlib |
---|
182 | do |
---|
183 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
184 | echo '$(LIBO)/lib'$topdiri".a : " '$(LIBO)/lib'$topdiri".a("$fili".o)" |
---|
185 | echo |
---|
186 | done |
---|
187 | echo '.PRECIOUS : $(LIBO)/lib'$topdiri'.a' |
---|
188 | echo |
---|
189 | echo |
---|
190 | echo "# Compilation of elements in $diri of library lib"$topdiri".a" |
---|
191 | echo |
---|
192 | for trufile in $listlib ; do |
---|
193 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
194 | F90=0 ; egrep -i '^ *use ' $trufile > /dev/null 2>&1 && F90=1 |
---|
195 | egrep -i '^ *module ' $trufile > /dev/null 2>&1 && F90=1 |
---|
196 | egrep -i '#include*.inc ' $trufile > /dev/null 2>&1 && F90=1 |
---|
197 | str1='$(LIBO)/lib'$topdiri'.a('$fili'.o) : $(LIBF)/'$trufile |
---|
198 | [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F |
---|
199 | |
---|
200 | ########################################################################## |
---|
201 | # TRAITEMENT DES DEPENDANCES |
---|
202 | # Differents cas de dependance correspondant a des include ou des |
---|
203 | # use module. |
---|
204 | # soit dans le repertoire local soit dans un autre. |
---|
205 | # Pour dyn3d, il faudrait remplacer la chaine de caractere par $DYN |
---|
206 | # ou quelque chose du genre. |
---|
207 | ########################################################################## |
---|
208 | |
---|
209 | 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 |
---|
210 | echo $trufile $fili $stri >> $logfile |
---|
211 | strj=`echo $stri | tr [A-Z] [a-z]` |
---|
212 | str2="" |
---|
213 | for dirinc in $src_dirs ; do |
---|
214 | # Recherche dans l'ordre hierarchique inverse car seule la derniere |
---|
215 | # ligne est conservee |
---|
216 | # if [ $dirinc = phydev ] ; then |
---|
217 | # dirstr='$(PHYS)' |
---|
218 | # libstr='phy$(PHYS)' |
---|
219 | # else |
---|
220 | dirstr=$dirinc |
---|
221 | libstr=$dirinc |
---|
222 | # fi |
---|
223 | echo dirinc $dirinc >> $logfile |
---|
224 | if [ -f $dirinc/$stri ] ; then |
---|
225 | str2='$(LIBF)/'$dirstr/$stri |
---|
226 | elif [ -f $dirinc/$strj ] ; then |
---|
227 | str2='$(LIBF)/'$dirstr/$stri |
---|
228 | elif [ -f $dirinc/$strj.[fF]90 ] || [ -f $dirinc/$strj.[fF] ] ; then |
---|
229 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
230 | str2='$(LIBO)/lib'$strlib'.a('$strj'.o)' |
---|
231 | elif [ -f $dirinc/$stri.[fF]90 ] || [ -f $dirinc/$stri.[fF] ] ; then |
---|
232 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
233 | str2='$(LIBO)/lib'$strlib'.a('$stri'.o)' |
---|
234 | fi |
---|
235 | echo stri $stri >> $logfile |
---|
236 | echo str2 $str2 >> $logfile |
---|
237 | done |
---|
238 | echo dernier str2 $str2 >> $logfile |
---|
239 | if [ "$str2" = "" ] ; then |
---|
240 | echo Warn: Include $diri $trufile $fili $stri pas trouve >> $logfile |
---|
241 | elif [ "$str2" = "$str1" ] ; then |
---|
242 | echo Warn: Include $diri $trufile $fili $stri $str1 trouve 2x >> $logfile |
---|
243 | else |
---|
244 | echo $str1 \\ |
---|
245 | str1=$str2 |
---|
246 | fi |
---|
247 | done # Fin de la boucle sur les dependances et ecriture de la derniere |
---|
248 | echo $str1 |
---|
249 | # Compile in LIBO directory; and before compiling, remove |
---|
250 | # object from library |
---|
251 | echo ' cd $(LIBO); \' |
---|
252 | echo ' $(AR) d $(LIBO)/lib'$topdiri'.a '$fili'.o ; \' |
---|
253 | if [ "$F90" -eq '0' ] ; then |
---|
254 | ## Fixed Form Fortran 77 |
---|
255 | echo ' $(COMPILE) $(LIBF)/'$trufile' ; \' |
---|
256 | else |
---|
257 | ## Fortran 90 |
---|
258 | if [ -f $fili.F90 ] ; then |
---|
259 | ## Free Form |
---|
260 | echo ' $(COMPTRU90) $(LIBF)/'$trufile' ; \' |
---|
261 | else |
---|
262 | echo ' $(COMPILE90) $(LIBF)/'$trufile' ; \' |
---|
263 | fi |
---|
264 | fi |
---|
265 | # Put generated object in library |
---|
266 | echo ' $(AR) r $(LIBO)/lib'$topdiri'.a '$fili'.o ; $(RM) '$fili'.o ; \' |
---|
267 | echo ' cd $(GCM)' |
---|
268 | echo |
---|
269 | done |
---|
270 | # |
---|
271 | echo |
---|
272 | cd $libf |
---|
273 | ############################## |
---|
274 | ## CAS DES FICHIERS EN C |
---|
275 | ###### |
---|
276 | elif [ "`ls $diri/*.c`" != "" ] ; then |
---|
277 | cd $diri >/dev/null 2>&1 |
---|
278 | echo |
---|
279 | listlib="" |
---|
280 | for i in `ls *.c` |
---|
281 | do |
---|
282 | fili=`basename $i .c` |
---|
283 | # Check if file is a function or main program |
---|
284 | # i.e. look for "int main" keywords (with possibly some leading spaces) |
---|
285 | test=` ( head $i | grep '^ \{0,\}int main' ) ` |
---|
286 | if [ "$test" = "" ] ; then |
---|
287 | # if it is not a main program, add it to the list |
---|
288 | listlib=$listlib" "$fili |
---|
289 | fi |
---|
290 | done |
---|
291 | # |
---|
292 | echo |
---|
293 | echo |
---|
294 | echo '#=======================================================================' |
---|
295 | echo '# Contenu de la bibliotheque correspondant au Directory '$diri |
---|
296 | echo '#=======================================================================' |
---|
297 | echo |
---|
298 | for fili in $listlib |
---|
299 | do |
---|
300 | echo '$(LIBO)/lib'$diri".a : " '$(LIBO)/lib'$diri".a("$fili".o)" |
---|
301 | echo |
---|
302 | done |
---|
303 | echo '.PRECIOUS : $(LIBO)/lib'$diri'.a' |
---|
304 | echo |
---|
305 | echo |
---|
306 | echo '# Compilation des membres de la bibliotheque lib'$diri'.a' |
---|
307 | echo |
---|
308 | for fili in $listlib |
---|
309 | do |
---|
310 | str1='$(LIBO)/lib'$diri'.a('$fili'.o) : $(LIBF)/'$diri/$fili.c |
---|
311 | for stri in ` ( sed -n "/\#include/s/\#include//p" $fili.c | sed 's/\"//g' ) ` |
---|
312 | do |
---|
313 | if [ -f $stri ] ; then |
---|
314 | echo $str1 \\ |
---|
315 | str1='$(LIBF)/'$diri'/'$stri |
---|
316 | else |
---|
317 | for dirinc in dyn3d grid misc |
---|
318 | do |
---|
319 | if [ -f ../$dirinc/$stri ] ; then |
---|
320 | echo $str1 \\ |
---|
321 | str1='$(LIBF)/'`cd .. ; ls */$stri | head -1` |
---|
322 | fi |
---|
323 | done |
---|
324 | fi |
---|
325 | done |
---|
326 | echo $str1 |
---|
327 | # Compile in LIBO directory; and before compiling, remove |
---|
328 | # object from library |
---|
329 | echo ' cd $(LIBO); \' |
---|
330 | echo ' $(AR) d $(LIBO)/lib'$diri'.a '$fili'.o ; \' |
---|
331 | ## C |
---|
332 | echo ' $(COMPILEC) $(LIBF)/'$diri'/'$fili'.c; \' |
---|
333 | # Put generated object in library |
---|
334 | echo ' $(AR) r $(LIBO)/lib'$diri'.a '$fili'.o ; $(RM) '$fili'.o ; \' |
---|
335 | echo ' cd $(GCM)' |
---|
336 | echo |
---|
337 | done |
---|
338 | # |
---|
339 | echo |
---|
340 | cd $libf |
---|
341 | ############################## |
---|
342 | fi |
---|
343 | fi |
---|
344 | done |
---|