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