--- MITgcm/tools/genmake2 2003/11/25 17:22:47 1.49 +++ MITgcm/tools/genmake2 2005/10/15 00:35:36 1.133 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.49 2003/11/25 17:22:47 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.133 2005/10/15 00:35:36 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 @@ -62,18 +67,198 @@ 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() { + # Do we have defaults for $FS and/or $FS90 ? + tfs=f + tfs9=f90 + if test "x$FS" != x ; then + tfs="$FS" + fi + if test "x$FS90" != x ; then + tfs9="$FS90" + fi + + # First check the ability to create a *.F/.f pair. + cat <> genmake_hello.F + program hello + write(*,*) 'hi' + stop + end +EOF + cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 ; then + if test "x$FS" = x ; then + FS='for' + FS90='fr9' + check_for_broken_Ff + else + cat <&1 +ERROR: Your file system cannot distinguish between *.F and *.f files + (fails the "cp" test) and this program cannot find a suitable + replacement extension. Please try a different build environment or + contact the list for help. + +EOF + exit -1 + fi + return + fi + rm -f genmake_hello.* + + # Check the ability of ${MAKE} and ${LN} to use the current set + # of extensions. + cat <> genmake_hello.F + program hello + write(*,*) 'hi' + stop + end +EOF + test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst" + cat <> $MAKEFILE +.SUFFIXES: +.SUFFIXES: .$tfs .F +.F.$tfs: + $LN \$< \$@ +EOF + $MAKE "genmake_hello."$tfs > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then + if test "x$FS" = x ; then + FS='for' + FS90='fr9' + check_for_broken_Ff + else + cat <&1 +ERROR: Your file system cannot distinguish between *.F and *.f files + (fails the "make/ln" test) and this program cannot find a suitable + replacement extension. Please try a different build environment or + contact the list for help. + +EOF + exit -1 + return + fi + fi + rm -f genmake_hello.* $MAKEFILE + test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE + + # If we make it here, use the extensions + FS=$tfs + FS90=$tfs9 + return +} + + +look_for_makedepend() { + + # 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 + RV0=$? + test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst" + # echo 'MAKEFILE="'$MAKEFILE'"' + cat <> $MAKEFILE +# THIS IS A TEST MAKEFILE GENERATED BY "genmake2" +# +# Some "makedepend" implementations will die if they cannot +# find a Makefile -- so this file is here to gives them an +# empty one to find and parse. +EOF + cat <> genmake_tc.f + program test + write(*,*) 'test' + stop + end +EOF + makedepend genmake_tc.f > /dev/null 2>&1 + RV1=$? + test -f $MAKEFILE && rm -f $MAKEFILE + test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE + if test "x${RV0}${RV1}" = x00 ; then + MAKEDEPEND=makedepend + else + echo " a system-default makedepend was not found." + + # Try to build the cyrus implementation + build_cyrus_makedepend + RETVAL=$? + if test "x$RETVAL" != x0 ; then + MAKEDEPEND='$(TOOLSDIR)/xmakedepend' + fi + rm -f ./genmake_cy_md + fi + else + # echo "MAKEDEPEND=${MAKEDEPEND}" + echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1 + RETVAL=$? + if test x"$RETVAL" = x0 ; then + build_cyrus_makedepend + fi + fi +} + + +build_cyrus_makedepend() { + rm -f ./genmake_cy_md + ( + cd $ROOTDIR/tools/cyrus-imapd-makedepend \ + && ./configure > /dev/null 2>&1 \ + && make > /dev/null 2>&1 + if test -x ./makedepend.exe ; then + $LN ./makedepend.exe ./makedepend + fi + ./makedepend ifparser.c > /dev/null 2>&1 \ + && echo "true" + ) > ./genmake_cy_md + grep true ./genmake_cy_md > /dev/null 2>&1 + RETVAL=$? + rm -f ./genmake_cy_md + if test "x$RETVAL" = x0 ; then + MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend' + return 0 + else + echo "WARNING: unable to build cyrus-imapd-makedepend" + return 1 + fi +} + # Guess possible config options for this host find_possible_configs() { tmp1=`uname`"_"`uname -m` tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` 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/'` + 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 + echo $PLATFORM | grep cygwin > /dev/null 2>&1 && PLATFORM=cygwin_ia32 OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")` echo " The platform appears to be: $PLATFORM" @@ -93,18 +278,50 @@ CPP="cpp -traditional -P" fi - # makedepend is not always available - if test "x${MAKEDEPEND}" = x ; then - which makedepend >& /dev/null - RETVAL=$? - if test "x${RETVAL}" = x1 ; then - echo " makedepend was not found. Using xmakedpend instead." - MAKEDEPEND='$(TOOLSDIR)/xmakedepend' - fi + look_for_makedepend + + #================================================================ + # look for possible C compilers + tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc" + p_CC= + for c in $tmp ; do + rm -f ./genmake_hello.c ./genmake_hello + cat >> genmake_hello.c << EOF +#include +int main(int argc, char **argv) { + printf("Hello!\n"); + return 0; +} +EOF + $c -o genmake_hello genmake_hello.c > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + p_CC="$p_CC $c" + fi + done + rm -f ./genmake_hello.c ./genmake_hello + if test "x${p_CC}" = x ; then + cat 1>&2 <&2 < genmake_test.c </dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3` RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm @@ -336,13 +595,13 @@ EOF return 1 fi - cat > genmake_tcomp.f < genmake_tcomp.$FS <> genmake_warnings 2>&1 + $FC $FFLAGS $DEFINES -c genmake_tcomp.$FS >> genmake_warnings 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm @@ -354,7 +613,7 @@ EOF return 1 fi - f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3` + f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3` RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm @@ -408,19 +667,19 @@ *curtim = *curtim/1.E6; } EOF - make genmake_tc_1.o >> genmake_tc.log 2>&1 + make genmake_tc_1.o >> genmake_warnings 2>&1 RET_C=$? - cat < genmake_tc_2.f + cat < genmake_tc_2.$FS program hello - Real*8 wtime + REAL*8 wtime external cloc call cloc(wtime) print *," HELLO WORLD", wtime - end program hello + end EOF - $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1 + $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1 RET_F=$? - test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1 + test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_CLOC=t @@ -430,6 +689,162 @@ } +check_HAVE_SETRLSTK() { + get_fortran_c_namemangling + cat < genmake_tc_1.c +$FC_NAMEMANGLE +#include +#include +#include +void FC_NAMEMANGLE(setrlstk) () +{ + struct rlimit rls; + rls.rlim_cur = RLIM_INFINITY; + rls.rlim_max = RLIM_INFINITY; + setrlimit(RLIMIT_STACK, &rls); + return; +} +EOF + make genmake_tc_1.o >> genmake_warnings 2>&1 + RET_C=$? + cat < genmake_tc_2.$FS + program hello + external setrlstk + call setrlstk() + end +EOF + $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1 + RET_F=$? + test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1 + RETVAL=$? + if test "x$RETVAL" = x0 ; then + HAVE_SETRLSTK=t + DEFINES="$DEFINES -DHAVE_SETRLSTK" + fi + rm -f genmake_tc* +} + + +check_HAVE_STAT() { + get_fortran_c_namemangling + cat < genmake_tc_1.c +$FC_NAMEMANGLE +#include +#include +#include +#include +#include +void FC_NAMEMANGLE(tfsize) ( int *nbyte ) +{ + char name[512]; + struct stat astat; + + name[0] = 'a'; name[1] = '\0'; + if (! stat(name, &astat)) + *nbyte = (int)(astat.st_size); + else + *nbyte = -1; +} +EOF + make genmake_tc_1.o >> genmake_tc.log 2>&1 + RET_C=$? + cat < genmake_tc_2.$FS + program hello + integer nbyte + call tfsize(nbyte) + print *," HELLO WORLD", nbyte + end +EOF + $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS 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_STAT=t + DEFINES="$DEFINES -DHAVE_STAT" + fi + rm -f genmake_tc* +} + + +check_netcdf_libs() { + if test ! "x$SKIP_NETCDF_CHECK" = x ; then + return + fi + echo "" > genmake_tnc.log + cat < genmake_tnc.F + program fgennc +#include "netcdf.inc" +EOF + if test ! "x$MPI" = x ; then + echo '#include "mpif.h"' >> genmake_tnc.F + fi + cat <> genmake_tnc.F + 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 + echo "Executing:" > genmake_tnc.log + echo " $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS" \ + >> genmake_tnc.log + RET_CPP=f + $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \ + && RET_CPP=t + if test "x$RET_CPP" = xf ; then + echo " WARNING: CPP failed to pre-process the netcdf test." \ + >> genmake_tnc.log + echo " Please check that \$INCLUDES is properly set." \ + >> genmake_tnc.log + fi + echo "Executing:" > genmake_tnc.log + echo " $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS" >> genmake_tnc.log + echo " $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log + $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \ + && $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1 + RET_COMPILE=$? + + #EH3 Remove test program execution for machines that either disallow + #EH3 execution or cannot support it (eg. cross-compilers) + #EH3 + #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1 + #EH3 RETVAL=$? + #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + + if test "x$RET_COMPILE" = x0 ; then + HAVE_NETCDF=t + else + # try again with "-lnetcdf" added to the libs + echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log + echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log + echo " && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log + $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \ + && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \ + && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1 + RET_COMPILE=$? + if test "x$RET_COMPILE" = x0 ; then + LIBS="$LIBS -lnetcdf" + HAVE_NETCDF=t + else + echo "=== genmake_tnc.F ===" >> genmake_warnings + cat genmake_tnc.F >> genmake_warnings + echo "=== genmake_tnc.F ===" >> genmake_warnings + cat genmake_tnc.log >> genmake_warnings + fi + fi + rm -f genmake_tnc* +} + + + +############################################################################### +# Sequential part of script starts here +############################################################################### + # Set defaults here COMMANDL="$0 $@" @@ -437,48 +852,63 @@ LN= S64= KPP= -FC= +#FC= +#CC=gcc +#CPP= LINK= -# DEFINES="-DWORDLENGTH=4" DEFINES= PACKAGES= ENABLE= DISABLE= -MAKEFILE= -MAKEDEPEND= +# MAKEFILE= +# MAKEDEPEND= PDEPEND= DUMPSTATE=t PDEFAULT= OPTFILE= -INCLUDES="-I." +INCLUDES="-I. $INCLUDES" FFLAGS= FOPTIM= CFLAGS= KFLAGS1= KFLAGS2= +#LDADD= LIBS= KPPFILES= NOOPTFILES= NOOPTFLAGS= +MPI= +MPIPATH= +TS= +HAVE_TEST_L= -# DEFINES checked by test compilation +# DEFINES checked by test compilation or command-line HAVE_SYSTEM= HAVE_FDATE= FC_NAMEMANGLE= HAVE_CLOC= +HAVE_SETRLSTK= +HAVE_STAT= +HAVE_NETCDF= +HAVE_ETIME= +IGNORE_TIME= MODS= TOOLSDIR= SOURCEDIRS= INCLUDEDIRS= -STANDARDDIRS= +STANDARDDIRS="USE_THE_DEFAULT" +G2ARGS= +BASH= PWD=`pwd` -MAKE=make -AWK=awk -THISHOSTNAME=`hostname` +test "x$MAKE" = x && MAKE=make +test "x$AWK" = x && AWK=awk +THISHOST=`hostname` THISCWD=`pwd` THISDATE=`date` +THISUSER=`echo $USER` +THISVER= MACHINE=`uname -a` EXECUTABLE= EXEHOOK= @@ -488,6 +918,8 @@ if test "x$MITGCM_IEEE" != x ; then IEEE=$MITGCM_IEEE fi +FS= +FS90= AUTODIFF_PKG_USED=f AD_OPTFILE= @@ -505,14 +937,14 @@ # The following state can be set directly by command-line switches gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE" -gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS" +gm_s2="FC CPP IEEE TS 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_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE" gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF" -gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE" +gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME" # 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" @@ -541,8 +973,8 @@ break fi done -echo -n " getting local config information: " -if test -e $gm_local ; then +printf " getting local config information: " +if test -f $gm_local ; then echo "using $gm_local" . $gm_local # echo "DISABLE=$DISABLE" @@ -551,7 +983,7 @@ echo "none found" fi -# echo "$0::$1:$2:$3:$4:$5:$6:$7:" +#echo "$0::$1:$2:$3:$4:$5:$6:$7:" #OPTIONS= #n=0 #for i ; do @@ -563,7 +995,9 @@ #done #parse_options ac_prev= -for ac_option ; do +for ac_option in "$@" ; do + + G2ARGS="$G2ARGS \"$ac_option\"" # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then @@ -586,7 +1020,7 @@ -optfile=* | --optfile=* | -of=* | --of=*) OPTFILE=$ac_optarg ;; - -adoptfile | --adoptfile | -ad | --ad) + -adoptfile | --adoptfile | -adof | --adof) ac_prev=AD_OPTFILE ;; -adoptfile=* | --adoptfile=* | -adof=* | --adof=*) AD_OPTFILE=$ac_optarg ;; @@ -606,6 +1040,16 @@ -make=* | --make=* | -m=* | --m=*) MAKE=$ac_optarg ;; + -bash | --bash) + ac_prev=BASH ;; + -bash=* | --bash=*) + BASH=$ac_optarg ;; + + -makedepend | --makedepend | -md | --md) + ac_prev=MAKEDEPEND ;; + -makedepend=* | --makedepend=* | -md=* | --md=*) + MAKEDEPEND=$ac_optarg ;; + -makefile | --makefile | -ma | --ma) ac_prev=MAKEFILE ;; -makefile=* | --makefile=* | -ma=* | --ma=*) @@ -647,16 +1091,40 @@ # ac_prev=cpp ;; # -cpp=* | --cpp=*) # CPP=$ac_optarg ;; - + + -cc | --cc) + ac_prev=CC ;; + -cc=* | --cc=*) + CC=$ac_optarg ;; + -fortran | --fortran | -fc | --fc) ac_prev=FC ;; -fc=* | --fc=*) FC=$ac_optarg ;; + -fs | --fs) + ac_prev=FS ;; + -fs=* | --fs=*) + FS=$ac_optarg ;; + + -fs90 | --fs90) + ac_prev=FS90 ;; + -fs90=* | --fs90=*) + FS90=$ac_optarg ;; + -ieee | --ieee) IEEE=true ;; -noieee | --noieee) IEEE= ;; + + -ts | --ts) + TS=true ;; + + -mpi | --mpi) + MPI=true ;; + -mpi=* | --mpi=*) + MPIPATH=$ac_optarg + MPI=true ;; # -jam | --jam) # JAM=1 ;; @@ -675,6 +1143,9 @@ ac_prev=TAMC_EXTRA ;; -tamc_extra=* | --tamc_extra=*) TAMC_EXTRA=$ac_optarg ;; + + -ignoretime | -ignore_time | --ignoretime | --ignore_time) + IGNORE_TIME="-DIGNORE_TIME" ;; -*) echo "Error: unrecognized option: "$ac_option @@ -690,6 +1161,7 @@ done + if test -f ./.genmakerc ; then echo echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\"" @@ -702,14 +1174,16 @@ echo fi +# Find the MITgcm ${ROOTDIR} if test "x${ROOTDIR}" = x ; then - if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then + tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'` + if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then ROOTDIR=".." else for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then ROOTDIR=$d - echo -n "Warning: ROOTDIR was not specified but there appears to be" + printf "Warning: ROOTDIR was not specified but there appears to be" echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it." break fi @@ -727,6 +1201,15 @@ exit 1 fi +# Find the MITgcm ${THISVER} +if test -f "${ROOTDIR}/doc/tag-index" ; then + THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1` +fi + +if test "x$MAKEFILE" = x ; then + MAKEFILE="Makefile" +fi + echo " getting OPTFILE information: " if test "x${OPTFILE}" = x ; then if test "x$MITGCM_OF" = x ; then @@ -743,7 +1226,7 @@ . "$OPTFILE" RETVAL=$? if test "x$RETVAL" != x0 ; then - echo -n "Error: failed to source OPTFILE \"$OPTFILE\"" + printf "Error: failed to source OPTFILE \"$OPTFILE\"" echo "--please check that variable syntax is bash-compatible" exit 1 fi @@ -770,7 +1253,7 @@ . "$AD_OPTFILE" RETVAL=$? if test "x$RETVAL" != x0 ; then - echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\"" + printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\"" echo "--please check that variable syntax is bash-compatible" exit 1 fi @@ -783,8 +1266,15 @@ fi fi -# Check that FC, LINK, CPP, S64, LN, and MAKE are defined. If not, +#==================================================================== +# Set default values if not set by the optfile +# +# Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not, # either set defaults or complain and abort! +if test ! "x$BASH" = x ; then + # add a trailing space so that it works within the Makefile syntax (see below) + BASH="$BASH " +fi if test "x$FC" = x ; then cat <&2 @@ -795,15 +1285,34 @@ EOF exit 1 fi +if test "x$CC" = x ; then + CC=cc +# cat <&2 +# Error: no C compiler: please specify using one of the following: +# 1) within the options file ("CC=...") as specified by "-of=OPTFILE" +# 2) the "-cc=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 if test "x$MAKE" = x ; then MAKE="make" fi +if test "x$CPP" = x ; then + CPP=cpp +fi +#EH3 === UGLY === +# The following is 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 @@ -820,9 +1329,7 @@ else rm -f test_cpp fi -if test "x$MAKEDEPEND" = x ; then - MAKEDEPEND=makedepend -fi +look_for_makedepend if test "x$LN" = x ; then LN="ln -s" fi @@ -838,17 +1345,34 @@ EOF exit 1 fi +test -L genmake_tlink > /dev/null 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + HAVE_TEST_L=t +fi rm -f genmake_test_ln genmake_tlink +# Check for broken *.F/*.f handling and fix if possible +check_for_broken_Ff + +if test ! "x$MPI" = x ; then + echo " Turning on MPI cpp macros" + DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI" +fi + +if test ! "x$TS" = x ; then + echo " Turning on timing per timestep" + DEFINES="$DEFINES -DTIME_PER_TIMESTEP" +fi printf "\n=== Checking system libraries ===\n" -echo -n " Do we have the system() command using $FC... " -cat > genmake_tcomp.f < genmake_tcomp.$FS < genmake_tcomp.log 2>&1 +$FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_SYSTEM=t @@ -860,16 +1384,16 @@ fi rm -f genmake_tcomp* -echo -n " Do we have the fdate() command using $FC... " -cat > genmake_tcomp.f < genmake_tcomp.$FS < genmake_tcomp.log 2>&1 +$FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_FDATE=t @@ -881,46 +1405,86 @@ fi rm -f genmake_tcomp* -echo -n " Can we call simple C routines (here, \"cloc()\") using $FC... " +printf " Do we have the etime() command using $FC... " +cat > genmake_tcomp.$FS < genmake_tcomp.log 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + HAVE_ETIME=t + DEFINES="$DEFINES -DHAVE_ETIME" + echo "yes" +else + HAVE_ETIME= + 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 -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 +rm -f genmake_t* + +printf " Can we unlimit the stack size using $FC... " +check_HAVE_SETRLSTK +if test "x$HAVE_SETRLSTK" != x ; then + echo "yes" +else + echo "no" fi rm -f genmake_t* +printf " Can we use stat() through C calls... " +check_HAVE_STAT +if test "x$HAVE_STAT" != 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 +DEFINES="$DEFINES $IGNORE_TIME" 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 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 + tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'` + if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then EXEDIR=../exe else EXEDIR=. @@ -935,11 +1499,34 @@ 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' + echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + S64='$(TOOLSDIR)/set64bitConst.sh' + else + echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + S64='$(TOOLSDIR)/set64bitConst.csh' + else + cat <&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" @@ -1016,7 +1617,7 @@ 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 @@ -1024,12 +1625,20 @@ PACKAGES="$PACKAGES $i" done echo " before group expansion packages are: $PACKAGES" - expand_pkg_groups + RET=1 + while test $RET = 1 ; do expand_pkg_groups; RET=$?; 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" @@ -1046,21 +1655,57 @@ 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" +# Check availability of NetCDF and then either build the MNC template +# files or delete mnc from the list of available packages. +echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + if test "x$HAVE_NETCDF" != xt ; then + cat < 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 + fi +fi + echo " applying package dependency rules" ck= while test "x$ck" != xtt ; do @@ -1125,7 +1770,8 @@ echo " the dependency rules for \"$dname\"" exit 1 fi - i=$(( $i + 1 )) + i=`echo "$i + 1" | bc -l` + #i=$(( $i + 1 )) done ck=$ck"t" done @@ -1144,7 +1790,6 @@ fi done - # Create a list of #define and #undef to enable/disable packages PACKAGES_DOT_H=PACKAGES_CONFIG.h # The following UGLY HACK sets multiple "#undef"s and it needs to go @@ -1164,23 +1809,22 @@ fi done if test "x$has_pack" = xf ; then - undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'` + undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef" fi fi done ENABLED_PACKAGES= for i in $PACKAGES ; do - def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'` + def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` 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) - DEFINES="$DEFINES -DALLOW_AIM" ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM" - echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)" + echo "Warning: ALLOW_AIM is set to enable aim_v23." ;; esac #EH3 WARNING : This is an UGLY HACK that needs to be removed!!! @@ -1189,51 +1833,60 @@ 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. @@ -1247,14 +1900,16 @@ cat $i/$j >> ad_files done done +if test ! "x"$FS = "x.f" ; then + cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f + mv -f ad_files_f ad_files +fi 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 echo "Warning: can't find INCLUDEDIRS=\"$i\"" fi done @@ -1264,11 +1919,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= @@ -1277,6 +1932,7 @@ for sf in $sfiles ; do if test ! -r ".links.tmp/$sf" ; then if test -f "$d/$sf" ; then + ignore_f=f case $d/$sf in ./$PACKAGES_DOT_H) ;; @@ -1284,34 +1940,44 @@ ;; ./FC_NAMEMANGLE.h) ;; + ./BUILD_INFO.h) + ;; *) - touch .links.tmp/$sf - deplist="$deplist $sf" + # For the local directory *ONLY*, + # ignore all soft-links + if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then + ignore_f=t + else + touch .links.tmp/$sf + deplist="$deplist $sf" + fi ;; esac - extn=`echo $sf | $AWK -F '.' '{print $NF}'` - case $extn in - F) - 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 - ;; - h) - echo " \\" >> hlist.inc - echo -n " $sf" >> hlist.inc - ;; - flow) - echo " \\" >> ad_flow_files.inc - echo -n " $sf" >> ad_flow_files.inc - ;; - esac + if test "x$ignore_f" = xf ; then + extn=`echo $sf | $AWK -F. '{print $NF}'` + case $extn in + F) + echo " \\" >> srclist.inc + printf " $sf" >> srclist.inc + ;; + F90) + echo " \\" >> f90srclist.inc + printf " $sf" >> f90srclist.inc + ;; + c) + echo " \\" >> csrclist.inc + printf " $sf" >> csrclist.inc + ;; + h) + echo " \\" >> hlist.inc + printf " $sf" >> hlist.inc + ;; + flow) + echo " \\" >> ad_flow_files.inc + printf " $sf" >> ad_flow_files.inc + ;; + esac + fi fi fi done @@ -1329,7 +1995,7 @@ echo "" >> hlist.inc echo "" >> ad_flow_files.inc -if test -e $MAKEFILE ; then +if test -f $MAKEFILE ; then mv -f $MAKEFILE "$MAKEFILE.bak" fi echo " Writing makefile: $MAKEFILE" @@ -1338,15 +2004,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 +echo "# ${THISUSER}@${THISHOST}:${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 >> $MAKEFILE +echo 'F77FILES = $(SRCFILES:.F=.'$FS')' >> $MAKEFILE +echo 'F90FILES = $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE - +echo >> $MAKEFILE +echo '.SUFFIXES:' >> $MAKEFILE +echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .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) + -rm -f makedepend.out -links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) ${PACKAGES_DOT_H} AD_CONFIG.h +lib: libmitgcmuv.a + +libmitgcmuv.a: \$(OBJFILES) + ar rcv libmitgcmuv.a \$(OBJFILES) + +links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES) small_f: \$(F77FILES) \$(F90FILES) @@ -1464,49 +2142,67 @@ @\$(EXECUTABLE) > \$@ clean: - -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} *.template + -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template Clean: @make clean @make cleanlinks - -rm -f ${PACKAGES_DOT_H} AD_CONFIG.h - -rm -f Makefile.bak genmake_state genmake_*optfile genmake_warnings 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 {} \; -find \$(EXEDIR) -name "*.data" -exec rm {} \; -find \$(EXEDIR) -name "fort.*" -exec rm {} \; - -rm -f \$(EXECUTABLE) output.txt + -rm -f \$(EXECUTABLE) output.txt STD* #eh3 Makefile: makefile makefile: - $THIS_SCRIPT $@ + $THIS_SCRIPT $G2ARGS cleanlinks: -find . -type l -exec rm {} \; -# Special targets +# Special targets (SPECIAL_FILES) which are create by make ${PACKAGES_DOT_H}: @echo Creating \$@ ... - @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@ + @$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 \$@ ... - @\$(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 > \$@ + @$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 ( .F - .f - .o ) -.F.f: +BUILD_INFO.h: + @echo Creating \$@ ... +EOF + +test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE +test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE +test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE +test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE + +cat >>$MAKEFILE < \$@ -.f.o: +.$FS.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< -.F90.f90: +.F90.$FS90: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.f90.o: +.$FS90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .c.o: \$(CC) \$(CFLAGS) -c \$< -# Special exceptions that use the ( .F - .p - .f - .o ) rule-chain +# Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain .F.p: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.p.f: +.p.$FS: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< #========================================= @@ -1533,11 +2229,11 @@ 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 @@ -1546,75 +2242,96 @@ # ... AD ... adall: ad_taf -adtaf: ad_taf_output.f -adtamc: ad_tamc_output.f +adtaf: ad_taf_output.$FS +adtamc: ad_tamc_output.$FS -ad_input_code.f: \$(AD_FILES) \$(HEADERFILES) - @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ad_config.template +ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES) + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > 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 + cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS -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 \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f +ad_taf_output.$FS: ad_input_code.$FS + \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS + cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS 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 + \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS + cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS 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 \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f +ad_tamc_output.$FS: ad_input_code.$FS + \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS + cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS ad_tamc: ad_tamc_output.o \$(OBJFILES) \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS) +adonlyfwd: + patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff + +adtrick: + patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff # ... FTL ... ftlall: ftl_taf -ftltaf: ftl_taf_output.f -ftltamc: ftl_tamc_output.f +ftltaf: ftl_taf_output.$FS +ftltamc: ftl_tamc_output.$FS -ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES) - @\$(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 +ftl_input_code.$FS: \$(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 + cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS -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 +ftl_taf_output.$FS: ftl_input_code.$FS + \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS + cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS 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 + \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS + cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS 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 \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f +ftl_tamc_output.$FS: ftl_input_code.$FS + \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS + cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS 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 +svdtaf: ad_taf_output.$FS ftl_taf_output.$FS + @echo "--->>> Only ran TAF to generate SVD code! <<<---" + @echo "--->>> Do make svdall afterwards to compile. <<<---" +svdall: svd_touch svd_taf -svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES) +svd_taf: \$(OBJFILES) \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS) + @echo "--->>> Only COMPILE svd code! <<<---" + @echo "--->>> Assumes you previously <<<---" + @echo "--->>> did make svdtaf <<<---" + +svd_touch: + @echo "--->>> Only COMPILE svd code! <<<---" + @echo "--->>> Assumes you previously <<<---" + @echo "--->>> did make svdtaf <<<---" + touch ad_taf_output.$FS ftl_taf_output.$FS + \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS + \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS + @$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 #========================================= @@ -1631,7 +2348,7 @@ if test "x$RETVAL" != x0 ; then echo "Error: unable to add file \"$i\" to the exceptions list" fi - echo "$base.f: $base.p" >> $MAKEFILE + echo "$base.$FS: $base.p" >> $MAKEFILE done echo " Making list of NOOPTFILES" @@ -1641,7 +2358,7 @@ if test "x$RETVAL" != x0 ; then echo "Error: unable to add file \"$i\" to the exceptions list" fi - echo "$base.o: $base.f" >> $MAKEFILE + echo "$base.o: $base.$FS" >> $MAKEFILE printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE done @@ -1655,11 +2372,11 @@ printf "\n=== Done ===\n" # Create special header files -$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" +$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 + 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" @@ -1669,13 +2386,13 @@ fi fi if test ! -f AD_CONFIG.h ; then - $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 + $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