--- MITgcm/tools/genmake2 2003/08/26 16:22:15 1.4 +++ MITgcm/tools/genmake2 2003/09/29 16:15:23 1.11 @@ -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.11 2003/09/29 16:15:23 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -12,185 +12,130 @@ # Guess possible config options for this host find_possible_configs() { - p_PLATFORM=`uname`"-"`uname -m` - echo "The platform appears to be:" - echo " "$p_PLATFORM - - p_LN= + tmp1=`uname`"_"`uname -m` + tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` + PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/'` + OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")` + echo " The platform appears to be: $PLATFORM" +# if test "x$OFLIST" = x ; then +# echo " No pre-defined options files were found matching this platform" +# echo " but examples for other platforms can be found in:" +# echo " $ROOTDIR/tools/build_options" +# else +# echo " Options files (located in $ROOTDIR/tools/build_options) that" +# echo " may work with this machine are:" +# for i in $OFLIST ; do +# echo " $i" +# done +# fi + echo "test" > test ln -s ./test link RETVAL=$? if test "x${RETVAL}" = x0 ; then - p_LN="ln -s" + LN="ln -s" + else + echo "Error: \"ln -s\" does not appear to work on this system!" + echo " For help, please contact ." + exit 1 fi rm -f test link - p_CPP=`which cpp` - - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - p_LN="ln -s" + if test "x$CPP" = x ; then + CPP="cpp -traditional -P" fi - rm -f test link # look for possible fortran compilers + tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95" p_FC= - for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do - which $c > /dev/null 2>&1 + for c in $tmp ; do + rm -f ./hello.f ./hello + cat >> hello.f < /dev/null 2>&1 RETVAL=$? if test "x${RETVAL}" = x0 ; then p_FC="$p_FC $c" fi done - echo "Possible FORTRAN compilers appear to be: " if test "x${p_FC}" = x ; then - echo " None found!!!" - else - echo " "$p_FC - fi + cat 1>&2 </dev/null` - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - cat >>test.f < out" - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - a=`cat out` - for i in $a ; do - case $i in - -*) - mpi_libs="$mpi_libs $i" ;; - esac - done - echo "The MPI libs appear to be:" - echo " "$mpi_libs + exit 1 + else + echo " The possible FORTRAN compilers found in your path are:" + echo " "$p_FC + if test "x$FC" = x ; then + FC=`echo $p_FC | awk '{print $1}'` fi - rm -f test.f out fi -} + for i in $p_FC ; do + p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i + if test -r $p_OF ; then + OPTFILE=$p_OF + echo " The options file: $p_OF" + echo " appears to match so we'll use it." + break + fi + done + if test "x$OPTFILE" = x ; then + cat 1>&2 <. + +EOF + exit 1 + fi + +# # look for possible MPI libraries +# mpi_libs= +# mpi_fort=`which mpif77 2>/dev/null` +# RETVAL=$? +# if test "x${RETVAL}" = x0 ; then +# cat >>test.f < out" +# RETVAL=$? +# if test "x${RETVAL}" = x0 ; then +# a=`cat out` +# for i in $a ; do +# case $i in +# -*) +# mpi_libs="$mpi_libs $i" ;; +# esac +# done +# echo "The MPI libs appear to be:" +# echo " "$mpi_libs +# fi +# rm -f test.f out +# fi - # 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 @@ -222,8 +167,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 +202,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,18 +222,22 @@ #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = ( ) # Set defaults here +COMMANDL="$0 $@" + PLATFORM= LN= S64= KPP= FC= LINK= +DEFINES="-DWORDLENGTH=4" PACKAGES= ENABLE= DISABLE= MAKEFILE= MAKEDEPEND= PDEPEND= +DUMPSTATE=t PDEFAULT= OPTFILE= INCLUDES="-I." @@ -324,6 +262,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 +338,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 +403,9 @@ -nojam | --nojam) JAM=0 ;; + -ds | --ds) + DUMPSTATE=t ;; + -*) echo "Error: unrecognized option: "$ac_option usage @@ -458,31 +420,97 @@ done +if test "x${ROOTDIR}" = x ; then + if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then + ROOTDIR=".." + else + for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do + if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then + ROOTDIR=$d + echo -n "Warning: ROOTDIR was not specified but there appears to be" + echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it." + break + fi + done + fi +fi +if test "x${ROOTDIR}" = x ; then + echo "Error: Cannot determine ROOTDIR for MITgcm code." + echo " Please specify a ROOTDIR using either an options " + echo " file or a command-line option." + exit 1 +fi +if test ! -d ${ROOTDIR} ; then + echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!" + exit 1 +fi + echo " getting OPTFILE information: " if test "x${OPTFILE}" = x ; then - echo "Warning: no OPTFILE specified so we'll look for possible settings" - printf "\n=== Searching for possible settings for OPTFILE ===\n" - find_possible_configs -else - if test "x$OPTFILE" = xNONE ; then - echo " OPTFILE=NONE so we'll try to use default settings" + if test "x$MITGCM_OF" = x ; then + echo "Warning: no OPTFILE specified so we'll look for possible settings" + printf "\n=== Searching for possible settings for OPTFILE ===\n" + find_possible_configs else - if test -f "$OPTFILE" -a -r "$OPTFILE" ; then - echo " using OPTFILE=\"$OPTFILE\"" - source "$OPTFILE" - RETVAL=$? - if test "x$RETVAL" != x0 ; then - echo -n "Error: failed to source OPTFILE \"$OPTFILE\"" - echo "--please check that variable syntax is bash-compatible" - exit 1 - fi - else - echo "Error: can't read OPTFILE=\"$OPTFILE\"" + OPTFILE=$MITGCM_OF + fi +fi +if test "x$OPTFILE" != xNONE ; then + if test -f "$OPTFILE" -a -r "$OPTFILE" ; then + echo " using OPTFILE=\"$OPTFILE\"" + source "$OPTFILE" + RETVAL=$? + if test "x$RETVAL" != x0 ; then + echo -n "Error: failed to source OPTFILE \"$OPTFILE\"" + 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 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 + CPP="cpp" +fi +echo "#define A a" | cpp > test_cpp 2>&1 +RETVAL=$? +if test "x$RETVAL" != x0 ; then + cat <&2 + +Error: C pre-processor "$CPP" failed the test case: please specify using: + + 1) within the options file ("CPP=...") as specified by "-of=OPTFILE" + 2) the "./gm_local" file + +EOF + exit 1 +else + rm -f test_cpp +fi +if test "x$MAKEDEPEND" = x ; then + MAKEDEPEND=makedepend +fi + printf "\n=== Setting defaults ===\n" echo -n " Adding MODS directories: " for d in $MODS ; do @@ -505,31 +533,6 @@ PLATFORM=$p_PLATFORM fi -if test "x${ROOTDIR}" = x ; then - if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then - ROOTDIR=".." - else - for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do - if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then - ROOTDIR=$d - echo -n "Warning: ROOTDIR was not specified but there appears to be" - echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it." - break - fi - done - fi -fi -if test "x${ROOTDIR}" = x ; then - echo "Error: Cannot determine ROOTDIR for MITgcm code." - echo " Please specify a ROOTDIR using either an options " - echo " file or a command-line option." - exit 1 -fi -if test ! -d ${ROOTDIR} ; then - echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!" - exit 1 -fi - if test "x${EXEDIR}" = x ; then if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then EXEDIR=../exe @@ -549,6 +552,9 @@ echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!" exit 1 fi +if test "x$S64" = x ; then + S64='$(TOOLSDIR)/set64bitConst.sh' +fi EXECUTABLE=${EXECUTABLE:-mitgcmuv} @@ -755,9 +761,9 @@ # done # echo -echo " Setting package-specific CPP flags in CPP_OPTIONS.h:" +echo " Searching for CPP_OPTIONS.h (macros and flags for configuring the model):" CPP_OPTIONS= -spaths="$SOURCEDIRS" +spaths=". $SOURCEDIRS" for i in $spaths ; do try="$i/CPP_OPTIONS.h" # echo -n " trying $try : " @@ -784,8 +790,8 @@ fi cat <>CPP_OPTIONS.h.tmp C=== GENMAKE v2 === -C The following defines have been set by GENMAKE, so please edit -C them only if you know what you're doing. In general, you should +C The following defines have been set by GENMAKE, so please do not +C edit anything below these comments. In general, you should C add or remove packages by re-running genmake with different C "-enable" and/or "-disable" options. @@ -892,7 +898,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 +1049,7 @@ depend: @make links \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES) - ../../../tools/f90mkdepend >> \$(MAKEFILE) + ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE) links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) @@ -1091,6 +1097,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 +1130,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