--- MITgcm/tools/genmake2 2004/12/10 13:07:47 1.112 +++ MITgcm/tools/genmake2 2006/04/07 02:53:55 1.146 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.112 2004/12/10 13:07:47 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.146 2006/04/07 02:53:55 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -13,20 +13,28 @@ test_for_package_in_cpp_options() { cpp_options=$1 pkg=$2 - 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 + test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg[ ]" + test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg[ ]" + test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg[ ]" + test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg[ ]" + test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg$" + test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg$" + test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg$" + test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg$" } # 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 + test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI[ ]" + test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI[ ]" + test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI[ ]" + test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI[ ]" + test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI$" + test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI$" + test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI$" + test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI$" } # Search for particular string in a file. Return 1 if detected, 0 if not @@ -39,7 +47,7 @@ if test "x${RETVAL}" = x0 ; then printf "Error: In $file there is an illegal line: " grep -i "$strng" $file - return 1 + exit 99 fi return 0 } @@ -122,8 +130,8 @@ stop end EOF - test -f Makefile && mv -f Makefile Makefile.bak - cat <> Makefile + test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst" + cat <> $MAKEFILE .SUFFIXES: .SUFFIXES: .$tfs .F .F.$tfs: @@ -148,8 +156,8 @@ return fi fi - rm -f genmake_hello.* Makefile - test -f Makefile && mv -f Makefile.bak Makefile + rm -f genmake_hello.* $MAKEFILE + test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE # If we make it here, use the extensions FS=$tfs @@ -181,6 +189,15 @@ 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' @@ -189,6 +206,8 @@ 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 @@ -237,6 +256,41 @@ fi } + +build_embed_encode() +{ + printf " building the embed-encode utility... " + if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then + if test ! -d "$ROOTDIR/tools/embed_encode" ; then + echo + echo " Error: can't locate \"$ROOTDIR/tools/embed_encode\"" + echo + EMBED_SRC=f + return 1 + fi + clist="cc gcc c89 $CC" + for ic in $clist ; do + comm="$ic -o encode_files encode_files.c" + ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" = x0 ; then + echo "OK" + DEFINES="$DEFINES -DHAVE_EMBED_SRC" + return 0 + fi + done + echo + echo " Error: unable to build $ROOTDIR/embed_encode/encode_files" + echo " so it has been disabled" + echo + EMBED_SRC=f + return 1 + fi + echo "OK" + DEFINES="$DEFINES -DHAVE_EMBED_SRC" +} + + # Guess possible config options for this host find_possible_configs() { @@ -310,7 +364,7 @@ #================================================================ # look for possible FORTRAN compilers - tmp="$MITGCM_FC $FC efc 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 gfortran" p_FC= for c in $tmp ; do rm -f ./hello.f ./hello @@ -342,10 +396,18 @@ else echo " The possible FORTRAN compilers found in your path are:" echo " "$p_FC - if test "x$FC" = x ; then - FC=`echo $p_FC | $AWK '{print $1}'` - echo " Setting FORTRAN compiler to: "$FC - fi + fi + + # Use the first of the compilers found in the current PATH + # that has a correctly-named optfile + if test "x$OPTFILE" = x -a "x$FC" = x ; then + for i in $p_FC ; do + OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i + if test -r $OPTFILE ; then + echo " Setting OPTFILE to: "$OPTFILE + break + fi + done fi if test "x$OPTFILE" = x ; then @@ -516,6 +578,26 @@ *only* works if it is supported by the OPTFILE that is being used. + -ignoretime | -ignore_time | --ignoretime | --ignore_time + Ignore all the "wall clock" routines entirely. This will + not in any way hurt the model results -- it simply means + that the code that checks how long the model spends in + various routines will give junk values. + + -ts | --ts + Produce timing information per timestep + -papis | --papis + Produce summary MFlop/s with PAPI per timestep + -foolad | --foolad + Fool the AD code generator + -papi | --papi + Performance analysis with PAPI + -hpmt | --hpmt + Performance analysis with the HPM Toolkit + + -gsl | --gsl + Use GSL to control floating point rounding and precision + -mpi | --mpi Include MPI header files and link to MPI libraries -mpi=PATH | --mpi=PATH @@ -523,6 +605,11 @@ set to PATH. i.e. Include files from \$PATH/include, link to libraries from \$PATH/lib and use binaries from \$PATH/bin. + -es | --es | -embed-source | --embed-source + Embed a tarball containing the full source code + (including the Makefile, etc.) used to build the + executable [off by default] + -bash NAME Explicitly specify the Bourne or BASH shell to use @@ -581,13 +668,13 @@ EOF return 1 fi - cat > genmake_tcomp.f < genmake_tcomp.$FS <> genmake_warnings 2>&1 + $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm @@ -653,19 +740,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 @@ -675,6 +762,102 @@ } +check_HAVE_SIGREG() { + get_fortran_c_namemangling + cat < genmake_tc_1.c +$FC_NAMEMANGLE +#include +#include +#include +#include +#include + +int * ip; + +static void killhandler( + unsigned int sn, siginfo_t si, struct ucontext *sc ) +{ + *ip = *ip + 1; + return; +} + +void FC_NAMEMANGLE(sigreg) (int * aip) +{ + struct sigaction s; + ip = aip; + s.sa_flags = SA_SIGINFO; + s.sa_sigaction = (void *)killhandler; + if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) { + printf("Sigaction returned error = %d\n", errno); + exit(0); + } + return; +} +EOF + make genmake_tc_1.o >> genmake_warnings 2>&1 + RET_C=$? + cat < genmake_tc_2.$FS + program hello + integer anint + common /iv/ anint + external sigreg + call sigreg(anint) + end +EOF + echo >> genmake_warnings + echo "running: check_HAVE_SIGREG()" >> genmake_warnings + cat genmake_tc_2.$FS >> genmake_warnings + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 + RETVAL=$? + if test "x$RETVAL" = x0 ; then + HAVE_SIGREG=t + DEFINES="$DEFINES -DHAVE_SIGREG" + fi + rm -f genmake_tc* +} + + +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 + echo >> genmake_warnings + echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings + cat genmake_tc_2.$FS >> genmake_warnings + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> genmake_warnings + $COMM >> 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 @@ -698,16 +881,19 @@ EOF make genmake_tc_1.o >> genmake_tc.log 2>&1 RET_C=$? - cat < genmake_tc_2.f + cat < genmake_tc_2.$FS program hello integer nbyte call tfsize(nbyte) print *," HELLO WORLD", nbyte - end program hello + end 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 + echo >> genmake_warnings + echo "running: check_HAVE_STAT()" >> genmake_warnings + cat genmake_tc_2.$FS >> genmake_warnings + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> genmake_warnings + $COMM >> genmake_tc.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_STAT=t @@ -718,10 +904,19 @@ check_netcdf_libs() { - echo "" > genmake_tnc.log - cat < genmake_tnc.for + if test ! "x$SKIP_NETCDF_CHECK" = x ; then + return + fi + echo >> genmake_warnings + echo "running: check_netcdf_libs()" >> genmake_warnings + 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) @@ -731,24 +926,25 @@ IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) end EOF - echo "Executing:" > genmake_tnc.log - echo " $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f" \ - > genmake_tnc.log + echo "=== genmake_tnc.F ===" > genmake_tnc.log + cat genmake_tnc.F >> genmake_tnc.log + echo "=== genmake_tnc.F ===" >> genmake_tnc.log RET_CPP=f - $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null \ - && RET_CPP=t + COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F" + echo "$COMM" >> genmake_tnc.log + $COMM > 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 + >> genmake_tnc.log echo " Please check that \$INCLUDES is properly set." \ - > genmake_tnc.log + >> genmake_tnc.log fi - echo "Executing:" > genmake_tnc.log - echo " $FC $FFLAGS $FOPTIM -c genmake_tnc.f" > genmake_tnc.log - echo " $LINK -o genmake_tnc.o $LIBS" > genmake_tnc.log - $FC $FFLAGS $FOPTIM -c genmake_tnc.f >> genmake_tnc.log 2>&1 \ + 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=$? + cat genmake_tnc.log >> genmake_warnings #EH3 Remove test program execution for machines that either disallow #EH3 execution or cannot support it (eg. cross-compilers) @@ -761,15 +957,18 @@ HAVE_NETCDF=t else # try again with "-lnetcdf" added to the libs - $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null \ - && $FC $FFLAGS $FOPTIM -c genmake_tnc.f >> genmake_tnc.log 2>&1 \ + echo "try again with added '-lnetcdf'" > genmake_tnc.log + 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=$? + cat genmake_tnc.log >> genmake_warnings if test "x$RET_COMPILE" = x0 ; then LIBS="$LIBS -lnetcdf" HAVE_NETCDF=t - else - cat genmake_tnc.log >> genmake_warnings fi fi rm -f genmake_tnc* @@ -788,16 +987,16 @@ LN= S64= KPP= -FC= +#FC= #CC=gcc -CPP= +#CPP= LINK= DEFINES= PACKAGES= ENABLE= DISABLE= -MAKEFILE= -#MAKEDEPEND= +# MAKEFILE= +# MAKEDEPEND= PDEPEND= DUMPSTATE=t PDEFAULT= @@ -815,15 +1014,24 @@ NOOPTFLAGS= MPI= MPIPATH= +TS= +PAPIS= +FOOLAD= +PAPI= +HPMT= +GSL= +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= @@ -834,8 +1042,9 @@ G2ARGS= BASH= PWD=`pwd` -MAKE=make -AWK=awk +test "x$MAKE" = x && MAKE=make +test "x$AWK" = x && AWK=awk +EMBED_SRC= THISHOST=`hostname` THISCWD=`pwd` THISDATE=`date` @@ -869,7 +1078,7 @@ # 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 CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS" +gm_s2="FC CPP IEEE TS PAPIS PAPI HPMT GSL 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 " @@ -1049,6 +1258,20 @@ -noieee | --noieee) IEEE= ;; + -ts | --ts) + TS=true ;; + -papis | --papis) + PAPIS=true ;; + -foolad | --foolad) + FOOLAD=true ;; + -papi | --papi) + PAPI=true ;; + -hpmt | --hpmt) + HPMT=true ;; + + -gsl | --gsl) + GSL=true ;; + -mpi | --mpi) MPI=true ;; -mpi=* | --mpi=*) @@ -1072,6 +1295,12 @@ ac_prev=TAMC_EXTRA ;; -tamc_extra=* | --tamc_extra=*) TAMC_EXTRA=$ac_optarg ;; + + -ignoretime | -ignore_time | --ignoretime | --ignore_time) + IGNORE_TIME="-DIGNORE_TIME" ;; + + -es | --es | -embed-source | --embed-source) + EMBED_SRC=t ;; -*) echo "Error: unrecognized option: "$ac_option @@ -1087,6 +1316,7 @@ done + if test -f ./.genmakerc ; then echo echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\"" @@ -1128,7 +1358,11 @@ # Find the MITgcm ${THISVER} if test -f "${ROOTDIR}/doc/tag-index" ; then - THISVER=`grep checkpoint ${ROOTDIR}/doc/tag-index | head -1` + THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1` +fi + +if test "x$MAKEFILE" = x ; then + MAKEFILE="Makefile" fi echo " getting OPTFILE information: " @@ -1160,9 +1394,6 @@ fi fi -# Check for broken systems that cannot correctly distinguish *.F and *.f files -# check_for_broken_Ff - echo " getting AD_OPTFILE information: " if test "x${AD_OPTFILE}" = x ; then if test "x$MITGCM_AD_OF" = x ; then @@ -1190,6 +1421,9 @@ fi fi +#==================================================================== +# 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 @@ -1266,6 +1500,11 @@ 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 @@ -1276,14 +1515,65 @@ DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI" fi +if test ! "x$TS" = x ; then + echo " Turning on timing per timestep" + if test ! "x$FOOLAD" = x ; then + DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP" + else + DEFINES="$DEFINES -DTIME_PER_TIMESTEP" + fi +fi +if test ! "x$PAPIS" = x ; then + echo " Turning on PAPI flop summary per timestep" + echo " Please make sure PAPIINC, PAPILIB are defined" + if test ! "x$FOOLAD" = x ; then + DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP" + else + DEFINES="$DEFINES -DUSE_PAPI_FLOPS" + fi + INCLUDES="$INCLUDES $PAPIINC" + LIBS="$LIBS $PAPILIB" +fi +if test ! "x$PAPI" = x ; then + if test ! "x$PAPIS" = x ; then + echo " PAPI performance analysis and flop summary per timestep cannot co-exist!" + echo " Sticking with PAPI flop summary per timestep!" + else + echo " Turning on performance analysis with PAPI" + echo " Please make sure PAPIINC, PAPILIB are defined" + DEFINES="$DEFINES -DUSE_PAPI" + INCLUDES="$INCLUDES $PAPIINC" + LIBS="$LIBS $PAPILIB" + fi +fi +if test ! "x$HPMT" = x ; then + if test ! "x$PAPI" = x ; then + echo " PAPI and the HPM Toolkit cannot co-exist!" + echo " Sticking with PAPI!" + else + echo " Turning on performance analysis with the HPM Toolkit" + echo " Please make sure HPMTINC, HPMTLIB are defined" + DEFINES="$DEFINES -DUSE_LIBHPM" + INCLUDES="$INCLUDES $HPMTINC" + LIBS="$LIBS $HPMTLIB" + fi +fi +if test ! "x$GSL" = x ; then + echo " Turning on use of GSL to control floating point calculations" + echo " Please make sure GSLINC, GSLLIB are defined" + DEFINES="$DEFINES -DUSE_GSL_IEEE" + INCLUDES="$INCLUDES $GSLINC" + LIBS="$LIBS $GSLLIB" +fi + printf "\n=== Checking system libraries ===\n" printf " Do we have the system() command using $FC... " -cat > genmake_tcomp.f < genmake_tcomp.$FS < genmake_tcomp.log 2>&1 +$FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_SYSTEM=t @@ -1296,15 +1586,15 @@ rm -f genmake_tcomp* printf " Do we have the fdate() command using $FC... " -cat > genmake_tcomp.f < genmake_tcomp.$FS < genmake_tcomp.log 2>&1 +$FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_FDATE=t @@ -1317,7 +1607,7 @@ rm -f genmake_tcomp* printf " Do we have the etime() command using $FC... " -cat > genmake_tcomp.f < genmake_tcomp.$FS < genmake_tcomp.log 2>&1 +$FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_ETIME=t @@ -1344,6 +1634,29 @@ echo "yes" else echo "no" + if test "x$EMBED_SRC" = xt ; then + echo " WARNING: you requested file embedding but it has" + echo " been disabled since C code cannot be called" + EMBED_SRC= + fi +fi +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 register a signal handler using $FC... " +check_HAVE_SIGREG +if test "x$HAVE_SIGREG" != x ; then + echo "yes" +else + echo "no" fi rm -f genmake_t* @@ -1363,6 +1676,14 @@ else echo "no" fi +DEFINES="$DEFINES $IGNORE_TIME" + +if test "x$EMBED_SRC" = xt ; then + build_embed_encode +fi +if test "x$EMBED_SRC" = xt ; then + ENABLE="$ENABLE embed_files" +fi printf "\n=== Setting defaults ===\n" @@ -1380,9 +1701,6 @@ done echo -if test "x$MAKEFILE" = x ; then - MAKEFILE="Makefile" -fi if test "x${PLATFORM}" = x ; then PLATFORM=$p_PLATFORM fi @@ -1714,14 +2032,14 @@ 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" @@ -1805,7 +2123,10 @@ 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 ===" @@ -1816,9 +2137,52 @@ fi done +if test ! "x$DIVA" = x ; then + echo " Creating the pseudo-MPI include directory" + INCLUDES="-I./mpi_headers $INCLUDES" + rm -rf ./mpi_headers + mkdir -p ./mpi_headers + + if test "x$MPIINCLUDEDIR" = x ; then + if test "x$MPIHOME" = x ; then + MPIHOME='/usr' + fi + MPIINCLUDEDIR='$MPIHOME/include' + fi + + if test -r $MPIINCLUDEDIR/mpif.h ; then + for i in $MPI_HEADER_FILES; do + cp -p $MPIINCLUDEDIR/$i ./mpi_headers + done + + perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h + else + echo " We cannot create a copy of mpif.h!" + exit -1 + fi +fi + echo " Determining the list of source and include files" rm -rf .links.tmp mkdir .links.tmp +touch .links.tmp/foo +if test ! -r ".links.tmp/foo" ; then + echo + echo "ERROR : something is wrong with your directory permissions or" + echo " your user file-creation mask (\"umask\") since creating a" + echo " sub-dir, touch-ing a file within it, and then reading it is" + echo " not working. Please try setting your umask to something" + echo " sane such as:" + echo + echo " umask 0002" + echo + echo " and please verify that you have the proper permissions for" + echo " creating sub-directories and then reading files created" + echo " within them." + echo + exit 1 +fi +rm -f .links.tmp/foo echo "# This section creates symbolic links" > srclinks.tmp echo "" >> srclinks.tmp printf 'SRCFILES = ' > srclist.inc @@ -1834,43 +2198,59 @@ 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) + ignore_f=t ;; ./AD_CONFIG.h) + ignore_f=t ;; ./FC_NAMEMANGLE.h) + ignore_f=t ;; ./BUILD_INFO.h) + ignore_f=t + ;; + ./EMBEDDED_FILES.h) + ignore_f=t ;; *) - 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 - 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 + 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 @@ -1946,11 +2326,15 @@ # These files are created by Makefile SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h - EOF -# Note: figure out some way to add Hyades JAM libraries here - +if test "x$EMBED_SRC" = xt ; then + echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE +else + echo "EMBEDDED_FILES = " >>$MAKEFILE +fi + +# Note: figure out some way to add Hyades JAM libraries here cat >>$MAKEFILE <> $MAKEFILE echo >> $MAKEFILE echo 'F77FILES = $(SRCFILES:.F=.'$FS')' >> $MAKEFILE -echo 'F90FILES = $(F90SRCFILES:.F=.'$FS90')' >> $MAKEFILE +echo 'F90FILES = $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE echo >> $MAKEFILE echo '.SUFFIXES:' >> $MAKEFILE @@ -2012,7 +2396,7 @@ cat >>$MAKEFILE <> \$(MAKEFILE) -rm -f makedepend.out +lib: libmitgcmuv.a + +libmitgcmuv.a: \$(OBJFILES) + ar rcv libmitgcmuv.a \$(OBJFILES) + links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES) small_f: \$(F77FILES) \$(F90FILES) @@ -2041,7 +2430,8 @@ -find \$(EXEDIR) -name "*.meta" -exec rm {} \; -find \$(EXEDIR) -name "*.data" -exec rm {} \; -find \$(EXEDIR) -name "fort.*" -exec rm {} \; - -rm -f \$(EXECUTABLE) output.txt STD* + -rm -f \$(EXECUTABLE) *.txt STD* *diagnostics.log datetime + -rm -rf mnc_test_* #eh3 Makefile: makefile makefile: @@ -2069,6 +2459,25 @@ test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE +if test "x$EMBED_SRC" = xt ; then + cat >>$MAKEFILE <>$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 + 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) @@ -2167,38 +2576,38 @@ # ... 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) +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 +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 @@ -2214,9 +2623,9 @@ @echo "--->>> Only COMPILE svd code! <<<---" @echo "--->>> Assumes you previously <<<---" @echo "--->>> did make svdtaf <<<---" - touch ad_taf_output.f ftl_taf_output.f - \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.f - \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.f + 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