--- MITgcm/tools/genmake2 2003/10/21 15:29:20 1.14 +++ MITgcm/tools/genmake2 2004/04/07 20:28:09 1.75 @@ -1,6 +1,6 @@ -#!/bin/bash +#! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.14 2003/10/21 15:29:20 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.75 2004/04/07 20:28:09 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -13,30 +13,35 @@ 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 + test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99 + test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99 + test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99 + test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99 +} + +# Search for particular CPP #cmds associated with MPI +# usage: test_for_mpi_in_cpp_eeoptions CPP_file +test_for_mpi_in_cpp_eeoptions() { + cpp_options=$1 + test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99 + test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99 + test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99 + test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99 +} + +# Search for particular string in a file. Return 1 if detected, 0 if not +# usage: test_for_string_in_file file string +test_for_string_in_file() { + file=$1 + strng=$2 + grep -i "$strng" $file > /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 + printf "Error: In $file there is an illegal line: " + grep -i "$strng" $file + return 1 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 + return 0 } # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to @@ -46,14 +51,14 @@ 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 + 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 }'` + replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'` echo " replacing \"$i\" with: $replace" new_packages="$new_packages $replace" else @@ -62,30 +67,66 @@ done PACKAGES=$new_packages rm -f ./p[1,2].tmp + return $matched else echo "Warning: can't read package groups definition file: $PKG_GROUPS" fi } +# Check for broken environments (eg. cygwin, MacOSX w/HFS+) that +# cannot distinguish [*.F/*.F90] from [*.f/*.f90] files. +check_for_broken_Ff() { + # First check the ability to create a *.F/.f pair. + cat <> ./hello.F + program hello + write(*,*) 'hi' + stop + end +EOF + cp ./hello.F ./hello.f + RETVAL=$? + if test "x$RETVAL" != x0 ; then + FEXT='fp' + F90EXT='fp90' + return + fi + rm -f ./hello.f + + # Then check the ability of ${MAKE} to use the two. + test -e Makefile && mv -f Makefile Makefile.bak + cat <> Makefile +.SUFFIXES: +hello.f: hello.F + cp -f hello.F hello.f +EOF + ( $MAKE hello.f ) > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 -o ! -f ./hello.f ; then + FEXT='fp' + F90EXT='fp90' + return + fi + rm -f ./hello.f ./hello.F Makefile + test -e Makefile && mv -f Makefile.bak Makefile + + # Both tests passed, so use the default. + FEXT='F' + F90EXT='F90' +} + + # 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/' | sed -e 's/athlon/ia32/'` + tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'` + tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'` + tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'` + tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'` + PLATFORM=$tmp3 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 @@ -103,8 +144,52 @@ CPP="cpp -traditional -P" fi + # The "original" makedepend is part of the Imake system that is + # most often distributed with XFree86 or with an XFree86 source + # package. As a result, many machines (eg. generic Linux) do not + # have a system-default "makedepend" available. For those + # systems, we have two fall-back options: + # + # 1) a makedepend implementation shipped with the cyrus-imapd + # package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/ + # + # 2) a known-buggy xmakedpend shell script + # + # So the choices are, in order: + # + # 1) use the user-specified program + # 2) use a system-wide default + # 3) locally build and use the cyrus implementation + # 4) fall back to the buggy local xmakedpend script + # + if test "x${MAKEDEPEND}" = x ; then + which makedepend > /dev/null 2>&1 + RETVAL=$? + if test ! "x${RETVAL}" = x0 ; then + echo " a system-default makedepend was not found." + + # Try to build the cyrus impl + rm -f ./genmake_cy_md + ( + cd $ROOTDIR/tools/cyrus-imapd-makedepend \ + && ./configure > /dev/null 2>&1 \ + && make > /dev/null 2>&1 \ + && ./makedepend ifparser.c > /dev/null 2>&1 \ + && echo "true" + ) > ./genmake_cy_md + grep true ./genmake_cy_md > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" = x0 ; then + MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend' + else + MAKEDEPEND='$(TOOLSDIR)/xmakedepend' + fi + rm -f ./genmake_cy_md + fi + 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 @@ -121,6 +206,7 @@ p_FC="$p_FC $c" fi done + rm -f ./hello.f ./hello if test "x${p_FC}" = x ; then cat 1>&2 <&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 + . ./.pd_tmp rm -f ./.pd_tmp - echo -n "PNAME = "${} + printf "PNAME = "${} } # Explain usage usage() { - echo - echo "Usage: "$0" [OPTIONS]" - echo " where [OPTIONS] can be:" - echo - echo " -help | --help | -h | --h" - echo " -nooptfile | --nooptfile" - echo " -optfile NAME | --optfile NAME | -of NAME | --of NAME" - echo " -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME" - echo " -pdepend NAME | --pdepend NAME" - echo " -pdepend=NAME | --pdepend=NAME" - echo " -pdefault NAME | --pdefault NAME" - echo " -pdefault=NAME | --pdefault=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" - echo " -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME" - echo " -mods NAME | --mods NAME | -mo NAME | --mo NAME" - echo " -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME" - echo " -disable NAME | --disable NAME" - 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" -# echo " -cpp=NAME | --cpp=NAME" - echo " -fortran NAME | --fortran NAME | -fc NAME | --fc NAME" - echo " -fc=NAME | --fc=NAME" - echo " -[no]ieee | --[no]ieee" - echo " -[no]mpi | --[no]mpi" - 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'" - echo - echo " which, depending upon your shell, may need to be single-quoted" - echo " if it contains spaces, dashes, or other special characters." +cat < genmake_test.c <> genmake_warnings 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 ; then + FC_NAMEMANGLE=$default_nm + cat <> genmake_errors + +WARNING: C test compile fails +WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE' +WARNING: Please contact if you need help here +EOF + return 1 + fi + c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3` + RETVAL=$? + if test "x$RETVAL" != x0 ; then + FC_NAMEMANGLE=$default_nm + cat <> genmake_warnings + +WARNING: The "nm" command failed. +WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE' +WARNING: Please contact if you need help here +EOF + return 1 + fi + cat > genmake_tcomp.f <> genmake_warnings 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 ; then + FC_NAMEMANGLE=$default_nm + cat <> genmake_warnings + +WARNING: FORTRAN test compile fails -- please see "genmake_errors" +WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE' +WARNING: Please contact if you need help here. +EOF + return 1 + fi + f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3` + RETVAL=$? + if test "x$RETVAL" != x0 ; then + FC_NAMEMANGLE=$default_nm + cat <> genmake_warnings + +WARNING: The "nm" command failed. +WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE' +WARNING: Please contact if you need help here. +EOF + return 1 + fi + + c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'` + f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'` + c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'` + f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'` + + nmangle="X" + if test "x$c_a" != "x$f_a" ; then + comm="echo x$f_a | sed -e 's|x$c_a||'" + a=`eval $comm` + nmangle="$a ## $nmangle" + fi + if test "x$c_b" != "x$f_b" ; then + comm="echo x$f_b | sed -e 's|x$c_b||'" + b=`eval $comm` + nmangle="$nmangle ## $b" + fi + + FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle" + + # cleanup the testing files + rm -f genmake_tcomp.* genmake_test.* +} + + +check_HAVE_CLOC() { + get_fortran_c_namemangling + cat < genmake_tc_1.c +$FC_NAMEMANGLE +#include +#include +#include +#include +#include +void FC_NAMEMANGLE(cloc) ( double *curtim ) +{ + struct timeval tv1; + gettimeofday(&tv1 , (void *)NULL ); + *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6); + *curtim = *curtim/1.E6; +} +EOF + make genmake_tc_1.o >> genmake_tc.log 2>&1 + RET_C=$? + cat < genmake_tc_2.f + program hello + Real*8 wtime + external cloc + call cloc(wtime) + print *," HELLO WORLD", wtime + end program hello +EOF + $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1 + RET_F=$? + test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1 + RETVAL=$? + if test "x$RETVAL" = x0 ; then + HAVE_CLOC=t + DEFINES="$DEFINES -DHAVE_CLOC" + fi + rm -f genmake_tc* +} + + +check_netcdf_libs() { + cat < genmake_tnc.for + program fgennc +#include "netcdf.inc" + integer iret, ncid, xid + iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid) + IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) + iret = nf_def_dim(ncid, 'X', 11, xid) + IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) + iret = nf_close(ncid) + IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) + end +EOF + $CPP genmake_tnc.for > genmake_tnc.f \ + && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1 + RET_COMPILE=$? + test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1 + RETVAL=$? + if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + HAVE_NETCDF=t + else + # try again with "-lnetcdf" added to the libs + $CPP genmake_tnc.for > genmake_tnc.f \ + && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \ + $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1 + RET_COMPILE=$? + test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1 + RETVAL=$? + if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + LIBS="$LIBS -lnetcdf" + HAVE_NETCDF=t + else + cat genmake_tnc.log >> genmake_warnings + fi + fi + rm -f genmake_tnc* +} + + + +############################################################################### +# Sequential part of script starts here +############################################################################### # Set defaults here COMMANDL="$0 $@" @@ -289,8 +590,9 @@ S64= KPP= FC= +CPP= LINK= -DEFINES="-DWORDLENGTH=4" +DEFINES= PACKAGES= ENABLE= DISABLE= @@ -306,19 +608,32 @@ CFLAGS= KFLAGS1= KFLAGS2= +#LDADD= LIBS= KPPFILES= NOOPTFILES= NOOPTFLAGS= +MPI= +MPIPATH= + +# DEFINES checked by test compilation +HAVE_SYSTEM= +HAVE_FDATE= +FC_NAMEMANGLE= +HAVE_CLOC= +HAVE_NETCDF= MODS= TOOLSDIR= SOURCEDIRS= INCLUDEDIRS= -STANDARDDIRS= +STANDARDDIRS="USE_THE_DEFAULT" +G2ARGS= +BASH= PWD=`pwd` MAKE=make +AWK=awk THISHOSTNAME=`hostname` THISCWD=`pwd` THISDATE=`date` @@ -331,41 +646,65 @@ if test "x$MITGCM_IEEE" != x ; then IEEE=$MITGCM_IEEE fi +FEXT= +F90EXT= 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 STANDARDDIRS" +gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE" +gm_s2="FC CPP 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" +gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE" # 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_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_s8" +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" +cat <&2 @@ -617,9 +985,21 @@ if test "x$LINK" = x ; then LINK=$FC fi +if test "x$MAKE" = x ; then + MAKE="make" +fi if test "x$CPP" = x ; then - CPP="cpp" + CPP=cpp fi +#EH3 === UGLY === +# The following an ugly little hack to check for $CPP in /lib/ and it +# should eventually be replaced with a more general function that +# searches a combo of the user's path and a list of "usual suspects" +# to find the correct location for binaries such as $CPP. +for i in " " "/lib/" ; do + echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP +done +#EH3 === UGLY === echo "#define A a" | $CPP > test_cpp 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then @@ -629,6 +1009,7 @@ 1) within the options file ("CPP=...") as specified by "-of=OPTFILE" 2) the "./genmake_local" file + 3) with the CPP environment variable EOF exit 1 @@ -638,16 +1019,95 @@ if test "x$MAKEDEPEND" = x ; then MAKEDEPEND=makedepend fi +if test "x$LN" = x ; then + LN="ln -s" +fi +echo "test" > genmake_test_ln +$LN genmake_test_ln genmake_tlink +RETVAL=$? +if test "x$RETVAL" != x0 ; then + cat <&2 + +Error: The command "ln -s" failed -- please specify a working soft-link + command in the optfile. + +EOF + exit 1 +fi +rm -f genmake_test_ln genmake_tlink + +if test ! "x$MPI" = x ; then + echo " Turning on MPI cpp macros" + DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI" +fi + +printf "\n=== Checking system libraries ===\n" +printf " 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* + +printf " 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* + +printf " Can we call simple C routines (here, \"cloc()\") using $FC... " +check_HAVE_CLOC +if test "x$HAVE_CLOC" != x ; then + echo "yes" +else + echo "no" +fi +rm -f genmake_t* + +printf " Can we create NetCDF-enabled binaries... " +check_netcdf_libs +if test "x$HAVE_NETCDF" != x ; then + echo "yes" +else + echo "no" +fi + printf "\n=== Setting defaults ===\n" -echo -n " Adding MODS directories: " +printf " 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" + printf " $d" SOURCEDIRS="$SOURCEDIRS $d" INCLUDEDIRS="$INCLUDEDIRS $d" fi @@ -677,12 +1137,13 @@ TOOLSDIR="$ROOTDIR/tools" fi if test ! -d ${TOOLSDIR} ; then - echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!" + echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!" exit 1 fi if test "x$S64" = x ; then S64='$(TOOLSDIR)/set64bitConst.sh' fi +THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'` EXECUTABLE=${EXECUTABLE:-mitgcmuv} @@ -691,17 +1152,31 @@ # they appear as regular source code if test -r $ROOTDIR"/eesupp/src/Makefile" ; then echo " Making source files in eesupp from templates" - $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1 + ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1 RETVAL=$? if test "x${RETVAL}" = x0 ; then rm -f make_eesupp.errors else echo "Error: problem encountered while building source files in eesupp:" - cat make_eesupp.errors + cat make_eesupp.errors 1>&2 exit 1 fi fi +#same for exch2 +if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then + echo " Making source files in exch2 from templates" + ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + rm -f make_exch2.errors + else + echo "Error: problem encountered while building source files in exch2:" + cat make_exch2.errors 1>&2 + exit 1 + fi +fi + printf "\n=== Determining package settings ===\n" if test "x${PDEPEND}" = x ; then tmp=$ROOTDIR"/pkg/pkg_depend" @@ -721,20 +1196,20 @@ # 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 echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\"" exit 1 fi -source ./.pd_tmp +. ./.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: " +echo " checking default package list: " if test "x${PDEFAULT}" = x ; then for i in "." $MODS ; do if test -r $i"/packages.conf" ; then @@ -747,18 +1222,17 @@ PDEFAULT="$ROOTDIR/pkg/pkg_default" fi if test "x${PDEFAULT}" = xNONE ; then - echo "default packages file disabled" + echo " default packages file disabled" else if test ! -r $PDEFAULT ; then - echo "" echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\"" else - echo " using PDEFAULT=\"$PDEFAULT\"" + 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 " + printf "Error: can't parse default package list " echo "-- please check PDEFAULT=\"$PDEFAULT\"" exit 1 fi @@ -766,12 +1240,19 @@ PACKAGES="$PACKAGES $i" done echo " before group expansion packages are: $PACKAGES" - expand_pkg_groups + while ! expand_pkg_groups; do echo > /dev/null; done echo " after group expansion packages are: $PACKAGES" fi fi echo " applying DISABLE settings" +for i in $PACKAGES ; do + echo $i >> ./.tmp_pack +done +for i in `grep "-" ./.tmp_pack` ; do + j=`echo $i | sed 's/[-]//'` + DISABLE="$DISABLE $j" +done pack= for p in $PACKAGES ; do addit="t" @@ -788,19 +1269,20 @@ echo " applying ENABLE settings" echo "" > ./.tmp_pack PACKAGES="$PACKAGES $ENABLE" +# Test if each explicitly referenced package exists for i in $PACKAGES ; do - if test ! -d "$ROOTDIR/pkg/$i" ; then + j=`echo $i | sed 's/[-+]//'` + if test ! -d "$ROOTDIR/pkg/$j" ; then echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\"" - exit 1 + exit 1 fi echo $i >> ./.tmp_pack done -pack=`cat ./.tmp_pack | sort | uniq` -rm -f ./.tmp_pack PACKAGES= -for i in $pack ; do +for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do PACKAGES="$PACKAGES $i" done +rm -f ./.tmp_pack echo " packages are: $PACKAGES" echo " applying package dependency rules" @@ -886,45 +1368,42 @@ 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 - -# 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. +# Build MNC templates and check for ability to build and use NetCDF +echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + rm -f make_mnc.errors + else + echo "Error: problem encountered while building source files in pkg/mnc:" + cat make_mnc.errors 1>&2 + exit 1 + fi + if test "x$HAVE_NETCDF" != xt ; then + cat <> $PACKAGES_DOT_H".tmp" -# DEFINES="$DEFINES -U$undef" - -#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" - ;; - 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)}'` + DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef" fi fi done -cat <>$PACKAGES_DOT_H".tmp" - -C Packages enabled by genmake: -EOF +ENABLED_PACKAGES= for i in $PACKAGES ; do - def=`echo "ALLOW_$i" | awk '{print toupper($0)}'` - echo "#define $def" >> $PACKAGES_DOT_H".tmp" + def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'` + ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def" #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" >> $PACKAGES_DOT_H".tmp" - DEFINES="$DEFINES -DALLOW_AIM" - echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)" + ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM" + echo "Warning: ALLOW_AIM is set to enable aim_v23." ;; esac #EH3 WARNING : This is an UGLY HACK that needs to be removed!!! done -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:-.} -if test "x$STANDARDDIRS" = x ; then +if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then STANDARDDIRS="eesupp model" fi -for d in $STANDARDDIRS ; do - adr="$ROOTDIR/$d/src" - if test ! -d $adr ; then - echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\"" - echo " is correct and that you correctly specified the STANDARDDIRS option" - exit 1 - else - SOURCEDIRS="$SOURCEDIRS $adr" - fi - adr="$ROOTDIR/$d/inc" - if test ! -d $adr ; then - echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\"" - echo " is correct and that you correctly specified the STANDARDDIRS option" - exit 1 - else - INCLUDEDIRS="$INCLUDEDIRS $adr" - fi -done +if test "x$STANDARDDIRS" != x ; then + for d in $STANDARDDIRS ; do + adr="$ROOTDIR/$d/src" + if test ! -d $adr ; then + echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\"" + echo " is correct and that you correctly specified the STANDARDDIRS option" + exit 1 + else + SOURCEDIRS="$SOURCEDIRS $adr" + fi + adr="$ROOTDIR/$d/inc" + if test ! -d $adr ; then + echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\"" + echo " is correct and that you correctly specified the STANDARDDIRS option" + exit 1 + else + INCLUDEDIRS="$INCLUDEDIRS $adr" + fi + done +fi -echo " Searching for CPP_OPTIONS.h in order to warn about the presence" -echo " of \"#define ALLOW_PKGNAME\"-type statements:" +echo " Searching for *OPTIONS.h files in order to warn about the presence" +echo " of \"#define \"-type statements that are no longer allowed:" CPP_OPTIONS= +CPP_EEOPTIONS= spaths=". $INCLUDEDIRS" +names=`ls -1 "$ROOTDIR/pkg"` for i in $spaths ; do try="$i/CPP_OPTIONS.h" - # echo -n " trying $try : " - if test -f $try -a -r $try ; then + if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then echo " found CPP_OPTIONS=\"$try\"" CPP_OPTIONS="$try" - break + # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h + for n in $names ; do + test_for_package_in_cpp_options $CPP_OPTIONS $n + done + fi + try="$i/CPP_EEOPTIONS.h" + if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then + echo " found CPP_EEOPTIONS=\"$try\"" + # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h +#**** not yet enabled **** +# test_for_mpi_in_cpp_eeoptions $try +#**** not yet enabled **** + CPP_EEOPTIONS="$try" 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. @@ -1055,17 +1506,6 @@ 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 ===" @@ -1083,11 +1523,11 @@ 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 'F90SRCFILES = ' > f90srclist.inc -echo -n 'HEADERFILES = ' > hlist.inc -echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc +printf 'SRCFILES = ' > srclist.inc +printf 'CSRCFILES = ' > csrclist.inc +printf 'F90SRCFILES = ' > f90srclist.inc +printf 'HEADERFILES = ' > hlist.inc +printf 'AD_FLOW_FILES = ' > ad_flow_files.inc alldirs="$SOURCEDIRS $INCLUDEDIRS ." for d in $alldirs ; do deplist= @@ -1096,29 +1536,39 @@ 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}'` - touch .links.tmp/$sf - deplist="$deplist $sf" + case $d/$sf in + ./$PACKAGES_DOT_H) + ;; + ./AD_CONFIG.h) + ;; + ./FC_NAMEMANGLE.h) + ;; + *) + touch .links.tmp/$sf + deplist="$deplist $sf" + ;; + esac + extn=`echo $sf | $AWK -F '.' '{print $NF}'` case $extn in F) echo " \\" >> srclist.inc - echo -n " $sf" >> srclist.inc + printf " $sf" >> srclist.inc ;; F90) echo " \\" >> f90srclist.inc - echo -n " $sf" >> f90srclist.inc + printf " $sf" >> f90srclist.inc ;; c) echo " \\" >> csrclist.inc - echo -n " $sf" >> csrclist.inc + printf " $sf" >> csrclist.inc ;; h) echo " \\" >> hlist.inc - echo -n " $sf" >> hlist.inc + printf " $sf" >> hlist.inc ;; flow) echo " \\" >> ad_flow_files.inc - echo -n " $sf" >> ad_flow_files.inc + printf " $sf" >> ad_flow_files.inc ;; esac fi @@ -1147,10 +1597,17 @@ echo "# This makefile was generated automatically on" >> $MAKEFILE echo "# $THISDATE" >> $MAKEFILE echo "# by the command:" >> $MAKEFILE -echo "# $0 $@" >> $MAKEFILE +echo "# $0 $G2ARGS" >> $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 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 +echo >> $MAKEFILE +echo 'F77FILES = $(SRCFILES:.'$FEXT'=.f)' >> $MAKEFILE +echo 'F90FILES = $(F90SRCFILES:.'$F90EXT'=.f90)' >> $MAKEFILE +echo 'OBJFILES = $(SRCFILES:.'$FEXT'=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.'$F90EXT'=.o)' >> $MAKEFILE +echo >> $MAKEFILE +echo '.SUFFIXES:' >> $MAKEFILE +echo '.SUFFIXES: .o .f .p .'$FEXT' .c .'$F90EXT' .f90' >> $MAKEFILE rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc rm -f ad_flow_files.inc cat >>$MAKEFILE <> \$(MAKEFILE) + \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE) + -rm -f makedepend.out -links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) +links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES) small_f: \$(F77FILES) \$(F90FILES) @@ -1261,11 +1729,12 @@ @\$(EXECUTABLE) > \$@ clean: - -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} + -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} *.template Clean: @make clean @make cleanlinks - -rm -f Makefile.bak genmake_state genmake_optfile make.log + -rm -f \$(SPECIAL_FILES) + -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak CLEAN: @make Clean -find \$(EXEDIR) -name "*.meta" -exec rm {} \; @@ -1273,26 +1742,37 @@ -find \$(EXEDIR) -name "fort.*" -exec rm {} \; -rm -f \$(EXECUTABLE) output.txt -Makefile: makefile +#eh3 Makefile: makefile makefile: - ${0} $@ + $THIS_SCRIPT $G2ARGS cleanlinks: -find . -type l -exec rm {} \; -# The normal chain of rules is ( .F - .f - .o ) -.F.f: +# Special targets ($SPECIAL_FILES) which are create by make +${PACKAGES_DOT_H}: + @echo Creating \$@ ... + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@ +AD_CONFIG.h: + @echo Creating \$@ ... + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > \$@ +FC_NAMEMANGLE.h: + @echo Creating \$@ ... + echo "$FC_NAMEMANGLE" > \$@ + +# The normal chain of rules is ( .$FEXT - .f - .o ) +.$FEXT.f: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .f.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< -.F90.f90: +.$F90EXT.f90: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .f90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .c.o: \$(CC) \$(CFLAGS) -c \$< -# Special exceptions that use the ( .F - .p - .f - .o ) rule-chain -.F.p: +# Special exceptions that use the ( .$FEXT - .p - .f - .o ) rule-chain +.$FEXT.p: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .p.f: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< @@ -1303,6 +1783,9 @@ TAMC = ${TAMC} TAF = ${TAF} +TAF_EXTRA = ${TAF_EXTRA} +TAMC_EXTRA = ${TAMC_EXTRA} + EOF ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS" @@ -1318,45 +1801,87 @@ echo " Add the source list for AD code generation" echo >> $MAKEFILE -echo -n "AD_FILES = " >> $MAKEFILE +printf "AD_FILES = " >> $MAKEFILE AD_FILES=`cat ad_files` for i in $AD_FILES ; do echo " \\" >> $MAKEFILE - echo -n " $i" >> $MAKEFILE + printf " $i" >> $MAKEFILE done echo >> $MAKEFILE +rm -f ad_files cat >>$MAKEFILE < ad_config.template + cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h + -rm -f ad_config.template + @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) ad_input_code.f - cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f + \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f + cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f -ad_taf: ad_taf_output.o \$(OBJFILES) - \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) +adtafonly: + \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f + cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/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) ad_input_code.f - cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f + \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f + cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f ad_tamc: ad_tamc_output.o \$(OBJFILES) - \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS) + \$(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) + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template + cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h + -rm -f ftl_config.template + @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 \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f +ftltafonly: + \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f + cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f -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 +ftl_taf: ftl_taf_output.o \$(OBJFILES) + \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS) -flt_taf: flt_taf_output.o \$(OBJFILES) - \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) flt_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 \$(TOOLSDIR)/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 ... +svdtaf: ad_taf_output.f ftl_taf_output.f +svdall: svd_taf + +svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES) + \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS) #========================================= @@ -1397,10 +1922,28 @@ printf "\n=== Done ===\n" +# Create special header files +$BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp" +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 > /dev/null 2>&1 + 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 +if test ! -f AD_CONFIG.h ; then + $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > AD_CONFIG.h +fi + # Write the "state" for future records if test "x$DUMPSTATE" != xf ; then - echo -n "" > genmake_state + printf "" > genmake_state for i in $gm_state ; do t1="t2=\$$i" eval $t1