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