--- MITgcm/tools/genmake2 2003/09/29 16:15:23 1.11 +++ MITgcm/tools/genmake2 2003/11/11 20:38:27 1.29 @@ -1,6 +1,6 @@ #!/bin/bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.11 2003/09/29 16:15:23 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.29 2003/11/11 20:38:27 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -8,13 +8,72 @@ # 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() { tmp1=`uname`"_"`uname -m` tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` - PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/'` + tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'` + PLATFORM=`echo $tmp3 | 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 @@ -46,7 +105,7 @@ fi # look for possible fortran compilers - tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95" + tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95" p_FC= for c in $tmp ; do rm -f ./hello.f ./hello @@ -63,6 +122,7 @@ p_FC="$p_FC $c" fi done + rm -f ./hello.f ./hello if test "x${p_FC}" = x ; then cat 1>&2 <0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \ + | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \ > ./.pd_tmp source ./.pd_tmp rm -f ./.pd_tmp @@ -181,6 +241,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" @@ -251,13 +313,20 @@ NOOPTFILES= NOOPTFLAGS= +# DEFINES checked by test compilation +HAVE_SYSTEM= +HAVE_FDATE= +FC_NAMEMANGLE= + MODS= TOOLSDIR= SOURCEDIRS= INCLUDEDIRS= +STANDARDDIRS= PWD=`pwd` MAKE=make +AWK=awk THISHOSTNAME=`hostname` THISCWD=`pwd` THISDATE=`date` @@ -265,23 +334,55 @@ EXECUTABLE= EXEHOOK= EXEDIR= +PACKAGES_CONF= +IEEE= +if test "x$MITGCM_IEEE" != x ; then + IEEE=$MITGCM_IEEE +fi + +AUTODIFF_PKG_USED=f +AD_OPTFILE= +TAF= +AD_TAF_FLAGS= +FTL_TAF_FLAGS= +SVD_TAF_FLAGS= +TAF_EXTRA= +TAMC= +AD_TAMC_FLAGS= +FTL_TAF_FLAGS= +SVD_TAMC_FLAGS= +TAMC_EXTRA= + # 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" +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" +gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF" +gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE" -gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6" +# The following are all related to adjoint/tangent-linear stuff +gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS" +gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS" +gm_s12="TAF_EXTRA TAMC_EXTRA" + +gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7" +gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12" echo echo "=== Processing options files and arguments ===" -gm_local="./gm_local" +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" @@ -303,7 +404,6 @@ # n=$(( $n + 1 )) #done #parse_options - ac_prev= for ac_option ; do @@ -328,6 +428,11 @@ -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=*) @@ -373,6 +478,11 @@ -enable=* | --enable=*) ENABLE=$ac_optarg ;; + -standarddirs | --standarddirs) + ac_prev=STANDARDDIRS ;; + -standarddirs=* | --standarddirs=*) + STANDARDDIRS=$ac_optarg ;; + -noopt | --noopt) ac_prev=NOOPT ;; -noopt=* | --noopt=*) @@ -389,14 +499,14 @@ FC=$ac_optarg ;; -ieee | --ieee) - IEEE=1 ;; + IEEE=true ;; -noieee | --noieee) - IEEE=0 ;; + IEEE= ;; -mpi | --mpi) - MPI=1 ;; + MPI=true ;; -nompi | --nompi) - MPI=0 ;; + MPI= ;; -jam | --jam) JAM=1 ;; @@ -406,6 +516,16 @@ -ds | --ds) DUMPSTATE=t ;; + -taf_extra | --taf_extra) + ac_prev=TAF_EXTRA ;; + -taf_extra=* | --taf_extra=*) + TAF_EXTRA=$ac_optarg ;; + + -tamc_extra | --tamc_extra) + ac_prev=TAMC_EXTRA ;; + -tamc_extra=* | --tamc_extra=*) + TAMC_EXTRA=$ac_optarg ;; + -*) echo "Error: unrecognized option: "$ac_option usage @@ -420,6 +540,18 @@ done +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 if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then ROOTDIR=".." @@ -466,7 +598,7 @@ exit 1 fi if test "x$DUMPSTATE" != xf ; then - cp -f $OPTFILE "gm_optfile" + cp -f $OPTFILE "genmake_optfile" fi else echo "Error: can't read OPTFILE=\"$OPTFILE\"" @@ -474,6 +606,33 @@ 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 @@ -482,7 +641,7 @@ 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 + 3) the "./genmake_local" file EOF exit 1 fi @@ -492,7 +651,7 @@ if test "x$CPP" = x ; then CPP="cpp" fi -echo "#define A a" | cpp > test_cpp 2>&1 +echo "#define A a" | $CPP > test_cpp 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then cat <&2 @@ -500,7 +659,7 @@ 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 + 2) the "./genmake_local" file EOF exit 1 @@ -511,6 +670,89 @@ MAKEDEPEND=makedepend fi + +printf "\n=== Checking system libraries ===\n" +echo -n " Do we have the system() command using $FC... " +cat > genmake_tcomp.f < genmake_tcomp.log 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + HAVE_SYSTEM=t + DEFINES="$DEFINES -DHAVE_SYSTEM" + echo "yes" +else + HAVE_SYSTEM= + echo "no" +fi +rm -f genmake_tcomp* + +echo -n " Do we have the fdate() command using $FC... " +cat > genmake_tcomp.f < genmake_tcomp.log 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + HAVE_FDATE=t + DEFINES="$DEFINES -DHAVE_FDATE" + echo "yes" +else + HAVE_FDATE= + echo "no" +fi +rm -f genmake_tcomp* + +echo -n " The name mangling convention for $FC is... " +if test "x$FC_NAMEMANGLE" = x ; then + FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _" +fi +cat > genmake_tcomp.f < genmake_tcomp.log 2>&1 +RETVAL=$? +if test "x$RETVAL" != x0 ; then + cat genmake_tcomp.log >> genmake_errors + echo + echo "WARNING: test compile fails -- please see \"genmake_errors\"" + echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" + echo "WARNING: Please contact if you need help here." +else + tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3` + RETVAL=$? + if test "x$RETVAL" != x0 ; then + echo + echo "WARNING: The \"nm\" command failed." + echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" + echo "WARNING: Please contact if you need help here." + else + t0=`echo $tcall | sed -e 's|_tcall|_ ## X|g'` + nmres=`echo $t0 | sed -e 's|tcall_|X ## _|g'` + FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmres" + echo "'$FC_NAMEMANGLE'" + fi +fi +echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template +cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1 +RETVAL=$? +if test "x$RETVAL" != x0 ; then + mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h +fi +rm -f genmake_tcomp* + + printf "\n=== Setting defaults ===\n" echo -n " Adding MODS directories: " for d in $MODS ; do @@ -593,7 +835,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}} END{print "nname="nn}' \ + | $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 @@ -603,8 +845,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 @@ -616,7 +869,7 @@ else echo " using PDEFAULT=\"$PDEFAULT\"" # Strip the comments and add all the names - def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'` + def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'` RETVAL=$? if test "x${RETVAL}" != x0 ; then echo -n "Error: can't parse default package list " @@ -626,7 +879,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 @@ -645,7 +900,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 @@ -736,65 +991,28 @@ 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 fi done -# This is compatible with the old genmake. The "DISABLE_*" flags -# need to be replaced by the "ALLOW_*" flags set below. -# -# echo -n " Setting package-specific CPP flags: " -# pkrm=( mom_fluxform mom_vecinv generic_advdiff ) -# pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE ) -# echo -n " " -# i=0 -# while test $i -lt "${#pkrm[@]}" ; do -# echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1 -# RETVAL=$? -# if test "x$RETVAL" = x1 ; then -# DEFINES="$DEFINES ${pkdef[$i]}" -# echo -n " ${pkdef[$i]}" -# fi -# i=$(( $i + 1 )) -# done -# echo -echo " Searching for CPP_OPTIONS.h (macros and flags for configuring the model):" -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 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 @@ -813,51 +1031,54 @@ fi done if test "x$has_pack" = xf ; then - undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'` - echo "#undef $undef" >> CPP_OPTIONS.h.tmp - -#EH3 WARNING : This is an UGLY HACK that needs to be removed!!! - case $n in - mom_fluxform) - DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM" - ;; - mom_vecinv) - DEFINES="$DEFINES -DDISABLE_MOM_VECINV" - ;; - generic_advdiff) - DEFINES="$DEFINES -DDISABLE_GENERIC_ADVDIFF" - ;; - debug) - DEFINES="$DEFINES -DDISABLE_DEBUGMODE" - ;; - esac -#EH3 WARNING : This is an UGLY HACK that needs to be removed!!! - + undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'` + echo "#undef $undef" >> $PACKAGES_DOT_H".tmp" 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 + def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'` + 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 @@ -877,14 +1098,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 + +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 @@ -898,15 +1167,16 @@ echo -n 'CSRCFILES = ' > csrclist.inc echo -n 'F90SRCFILES = ' > f90srclist.inc echo -n 'HEADERFILES = ' > hlist.inc +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 - extn=`echo $sf | awk -F '.' '{print $NF}'` + extn=`echo $sf | $AWK -F '.' '{print $NF}'` touch .links.tmp/$sf deplist="$deplist $sf" case $extn in @@ -926,6 +1196,10 @@ echo " \\" >> hlist.inc echo -n " $sf" >> hlist.inc ;; + flow) + echo " \\" >> ad_flow_files.inc + echo -n " $sf" >> ad_flow_files.inc + ;; esac fi fi @@ -942,6 +1216,7 @@ echo "" >> csrclist.inc echo "" >> f90srclist.inc echo "" >> hlist.inc +echo "" >> ad_flow_files.inc if test -e $MAKEFILE ; then mv -f $MAKEFILE "$MAKEFILE.bak" @@ -955,6 +1230,11 @@ echo "# $0 $@" >> $MAKEFILE echo "# executed by:" >> $MAKEFILE echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE + +EXE_AD=$EXECUTABLE"_ad" +EXE_FTL=$EXECUTABLE"_ftl" +EXE_SVD=$EXECUTABLE"_svd" + cat >>$MAKEFILE <> $MAKEFILE -cat csrclist.inc >> $MAKEFILE -cat f90srclist.inc >> $MAKEFILE -cat hlist.inc >> $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 f90srclist.inc +rm -f ad_flow_files.inc cat >>$MAKEFILE < \$@ clean: + -cat AD_CONFIG.template > AD_CONFIG.h -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 +#eh3 Makefile: makefile makefile: ${0} $@ cleanlinks: @@ -1095,6 +1386,113 @@ .p.f: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< +#========================================= +#=== Automatic Differentiation Rules === + +TAMC = ${TAMC} +TAF = ${TAF} + +TAF_EXTRA = ${TAF_EXTRA} +TAMC_EXTRA = ${TAMC_EXTRA} + +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 +rm -f ad_files + +cat >>$MAKEFILE < AD_CONFIG.h + @make \$(F77FILES) + @make \$(AD_FLOW_FILES) + cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f + +ad_taf_output.f: ad_input_code.f + \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) 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 ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) + +ad_tamc_output.f: ad_input_code.f + \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f + cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f + +ad_tamc: ad_tamc_output.o \$(OBJFILES) + \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS) + + +# ... FTL ... +ftlall: ftl_taf +ftltaf: ftl_taf_output.f +ftltamc: ftl_tamc_output.f + +ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES) + cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h + @make \$(F77FILES) + @make \$(AD_FLOW_FILES) + cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f + +ftl_taf_output.f: ftl_input_code.f + \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f + cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f + +ftl_taf: ftl_taf_output.o \$(OBJFILES) + \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS) + +ftl_tamc_output.f: ftl_input_code.f + \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f + cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f + +ftl_tamc: ftl_tamc_output.o \$(OBJFILES) + \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS) + + +# ... SVD ... +svd: svd_taf +svd_taf_f: svd_taf_output.f + +svd_input_code.f: \$(SRCFILES) + cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h + @make \$(F77FILES) + @make \$(AD_FLOW_FILES) + cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f + +svd_taf_output.f: svd_input_code.f + \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f + cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f + +svd_taf: svd_taf_output.o \$(OBJFILES) + \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS) + + +#========================================= + EOF if test "x$EXEHOOK" != x ; then @@ -1131,13 +1529,52 @@ printf "\n=== Done ===\n" +# Write the "template" files for the adjoint builds +cat >AD_CONFIG.template <ad_config.template <ftl_config.template <svd_config.template < gm_state + echo -n "" > genmake_state for i in $gm_state ; do t1="t2=\$$i" eval $t1 - echo "$i='$t2'" >> gm_state + echo "$i='$t2'" >> genmake_state done fi