[135] | 1 | #!/bin/sh |
---|
| 2 | #set -xv |
---|
| 3 | # |
---|
| 4 | # Ehouarn: added the following feature: |
---|
| 5 | # create_make_gcm must be called with list of directories |
---|
| 6 | # which contain header (or modules) which should be scanned |
---|
| 7 | # by create_make_gcm when checking dependencies. |
---|
| 8 | # Example: |
---|
| 9 | # create_make_gcm dyn3d grid |
---|
| 10 | # means that header/modules will be looked for in directories |
---|
| 11 | # ., dyn3d and grid |
---|
| 12 | # |
---|
[1403] | 13 | |
---|
| 14 | # arguments given to create_make_gcm are the directories to scan |
---|
| 15 | src_dirs=$* |
---|
| 16 | |
---|
[135] | 17 | machine=`hostname` |
---|
| 18 | os=`uname` |
---|
| 19 | gcm=`pwd` |
---|
[1403] | 20 | logfile=$gcm/create_make_gcm.log |
---|
| 21 | rm -f $logfile ; touch -f $logfile |
---|
[135] | 22 | libf=$gcm/libf |
---|
| 23 | libo=$gcm/libo |
---|
| 24 | CRAY=0 |
---|
| 25 | if [ "$machine" = "atlas" -o "$machine" = "etoile" -o "$machine" = "axis" ] ; then |
---|
| 26 | CRAY=1 |
---|
| 27 | fi |
---|
| 28 | XNEC=0 |
---|
| 29 | if [ "$machine" = "rhodes" ] ; then |
---|
| 30 | XNEC=1 |
---|
| 31 | fi |
---|
| 32 | VPP=0 |
---|
| 33 | if [ "$machine" = "nymphea0" ] ; then |
---|
| 34 | VPP=1 |
---|
| 35 | fi |
---|
| 36 | # |
---|
| 37 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 38 | echo "# Definitions de Macros pour Make" |
---|
| 39 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 40 | echo |
---|
| 41 | echo "# create_make_gcm arguments: $*" |
---|
| 42 | echo |
---|
| 43 | echo "# Repertoires :" |
---|
| 44 | echo |
---|
| 45 | echo "GCM = "$gcm |
---|
| 46 | if [ "$CRAY" = '0' ] ; then |
---|
| 47 | echo "MACHINE = sun4" |
---|
| 48 | fi |
---|
| 49 | echo 'LIBF = $(GCM)/libf' |
---|
| 50 | if [ "$CRAY" = '0' ] ; then |
---|
| 51 | # echo 'LIBO = $(GCM)/libo/$(MACHINE)' |
---|
| 52 | echo 'LIBO = $(LIBOGCM)/$(MACHINE)' |
---|
| 53 | else |
---|
| 54 | echo 'LIBO = $(GCM)/libo' |
---|
| 55 | fi |
---|
| 56 | #echo 'LOCAL_DIR=$(GCM)' |
---|
| 57 | #echo $localdir |
---|
| 58 | echo "LOCAL_DIR=`echo $localdir`" |
---|
[1403] | 59 | echo 'MISC = $(LIBF)/misc' |
---|
| 60 | #echo 'AERONOMARS = $(LIBF)/aeronomars' |
---|
[135] | 61 | echo "FILTRE = filtre" |
---|
| 62 | echo "PHYS = " |
---|
| 63 | echo 'DYN = $(DYNTYPE)' |
---|
| 64 | echo 'LIBPHY = $(LIBO)/libphy$(PHYS).a' |
---|
[1403] | 65 | echo 'LIBDYN_PHY = $(LIBO)/libdynlmdz_phy$(PHYS).a' |
---|
[135] | 66 | echo 'DIRMAIN= $(DYN)$(DIM)d' |
---|
| 67 | echo 'RM=rm' |
---|
| 68 | echo |
---|
| 69 | echo "OPLINK = " |
---|
| 70 | echo |
---|
| 71 | echo '# Les differentes librairies pour l"edition des liens:' |
---|
| 72 | echo |
---|
[1403] | 73 | echo 'L_DYN = -ldyn$(DIM)d' |
---|
| 74 | echo 'L_FILTRE = -l$(FILTRE)' |
---|
| 75 | echo 'L_DYN_PHY = -ldynlmdz_phy$(PHYS) ' |
---|
| 76 | echo 'L_PHY = -lphy$(PHYS) ' |
---|
| 77 | echo 'L_MISC = -lmisc' |
---|
| 78 | #echo 'L_AERONOMARS = -laeronomars' |
---|
| 79 | echo 'L_ADJNT =' |
---|
[135] | 80 | echo |
---|
| 81 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 82 | echo "# Option de compilation FORTRAN" |
---|
| 83 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 84 | echo |
---|
| 85 | echo 'COMPILE = $(F77) $(OPTIM) $(INCLUDE) -c' |
---|
| 86 | echo 'COMPILE90 = $(F90) $(OPTIM90) $(INCLUDE) -c' |
---|
| 87 | echo 'COMPTRU90 = $(F90) $(OPTIMTRU90) $(INCLUDE) -c' |
---|
| 88 | echo "LINK = $LINK" |
---|
| 89 | echo "AR = $AR" |
---|
| 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" |
---|
[1403] | 100 | echo 'DYN = dyn$(DIM)d' |
---|
[135] | 101 | echo |
---|
[1403] | 102 | echo 'main : $(DYN) misc phys dyn_phy $(OPTION_DEP) ' |
---|
[135] | 103 | echo ' cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\' |
---|
| 104 | echo ' cd $(LOCAL_DIR); \' |
---|
[302] | 105 | echo ' $(COMPILE90) $(LIBF)/$(DIRMAIN)/$(SOURCE) -o $(PROG).o ; \' |
---|
[135] | 106 | if [ "$CRAY" = '0' ] ; then |
---|
[1403] | 107 | echo ' $(LINK) $(PROG).o -L$(LIBO) $(L_DYN) $(L_DYN_PHY) $(L_ADJNT) $(L_FILTRE) $(L_PHY) $(L_DYN_PHY) $(L_MISC) $(L_DYN) $(L_PHY) $(OPLINK) $(OPTION_LINK) -o $(LOCAL_DIR)/$(PROG).e ; $(RM) $(PROG).o ' |
---|
[135] | 108 | else |
---|
[1403] | 109 | echo ' $(LINK) $(PROG).o -L$(LIBO) $(L_DYN) $(L_DYN_PHY) $(L_ADJNT) $(L_FILTRE) $(L_PHY) $(L_DYN_PHY) $(L_MISC) $(L_DYN) $(L_PHY) $(OPLINK) $(OPTION_LINK) -o $(LOCAL_DIR)/$(PROG).e ; $(RM) $(PROG).o ' |
---|
[135] | 110 | fi |
---|
| 111 | echo |
---|
| 112 | echo 'dyn : $(LIBO)/libdyn$(DIM)d.a $(FILTRE)$(DIM)d' |
---|
| 113 | echo |
---|
| 114 | echo 'olddyn : $(LIBO)/libolddyn$(DIM)d.a $(FILTRE)$(DIM)d' |
---|
| 115 | echo |
---|
| 116 | echo 'phys : $(LIBPHY)' |
---|
| 117 | echo |
---|
[1403] | 118 | echo 'dyn3d : $(LIBO)/libdyn3d.a $(LIBO)/lib$(FILTRE).a' |
---|
| 119 | echo 'dyn2d : $(LIBO)/libdyn2d.a' |
---|
| 120 | echo 'dyn1d : ' |
---|
[135] | 121 | echo |
---|
[1403] | 122 | echo 'dyn_phy: $(LIBDYN_PHYS)' |
---|
| 123 | echo |
---|
| 124 | echo 'misc : $(LIBO)/libmisc.a' |
---|
| 125 | echo |
---|
| 126 | #echo 'aeronomars : $(LIBO)/libaeronomars.a' |
---|
| 127 | #echo |
---|
[135] | 128 | echo 'adjnt : $(LIBO)/libadjnt.a' |
---|
| 129 | echo |
---|
| 130 | echo '$(FILTRE)3d : $(LIBO)/lib$(FILTRE).a' |
---|
| 131 | echo |
---|
| 132 | echo '$(FILTRE)2d :' |
---|
| 133 | echo |
---|
| 134 | echo '$(FILTRE)1d :' |
---|
| 135 | echo |
---|
| 136 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 137 | echo "# Contenu des differentes bibliotheques" |
---|
| 138 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 139 | echo |
---|
| 140 | echo |
---|
| 141 | cd $libf >/dev/null 2>&1 |
---|
[1403] | 142 | |
---|
| 143 | for diri in $src_dirs ; do |
---|
| 144 | |
---|
[135] | 145 | if [ -d $diri ] ; then |
---|
[1403] | 146 | if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.[fF]90`" != "" ] ; then |
---|
| 147 | # cd $diri >/dev/null 2>&1 |
---|
[135] | 148 | echo |
---|
| 149 | listlib="" |
---|
[1403] | 150 | # Liste des fichiers .F et .F90 n'etant pas des programmes principaux |
---|
| 151 | for fili in `ls $diri/*.[fF]` ; do |
---|
[634] | 152 | # Check if file is a routine or main program |
---|
| 153 | # i.e: look for the "program" keword preceeded by leading spaces |
---|
[1403] | 154 | test=` ( head $fili | grep -i '^ *program' ) ` |
---|
| 155 | # if it is not a main program, add it to the list |
---|
| 156 | if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi |
---|
[135] | 157 | done |
---|
[1403] | 158 | for fili in `ls $diri/*.[fF]90` ; do |
---|
[634] | 159 | # Check if file is a routine or main program |
---|
| 160 | # i.e. look for "program" keyword (with possibly some leading spaces) |
---|
[1403] | 161 | test=` ( head $fili | grep -i '^ \{0,\}program' ) ` |
---|
| 162 | # if it is not a main program, add it to the list |
---|
| 163 | if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi |
---|
[135] | 164 | done |
---|
| 165 | echo |
---|
[1403] | 166 | echo $listlib >> $logfile |
---|
[135] | 167 | echo |
---|
[1403] | 168 | # topdiri contains main dir name (without trailing "/blabla" for subdirs) |
---|
| 169 | topdiri=${diri%/*} |
---|
| 170 | echo "#==================================================================" |
---|
[135] | 171 | echo "# Contenu de la bibliotheque correspondant au Directory "$diri |
---|
[1403] | 172 | echo "#==================================================================" |
---|
[135] | 173 | echo |
---|
[1403] | 174 | for trufile in $listlib ; do |
---|
| 175 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
| 176 | echo '$(LIBO)/lib'$topdiri".a : " '$(LIBO)/lib'$topdiri".a("$fili".o)" |
---|
[135] | 177 | echo |
---|
| 178 | done |
---|
[1403] | 179 | echo '.PRECIOUS : $(LIBO)/lib'$topdiri'.a' |
---|
[135] | 180 | echo |
---|
| 181 | echo |
---|
[1403] | 182 | echo "# Compilation of elements in $diri of library lib"$topdiri".a" |
---|
[135] | 183 | echo |
---|
[1403] | 184 | for trufile in $listlib ; do |
---|
| 185 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
[135] | 186 | F90=0 ; egrep -i '^ *use ' $trufile > /dev/null 2>&1 && F90=1 |
---|
| 187 | egrep -i '^ *module ' $trufile > /dev/null 2>&1 && F90=1 |
---|
| 188 | egrep -i '#include*.inc ' $trufile > /dev/null 2>&1 && F90=1 |
---|
[1403] | 189 | str1='$(LIBO)/lib'$topdiri'.a('$fili'.o) : $(LIBF)/'$trufile |
---|
| 190 | [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F |
---|
| 191 | |
---|
| 192 | ########################################################################## |
---|
| 193 | # TRAITEMENT DES DEPENDANCES |
---|
| 194 | # Differents cas de dependance correspondant a des include ou des |
---|
| 195 | # use module. |
---|
| 196 | # soit dans le repertoire local soit dans un autre. |
---|
| 197 | # Pour dyn3d, il faudrait remplacer la chaine de caractere par $DYN |
---|
| 198 | # ou quelque chose du genre. |
---|
| 199 | ########################################################################## |
---|
| 200 | |
---|
| 201 | 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 |
---|
| 202 | echo $trufile $fili $stri >> $logfile |
---|
| 203 | strj=`echo $stri | tr [A-Z] [a-z]` |
---|
| 204 | str2="" |
---|
| 205 | for dirinc in $src_dirs ; do |
---|
| 206 | # Recherche dans l'ordre hierarchique inverse car seule la derniere |
---|
| 207 | # ligne est conservee |
---|
| 208 | # if [ $dirinc = phydev ] ; then |
---|
| 209 | # dirstr='$(PHYS)' |
---|
| 210 | # libstr='phy$(PHYS)' |
---|
| 211 | # else |
---|
| 212 | dirstr=$dirinc |
---|
| 213 | libstr=$dirinc |
---|
| 214 | # fi |
---|
| 215 | echo dirinc $dirinc >> $logfile |
---|
| 216 | if [ -f $dirinc/$stri ] ; then |
---|
| 217 | str2='$(LIBF)/'$dirstr/$stri |
---|
| 218 | elif [ -f $dirinc/$strj ] ; then |
---|
| 219 | str2='$(LIBF)/'$dirstr/$stri |
---|
| 220 | elif [ -f $dirinc/$strj.[fF]90 ] || [ -f $dirinc/$strj.[fF] ] ; then |
---|
| 221 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
| 222 | str2='$(LIBO)/lib'$strlib'.a('$strj'.o)' |
---|
| 223 | elif [ -f $dirinc/$stri.[fF]90 ] || [ -f $dirinc/$stri.[fF] ] ; then |
---|
| 224 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
| 225 | str2='$(LIBO)/lib'$strlib'.a('$stri'.o)' |
---|
| 226 | fi |
---|
| 227 | echo stri $stri >> $logfile |
---|
| 228 | echo str2 $str2 >> $logfile |
---|
| 229 | done |
---|
| 230 | echo dernier str2 $str2 >> $logfile |
---|
| 231 | if [ "$str2" = "" ] ; then |
---|
| 232 | echo Warn: Include $diri $trufile $fili $stri pas trouve >> $logfile |
---|
| 233 | elif [ "$str2" = "$str1" ] ; then |
---|
| 234 | echo Warn: Include $diri $trufile $fili $stri $str1 trouve 2x >> $logfile |
---|
| 235 | else |
---|
[135] | 236 | echo $str1 \\ |
---|
[1403] | 237 | str1=$str2 |
---|
[135] | 238 | fi |
---|
[1403] | 239 | done # Fin de la boucle sur les dependances et ecriture de la derniere |
---|
[135] | 240 | echo $str1 |
---|
[1403] | 241 | # Compile in LIBO directory; and before compiling, remove |
---|
| 242 | # object from library |
---|
| 243 | echo ' cd $(LIBO); \' |
---|
| 244 | echo ' $(AR) d $(LIBO)/lib'$topdiri'.a '$fili'.o ; \' |
---|
[135] | 245 | if [ "$F90" -eq '0' ] ; then |
---|
[1403] | 246 | ## Fixed Form Fortran 77 |
---|
| 247 | echo ' $(COMPILE) $(LIBF)/'$trufile' ; \' |
---|
[135] | 248 | else |
---|
[375] | 249 | ## Fortran 90 |
---|
[1403] | 250 | if [ `echo $trufile | cut -d. -f2` = F90 ] ; then |
---|
| 251 | ## Free Form |
---|
| 252 | echo ' $(COMPTRU90) $(LIBF)/'$trufile' ; \' |
---|
[135] | 253 | else |
---|
[1403] | 254 | echo ' $(COMPILE90) $(LIBF)/'$trufile' ; \' |
---|
[135] | 255 | fi |
---|
| 256 | fi |
---|
[375] | 257 | # Put generated object in library |
---|
[1403] | 258 | echo ' $(AR) r $(LIBO)/lib'$topdiri'.a '$fili'.o ; $(RM) '$fili'.o ; \' |
---|
[135] | 259 | echo |
---|
| 260 | done |
---|
| 261 | # |
---|
| 262 | echo |
---|
| 263 | cd $libf |
---|
| 264 | fi |
---|
| 265 | fi |
---|
| 266 | done |
---|