--- MITgcm/tools/genmake2 2003/10/02 18:26:44 1.11.2.8 +++ 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.11.2.8 2003/10/02 18:26:44 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 @@ -49,7 +49,7 @@ cat ./p1.tmp | awk '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp matched=0 for i in $PACKAGES ; do - line=`grep $i ./p2.tmp` + line=`grep "^ *$i" ./p2.tmp` RETVAL=$? if test "x$RETVAL" = x0 ; then matched=1 @@ -72,7 +72,7 @@ tmp1=`uname`"_"`uname -m` tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` - PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/'` + 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 @@ -239,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" @@ -313,6 +315,7 @@ TOOLSDIR= SOURCEDIRS= INCLUDEDIRS= +STANDARDDIRS= PWD=`pwd` MAKE=make @@ -323,23 +326,42 @@ EXECUTABLE= EXEHOOK= EXEDIR= +PACKAGES_CONF= +IEEE= +if test "x$MITGCM_IEEE" != x ; then + IEEE=$MITGCM_IEEE +fi + +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" +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_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_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="./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" @@ -361,7 +383,6 @@ # n=$(( $n + 1 )) #done #parse_options - ac_prev= for ac_option ; do @@ -386,6 +407,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=*) @@ -431,6 +457,11 @@ -enable=* | --enable=*) ENABLE=$ac_optarg ;; + -standarddirs | --standarddirs) + ac_prev=STANDARDDIRS ;; + -standarddirs=* | --standarddirs=*) + STANDARDDIRS=$ac_optarg ;; + -noopt | --noopt) ac_prev=NOOPT ;; -noopt=* | --noopt=*) @@ -447,14 +478,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 ;; @@ -478,6 +509,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=".." @@ -524,7 +567,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\"" @@ -532,6 +575,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 @@ -540,7 +610,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 @@ -550,7 +620,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 @@ -558,7 +628,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 @@ -807,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 @@ -923,7 +996,9 @@ 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 @@ -967,6 +1042,31 @@ 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" @@ -987,10 +1087,11 @@ 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 @@ -1015,6 +1116,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 @@ -1031,6 +1136,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" @@ -1072,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 @@ -1117,15 +1226,18 @@ EOF -cat srclist.inc >> $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 <> $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 @@ -1223,10 +1400,10 @@ # Write the "state" for future records if test "x$DUMPSTATE" != xf ; then - echo -n "" > 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