[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) ' |
---|
[1521] | 76 | echo 'L_PHY = -lphy$(PHYS) -lphy_common' |
---|
[1403] | 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 |
---|
[1521] | 102 | echo 'main : $(DYN) misc phys phy_common 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 ; \' |
---|
[1403] | 106 | 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] | 107 | echo |
---|
| 108 | echo 'dyn : $(LIBO)/libdyn$(DIM)d.a $(FILTRE)$(DIM)d' |
---|
| 109 | echo |
---|
| 110 | echo 'olddyn : $(LIBO)/libolddyn$(DIM)d.a $(FILTRE)$(DIM)d' |
---|
| 111 | echo |
---|
| 112 | echo 'phys : $(LIBPHY)' |
---|
[1521] | 113 | echo 'phy_common : $(LIBPHY_COMMON)' |
---|
[135] | 114 | echo |
---|
[1403] | 115 | echo 'dyn3d : $(LIBO)/libdyn3d.a $(LIBO)/lib$(FILTRE).a' |
---|
| 116 | echo 'dyn2d : $(LIBO)/libdyn2d.a' |
---|
| 117 | echo 'dyn1d : ' |
---|
[135] | 118 | echo |
---|
[1403] | 119 | echo 'dyn_phy: $(LIBDYN_PHYS)' |
---|
| 120 | echo |
---|
| 121 | echo 'misc : $(LIBO)/libmisc.a' |
---|
| 122 | echo |
---|
| 123 | #echo 'aeronomars : $(LIBO)/libaeronomars.a' |
---|
| 124 | #echo |
---|
[135] | 125 | echo 'adjnt : $(LIBO)/libadjnt.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 |
---|
[1403] | 139 | |
---|
| 140 | for diri in $src_dirs ; do |
---|
| 141 | |
---|
[135] | 142 | if [ -d $diri ] ; then |
---|
[1403] | 143 | if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.[fF]90`" != "" ] ; then |
---|
| 144 | # cd $diri >/dev/null 2>&1 |
---|
[135] | 145 | echo |
---|
| 146 | listlib="" |
---|
[1403] | 147 | # Liste des fichiers .F et .F90 n'etant pas des programmes principaux |
---|
| 148 | for fili in `ls $diri/*.[fF]` ; do |
---|
[634] | 149 | # Check if file is a routine or main program |
---|
| 150 | # i.e: look for the "program" keword preceeded by leading spaces |
---|
[1403] | 151 | test=` ( head $fili | grep -i '^ *program' ) ` |
---|
| 152 | # if it is not a main program, add it to the list |
---|
| 153 | if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi |
---|
[135] | 154 | done |
---|
[1403] | 155 | for fili in `ls $diri/*.[fF]90` ; do |
---|
[634] | 156 | # Check if file is a routine or main program |
---|
| 157 | # i.e. look for "program" keyword (with possibly some leading spaces) |
---|
[1403] | 158 | test=` ( head $fili | grep -i '^ \{0,\}program' ) ` |
---|
| 159 | # if it is not a main program, add it to the list |
---|
| 160 | if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi |
---|
[135] | 161 | done |
---|
| 162 | echo |
---|
[1403] | 163 | echo $listlib >> $logfile |
---|
[135] | 164 | echo |
---|
[1403] | 165 | # topdiri contains main dir name (without trailing "/blabla" for subdirs) |
---|
| 166 | topdiri=${diri%/*} |
---|
| 167 | echo "#==================================================================" |
---|
[135] | 168 | echo "# Contenu de la bibliotheque correspondant au Directory "$diri |
---|
[1403] | 169 | echo "#==================================================================" |
---|
[135] | 170 | echo |
---|
[1403] | 171 | for trufile in $listlib ; do |
---|
| 172 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
| 173 | echo '$(LIBO)/lib'$topdiri".a : " '$(LIBO)/lib'$topdiri".a("$fili".o)" |
---|
[135] | 174 | echo |
---|
| 175 | done |
---|
[1403] | 176 | echo '.PRECIOUS : $(LIBO)/lib'$topdiri'.a' |
---|
[135] | 177 | echo |
---|
| 178 | echo |
---|
[1403] | 179 | echo "# Compilation of elements in $diri of library lib"$topdiri".a" |
---|
[135] | 180 | echo |
---|
[1403] | 181 | for trufile in $listlib ; do |
---|
| 182 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
[135] | 183 | F90=0 ; egrep -i '^ *use ' $trufile > /dev/null 2>&1 && F90=1 |
---|
| 184 | egrep -i '^ *module ' $trufile > /dev/null 2>&1 && F90=1 |
---|
| 185 | egrep -i '#include*.inc ' $trufile > /dev/null 2>&1 && F90=1 |
---|
[1403] | 186 | str1='$(LIBO)/lib'$topdiri'.a('$fili'.o) : $(LIBF)/'$trufile |
---|
| 187 | [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F |
---|
| 188 | |
---|
| 189 | ########################################################################## |
---|
| 190 | # TRAITEMENT DES DEPENDANCES |
---|
| 191 | # Differents cas de dependance correspondant a des include ou des |
---|
| 192 | # use module. |
---|
| 193 | # soit dans le repertoire local soit dans un autre. |
---|
| 194 | # Pour dyn3d, il faudrait remplacer la chaine de caractere par $DYN |
---|
| 195 | # ou quelque chose du genre. |
---|
| 196 | ########################################################################## |
---|
| 197 | |
---|
| 198 | 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 |
---|
| 199 | echo $trufile $fili $stri >> $logfile |
---|
| 200 | strj=`echo $stri | tr [A-Z] [a-z]` |
---|
| 201 | str2="" |
---|
| 202 | for dirinc in $src_dirs ; do |
---|
| 203 | # Recherche dans l'ordre hierarchique inverse car seule la derniere |
---|
| 204 | # ligne est conservee |
---|
| 205 | # if [ $dirinc = phydev ] ; then |
---|
| 206 | # dirstr='$(PHYS)' |
---|
| 207 | # libstr='phy$(PHYS)' |
---|
| 208 | # else |
---|
| 209 | dirstr=$dirinc |
---|
| 210 | libstr=$dirinc |
---|
| 211 | # fi |
---|
| 212 | echo dirinc $dirinc >> $logfile |
---|
| 213 | if [ -f $dirinc/$stri ] ; then |
---|
| 214 | str2='$(LIBF)/'$dirstr/$stri |
---|
| 215 | elif [ -f $dirinc/$strj ] ; then |
---|
| 216 | str2='$(LIBF)/'$dirstr/$stri |
---|
| 217 | elif [ -f $dirinc/$strj.[fF]90 ] || [ -f $dirinc/$strj.[fF] ] ; then |
---|
| 218 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
| 219 | str2='$(LIBO)/lib'$strlib'.a('$strj'.o)' |
---|
| 220 | elif [ -f $dirinc/$stri.[fF]90 ] || [ -f $dirinc/$stri.[fF] ] ; then |
---|
| 221 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
| 222 | str2='$(LIBO)/lib'$strlib'.a('$stri'.o)' |
---|
| 223 | fi |
---|
| 224 | echo stri $stri >> $logfile |
---|
| 225 | echo str2 $str2 >> $logfile |
---|
| 226 | done |
---|
| 227 | echo dernier str2 $str2 >> $logfile |
---|
| 228 | if [ "$str2" = "" ] ; then |
---|
| 229 | echo Warn: Include $diri $trufile $fili $stri pas trouve >> $logfile |
---|
| 230 | elif [ "$str2" = "$str1" ] ; then |
---|
| 231 | echo Warn: Include $diri $trufile $fili $stri $str1 trouve 2x >> $logfile |
---|
| 232 | else |
---|
[135] | 233 | echo $str1 \\ |
---|
[1403] | 234 | str1=$str2 |
---|
[135] | 235 | fi |
---|
[1403] | 236 | done # Fin de la boucle sur les dependances et ecriture de la derniere |
---|
[135] | 237 | echo $str1 |
---|
[1403] | 238 | # Compile in LIBO directory; and before compiling, remove |
---|
| 239 | # object from library |
---|
| 240 | echo ' cd $(LIBO); \' |
---|
| 241 | echo ' $(AR) d $(LIBO)/lib'$topdiri'.a '$fili'.o ; \' |
---|
[135] | 242 | if [ "$F90" -eq '0' ] ; then |
---|
[1403] | 243 | ## Fixed Form Fortran 77 |
---|
| 244 | echo ' $(COMPILE) $(LIBF)/'$trufile' ; \' |
---|
[135] | 245 | else |
---|
[375] | 246 | ## Fortran 90 |
---|
[1403] | 247 | if [ `echo $trufile | cut -d. -f2` = F90 ] ; then |
---|
| 248 | ## Free Form |
---|
| 249 | echo ' $(COMPTRU90) $(LIBF)/'$trufile' ; \' |
---|
[135] | 250 | else |
---|
[1403] | 251 | echo ' $(COMPILE90) $(LIBF)/'$trufile' ; \' |
---|
[135] | 252 | fi |
---|
| 253 | fi |
---|
[375] | 254 | # Put generated object in library |
---|
[1403] | 255 | echo ' $(AR) r $(LIBO)/lib'$topdiri'.a '$fili'.o ; $(RM) '$fili'.o ; \' |
---|
[135] | 256 | echo |
---|
| 257 | done |
---|
| 258 | # |
---|
| 259 | echo |
---|
| 260 | cd $libf |
---|
| 261 | fi |
---|
| 262 | fi |
---|
| 263 | done |
---|