--- MITgcm/tools/genmake2 2003/08/26 16:22:15 1.4 +++ MITgcm/tools/genmake2 2003/09/26 18:16:38 1.9 @@ -1,6 +1,6 @@ #!/bin/bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.4 2003/08/26 16:22:15 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.9 2003/09/26 18:16:38 adcroft Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -80,119 +80,6 @@ } -parse_options() { - - ac_prev= - for ac_option in "${OPTIONS[@]}" ; do - - # echo "ac_option = :$ac_option:" - - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" - ac_prev= - continue - fi - - ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` - - case $ac_option in - - -help | --help | -h | --h) - usage ;; - - -nooptfile | --nooptfile) - OPTFILE="NONE" ;; - -optfile | --optfile | -of | --of) - ac_prev=optfile ;; - -optfile=* | --optfile=* | -of=* | --of=*) - OPTFILE=$ac_optarg ;; - - -pdepend | --pdepend) - ac_prev=pdepend ;; - -pdepend=* | --pdepend=*) - PDEPEND=$ac_optarg ;; - - -pdefault | --pdefault) - ac_prev=pdefault ;; - -pdefault=* | --pdefault=*) - PDEFAULT=$ac_optarg ;; - - -makefile | -ma) - ac_prev=makefile ;; - --makefile=* | -ma=*) - MAKEFILE=$ac_optarg ;; - - -platform | --platform | -pl | --pl) - ac_prev=platform ;; - -platform=* | --platform=* | -pl=* | --pl=*) - PLATFORM=$ac_optarg ;; - - -rootdir | --rootdir | -rd | --rd) - ac_prev=rootdir ;; - -rootdir=* | --rootdir=* | -rd=* | --rd=*) - ROOTDIR=$ac_optarg ;; - - -mods | --mods | -mo | --mo) - ac_prev=mods ;; - -mods=* | --mods=* | -mo=* | --mo=*) - MODS=$ac_optarg ;; - - -disable | --disable) - ac_prev=disable ;; - -disable=* | --disable=*) - DISABLE=$ac_optarg ;; - - -enable | --enable) - ac_prev=enable ;; - -enable=* | --enable=*) - ENABLE=$ac_optarg ;; - - -noopt | --noopt) - ac_prev=noopt ;; - -noopt=* | --noopt=*) - NOOPT=$ac_optarg ;; - -# -cpp | --cpp) -# ac_prev=cpp ;; -# -cpp=* | --cpp=*) -# CPP=$ac_optarg ;; - - -fortran | --fortran | -fc | --fc) - ac_prev=fc ;; - -fc=* | --fc=*) - FC=$ac_optarg ;; - - -ieee | --ieee) - IEEE=1 ;; - -noieee | --noieee) - IEEE=0 ;; - - -mpi | --mpi) - MPI=1 ;; - -nompi | --nompi) - MPI=0 ;; - - -jam | --jam) - JAM=1 ;; - -nojam | --nojam) - JAM=0 ;; - - -*) - echo "Error: unrecognized option: "$ac_option - usage - ;; - - *) - echo "Error: unrecognized argument: "$ac_option - usage - ;; - - esac - - done -} - # Parse the package dependency information get_pdepend_list() { @@ -222,8 +109,10 @@ echo " -pdepend=NAME | --pdepend=NAME" echo " -pdefault NAME | --pdefault NAME" echo " -pdefault=NAME | --pdefault=NAME" - echo " -makefile NAME | -ma NAME" - echo " --makefile=NAME | -ma=NAME" + echo " -make NAME | -m NAME" + echo " --make=NAME | -m=NAME" + echo " -makefile NAME | -mf NAME" + echo " --makefile=NAME | -mf=NAME" echo " -platform NAME | --platform NAME | -pl NAME | --pl NAME" echo " -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME" echo " -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME" @@ -255,19 +144,6 @@ exit 1 } -# Dump all important state -dump_state() { - fname=$1 - echo " " > $fname - RETVAL=$? - if test "x${RETVAL}" = x ; then - echo "Error: cannot write to $fname" - exit 1 - fi - echo "makefile "$makefile > $fname -} - - #eh3 # This is the generic configuration. #eh3 set LN = ( 'ln -s' ) #eh3 set CPP = ( '/lib/cpp -P' ) @@ -288,6 +164,8 @@ #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = ( ) # Set defaults here +COMMANDL="$0 $@" + PLATFORM= LN= S64= @@ -300,6 +178,7 @@ MAKEFILE= MAKEDEPEND= PDEPEND= +DUMPSTATE=f PDEFAULT= OPTFILE= INCLUDES="-I." @@ -324,6 +203,22 @@ THISCWD=`pwd` THISDATE=`date` MACHINE=`uname -a` +EXECUTABLE= +EXEHOOK= +EXEDIR= + +# The following state can be set directly by command-line switches +gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT" +gm_s2="FC IEEE MPI JAM DUMPSTATE" + +# The following state is not directly set by command-line switches +gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM " +gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS" +gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE" +gm_s6="EXECUTABLE EXEHOOK EXEDIR" + +gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6" + echo echo "=== Processing options files and arguments ===" @@ -384,9 +279,14 @@ -pdefault=* | --pdefault=*) PDEFAULT=$ac_optarg ;; - -makefile | -ma) + -make | --make | -m | --m) + ac_prev=MAKE ;; + -make=* | --make=* | -m=* | --m=*) + MAKE=$ac_optarg ;; + + -makefile | --makefile | -ma | --ma) ac_prev=MAKEFILE ;; - --makefile=* | -ma=*) + -makefile=* | --makefile=* | -ma=* | --ma=*) MAKEFILE=$ac_optarg ;; -platform | --platform | -pl | --pl) @@ -444,6 +344,9 @@ -nojam | --nojam) JAM=0 ;; + -ds | --ds) + DUMPSTATE=t ;; + -*) echo "Error: unrecognized option: "$ac_option usage @@ -476,6 +379,9 @@ echo "--please check that variable syntax is bash-compatible" exit 1 fi + if test "x$DUMPSTATE" != xf ; then + cp -f $OPTFILE "gm_optfile" + fi else echo "Error: can't read OPTFILE=\"$OPTFILE\"" exit 1 @@ -483,6 +389,41 @@ fi fi +# Check that FC, LINK, CPP, and S64 are defined. If not, complain +# and abort! +if test "x$FC" = x ; then + cat <&2 + +Error: no Fortran compiler: please specify using one of the following: + 1) within the options file ("FC=...") as specified by "-of=OPTFILE" + 2) the "-fc=XXX" command-line option + 3) the "./gm_local" file +EOF + exit 1 +fi +if test "x$LINK" = x ; then + LINK=$FC +fi +if test "x$CPP" = x ; then + cat <&2 + +Error: no C pre-processor: please specify using one of the following: + 1) within the options file ("CPP=...") as specified by "-of=OPTFILE" + 2) the "./gm_local" file +EOF + exit 1 +fi +if test "x$S64" = x ; then + cat <&2 + +Error: no C pre-processor: please specify using one of the following: + 1) within the options file ("S64=...") as specified by "-of=OPTFILE" + 2) the "./gm_local" file +EOF + exit 1 +fi + + printf "\n=== Setting defaults ===\n" echo -n " Adding MODS directories: " for d in $MODS ; do @@ -892,7 +833,7 @@ echo -n 'CSRCFILES = ' > csrclist.inc echo -n 'F90SRCFILES = ' > f90srclist.inc echo -n 'HEADERFILES = ' > hlist.inc -alldirs=". $SOURCEDIRS $INCLUDEDIRS" +alldirs="$SOURCEDIRS $INCLUDEDIRS ." for d in $alldirs ; do deplist= sfiles=`( cd $d; echo *.[h,c,F] )` @@ -1043,7 +984,7 @@ depend: @make links \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES) - ../../../tools/f90mkdepend >> \$(MAKEFILE) + ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE) links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) @@ -1091,6 +1032,10 @@ EOF +if test "x$EXEHOOK" != x ; then + printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE +fi + echo " Making list of \"exceptions\" that need \".p\" files" for i in $KPPFILES ; do base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'` @@ -1120,3 +1065,14 @@ printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE printf "\n=== Done ===\n" + + +# Write the "state" for future records +if test "x$DUMPSTATE" != xf ; then + echo -n "" > gm_state + for i in $gm_state ; do + t1="t2=\$$i" + eval $t1 + echo "$i='$t2'" >> gm_state + done +fi