--- MITgcm/tools/genmake2 2003/08/16 14:01:08 1.1 +++ MITgcm/tools/genmake2 2003/10/21 15:29:20 1.14 @@ -1,6 +1,6 @@ #!/bin/bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.1 2003/08/16 14:01:08 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.14 2003/10/21 15:29:20 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -8,189 +8,192 @@ # modified by aja 01/00 # rewritten in bash by eh3 08/03 +# Search for particular CPP #cmds associated with packages +# usage: test_for_package_in_cpp_options CPP_file package_name +test_for_package_in_cpp_options() { + cpp_options=$1 + pkg=$2 + grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg" + exit 99 + fi + grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg" + exit 99 + fi + grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg" + exit 99 + fi + grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg" + exit 99 + fi +} + +# Read the $ROOTDIR/pkg/pkg_groups file and expand any references to +# the package list. +expand_pkg_groups() { + new_packages= + PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups" + if test -r $PKG_GROUPS ; then + cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp + cat ./p1.tmp | awk '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp + matched=0 + for i in $PACKAGES ; do + line=`grep "^ *$i" ./p2.tmp` + RETVAL=$? + if test "x$RETVAL" = x0 ; then + matched=1 + replace=`echo $line | awk '{ $1=""; $2=""; print $0 }'` + echo " replacing \"$i\" with: $replace" + new_packages="$new_packages $replace" + else + new_packages="$new_packages $i" + fi + done + PACKAGES=$new_packages + rm -f ./p[1,2].tmp + else + echo "Warning: can't read package groups definition file: $PKG_GROUPS" + fi +} # 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/' | sed -e 's/athlon/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 @@ -210,9 +213,10 @@ # Explain usage usage() { - echo "" + echo echo "Usage: "$0" [OPTIONS]" - echo " where [OPTIONS] can be:"$'\n' + echo " where [OPTIONS] can be:" + echo echo " -help | --help | -h | --h" echo " -nooptfile | --nooptfile" echo " -optfile NAME | --optfile NAME | -of NAME | --of NAME" @@ -221,8 +225,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" @@ -233,6 +239,8 @@ echo " -disable=NAME | --disable=NAME" echo " -enable NAME | --enable NAME" echo " -enable=NAME | --enable=NAME" + echo " -standarddirs NAME | --standarddirs NAME" + echo " -standarddirs=NAME | --standarddirs=NAME" echo " -noopt NAME | --noopt NAME" echo " -noopt=NAME | --noopt=NAME" # echo " -cpp NAME | --cpp NAME" @@ -241,29 +249,19 @@ echo " -fc=NAME | --fc=NAME" echo " -[no]ieee | --[no]ieee" echo " -[no]mpi | --[no]mpi" - echo " -[no]jam | --[no]jam"$'\n' - echo " and NAME is a string such as:"$'\n' + echo " -[no]jam | --[no]jam" + echo + echo " and NAME is a string such as:" + echo echo " --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'" echo " -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'" - echo " -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"$'\n' + echo " -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'" + echo echo " which, depending upon your shell, may need to be single-quoted" echo " if it contains spaces, dashes, or other special characters." 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' ) @@ -284,21 +282,25 @@ #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. +INCLUDES="-I." FFLAGS= FOPTIM= CFLAGS= @@ -313,6 +315,7 @@ TOOLSDIR= SOURCEDIRS= INCLUDEDIRS= +STANDARDDIRS= PWD=`pwd` MAKE=make @@ -320,73 +323,202 @@ THISCWD=`pwd` THISDATE=`date` MACHINE=`uname -a` +EXECUTABLE= +EXEHOOK= +EXEDIR= +PACKAGES_CONF= +IEEE= +if test "x$MITGCM_IEEE" != x ; then + IEEE=$MITGCM_IEEE +fi -echo $'\n'"=== Processing options files and arguments ===" -gm_local="./gm_local" +AUTODIFF_PKG_USED=f +AD_OPTFILE= + +# 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 STANDARDDIRS" + +# 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 PACKAGES_CONF" + +# The following are all related to adjoint/tangent-linear stuff +gm_s7="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF DIFF_FLAGS AD_TAMC_FLAGS AD_TAF_FLAGS" +gm_s8="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS" +gm_s9="" + +gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8" + + +echo +echo "=== Processing options files and arguments ===" +gm_local="genmake_local" +for i in . $MODS ; do + if test -r $i/$gm_local ; then + source $i/$gm_local + break + fi +done echo -n " getting local config information: " if test -e $gm_local ; then echo "using $gm_local" source $gm_local - echo "DISABLE=$DISABLE"$'\n'"ENABLE=$ENABLE" + # echo "DISABLE=$DISABLE" + # echo "ENABLE=$ENABLE" else echo "none found" fi # echo "$0::$1:$2:$3:$4:$5:$6:$7:" -OPTIONS=() -n=0 -for i ; do - setvar="OPTIONS[$n]='$i'" - # echo " $setvar" - eval "$setvar" - n=$(( $n + 1 )) -done -parse_options - -echo " getting OPTFILE information: " -if test "x${OPTFILE}" = x ; then - echo "Warning: no OPTFILE specified so we'll look for possible settings" - echo $'\n'"=== Searching for possible settings for OPTFILE ===" - find_possible_configs -else - if test "x$OPTFILE" = xNONE ; then - echo " OPTFILE=NONE so we'll try to use default settings" - 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\"" - exit 1 - fi - fi -fi - -echo $'\n'"=== Setting defaults ===" -echo -n " Adding MODS directories: " -for d in $MODS ; do - if test ! -d $d ; then - echo $'\n\n'"Error: MODS directory \"$d\" not found!" - exit 1 - else - echo -n " $d" - SOURCEDIRS="$SOURCEDIRS $d" - INCLUDEDIRS="$INCLUDEDIRS $d" +#OPTIONS= +#n=0 +#for i ; do +# echo "$i $n" +# setvar="OPTIONS[$n]='$i'" +# # echo " $setvar" +# eval "$setvar" +# n=$(( $n + 1 )) +#done +#parse_options +ac_prev= +for ac_option ; do + + # 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 ;; + + -adoptfile | --adoptfile | -ad | --ad) + ac_prev=AD_OPTFILE ;; + -adoptfile=* | --adoptfile=* | -adof=* | --adof=*) + AD_OPTFILE=$ac_optarg ;; + + -pdepend | --pdepend) + ac_prev=PDEPEND ;; + -pdepend=* | --pdepend=*) + PDEPEND=$ac_optarg ;; + + -pdefault | --pdefault) + ac_prev=PDEFAULT ;; + -pdefault=* | --pdefault=*) + PDEFAULT=$ac_optarg ;; + + -make | --make | -m | --m) + ac_prev=MAKE ;; + -make=* | --make=* | -m=* | --m=*) + MAKE=$ac_optarg ;; + + -makefile | --makefile | -ma | --ma) + ac_prev=MAKEFILE ;; + -makefile=* | --makefile=* | -ma=* | --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 ;; + + -standarddirs | --standarddirs) + ac_prev=STANDARDDIRS ;; + -standarddirs=* | --standarddirs=*) + STANDARDDIRS=$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=true ;; + -noieee | --noieee) + IEEE= ;; + + -mpi | --mpi) + MPI=true ;; + -nompi | --nompi) + MPI= ;; + + -jam | --jam) + JAM=1 ;; + -nojam | --nojam) + JAM=0 ;; + + -ds | --ds) + DUMPSTATE=t ;; + + -*) + echo "Error: unrecognized option: "$ac_option + usage + ;; + + *) + echo "Error: unrecognized argument: "$ac_option + usage + ;; + + esac + done -echo -if test "x$MAKEFILE" = x ; then - MAKEFILE="Makefile" -fi -if test "x${PLATFORM}" = x ; then - PLATFORM=$p_PLATFORM +if test -f ./.genmakerc ; then + echo + echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\"" + echo " file. This file format is no longer supported. Please see:" + echo + echo " http://mitgcm.org/devel_HOWTO/" + echo + echo " for directions on how to setup and use the new \"genmake2\" input" + echo " files and send an email to MITgcm-support@mitgcm.org if you want help." + echo fi if test "x${ROOTDIR}" = x ; then @@ -414,6 +546,121 @@ exit 1 fi +echo " getting OPTFILE information: " +if test "x${OPTFILE}" = x ; then + 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 + 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 "genmake_optfile" + fi + else + echo "Error: can't read OPTFILE=\"$OPTFILE\"" + exit 1 + fi +fi + +echo " getting AD_OPTFILE information: " +if test "x${AD_OPTFILE}" = x ; then + if test "x$MITGCM_AD_OF" = x ; then + AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default + else + AD_OPTFILE=$MITGCM_AD_OF + fi +fi +if test "x${AD_OPTFILE}" != xNONE ; then + if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then + echo " using AD_OPTFILE=\"$AD_OPTFILE\"" + source "$AD_OPTFILE" + RETVAL=$? + if test "x$RETVAL" != x0 ; then + echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\"" + echo "--please check that variable syntax is bash-compatible" + exit 1 + fi + if test "x$DUMPSTATE" != xf ; then + cp -f $AD_OPTFILE "genmake_ad_optfile" + fi + else + echo "Error: can't read AD_OPTFILE=\"$AD_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 "./genmake_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 "./genmake_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 + if test ! -d $d ; then + echo + echo "Error: MODS directory \"$d\" not found!" + exit 1 + else + echo -n " $d" + SOURCEDIRS="$SOURCEDIRS $d" + INCLUDEDIRS="$INCLUDEDIRS $d" + fi +done +echo + +if test "x$MAKEFILE" = x ; then + MAKEFILE="Makefile" +fi +if test "x${PLATFORM}" = x ; then + PLATFORM=$p_PLATFORM +fi + if test "x${EXEDIR}" = x ; then if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then EXEDIR=../exe @@ -433,6 +680,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} @@ -443,7 +693,7 @@ echo " Making source files in eesupp from templates" $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1 RETVAL=$? - if test "x${RETVAL}" == "x0" ; then + if test "x${RETVAL}" = x0 ; then rm -f make_eesupp.errors else echo "Error: problem encountered while building source files in eesupp:" @@ -452,7 +702,7 @@ fi fi -echo $'\n'"=== Determining package settings ===" +printf "\n=== Determining package settings ===\n" if test "x${PDEPEND}" = x ; then tmp=$ROOTDIR"/pkg/pkg_depend" if test -r $tmp ; then @@ -471,7 +721,7 @@ # Strip the comments and then convert the dependency file into # two arrays: PNAME, DNAME cat $PDEPEND | sed -e 's/#.*$//g' \ - | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \ + | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \ > ./.pd_tmp RETVAL=$? if test ! "x${RETVAL}" = x0 ; then @@ -481,8 +731,19 @@ source ./.pd_tmp rm -f ./.pd_tmp +# Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups" +# file should eventually be added so that, for convenience, one can +# specify groups of packages using names like "ocean" and "atmosphere". echo -n " checking default package list: " if test "x${PDEFAULT}" = x ; then + for i in "." $MODS ; do + if test -r $i"/packages.conf" ; then + PDEFAULT=$i"/packages.conf" + break + fi + done +fi +if test "x${PDEFAULT}" = x ; then PDEFAULT="$ROOTDIR/pkg/pkg_default" fi if test "x${PDEFAULT}" = xNONE ; then @@ -504,7 +765,9 @@ for i in $def ; do PACKAGES="$PACKAGES $i" done - echo " packages are: $PACKAGES" + echo " before group expansion packages are: $PACKAGES" + expand_pkg_groups + echo " after group expansion packages are: $PACKAGES" fi fi @@ -523,7 +786,7 @@ done PACKAGES="$pack" echo " applying ENABLE settings" -rm -f ./.tmp_pack +echo "" > ./.tmp_pack PACKAGES="$PACKAGES $ENABLE" for i in $PACKAGES ; do if test ! -d "$ROOTDIR/pkg/$i" ; then @@ -544,11 +807,14 @@ ck= while test "x$ck" != xtt ; do i=0 - rtot=${#PNAME[@]} + # rtot=${#PNAME[@]} + rtot=$nname while test $i -lt $rtot ; do # Is $pname in the current $PACKAGES list? - pname=${PNAME[$i]} + # pname=${PNAME[$i]} + tmp="pname=\"\$PNAME_$i\"" + eval $tmp pin="f" for p in $PACKAGES ; do if test "x$p" = "x$pname" ; then @@ -557,15 +823,17 @@ done # Is the DNAME entry a (+) or (-) rule ? + tmp="dname=\"\$DNAME_$i\"" + eval $tmp plus="-" - echo "${DNAME[$i]}" | grep '^+' > /dev/null 2>&1 + echo $dname | grep '^+' > /dev/null 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then plus="+" fi # Is $dname in the current $PACKAGES list? - dname=`echo ${DNAME[$i]} | sed -e 's/^[+-]//'` + dname=`echo $dname | sed -e 's/^[+-]//'` din="f" for p in $PACKAGES ; do if test "x$p" = "x$dname" ; then @@ -609,6 +877,9 @@ if test -d $adr ; then SOURCEDIRS="$SOURCEDIRS $adr" INCLUDEDIRS="$INCLUDEDIRS $adr" + if test "x$i" = xautodiff ; then + AUTODIFF_PKG_USED=t + fi else echo "Error: the directory \"$adr\" for package $i doesn't exist" exit 1 @@ -634,40 +905,18 @@ # done # echo -echo " Setting package-specific CPP flags in CPP_OPTIONS.h:" -CPP_OPTIONS= -spaths=". $SOURCEDIRS" -for i in $spaths ; do - try="$i/CPP_OPTIONS.h" - # echo -n " trying $try : " - if test -f $try -a -r $try ; then - echo " found CPP_OPTIONS=\"$try\"" - CPP_OPTIONS="$try" - if test "x$i" != "x." ; then - cp -f $CPP_OPTIONS . - fi - break - fi -done -if test "x$CPP_OPTIONS" = x ; then - echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths" - exit 1 -fi -if test -e CPP_OPTIONS.h ; then - if test ! -e CPP_OPTIONS.h.bak ; then - cp -f CPP_OPTIONS.h CPP_OPTIONS.h.bak - fi - cat CPP_OPTIONS.h \ - | awk 'BEGIN{p=1;} ($1=="C===" && $2=="GENMAKE"){p=0;} {if (p==1) print $0}' \ - > CPP_OPTIONS.h.tmp -fi -cat <>CPP_OPTIONS.h.tmp +# Create a list of #define and #undef to enable/disable packages +PACKAGES_DOT_H=PACKAGES_CONFIG.h +cat <$PACKAGES_DOT_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. +#ifndef PACKAGES_H +#define PACKAGES_H + C Packages disabled by genmake: EOF # The following UGLY HACK sets multiple "#undef"s and it needs to go @@ -687,7 +936,8 @@ done if test "x$has_pack" = xf ; then undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'` - echo "#undef $undef" >> CPP_OPTIONS.h.tmp + echo "#undef $undef" >> $PACKAGES_DOT_H".tmp" +# DEFINES="$DEFINES -U$undef" #EH3 WARNING : This is an UGLY HACK that needs to be removed!!! case $n in @@ -697,9 +947,6 @@ mom_vecinv) DEFINES="$DEFINES -DDISABLE_MOM_VECINV" ;; - generic_advdiff) - DEFINES="$DEFINES -DDISABLE_GENERIC_ADVDIFF" - ;; debug) DEFINES="$DEFINES -DDISABLE_DEBUGMODE" ;; @@ -709,28 +956,49 @@ fi fi done -cat <>CPP_OPTIONS.h.tmp +cat <>$PACKAGES_DOT_H".tmp" C Packages enabled by genmake: EOF for i in $PACKAGES ; do def=`echo "ALLOW_$i" | awk '{print toupper($0)}'` - echo "#define $def" >> CPP_OPTIONS.h.tmp + echo "#define $def" >> $PACKAGES_DOT_H".tmp" +#eh3 DEFINES="$DEFINES -D$def" #EH3 WARNING : This is an UGLY HACK that needs to be removed!!! case $i in aim_v23) - echo "#define ALLOW_AIM" >> CPP_OPTIONS.h.tmp + echo "#define ALLOW_AIM" >> $PACKAGES_DOT_H".tmp" + DEFINES="$DEFINES -DALLOW_AIM" + echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)" ;; esac #EH3 WARNING : This is an UGLY HACK that needs to be removed!!! done -mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h +cat <>$PACKAGES_DOT_H".tmp" + +#endif /* PACKAGES_H */ +EOF + +if test ! -f $PACKAGES_DOT_H ; then + mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H +else + cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H + RETVAL=$? + if test "x$RETVAL" = x0 ; then + rm -f $PACKAGES_DOT_H".tmp" + else + mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak" + mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H + fi +fi echo " Adding STANDARDDIRS" BUILDDIR=${BUILDDIR:-.} -STANDARDDIRS=${STANDARDDIRS:-"eesupp model"} +if test "x$STANDARDDIRS" = x ; then + STANDARDDIRS="eesupp model" +fi for d in $STANDARDDIRS ; do adr="$ROOTDIR/$d/src" if test ! -d $adr ; then @@ -750,13 +1018,62 @@ fi done +echo " Searching for CPP_OPTIONS.h in order to warn about the presence" +echo " of \"#define ALLOW_PKGNAME\"-type statements:" +CPP_OPTIONS= +spaths=". $INCLUDEDIRS" +for i in $spaths ; do + try="$i/CPP_OPTIONS.h" + # echo -n " trying $try : " + if test -f $try -a -r $try ; then + echo " found CPP_OPTIONS=\"$try\"" + CPP_OPTIONS="$try" + break + fi +done +if test "x$CPP_OPTIONS" = x ; then + echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths" + exit 1 +fi +# New safety test: make sure packages are not mentioned in CPP_OPTIONS.h +names=`ls -1 "$ROOTDIR/pkg"` +for n in $names ; do + test_for_package_in_cpp_options $CPP_OPTIONS $n +done + + +# Here, we build the list of files to be "run through" the adjoint +# compiler. +if test -f ./ad_files ; then + rm -f ./ad_files +fi +echo " Creating the list of files for the adjoint compiler." +for i in $SOURCEDIRS ; do + list_files=`( cd $i && ls -1 *.list 2>/dev/null )` + for j in $list_files ; do + cat $i/$j >> ad_files + done +done + +cat < adjoint_sed +s/call adopen(/call adopen ( mythid,\\ + \& /g +s/call adclose(/call adclose( mythid,\\ + \& /g +s/call adread(/call adread ( mythid,\\ + \& /g +s/call adwrite(/call adwrite( mythid,\\ + \& /g -echo $'\n'"=== Creating the Makefile ===" +EOF + +echo +echo "=== Creating the Makefile ===" echo " setting INCLUDES" for i in $INCLUDEDIRS ; do - if test -d $i ; then - INCLUDES="$INCLUDES -I$i" - else + if ! test -d $i ; then +# INCLUDES="$INCLUDES -I$i" +# else echo "Warning: can't find INCLUDEDIRS=\"$i\"" fi done @@ -766,13 +1083,16 @@ mkdir .links.tmp echo "# This section creates symbolic links" > srclinks.tmp echo "" >> srclinks.tmp -echo -n 'SRCFILES = ' > srclist.inc -echo -n 'CSRCFILES = ' > csrclist.inc +echo -n 'SRCFILES = ' > srclist.inc +echo -n 'CSRCFILES = ' > csrclist.inc +echo -n 'F90SRCFILES = ' > f90srclist.inc echo -n 'HEADERFILES = ' > hlist.inc -alldirs=". $SOURCEDIRS $INCLUDEDIRS" +echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc +alldirs="$SOURCEDIRS $INCLUDEDIRS ." for d in $alldirs ; do deplist= - sfiles=`( cd $d; echo *.[h,c,F] )` + sfiles=`( cd $d; echo *.[h,c,F] *.flow )` + sfiles=`( echo $sfiles; cd $d; echo *.F90 )` for sf in $sfiles ; do if test ! -r ".links.tmp/$sf" ; then if test -f "$d/$sf" ; then @@ -784,6 +1104,10 @@ echo " \\" >> srclist.inc echo -n " $sf" >> srclist.inc ;; + F90) + echo " \\" >> f90srclist.inc + echo -n " $sf" >> f90srclist.inc + ;; c) echo " \\" >> csrclist.inc echo -n " $sf" >> csrclist.inc @@ -792,20 +1116,27 @@ echo " \\" >> hlist.inc echo -n " $sf" >> hlist.inc ;; + flow) + echo " \\" >> ad_flow_files.inc + echo -n " $sf" >> ad_flow_files.inc + ;; esac fi fi done if test "x$deplist" != x ; then - echo $'\n'"# These files are linked from $d" >> srclinks.tmp + echo "" >> srclinks.tmp + echo "# These files are linked from $d" >> srclinks.tmp echo "$deplist :" >> srclinks.tmp - echo $'\t$(LN) '$d'/$@ $@' >> srclinks.tmp + printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp fi done rm -rf .links.tmp echo "" >> srclist.inc echo "" >> csrclist.inc +echo "" >> f90srclist.inc echo "" >> hlist.inc +echo "" >> ad_flow_files.inc if test -e $MAKEFILE ; then mv -f $MAKEFILE "$MAKEFILE.bak" @@ -847,6 +1178,9 @@ EXECUTABLE = \$(EXEDIR)/${EXECUTABLE} TOOLSDIR = ${TOOLSDIR} +#eh3 new defines for the adjoint work +AUTODIFF = ${ROOTDIR}/pkg/autodiff + EOF # Note: figure out some way to add Hyades JAM libraries here @@ -862,6 +1196,8 @@ KPP = ${KPP} # Fortran compiler FC = ${FC} +# Fortran compiler +F90C = ${F90C} # Link editor LINK = ${LINK} @@ -875,6 +1211,9 @@ # Optim./debug for FC FFLAGS = ${FFLAGS} FOPTIM = ${FOPTIM} +# Optim./debug for FC +F90FLAGS = ${F90FLAGS} +F90OPTIM = ${F90OPTIM} # Flags for CC CFLAGS = ${CFLAGS} # Files that should not be optimized @@ -882,21 +1221,28 @@ NOOPTFLAGS = ${NOOPTFLAGS} # Flags and libraries needed for linking LIBS = ${LIBS} \$(XLIBS) +# Name of the Mekfile +MAKEFILE=${MAKEFILE} EOF -cat srclist.inc >> $MAKEFILE -cat csrclist.inc >> $MAKEFILE -cat hlist.inc >> $MAKEFILE -echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE -echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o)' >> $MAKEFILE +cat srclist.inc >> $MAKEFILE +cat csrclist.inc >> $MAKEFILE +cat f90srclist.inc >> $MAKEFILE +cat hlist.inc >> $MAKEFILE +cat ad_flow_files.inc >> $MAKEFILE +echo >> $MAKEFILE +echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE +echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE +echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE -rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp +rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc +rm -f ad_flow_files.inc cat >>$MAKEFILE <> \$(MAKEFILE) -links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) +links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) -small_f: \$(F77FILES) +small_f: \$(F77FILES) \$(F90FILES) output.txt: \$(EXECUTABLE) @printf 'running ... ' @\$(EXECUTABLE) > \$@ clean: - -rm -rf *.o *.f *.p ${RMFILES} work.{pc,pcl} + -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} Clean: @make clean @make cleanlinks - -rm -f Makefile.bak + -rm -f Makefile.bak genmake_state genmake_optfile make.log CLEAN: @make Clean -find \$(EXEDIR) -name "*.meta" -exec rm {} \; -find \$(EXEDIR) -name "*.data" -exec rm {} \; -find \$(EXEDIR) -name "fort.*" -exec rm {} \; - -rm -f \$(EXECUTABLE) + -rm -f \$(EXECUTABLE) output.txt +Makefile: makefile makefile: ${0} $@ cleanlinks: @@ -936,6 +1284,10 @@ \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .f.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< +.F90.f90: + \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ +.f90.o: + \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .c.o: \$(CC) \$(CFLAGS) -c \$< @@ -945,8 +1297,76 @@ .p.f: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< +#========================================= +#=== Automatic Differentiation Rules === + +TAMC = ${TAMC} +TAF = ${TAF} + EOF +ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS" +ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS" +ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS" +for i in $ad_vars ; do + name=$i + t1="t2=\$"`echo $i` + eval $t1 + printf "%-20s = " $name >> $MAKEFILE + echo $t2 >> $MAKEFILE +done + +echo " Add the source list for AD code generation" +echo >> $MAKEFILE +echo -n "AD_FILES = " >> $MAKEFILE +AD_FILES=`cat ad_files` +for i in $AD_FILES ; do + echo " \\" >> $MAKEFILE + echo -n " $i" >> $MAKEFILE +done +echo >> $MAKEFILE + +cat >>$MAKEFILE < ad_input_code.f + + +ad_taf_output.f: ad_input_code.f + \$(TAF) \$(AD_TAF_FLAGS) ad_input_code.f + cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f + +ad_taf: ad_taf_output.o \$(OBJFILES) + \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) + + +ad_tamc_output.f: ad_input_code.f + \$(TAMC) \$(AD_TAMC_FLAGS) ad_input_code.f + cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f + +ad_tamc: ad_tamc_output.o \$(OBJFILES) + \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS) + + +flt_taf_output.f: ad_input_code.f + \$(TAF) \$(FTL_TAF_FLAGS) ad_input_code.f + cat ad_input_code_ad.f | sed -f adjoint_sed > flt_taf_output.f + +flt_taf: flt_taf_output.o \$(OBJFILES) + \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) flt_taf_output.o \$(LIBS) + + + +#========================================= + +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'` @@ -965,7 +1385,7 @@ echo "Error: unable to add file \"$i\" to the exceptions list" fi echo "$base.o: $base.f" >> $MAKEFILE - echo $'\t$(FC) $(FFLAGS) $(NOOPTFLAGS) -c $<' >> $MAKEFILE + printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE done echo " Add rules for links" @@ -973,6 +1393,17 @@ rm -f srclinks.tmp echo " Adding makedepend marker" -echo $'\n\n'"# DO NOT DELETE" >> $MAKEFILE +printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE -echo $'\n'"=== Done ===" +printf "\n=== Done ===\n" + + +# Write the "state" for future records +if test "x$DUMPSTATE" != xf ; then + echo -n "" > genmake_state + for i in $gm_state ; do + t1="t2=\$$i" + eval $t1 + echo "$i='$t2'" >> genmake_state + done +fi