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 | |
---|
73 | echo |
---|
74 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
75 | echo "# Option de compilation FORTRAN" |
---|
76 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
77 | echo |
---|
78 | echo 'COMPILE = $(F77) $(OPTIM) $(INCLUDE) -c' |
---|
79 | echo 'COMPILE90 = $(F90) $(OPTIM90) $(INCLUDE) -c' |
---|
80 | echo 'COMPTRU90 = $(F90) $(OPTIMTRU90) $(INCLUDE) -c' |
---|
81 | echo "LINK = $LINK" |
---|
82 | echo "AR = $AR" |
---|
83 | echo |
---|
84 | echo |
---|
85 | echo '#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' |
---|
86 | echo '# Option de compilation C' |
---|
87 | echo '#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' |
---|
88 | echo |
---|
89 | echo 'COMPILEC = $(CCC) $(OPTIMC) $(INCLUDEC) -c' |
---|
90 | echo |
---|
91 | echo |
---|
92 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
93 | echo "# Creation des differents executables" |
---|
94 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
95 | echo |
---|
96 | echo "# Executables:" |
---|
97 | echo "# ------------" |
---|
98 | echo |
---|
99 | echo "PROG = code" |
---|
100 | echo 'DYN = dyn$(DIM)d' |
---|
101 | echo |
---|
102 | #echo 'main : chimie $(DYN) bibio phys $(OPTION_DEP) ' |
---|
103 | echo 'main : $(DYN) misc phys phy_common dyn_phy $(OPTION_DEP) ' |
---|
104 | echo ' cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\' |
---|
105 | echo ' cd $(LOCAL_DIR); \' |
---|
106 | echo ' $(COMPILE90) $(LIBF)/$(DIRMAIN)/$(SOURCE) -o $(PROG).o ; \' |
---|
107 | echo ' $(LINK) $(PROG).o -L$(LIBO) $(L_DYN) $(L_DYN_PHY) $(L_ADJNT) $(L_COSP) $(L_AERONOMARS) $(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 ' |
---|
108 | echo |
---|
109 | echo 'phys : $(LIBPHY)' |
---|
110 | echo 'phy_common : $(LIBPHY_COMMON)' |
---|
111 | echo 'dyn3d : $(LIBO)/libdyn$(DIM)d$(FLAG_PARA).a $(LIBO)/lib$(FILTRE).a $(LIBO)/libdyn3d_common.a' |
---|
112 | echo 'dyn2d : $(LIBO)/libdyn2d.a' |
---|
113 | echo 'dyn1d :' |
---|
114 | echo |
---|
115 | echo 'dyn_phy: $(LIBDYN_PHYS)' |
---|
116 | echo |
---|
117 | #echo 'chimie : $(LIBO)/libchimie.a' |
---|
118 | echo |
---|
119 | echo 'misc : $(LIBO)/libmisc.a' |
---|
120 | echo |
---|
121 | echo 'adjnt : $(LIBO)/libadjnt.a' |
---|
122 | echo |
---|
123 | echo 'cosp : $(LIBO)/libcosp.a' |
---|
124 | echo |
---|
125 | echo 'chimtitan : $(LIBO)/libchimtitan.a' |
---|
126 | echo |
---|
127 | echo 'aeronomars : $(LIBO)/libaeronomars.a' |
---|
128 | echo |
---|
129 | echo '$(FILTRE)3d : $(LIBO)/lib$(FILTRE).a' |
---|
130 | echo |
---|
131 | echo '$(FILTRE)2d :' |
---|
132 | echo |
---|
133 | echo '$(FILTRE)1d :' |
---|
134 | echo |
---|
135 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
136 | echo "# Contenu des differentes bibliotheques" |
---|
137 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
138 | echo |
---|
139 | echo |
---|
140 | cd $libf >/dev/null 2>&1 |
---|
141 | |
---|
142 | for diri in $src_dirs ; do |
---|
143 | |
---|
144 | if [ -d $diri ] ; then |
---|
145 | if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.[fF]90`" != "" ] ; then |
---|
146 | # cd $diri >/dev/null 2>&1 |
---|
147 | echo |
---|
148 | listlib="" |
---|
149 | # Liste des fichiers .F et .F90 n'etant pas des programmes principaux |
---|
150 | for fili in `ls $diri/*.[fF]` ; do |
---|
151 | # Check if file is a routine or main program |
---|
152 | # i.e: look for the "program" keword preceeded by leading spaces |
---|
153 | test=` ( head $fili | grep -i '^ *program' ) ` |
---|
154 | if [ "$test" = "" ] ; then |
---|
155 | # if it is not a main program, add it to the list |
---|
156 | listlib=$listlib" "$fili |
---|
157 | fi |
---|
158 | done |
---|
159 | for fili in `ls $diri/*.[fF]90` ; do |
---|
160 | # Check if file is a routine or main program |
---|
161 | # i.e. look for "program" keyword (with possibly some leading spaces) |
---|
162 | test=` ( head $fili | grep -i '^ \{0,\}program' ) ` |
---|
163 | if [ "$test" = "" ] ; then |
---|
164 | # if it is not a main program, add it to the list |
---|
165 | listlib=$listlib" "$fili |
---|
166 | fi |
---|
167 | done |
---|
168 | # |
---|
169 | echo |
---|
170 | echo $listlib >> $logfile |
---|
171 | echo |
---|
172 | # topdiri contains main dir name (without trailing "/blabla" for subdirs) |
---|
173 | topdiri=${diri%/*} |
---|
174 | echo "#=======================================================================" |
---|
175 | echo "# Contenu de la bibliotheque correspondant au Directory "$diri |
---|
176 | echo "#=======================================================================" |
---|
177 | echo |
---|
178 | for trufile in $listlib |
---|
179 | do |
---|
180 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
181 | echo '$(LIBO)/lib'$topdiri".a : " '$(LIBO)/lib'$topdiri".a("$fili".o)" |
---|
182 | echo |
---|
183 | done |
---|
184 | echo '.PRECIOUS : $(LIBO)/lib'$topdiri'.a' |
---|
185 | echo |
---|
186 | echo |
---|
187 | echo "# Compilation of elements in $diri of library lib"$topdiri".a" |
---|
188 | echo |
---|
189 | for trufile in $listlib ; do |
---|
190 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
191 | F90=0 ; egrep -i '^ *use ' $trufile > /dev/null 2>&1 && F90=1 |
---|
192 | egrep -i '^ *module ' $trufile > /dev/null 2>&1 && F90=1 |
---|
193 | egrep -i '#include*.inc ' $trufile > /dev/null 2>&1 && F90=1 |
---|
194 | str1='$(LIBO)/lib'$topdiri'.a('$fili'.o) : $(LIBF)/'$trufile |
---|
195 | [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F |
---|
196 | |
---|
197 | ########################################################################## |
---|
198 | # TRAITEMENT DES DEPENDANCES |
---|
199 | # Differents cas de dependance correspondant a des include ou des |
---|
200 | # use module. |
---|
201 | # soit dans le repertoire local soit dans un autre. |
---|
202 | # Pour dyn3d, il faudrait remplacer la chaine de caractere par $DYN |
---|
203 | # ou quelque chose du genre. |
---|
204 | ########################################################################## |
---|
205 | |
---|
206 | 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 |
---|
207 | echo $trufile $fili $stri >> $logfile |
---|
208 | strj=`echo $stri | tr [A-Z] [a-z]` |
---|
209 | str2="" |
---|
210 | for dirinc in $src_dirs ; do |
---|
211 | # Recherche dans l'ordre hierarchique inverse car seule la derniere |
---|
212 | # ligne est conservee |
---|
213 | # if [ $dirinc = phydev ] ; then |
---|
214 | # dirstr='$(PHYS)' |
---|
215 | # libstr='phy$(PHYS)' |
---|
216 | # else |
---|
217 | dirstr=$dirinc |
---|
218 | libstr=$dirinc |
---|
219 | # fi |
---|
220 | echo dirinc $dirinc >> $logfile |
---|
221 | if [ -f $dirinc/$stri ] ; then |
---|
222 | str2='$(LIBF)/'$dirstr/$stri |
---|
223 | elif [ -f $dirinc/$strj ] ; then |
---|
224 | str2='$(LIBF)/'$dirstr/$stri |
---|
225 | elif [ -f $dirinc/$strj.[fF]90 ] || [ -f $dirinc/$strj.[fF] ] ; then |
---|
226 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
227 | str2='$(LIBO)/lib'$strlib'.a('$strj'.o)' |
---|
228 | elif [ -f $dirinc/$stri.[fF]90 ] || [ -f $dirinc/$stri.[fF] ] ; then |
---|
229 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
230 | str2='$(LIBO)/lib'$strlib'.a('$stri'.o)' |
---|
231 | fi |
---|
232 | echo stri $stri >> $logfile |
---|
233 | echo str2 $str2 >> $logfile |
---|
234 | done |
---|
235 | echo dernier str2 $str2 >> $logfile |
---|
236 | if [ "$str2" = "" ] ; then |
---|
237 | echo Warn: Include $diri $trufile $fili $stri pas trouve >> $logfile |
---|
238 | elif [ "$str2" = "$str1" ] ; then |
---|
239 | echo Warn: Include $diri $trufile $fili $stri $str1 trouve 2x >> $logfile |
---|
240 | else |
---|
241 | echo $str1 \\ |
---|
242 | str1=$str2 |
---|
243 | fi |
---|
244 | done # Fin de la boucle sur les dependances et ecriture de la derniere |
---|
245 | echo $str1 |
---|
246 | # Compile in LIBO directory; and before compiling, remove |
---|
247 | # object from library |
---|
248 | echo ' cd $(LIBO); \' |
---|
249 | echo ' $(AR) d $(LIBO)/lib'$topdiri'.a '$fili'.o ; \' |
---|
250 | if [ "$F90" -eq '0' ] ; then |
---|
251 | ## Fixed Form Fortran 77 |
---|
252 | echo ' $(COMPILE) $(LIBF)/'$trufile' ; \' |
---|
253 | else |
---|
254 | ## Fortran 90 |
---|
255 | if [ -f $fili.F90 ] ; then |
---|
256 | ## Free Form |
---|
257 | echo ' $(COMPTRU90) $(LIBF)/'$trufile' ; \' |
---|
258 | else |
---|
259 | echo ' $(COMPILE90) $(LIBF)/'$trufile' ; \' |
---|
260 | fi |
---|
261 | fi |
---|
262 | # Put generated object in library |
---|
263 | echo ' $(AR) r $(LIBO)/lib'$topdiri'.a '$fili'.o ; $(RM) '$fili'.o ; \' |
---|
264 | echo ' cd $(GCM)' |
---|
265 | echo |
---|
266 | done |
---|
267 | # |
---|
268 | echo |
---|
269 | cd $libf |
---|
270 | ############################## |
---|
271 | ## CAS DES FICHIERS EN C |
---|
272 | ###### |
---|
273 | elif [ "`ls $diri/*.c`" != "" ] ; then |
---|
274 | cd $diri >/dev/null 2>&1 |
---|
275 | echo |
---|
276 | listlib="" |
---|
277 | for i in `ls *.c` |
---|
278 | do |
---|
279 | fili=`basename $i .c` |
---|
280 | # Check if file is a function or main program |
---|
281 | # i.e. look for "int main" keywords (with possibly some leading spaces) |
---|
282 | test=` ( head $i | grep '^ \{0,\}int main' ) ` |
---|
283 | if [ "$test" = "" ] ; then |
---|
284 | # if it is not a main program, add it to the list |
---|
285 | listlib=$listlib" "$fili |
---|
286 | fi |
---|
287 | done |
---|
288 | # |
---|
289 | echo |
---|
290 | echo |
---|
291 | echo '#=======================================================================' |
---|
292 | echo '# Contenu de la bibliotheque correspondant au Directory '$diri |
---|
293 | echo '#=======================================================================' |
---|
294 | echo |
---|
295 | for fili in $listlib |
---|
296 | do |
---|
297 | echo '$(LIBO)/lib'$diri".a : " '$(LIBO)/lib'$diri".a("$fili".o)" |
---|
298 | echo |
---|
299 | done |
---|
300 | echo '.PRECIOUS : $(LIBO)/lib'$diri'.a' |
---|
301 | echo |
---|
302 | echo |
---|
303 | echo '# Compilation des membres de la bibliotheque lib'$diri'.a' |
---|
304 | echo |
---|
305 | for fili in $listlib |
---|
306 | do |
---|
307 | str1='$(LIBO)/lib'$diri'.a('$fili'.o) : $(LIBF)/'$diri/$fili.c |
---|
308 | for stri in ` ( sed -n "/\#include/s/\#include//p" $fili.c | sed 's/\"//g' ) ` |
---|
309 | do |
---|
310 | if [ -f $stri ] ; then |
---|
311 | echo $str1 \\ |
---|
312 | str1='$(LIBF)/'$diri'/'$stri |
---|
313 | else |
---|
314 | for dirinc in dyn3d grid misc |
---|
315 | do |
---|
316 | if [ -f ../$dirinc/$stri ] ; then |
---|
317 | echo $str1 \\ |
---|
318 | str1='$(LIBF)/'`cd .. ; ls */$stri | head -1` |
---|
319 | fi |
---|
320 | done |
---|
321 | fi |
---|
322 | done |
---|
323 | echo $str1 |
---|
324 | # Compile in LIBO directory; and before compiling, remove |
---|
325 | # object from library |
---|
326 | echo ' cd $(LIBO); \' |
---|
327 | echo ' $(AR) d $(LIBO)/lib'$diri'.a '$fili'.o ; \' |
---|
328 | ## C |
---|
329 | echo ' $(COMPILEC) $(LIBF)/'$diri'/'$fili'.c; \' |
---|
330 | # Put generated object in library |
---|
331 | echo ' $(AR) r $(LIBO)/lib'$diri'.a '$fili'.o ; $(RM) '$fili'.o ; \' |
---|
332 | echo ' cd $(GCM)' |
---|
333 | echo |
---|
334 | done |
---|
335 | # |
---|
336 | echo |
---|
337 | cd $libf |
---|
338 | ############################## |
---|
339 | fi |
---|
340 | fi |
---|
341 | done |
---|