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