[1] | 1 | #!/bin/sh |
---|
| 2 | # |
---|
[66] | 3 | # $Id: create_make_gcm 1461 2010-12-03 11:12:25Z emillour $ |
---|
[1] | 4 | # |
---|
| 5 | #set -xv |
---|
[979] | 6 | |
---|
[1403] | 7 | # arguments given to create_make_gcm are the directories to scan |
---|
| 8 | src_dirs=$* |
---|
[979] | 9 | |
---|
[1] | 10 | machine=`hostname` |
---|
| 11 | os=`uname` |
---|
| 12 | gcm=`pwd` |
---|
[1302] | 13 | logfile=$gcm/create_make_gcm.log |
---|
| 14 | rm -f $logfile ; touch -f $logfile |
---|
[1] | 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`" |
---|
[1403] | 52 | echo 'MISC = $(LIBF)/misc' |
---|
| 53 | #echo 'DYN3D_COMMON = $(LIBF)/dyn3d_common' |
---|
[1] | 54 | echo "FILTRE = filtre" |
---|
| 55 | echo "PHYS = " |
---|
| 56 | echo 'LIBPHY = $(LIBO)/libphy$(PHYS).a' |
---|
[1403] | 57 | echo 'LIBDYN_PHY = $(LIBO)/libdynlmdz_phy$(PHYS).a' |
---|
[1] | 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:' |
---|
[1302] | 64 | echo 'L_DYN = -ldyn$(DIM)d$(FLAG_PARA) -ldyn3d_common' |
---|
[66] | 65 | echo 'L_FILTRE = -l$(FILTRE)' |
---|
[1403] | 66 | echo 'L_DYN_PHY = -ldynlmdz_phy$(PHYS) ' |
---|
[1521] | 67 | echo 'L_PHY = -lphy$(PHYS) -lphy_common' |
---|
[1403] | 68 | echo 'L_MISC = -lmisc' |
---|
[66] | 69 | echo 'L_ADJNT =' |
---|
| 70 | echo 'L_COSP = -lcosp' |
---|
[1107] | 71 | echo 'L_AERONOMARS = -laeronomars' |
---|
[1803] | 72 | echo 'L_AERONOSTD = -laeronostd' |
---|
[1] | 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 |
---|
[104] | 86 | echo '#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' |
---|
| 87 | echo '# Option de compilation C' |
---|
| 88 | echo '#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' |
---|
| 89 | echo |
---|
| 90 | echo 'COMPILEC = $(CCC) $(OPTIMC) $(INCLUDEC) -c' |
---|
| 91 | echo |
---|
| 92 | echo |
---|
[1] | 93 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 94 | echo "# Creation des differents executables" |
---|
| 95 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 96 | echo |
---|
| 97 | echo "# Executables:" |
---|
| 98 | echo "# ------------" |
---|
| 99 | echo |
---|
| 100 | echo "PROG = code" |
---|
[1302] | 101 | echo 'DYN = dyn$(DIM)d' |
---|
[1] | 102 | echo |
---|
| 103 | #echo 'main : chimie $(DYN) bibio phys $(OPTION_DEP) ' |
---|
[1521] | 104 | echo 'main : $(DYN) misc phys phy_common dyn_phy $(OPTION_DEP) ' |
---|
[1] | 105 | echo ' cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\' |
---|
| 106 | echo ' cd $(LOCAL_DIR); \' |
---|
| 107 | echo ' $(COMPILE90) $(LIBF)/$(DIRMAIN)/$(SOURCE) -o $(PROG).o ; \' |
---|
[1803] | 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 ' |
---|
[1] | 109 | echo |
---|
| 110 | echo 'phys : $(LIBPHY)' |
---|
[1521] | 111 | echo 'phy_common : $(LIBPHY_COMMON)' |
---|
[1302] | 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 :' |
---|
[1] | 115 | echo |
---|
[1403] | 116 | echo 'dyn_phy: $(LIBDYN_PHYS)' |
---|
[1302] | 117 | echo |
---|
[1] | 118 | #echo 'chimie : $(LIBO)/libchimie.a' |
---|
| 119 | echo |
---|
[1403] | 120 | echo 'misc : $(LIBO)/libmisc.a' |
---|
[1] | 121 | echo |
---|
| 122 | echo 'adjnt : $(LIBO)/libadjnt.a' |
---|
| 123 | echo |
---|
| 124 | echo 'cosp : $(LIBO)/libcosp.a' |
---|
| 125 | echo |
---|
[104] | 126 | echo 'chimtitan : $(LIBO)/libchimtitan.a' |
---|
| 127 | echo |
---|
[1107] | 128 | echo 'aeronomars : $(LIBO)/libaeronomars.a' |
---|
| 129 | echo |
---|
[1803] | 130 | echo 'aeronostd : $(LIBO)/libaeronostd.a' |
---|
| 131 | echo |
---|
[1] | 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 |
---|
[1302] | 144 | |
---|
[1403] | 145 | for diri in $src_dirs ; do |
---|
| 146 | |
---|
[1] | 147 | if [ -d $diri ] ; then |
---|
[1403] | 148 | if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.[fF]90`" != "" ] ; then |
---|
[979] | 149 | # cd $diri >/dev/null 2>&1 |
---|
[1] | 150 | echo |
---|
| 151 | listlib="" |
---|
[979] | 152 | # Liste des fichiers .F et .F90 n'etant pas des programmes principaux |
---|
[1403] | 153 | for fili in `ls $diri/*.[fF]` ; do |
---|
[634] | 154 | # Check if file is a routine or main program |
---|
| 155 | # i.e: look for the "program" keword preceeded by leading spaces |
---|
[979] | 156 | test=` ( head $fili | grep -i '^ *program' ) ` |
---|
[1] | 157 | if [ "$test" = "" ] ; then |
---|
[634] | 158 | # if it is not a main program, add it to the list |
---|
[1] | 159 | listlib=$listlib" "$fili |
---|
| 160 | fi |
---|
| 161 | done |
---|
[1403] | 162 | for fili in `ls $diri/*.[fF]90` ; do |
---|
[634] | 163 | # Check if file is a routine or main program |
---|
| 164 | # i.e. look for "program" keyword (with possibly some leading spaces) |
---|
[979] | 165 | test=` ( head $fili | grep -i '^ \{0,\}program' ) ` |
---|
[1] | 166 | if [ "$test" = "" ] ; then |
---|
[634] | 167 | # if it is not a main program, add it to the list |
---|
[1] | 168 | listlib=$listlib" "$fili |
---|
| 169 | fi |
---|
| 170 | done |
---|
| 171 | # |
---|
| 172 | echo |
---|
[1302] | 173 | echo $listlib >> $logfile |
---|
[1] | 174 | echo |
---|
[1403] | 175 | # topdiri contains main dir name (without trailing "/blabla" for subdirs) |
---|
| 176 | topdiri=${diri%/*} |
---|
[1] | 177 | echo "#=======================================================================" |
---|
| 178 | echo "# Contenu de la bibliotheque correspondant au Directory "$diri |
---|
| 179 | echo "#=======================================================================" |
---|
| 180 | echo |
---|
[979] | 181 | for trufile in $listlib |
---|
[1] | 182 | do |
---|
[979] | 183 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
[1403] | 184 | echo '$(LIBO)/lib'$topdiri".a : " '$(LIBO)/lib'$topdiri".a("$fili".o)" |
---|
[1] | 185 | echo |
---|
| 186 | done |
---|
[1403] | 187 | echo '.PRECIOUS : $(LIBO)/lib'$topdiri'.a' |
---|
[1] | 188 | echo |
---|
| 189 | echo |
---|
[1403] | 190 | echo "# Compilation of elements in $diri of library lib"$topdiri".a" |
---|
[1] | 191 | echo |
---|
[1302] | 192 | for trufile in $listlib ; do |
---|
[979] | 193 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
[1] | 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 |
---|
[1403] | 197 | str1='$(LIBO)/lib'$topdiri'.a('$fili'.o) : $(LIBF)/'$trufile |
---|
| 198 | [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F |
---|
[1] | 199 | |
---|
[979] | 200 | ########################################################################## |
---|
| 201 | # TRAITEMENT DES DEPENDANCES |
---|
[1] | 202 | # Differents cas de dependance correspondant a des include ou des |
---|
| 203 | # use module. |
---|
| 204 | # soit dans le repertoire local soit dans un autre. |
---|
[979] | 205 | # Pour dyn3d, il faudrait remplacer la chaine de caractere par $DYN |
---|
| 206 | # ou quelque chose du genre. |
---|
| 207 | ########################################################################## |
---|
[1] | 208 | |
---|
[1302] | 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 |
---|
[979] | 211 | strj=`echo $stri | tr [A-Z] [a-z]` |
---|
| 212 | str2="" |
---|
[1403] | 213 | for dirinc in $src_dirs ; do |
---|
[979] | 214 | # Recherche dans l'ordre hierarchique inverse car seule la derniere |
---|
| 215 | # ligne est conservee |
---|
[1403] | 216 | # if [ $dirinc = phydev ] ; then |
---|
| 217 | # dirstr='$(PHYS)' |
---|
| 218 | # libstr='phy$(PHYS)' |
---|
| 219 | # else |
---|
[1300] | 220 | dirstr=$dirinc |
---|
| 221 | libstr=$dirinc |
---|
[1403] | 222 | # fi |
---|
[1302] | 223 | echo dirinc $dirinc >> $logfile |
---|
[979] | 224 | if [ -f $dirinc/$stri ] ; then |
---|
[1300] | 225 | str2='$(LIBF)/'$dirstr/$stri |
---|
[979] | 226 | elif [ -f $dirinc/$strj ] ; then |
---|
[1300] | 227 | str2='$(LIBF)/'$dirstr/$stri |
---|
[1391] | 228 | elif [ -f $dirinc/$strj.[fF]90 ] || [ -f $dirinc/$strj.[fF] ] ; then |
---|
[1300] | 229 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
[979] | 230 | str2='$(LIBO)/lib'$strlib'.a('$strj'.o)' |
---|
[1391] | 231 | elif [ -f $dirinc/$stri.[fF]90 ] || [ -f $dirinc/$stri.[fF] ] ; then |
---|
[1300] | 232 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
| 233 | str2='$(LIBO)/lib'$strlib'.a('$stri'.o)' |
---|
[979] | 234 | fi |
---|
[1302] | 235 | echo stri $stri >> $logfile |
---|
| 236 | echo str2 $str2 >> $logfile |
---|
[979] | 237 | done |
---|
[1302] | 238 | echo dernier str2 $str2 >> $logfile |
---|
[979] | 239 | if [ "$str2" = "" ] ; then |
---|
[1302] | 240 | echo Warn: Include $diri $trufile $fili $stri pas trouve >> $logfile |
---|
[979] | 241 | elif [ "$str2" = "$str1" ] ; then |
---|
[1302] | 242 | echo Warn: Include $diri $trufile $fili $stri $str1 trouve 2x >> $logfile |
---|
[979] | 243 | else |
---|
[1] | 244 | echo $str1 \\ |
---|
[979] | 245 | str1=$str2 |
---|
[1] | 246 | fi |
---|
[979] | 247 | done # Fin de la boucle sur les dependances et ecriture de la derniere |
---|
[1] | 248 | echo $str1 |
---|
[66] | 249 | # Compile in LIBO directory; and before compiling, remove |
---|
| 250 | # object from library |
---|
| 251 | echo ' cd $(LIBO); \' |
---|
[1403] | 252 | echo ' $(AR) d $(LIBO)/lib'$topdiri'.a '$fili'.o ; \' |
---|
[1] | 253 | if [ "$F90" -eq '0' ] ; then |
---|
[66] | 254 | ## Fixed Form Fortran 77 |
---|
[979] | 255 | echo ' $(COMPILE) $(LIBF)/'$trufile' ; \' |
---|
[1] | 256 | else |
---|
[66] | 257 | ## Fortran 90 |
---|
[1] | 258 | if [ -f $fili.F90 ] ; then |
---|
[66] | 259 | ## Free Form |
---|
[979] | 260 | echo ' $(COMPTRU90) $(LIBF)/'$trufile' ; \' |
---|
[1] | 261 | else |
---|
[979] | 262 | echo ' $(COMPILE90) $(LIBF)/'$trufile' ; \' |
---|
[1] | 263 | fi |
---|
| 264 | fi |
---|
[66] | 265 | # Put generated object in library |
---|
[1403] | 266 | echo ' $(AR) r $(LIBO)/lib'$topdiri'.a '$fili'.o ; $(RM) '$fili'.o ; \' |
---|
[1] | 267 | echo ' cd $(GCM)' |
---|
| 268 | echo |
---|
| 269 | done |
---|
| 270 | # |
---|
| 271 | echo |
---|
[104] | 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` |
---|
[634] | 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' ) ` |
---|
[104] | 286 | if [ "$test" = "" ] ; then |
---|
[634] | 287 | # if it is not a main program, add it to the list |
---|
[104] | 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 |
---|
[1403] | 317 | for dirinc in dyn3d grid misc |
---|
[104] | 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 | ############################## |
---|
[1] | 342 | fi |
---|
| 343 | fi |
---|
| 344 | done |
---|