[524] | 1 | #!/bin/sh |
---|
| 2 | # |
---|
[1492] | 3 | # $Id: create_make_gcm 2408 2015-12-14 10:43:09Z lfalletti $ |
---|
[524] | 4 | # |
---|
| 5 | #set -xv |
---|
[1750] | 6 | |
---|
[2298] | 7 | # arguments given to create_make_gcm are the directories to scan |
---|
| 8 | src_dirs=$* |
---|
[1750] | 9 | |
---|
[524] | 10 | machine=`hostname` |
---|
| 11 | os=`uname` |
---|
| 12 | gcm=`pwd` |
---|
[1999] | 13 | logfile=$gcm/create_make_gcm.log |
---|
| 14 | rm -f $logfile ; touch -f $logfile |
---|
[524] | 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 |
---|
[536] | 25 | X6NEC=0 |
---|
| 26 | if [ "$machine" = "mercure" ] ; then |
---|
| 27 | X6NEC=1 |
---|
| 28 | fi |
---|
[768] | 29 | X8BRODIE=0 |
---|
| 30 | if [ "$machine" = "brodie" ] ; then |
---|
| 31 | X8BRODIE=1 |
---|
| 32 | fi |
---|
[524] | 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`" |
---|
[2298] | 52 | echo 'MISC = $(LIBF)/misc' |
---|
[524] | 53 | echo "FILTRE = filtre" |
---|
| 54 | echo "PHYS = " |
---|
| 55 | echo 'LIBPHY = $(LIBO)/libphy$(PHYS).a' |
---|
[2408] | 56 | echo 'LIBPHY_COMMON= $(LIBO)/libphy_common.a' |
---|
[2298] | 57 | echo 'LIBDYN_PHY = $(LIBO)/libdynlmdz_phy$(PHYS).a' |
---|
[768] | 58 | echo 'DIRMAIN=dyn$(DIM)d$(FLAG_PARA)' |
---|
[524] | 59 | echo 'RM=rm' |
---|
| 60 | echo |
---|
| 61 | echo "OPLINK = " |
---|
| 62 | echo |
---|
| 63 | echo '# Les differentes librairies pour l"edition des liens:' |
---|
[2056] | 64 | echo 'L_DYN = -ldyn$(DIM)d$(FLAG_PARA) -ldyn3d_common' |
---|
[1492] | 65 | echo 'L_FILTRE = -l$(FILTRE)' |
---|
[2298] | 66 | echo 'L_DYN_PHY = -ldynlmdz_phy$(PHYS) ' |
---|
[2408] | 67 | echo 'L_PHY = -lphy$(PHYS) -lphy_common' |
---|
[2298] | 68 | echo 'L_MISC = -lmisc' |
---|
[1492] | 69 | echo 'L_ADJNT =' |
---|
| 70 | echo 'L_COSP = -lcosp' |
---|
[768] | 71 | |
---|
[524] | 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 |
---|
| 83 | echo |
---|
| 84 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 85 | echo "# Creation des differents executables" |
---|
| 86 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 87 | echo |
---|
| 88 | echo "# Executables:" |
---|
| 89 | echo "# ------------" |
---|
| 90 | echo |
---|
| 91 | echo "PROG = code" |
---|
[2056] | 92 | echo 'DYN = dyn$(DIM)d' |
---|
[524] | 93 | echo |
---|
[2298] | 94 | #echo 'main : chimie $(DYN) misc phys $(OPTION_DEP) ' |
---|
[2408] | 95 | echo 'main : $(DYN) misc phys phy_common dyn_phy $(OPTION_DEP) ' |
---|
[524] | 96 | echo ' cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\' |
---|
| 97 | echo ' cd $(LOCAL_DIR); \' |
---|
[1403] | 98 | echo ' $(COMPILE90) $(LIBF)/$(DIRMAIN)/$(SOURCE) -o $(PROG).o ; \' |
---|
[2298] | 99 | 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 ' |
---|
[524] | 100 | echo |
---|
| 101 | echo 'phys : $(LIBPHY)' |
---|
[2408] | 102 | echo 'phy_common : $(LIBPHY_COMMON)' |
---|
[2056] | 103 | echo 'dyn3d : $(LIBO)/libdyn$(DIM)d$(FLAG_PARA).a $(LIBO)/lib$(FILTRE).a $(LIBO)/libdyn3d_common.a' |
---|
| 104 | echo 'dyn2d : $(LIBO)/libdyn2d.a' |
---|
| 105 | echo 'dyn1d :' |
---|
[524] | 106 | echo |
---|
[2298] | 107 | echo 'dyn_phy: $(LIBDYN_PHYS)' |
---|
[2056] | 108 | echo |
---|
[768] | 109 | #echo 'chimie : $(LIBO)/libchimie.a' |
---|
| 110 | echo |
---|
[2298] | 111 | echo 'misc : $(LIBO)/libmisc.a' |
---|
[524] | 112 | echo |
---|
| 113 | echo 'adjnt : $(LIBO)/libadjnt.a' |
---|
| 114 | echo |
---|
[1279] | 115 | echo 'cosp : $(LIBO)/libcosp.a' |
---|
| 116 | echo |
---|
[524] | 117 | echo '$(FILTRE)3d : $(LIBO)/lib$(FILTRE).a' |
---|
| 118 | echo |
---|
| 119 | echo '$(FILTRE)2d :' |
---|
| 120 | echo |
---|
| 121 | echo '$(FILTRE)1d :' |
---|
| 122 | echo |
---|
| 123 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 124 | echo "# Contenu des differentes bibliotheques" |
---|
| 125 | echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" |
---|
| 126 | echo |
---|
| 127 | echo |
---|
| 128 | cd $libf >/dev/null 2>&1 |
---|
[1750] | 129 | |
---|
[2298] | 130 | for diri in $src_dirs ; do |
---|
[1750] | 131 | |
---|
[524] | 132 | if [ -d $diri ] ; then |
---|
[2298] | 133 | if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.[fF]90`" != "" ] ; then |
---|
[1750] | 134 | # cd $diri >/dev/null 2>&1 |
---|
[524] | 135 | echo |
---|
| 136 | listlib="" |
---|
[1750] | 137 | # Liste des fichiers .F et .F90 n'etant pas des programmes principaux |
---|
[2298] | 138 | for fili in `ls $diri/*.[fF]` ; do |
---|
| 139 | # Check if file is a routine or main program |
---|
| 140 | # i.e: look for the "program" keword preceeded by leading spaces |
---|
| 141 | test=` ( head $fili | grep -i '^ *program' ) ` |
---|
| 142 | # if it is not a main program, add it to the list |
---|
[1750] | 143 | if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi |
---|
[524] | 144 | done |
---|
[2298] | 145 | for fili in `ls $diri/*.[fF]90` ; do |
---|
| 146 | # Check if file is a routine or main program |
---|
| 147 | # i.e. look for "program" keyword (with possibly some leading spaces) |
---|
| 148 | test=` ( head $fili | grep -i '^ \{0,\}program' ) ` |
---|
| 149 | # if it is not a main program, add it to the list |
---|
[1750] | 150 | if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi |
---|
[524] | 151 | done |
---|
| 152 | echo |
---|
[1999] | 153 | echo $listlib >> $logfile |
---|
[524] | 154 | echo |
---|
[2298] | 155 | # topdiri contains main dir name (without trailing "/blabla" for subdirs) |
---|
| 156 | topdiri=${diri%/*} |
---|
[1750] | 157 | echo "#==================================================================" |
---|
[524] | 158 | echo "# Contenu de la bibliotheque correspondant au Directory "$diri |
---|
[1750] | 159 | echo "#==================================================================" |
---|
[524] | 160 | echo |
---|
[1750] | 161 | for trufile in $listlib ; do |
---|
| 162 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
[2298] | 163 | echo '$(LIBO)/lib'$topdiri".a : " '$(LIBO)/lib'$topdiri".a("$fili".o)" |
---|
[524] | 164 | echo |
---|
| 165 | done |
---|
[2298] | 166 | echo '.PRECIOUS : $(LIBO)/lib'$topdiri'.a' |
---|
[524] | 167 | echo |
---|
| 168 | echo |
---|
[2298] | 169 | echo "# Compilation of elements in $diri of library lib"$topdiri".a" |
---|
[524] | 170 | echo |
---|
[1750] | 171 | for trufile in $listlib ; do |
---|
| 172 | fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1` |
---|
[524] | 173 | F90=0 ; egrep -i '^ *use ' $trufile > /dev/null 2>&1 && F90=1 |
---|
| 174 | egrep -i '^ *module ' $trufile > /dev/null 2>&1 && F90=1 |
---|
[536] | 175 | egrep -i '#include*.inc ' $trufile > /dev/null 2>&1 && F90=1 |
---|
[2298] | 176 | str1='$(LIBO)/lib'$topdiri'.a('$fili'.o) : $(LIBF)/'$trufile |
---|
[1750] | 177 | [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F |
---|
[1112] | 178 | |
---|
[1750] | 179 | ########################################################################## |
---|
| 180 | # TRAITEMENT DES DEPENDANCES |
---|
[1112] | 181 | # Differents cas de dependance correspondant a des include ou des |
---|
| 182 | # use module. |
---|
| 183 | # soit dans le repertoire local soit dans un autre. |
---|
[1750] | 184 | # Pour dyn3d, il faudrait remplacer la chaine de caractere par $DYN |
---|
| 185 | # ou quelque chose du genre. |
---|
| 186 | ########################################################################## |
---|
[1112] | 187 | |
---|
[1999] | 188 | 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 |
---|
| 189 | echo $trufile $fili $stri >> $logfile |
---|
[1750] | 190 | strj=`echo $stri | tr [A-Z] [a-z]` |
---|
| 191 | str2="" |
---|
[2298] | 192 | for dirinc in $src_dirs ; do |
---|
[1750] | 193 | # Recherche dans l'ordre hierarchique inverse car seule la derniere |
---|
| 194 | # ligne est conservee |
---|
[2298] | 195 | # if [ $dirinc = phydev ] ; then |
---|
| 196 | # dirstr='$(PHYS)' |
---|
| 197 | # libstr='phy$(PHYS)' |
---|
| 198 | # else |
---|
[1864] | 199 | dirstr=$dirinc |
---|
| 200 | libstr=$dirinc |
---|
[2298] | 201 | # fi |
---|
[1999] | 202 | echo dirinc $dirinc >> $logfile |
---|
[1750] | 203 | if [ -f $dirinc/$stri ] ; then |
---|
[1864] | 204 | str2='$(LIBF)/'$dirstr/$stri |
---|
[1750] | 205 | elif [ -f $dirinc/$strj ] ; then |
---|
[1864] | 206 | str2='$(LIBF)/'$dirstr/$stri |
---|
[2160] | 207 | elif [ -f $dirinc/$strj.[fF]90 ] || [ -f $dirinc/$strj.[fF] ] ; then |
---|
[1864] | 208 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
[1750] | 209 | str2='$(LIBO)/lib'$strlib'.a('$strj'.o)' |
---|
[2160] | 210 | elif [ -f $dirinc/$stri.[fF]90 ] || [ -f $dirinc/$stri.[fF] ] ; then |
---|
[1910] | 211 | strlib=`echo $libstr | awk -F/ ' { print $1 } '` |
---|
| 212 | str2='$(LIBO)/lib'$strlib'.a('$stri'.o)' |
---|
[1750] | 213 | fi |
---|
[1999] | 214 | echo stri $stri >> $logfile |
---|
| 215 | echo str2 $str2 >> $logfile |
---|
[1750] | 216 | done |
---|
[1999] | 217 | echo dernier str2 $str2 >> $logfile |
---|
[1750] | 218 | if [ "$str2" = "" ] ; then |
---|
[1999] | 219 | echo Warn: Include $diri $trufile $fili $stri pas trouve >> $logfile |
---|
[1750] | 220 | elif [ "$str2" = "$str1" ] ; then |
---|
[1999] | 221 | echo Warn: Include $diri $trufile $fili $stri $str1 trouve 2x >> $logfile |
---|
[1750] | 222 | else |
---|
[524] | 223 | echo $str1 \\ |
---|
[1750] | 224 | str1=$str2 |
---|
[524] | 225 | fi |
---|
[1750] | 226 | done # Fin de la boucle sur les dependances et ecriture de la derniere |
---|
[524] | 227 | echo $str1 |
---|
[1492] | 228 | # Compile in LIBO directory; and before compiling, remove |
---|
| 229 | # object from library |
---|
| 230 | echo ' cd $(LIBO); \' |
---|
[2298] | 231 | echo ' $(AR) d $(LIBO)/lib'$topdiri'.a '$fili'.o ; \' |
---|
[768] | 232 | if [ "$F90" -eq '0' ] ; then |
---|
[1492] | 233 | ## Fixed Form Fortran 77 |
---|
[1750] | 234 | echo ' $(COMPILE) $(LIBF)/'$trufile' ; \' |
---|
[524] | 235 | else |
---|
[1492] | 236 | ## Fortran 90 |
---|
[1750] | 237 | if [ `echo $trufile | cut -d. -f2` = F90 ] ; then |
---|
[1492] | 238 | ## Free Form |
---|
[1750] | 239 | echo ' $(COMPTRU90) $(LIBF)/'$trufile' ; \' |
---|
[524] | 240 | else |
---|
[1750] | 241 | echo ' $(COMPILE90) $(LIBF)/'$trufile' ; \' |
---|
[524] | 242 | fi |
---|
| 243 | fi |
---|
[1492] | 244 | # Put generated object in library |
---|
[2298] | 245 | echo ' $(AR) r $(LIBO)/lib'$topdiri'.a '$fili'.o ; $(RM) '$fili'.o ; \' |
---|
[524] | 246 | echo |
---|
| 247 | done |
---|
| 248 | # |
---|
| 249 | echo |
---|
| 250 | cd $libf |
---|
| 251 | fi |
---|
| 252 | fi |
---|
| 253 | done |
---|