--- MITgcm/tools/genmake2 2009/02/20 21:08:02 1.184 +++ MITgcm/tools/genmake2 2010/12/13 22:07:20 1.216 @@ -1,6 +1,7 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.184 2009/02/20 21:08:02 utke Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.216 2010/12/13 22:07:20 jmc Exp $ +# $Name: $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -8,6 +9,167 @@ # modified by aja 01/00 # rewritten in bash by eh3 08/03 +# Explain usage +usage() { +cat < ./p1.tmp cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp @@ -67,7 +228,7 @@ if test "x$RETVAL" = x0 ; then matched=1 replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'` - echo " replacing \"$i\" with: $replace" + echo " replacing \"$i\" with:$replace" new_packages="$new_packages $replace" else new_packages="$new_packages $i" @@ -110,9 +271,9 @@ 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 +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 @@ -146,9 +307,9 @@ 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 +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 @@ -165,7 +326,6 @@ return } - look_for_makedepend() { # The "original" makedepend is part of the Imake system that is @@ -194,8 +354,8 @@ 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 +# 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 @@ -212,7 +372,6 @@ MAKEDEPEND=makedepend else echo " a system-default makedepend was not found." - # Try to build the cyrus implementation build_cyrus_makedepend RETVAL=$? @@ -231,7 +390,6 @@ fi } - build_cyrus_makedepend() { rm -f ./genmake_cy_md ( @@ -256,7 +414,6 @@ fi } - build_embed_encode() { printf " building the embed-encode utility... " @@ -269,7 +426,7 @@ return 1 fi clist="cc gcc c89 $CC" - for ic in $clist ; do + for ic in $clist ; do comm="$ic -o encode_files encode_files.c" ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1 RETVAL=$? @@ -290,55 +447,27 @@ DEFINES="$DEFINES -DHAVE_EMBED_SRC" } - -# 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/'` - 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" - - echo "test" > test - ln -s ./test link - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - LN="ln -s" - else - echo "Error: \"ln -s\" does not appear to work on this system!" - echo " For help, please contact ." - exit 1 - fi - rm -f test link - - if test "x$CPP" = x ; then - CPP="cpp -traditional -P" - fi - - look_for_makedepend - - #================================================================ - # look for possible C compilers - tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc" - p_CC= - for c in $tmp ; do - rm -f ./genmake_hello.c ./genmake_hello - cat >> genmake_hello.c << EOF +# look for possible C compilers +look_for_C_compilers() { + echo >> $LOGFILE + echo "running: look_for_C_compilers()" >> $LOGFILE + 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 + tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc" + p_CC= + for c in $tmp ; do + COMM="$c $CFLAGS -o genmake_hello genmake_hello.c" + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RETVAL=$? if test "x${RETVAL}" = x0 ; then + echo " $c test successful" >> $LOGFILE p_CC="$p_CC $c" fi done @@ -354,34 +483,55 @@ EOF exit 1 else - echo " The possible C compilers found in your path are:" - echo " "$p_CC + echo " The possible C compilers found in your path are: $p_CC" | tee -a $LOGFILE if test "x$CC" = x ; then CC=`echo $p_CC | $AWK '{print $1}'` echo " Setting C compiler to: "$CC fi fi + echo " --> set CC='$CC'" >> $LOGFILE +} + +# Guess possible config options for this host +find_possible_optfile() { + + echo >> $LOGFILE + echo "running: find_possible_optfile()" >> $LOGFILE + tmp1=`uname`"_"`uname -m` + tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` + 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 + 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" | tee -a $LOGFILE #================================================================ # look for possible FORTRAN compilers - tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 gfortran g95" + echo " look for possible FORTRAN compilers" >> $LOGFILE + tmp="$MITGCM_FC $FC efc gfortran g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 g95" p_FC= - for c in $tmp ; do - rm -f ./hello.f ./hello - cat >> hello.f <> genmake_hello.f < /dev/null 2>&1 + for f in $tmp ; do + COMM="$f -o genmake_hello genmake_hello.f" + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RETVAL=$? if test "x${RETVAL}" = x0 ; then - p_FC="$p_FC $c" + echo " $f test successful" >> $LOGFILE + p_FC="$p_FC $f" fi done - rm -f ./hello.f ./hello + rm -f ./genmake_hello.f ./genmake_hello if test "x${p_FC}" = x ; then cat 1>&2 <&2 </dev/null` @@ -461,7 +600,7 @@ # if test "x${RETVAL}" = x0 ; then # a=`cat out` # for i in $a ; do -# case $i in +# case $i in # -*) # mpi_libs="$mpi_libs $i" ;; # esac @@ -471,7 +610,6 @@ # fi # rm -f test.f out # fi - } # Parse the package dependency information @@ -480,161 +618,15 @@ # strip the comments and then convert the dependency file into # two arrays: PNAME, DNAME cat $1 | sed -e 's/#.*$//g' \ - | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \ + | $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 PKG_DEPEND=\"$1\"" + exit 1 + fi . ./.pd_tmp rm -f ./.pd_tmp - - printf "PNAME = "${} -} - - -# Explain usage -usage() { -cat <> $LOGFILE default_nm="#define FC_NAMEMANGLE(X) X ## _" - + cat > genmake_test.c <> genmake_warnings 2>&1 + COMM="$CC $CFLAGS -c genmake_test.c" + echo ' '$COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm - cat <> genmake_errors + cat <> $LOGFILE -WARNING: C test compile fails -WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE' -WARNING: Please contact if you need help here + 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 @@ -666,11 +661,11 @@ RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm - cat <> genmake_warnings + cat <> $LOGFILE -WARNING: The "nm" command failed. -WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE' -WARNING: Please contact if you need help here + 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 @@ -680,15 +675,17 @@ call tsub( string ) end EOF - $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1 + COMM="$FC $FFLAGS -c genmake_tcomp.$FS" + echo ' '$COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm - cat <> genmake_warnings + cat <> $LOGFILE -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. + WARNING: FORTRAN test compile fails -- please see '$LOGFILE' + WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE' + WARNING: Please contact if you need help here. EOF return 1 fi @@ -696,11 +693,11 @@ RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm - cat <> genmake_warnings + cat <> $LOGFILE -WARNING: The "nm" command failed. -WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE' -WARNING: Please contact if you need help here. + 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 @@ -726,10 +723,13 @@ # cleanup the testing files rm -f genmake_tcomp.* genmake_test.* -} + echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE +} check_HAVE_CLOC() { + echo >> $LOGFILE + echo "running: check_HAVE_CLOC()" >> $LOGFILE get_fortran_c_namemangling cat < genmake_tc_1.c $FC_NAMEMANGLE @@ -747,8 +747,8 @@ } EOF COMM="$CC $CFLAGS -c genmake_tc_1.c" - echo $COMM >> genmake_warnings - $COMM >> genmake_warnings 2>&1 + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -759,23 +759,25 @@ end EOF COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" - echo $COMM >> genmake_warnings - $COMM >> genmake_warnings 2>&1 + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RET_F=$? - test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1 + test -x ./genmake_tc && ./genmake_tc >> $LOGFILE 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_CLOC=t DEFINES="$DEFINES -DHAVE_CLOC" fi rm -f genmake_tc* + echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE } - check_HAVE_SIGREG() { if test ! "x$HAVE_SIGREG" = x ; then return fi + echo >> $LOGFILE + echo "running: check_HAVE_SIGREG()" >> $LOGFILE get_fortran_c_namemangling cat < genmake_tc_1.c $FC_NAMEMANGLE @@ -808,8 +810,8 @@ } EOF COMM="$CC $CFLAGS -c genmake_tc_1.c" - echo $COMM >> genmake_warnings - $COMM >> genmake_warnings 2>&1 + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -819,21 +821,19 @@ call sigreg(anint) end EOF - echo >> genmake_warnings - echo "running: check_HAVE_SIGREG()" >> genmake_warnings - cat genmake_tc_2.$FS >> genmake_warnings + cat genmake_tc_2.$FS >> $LOGFILE COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" - echo $COMM >> genmake_warnings - $COMM >> genmake_warnings 2>&1 + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_SIGREG=t DEFINES="$DEFINES -DHAVE_SIGREG" fi rm -f genmake_tc* + echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE } - check_HAVE_SETRLSTK() { if test "x$HAVE_SETRLSTK" = xt ; then DEFINES="$DEFINES -DHAVE_SETRLSTK" @@ -842,6 +842,8 @@ if test ! "x$HAVE_SETRLSTK" = x ; then return fi + echo >> $LOGFILE + echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE get_fortran_c_namemangling cat < genmake_tc_1.c $FC_NAMEMANGLE @@ -858,8 +860,8 @@ } EOF COMM="$CC $CFLAGS -c genmake_tc_1.c" - echo $COMM >> genmake_warnings - $COMM >> genmake_warnings 2>&1 + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -867,22 +869,22 @@ call setrlstk() end EOF - echo >> genmake_warnings - echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings - cat genmake_tc_2.$FS >> genmake_warnings + cat genmake_tc_2.$FS >> $LOGFILE COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" - echo $COMM >> genmake_warnings - $COMM >> genmake_warnings 2>&1 + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_SETRLSTK=t DEFINES="$DEFINES -DHAVE_SETRLSTK" fi rm -f genmake_tc* + echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE } - check_HAVE_STAT() { + echo >> $LOGFILE + echo "running: check_HAVE_STAT()" >> $LOGFILE get_fortran_c_namemangling cat < genmake_tc_1.c $FC_NAMEMANGLE @@ -904,7 +906,7 @@ } EOF COMM="$CC $CFLAGS -c genmake_tc_1.c" - echo $COMM >> genmake_warnings + echo $COMM >> $LOGFILE $COMM >> genmake_tc.log 2>&1 RET_C=$? cat < genmake_tc_2.$FS @@ -914,11 +916,9 @@ print *," HELLO WORLD", nbyte end EOF - echo >> genmake_warnings - echo "running: check_HAVE_STAT()" >> genmake_warnings - cat genmake_tc_2.$FS >> genmake_warnings + cat genmake_tc_2.$FS >> $LOGFILE COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" - echo $COMM >> genmake_warnings + echo $COMM >> $LOGFILE $COMM >> genmake_tc.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then @@ -926,15 +926,15 @@ DEFINES="$DEFINES -DHAVE_STAT" fi rm -f genmake_tc* + echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE } - check_netcdf_libs() { if test ! "x$SKIP_NETCDF_CHECK" = x ; then return fi - echo >> genmake_warnings - echo "running: check_netcdf_libs()" >> genmake_warnings + echo >> $LOGFILE + echo "running: check_netcdf_libs()" >> $LOGFILE cat < genmake_tnc.F program fgennc #include "netcdf.inc" @@ -952,9 +952,9 @@ IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) end EOF - echo "=== 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 + echo "<<< genmake_tnc.F ===" >> genmake_tnc.log RET_CPP=f COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES" echo "$COMM" >> genmake_tnc.log @@ -970,7 +970,7 @@ $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \ && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1 RET_COMPILE=$? - cat genmake_tnc.log >> genmake_warnings + cat genmake_tnc.log >> $LOGFILE #EH3 Remove test program execution for machines that either disallow #EH3 execution or cannot support it (eg. cross-compilers) @@ -981,9 +981,10 @@ if test "x$RET_COMPILE" = x0 ; then HAVE_NETCDF=t + echo "check_netcdf: successful" >> $LOGFILE else # try again with "-lnetcdf" added to the libs - echo "try again with added '-lnetcdf'" > genmake_tnc.log + echo "==> try again with added '-lnetcdf'" > genmake_tnc.log echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log @@ -991,13 +992,15 @@ && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \ && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1 RET_COMPILE=$? - cat genmake_tnc.log >> genmake_warnings + echo >> $LOGFILE + cat genmake_tnc.log >> $LOGFILE if test "x$RET_COMPILE" = x0 ; then LIBS="$LIBS -lnetcdf" HAVE_NETCDF=t + echo "check_netcdf: successful" >> $LOGFILE else # try again with "-lnetcdff" added to the libs - echo "try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log + echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log @@ -1005,18 +1008,20 @@ && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \ && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1 RET_COMPILE=$? - cat genmake_tnc.log >> genmake_warnings + echo >> $LOGFILE + cat genmake_tnc.log >> $LOGFILE if test "x$RET_COMPILE" = x0 ; then LIBS="$LIBS -lnetcdff -lnetcdf" HAVE_NETCDF=t + echo "check_netcdf: successful" >> $LOGFILE fi fi fi rm -f genmake_tnc* + echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE } - ############################################################################### # Sequential part of script starts here ############################################################################### @@ -1038,9 +1043,9 @@ DISABLE= # MAKEFILE= # MAKEDEPEND= -PDEPEND= -DUMPSTATE=t -PDEFAULT= +PKG_DEPEND= +PKG_GROUPS= +DUMPSTATE=f OPTFILE= INCLUDES="-I. $INCLUDES" FFLAGS= @@ -1048,6 +1053,7 @@ FEXTRAFLAGS= USE_EXTENDED_SRC= EXTENDED_SRC_FLAG= +GET_FC_VERSION= CFLAGS= KFLAGS1= KFLAGS2= @@ -1058,6 +1064,9 @@ NOOPTFLAGS= MPI= MPIPATH= +OMP= +OMPFLAG= +USE_R4= TS= PAPIS= PCLS= @@ -1122,17 +1131,16 @@ 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" -gm_s2="FC CPP IEEE TS PAPIS PCLS PAPI PCL HPMT GSL DEVEL MPI JAM DUMPSTATE STANDARDDIRS" +gm_s1="OPTFILE PKG_DEPEND PKG_GROUPS MAKEFILE MAKEDEPEND PLATFORM ROOTDIR MODS DISABLE ENABLE" +gm_s2="FC CC IEEE USE_R4 TS PAPIS PCLS PAPI PCL HPMT GSL DEVEL MPI OMP 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 FEXTRAFLAGS" -gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS" -gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE" +gm_s3="LN S64 LINK MAKE PACKAGES INCLUDES FFLAGS FOPTIM FEXTRAFLAGS" +gm_s4="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS" +gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD THISHOST THISUSER THISDATE THISVER MACHINE" gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF" -gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME" +gm_s7="FC_NAMEMANGLE HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE 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" @@ -1146,13 +1154,17 @@ GENMAKE : -A program for GENerating MAKEfiles for the MITgcm project. For a -quick list of options, use "genmake -h" or for more detail see: - - http://mitgcm.org/devel_HOWTO/ +A program for GENerating MAKEfiles for the MITgcm project. + For a quick list of options, use "genmake2 -h" +or for more detail see the Developer's HOWTO manual at: + http://mitgcm.org/public/docs.html EOF +LOGFILE="genmake.log" +#- clean-up previous genmake logfiles: +rm -f genmake_state genmake_*optfile $LOGFILE + echo "=== Processing options files and arguments ===" gm_local="genmake_local" printf " getting local config information: " @@ -1166,15 +1178,6 @@ fi #echo "$0::$1:$2:$3:$4:$5:$6:$7:" -#OPTIONS= -#n=0 -#for i ; do -# echo "$i $n" -# setvar="OPTIONS[$n]='$i'" -# # echo " $setvar" -# eval "$setvar" -# n=$(( $n + 1 )) -#done #parse_options ac_prev= for ac_option in "$@" ; do @@ -1187,9 +1190,9 @@ ac_prev= continue fi - + ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` - + case $ac_option in -help | --help | -h | --h) @@ -1208,14 +1211,14 @@ AD_OPTFILE=$ac_optarg ;; -pdepend | --pdepend) - ac_prev=PDEPEND ;; + ac_prev=PKG_DEPEND ;; -pdepend=* | --pdepend=*) - PDEPEND=$ac_optarg ;; + PKG_DEPEND=$ac_optarg ;; - -pdefault | --pdefault) - ac_prev=PDEFAULT ;; - -pdefault=* | --pdefault=*) - PDEFAULT=$ac_optarg ;; + -pgroups | --pgroups) + ac_prev=PKG_GROUPS ;; + -pgroups=* | --pgroups=*) + PKG_GROUPS=$ac_optarg ;; -make | --make | -m | --m) ac_prev=MAKE ;; @@ -1299,6 +1302,9 @@ -noieee | --noieee) IEEE= ;; + -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 ) + USE_R4=true ;; + -ts | --ts) TS=true ;; -papis | --papis) @@ -1326,10 +1332,11 @@ MPIPATH=$ac_optarg MPI=true ;; -# -jam | --jam) -# JAM=1 ;; -# -nojam | --nojam) -# JAM=0 ;; + -omp | --omp) + OMP=true ;; + -omp=* | --omp=*) + OMPFLAG=$ac_optarg + OMP=true ;; -ds | --ds) DUMPSTATE=t ;; @@ -1361,9 +1368,8 @@ ;; esac - -done +done if test -f ./.genmakerc ; then echo @@ -1373,7 +1379,7 @@ echo " http://mitgcm.org/devel_HOWTO/" echo " and send an email to MITgcm-support@mitgcm.org if you need help." echo "WARNING: ignore \"./.genmakerc\" and continue." - echo + echo fi # Find the MITgcm ${ROOTDIR} @@ -1406,7 +1412,7 @@ # Find the MITgcm ${THISVER} version_file="${ROOTDIR}/doc/tag-index" if test -f $version_file ; then - THISVER=`grep '^checkpoint' $version_file | head -1` + THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file` #- remove ./BUILD_INFO.h file if older than version_file if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then echo " remove ./BUILD_INFO.h (older than ${version_file})" @@ -1423,7 +1429,7 @@ if test "x$MITGCM_OF" = x ; then echo "Warning: no OPTFILE specified so we'll look for possible settings" printf "\n=== Searching for possible settings for OPTFILE ===\n" - find_possible_configs + find_possible_optfile else OPTFILE=$MITGCM_OF fi @@ -1438,7 +1444,7 @@ echo "--please check that variable syntax is bash-compatible" exit 1 fi - if test "x$DUMPSTATE" != xf ; then + if test "x$DUMPSTATE" = xt ; then cp -f $OPTFILE "genmake_optfile" fi else @@ -1465,7 +1471,7 @@ echo "--please check that variable syntax is bash-compatible" exit 1 fi - if test "x$DUMPSTATE" != xf ; then + if test "x$DUMPSTATE" = xt ; then cp -f $AD_OPTFILE "genmake_ad_optfile" fi else @@ -1493,16 +1499,16 @@ EOF exit 1 fi +if test "x$GET_FC_VERSION" != x ; then + echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE + $FC $GET_FC_VERSION >> $LOGFILE 2>&1 + echo "--- compiler version ----" >> $LOGFILE +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 + look_for_C_compilers fi + if test "x$LINK" = x ; then LINK=$FC fi @@ -1510,7 +1516,7 @@ MAKE="make" fi if test "x$CPP" = x ; then - CPP=cpp + CPP="cpp -traditional -P" fi #EH3 === UGLY === # The following is an ugly little hack to check for $CPP in /lib/ and @@ -1537,7 +1543,10 @@ else rm -f test_cpp fi + look_for_makedepend + +# Check that soft-link command is set and usable if test "x$LN" = x ; then LN="ln -s" fi @@ -1547,7 +1556,7 @@ if test "x$RETVAL" != x0 ; then cat <&2 -Error: The command "ln -s" failed -- please specify a working soft-link +Error: The command "$LN" failed -- please specify a working soft-link command in the optfile. EOF @@ -1567,6 +1576,17 @@ echo " Turning on MPI cpp macros" DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI" fi +if test ! "x$OMP" = x ; then + echo " Add OMPFLAG and turn on OpenMP cpp macros" + FFLAGS="$FFLAGS $OMPFLAG" + F90FLAGS="$F90FLAGS $OMPFLAG" + DEFINES="$DEFINES -DUSE_OMP_THREADING" +fi + +if test ! "x$USE_R4" = x ; then + echo " Turning on LET_RS_BE_REAL4 cpp flag" + DEFINES="$DEFINES -DLET_RS_BE_REAL4" +fi if test ! "x$TS" = x ; then echo " Turning on timing per timestep" @@ -1773,25 +1793,24 @@ ENABLE="$ENABLE embed_files" fi - printf "\n=== Setting defaults ===\n" -printf " 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 - printf " $d" + printf "$d " SOURCEDIRS="$SOURCEDIRS $d" INCLUDEDIRS="$INCLUDEDIRS $d" fi done echo -if test "x${PLATFORM}" = x ; then - PLATFORM=$p_PLATFORM -fi +#if test "x${PLATFORM}" = x ; then +# PLATFORM=$p_PLATFORM +#fi if test "x${EXEDIR}" = x ; then tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'` @@ -1831,7 +1850,7 @@ ${TOOLSDIR}/set64bitConst.sh ${TOOLSDIR}/set64bitConst.csh - are working so please check paths or specify (with \$S64) a + are working so please check paths or specify (with \$S64) a working version of this script. EOF @@ -1843,12 +1862,26 @@ EXECUTABLE=${EXECUTABLE:-mitgcmuv} +# Set Standard Code Directories: +if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then + STANDARDDIRS="eesupp model" +fi +# if model in Standard-Code-Dir, add eesupp (needed to compile model) +echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1 +ckM=$? +echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1 +ckE=$? +if test $ckM = 0 -a $ckE = 1 ; then + STANDARDDIRS="$STANDARDDIRS eesupp" +fi + # We have a special set of source files in eesupp/src which are # generated from some template source files. We'll make them first so # they appear as regular source code if test -r $ROOTDIR"/eesupp/src/Makefile" ; then echo " Making source files in eesupp from templates" - ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1 + ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \ + ) > make_eesupp.errors 2>&1 RETVAL=$? if test "x${RETVAL}" = x0 ; then rm -f make_eesupp.errors @@ -1863,7 +1896,8 @@ for pdir in exch2 regrid ; do if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then echo " Making source files in pkg/${pdir} from templates" - ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE ) > make_${pdir}.errors 2>&1 + ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \ + ) > make_${pdir}.errors 2>&1 RETVAL=$? if test "x${RETVAL}" = x0 ; then rm -f make_${pdir}.errors @@ -1876,75 +1910,86 @@ done printf "\n=== Determining package settings ===\n" -if test "x${PDEPEND}" = x ; then +if test "x${PKG_DEPEND}" = x ; then tmp=$ROOTDIR"/pkg/pkg_depend" - if test -r $tmp ; then - PDEPEND=$tmp - else + if test -r $tmp ; then PKG_DEPEND=$tmp ; fi +fi +if test "x${PKG_DEPEND}" = x ; then echo "Warning: No package dependency information was specified." echo " Please check that ROOTDIR/pkg/pkg_depend exists." - fi else - if test ! -r ${PDEPEND} ; then - echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\"" + if test ! -r ${PKG_DEPEND} ; then + echo "Error: can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\"" exit 1 fi + echo " getting package dependency info from $PKG_DEPEND" +# Strip the comments and then convert the dependency file into arrays: PNAME, DNAME + get_pdepend_list $PKG_DEPEND fi -echo " getting package dependency info from $PDEPEND" -# 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}' \ - > ./.pd_tmp -RETVAL=$? -if test ! "x${RETVAL}" = x0 ; then - echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\"" - exit 1 + +# A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided +# to define the "default_pkg_list" and package groups (for convenience, one +# can specify a group of packages using names like "ocean" and "atmosphere"). +if test "x${PKG_GROUPS}" = x ; then + tmp=$ROOTDIR"/pkg/pkg_groups" + if test -r $tmp ; then PKG_GROUPS=$tmp ; fi +fi +if test "x${PKG_GROUPS}" = x ; then + echo "Warning: No package groups information was specified." + echo " Please check that ROOTDIR/pkg/pkg_groups exists." +else + if test ! -r ${PKG_GROUPS} ; then + echo "Error: can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\"" + exit 1 + fi + echo " getting package groups info from $PKG_GROUPS" fi -. ./.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 " checking default package list: " -if test "x${PDEFAULT}" = x ; then +# Search for packages to compile. +echo " checking list of packages to compile:" +PKG_LIST= +if test "x${PKG_LIST}" = x ; then for i in "." $MODS ; do if test -r $i"/packages.conf" ; then - PDEFAULT=$i"/packages.conf" + PKG_LIST=$i"/packages.conf" break fi done fi -if test "x${PDEFAULT}" = x ; then - PDEFAULT="$ROOTDIR/pkg/pkg_default" -fi -if test "x${PDEFAULT}" = xNONE ; then - echo " default packages file disabled" +if test "x${PKG_LIST}" = x ; then + pkg_list='default_pkg_list' + if test "x${PKG_GROUPS}" = x ; then + echo "Error: need package groups info to expand pkg_list=\"$pkg_list\"" + exit 1 + fi else - if test ! -r $PDEFAULT ; then - echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\"" + if test ! -r $PKG_LIST ; then + echo "Error: can't read package list from PKG_LIST=\"$PKG_LIST\"" + exit 1 else - echo " using PDEFAULT=\"$PDEFAULT\"" + echo " using PKG_LIST=\"$PKG_LIST\"" # Strip the comments and add all the names - def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'` + pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'` RETVAL=$? if test "x${RETVAL}" != x0 ; then - printf "Error: can't parse default package list " - echo "-- please check PDEFAULT=\"$PDEFAULT\"" + printf "Error: can't parse package list " + echo "-- please check PKG_LIST=\"$PKG_LIST\"" exit 1 fi - for i in $def ; do - PACKAGES="$PACKAGES $i" - done - echo " before group expansion packages are: $PACKAGES" - RET=1 - while test $RET = 1 ; do expand_pkg_groups; RET=$?; done - echo " after group expansion packages are: $PACKAGES" fi fi +for i in $pkg_list ; do + PACKAGES="$PACKAGES $i" +done +echo " before group expansion packages are:$PACKAGES" +if test "x${PKG_GROUPS}" != x ; then + RET=1 + while test $RET = 1 ; do expand_pkg_groups; RET=$?; done + echo " after group expansion packages are: $PACKAGES" +fi echo " applying DISABLE settings" +echo "" > ./.tmp_pack for i in $PACKAGES ; do echo $i >> ./.tmp_pack done @@ -1972,7 +2017,7 @@ for i in $PACKAGES ; do j=`echo $i | sed 's/[-+]//'` if test ! -d "$ROOTDIR/pkg/$j" ; then - echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\"" + echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'" exit 1 fi echo $i >> ./.tmp_pack @@ -1982,71 +2027,79 @@ PACKAGES="$PACKAGES $i" done rm -f ./.tmp_pack -echo " packages are: $PACKAGES" +echo " packages are: $PACKAGES" -# Check for package MNC: if NetCDF is available, then build the MNC +# Check for package MNC: if NetCDF is available, then build the MNC # template files ; otherwise, delete mnc from the list of packages. -echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1 -RETVAL=$? -if test "x$RETVAL" = x0 ; then - if test "x$HAVE_NETCDF" != xt ; then +echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1 +mnc_in=$? +if test "x$HAVE_NETCDF" != xt ; then + if test "x$mnc_in" = x0 ; then cat < make_mnc.errors 2>&1 - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - rm -f make_mnc.errors + # this prevent to add mnc (due to pdepend rules) if not available + DISABLE="$DISABLE mnc" + fi +else + # we have NetCDF, we try to build MNC template files + ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $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 + if test "x$mnc_in" = x0 ; then + exit 1 else - echo "Error: problem encountered while building source files in pkg/mnc:" - cat make_mnc.errors 1>&2 - exit 1 + DISABLE="$DISABLE mnc" fi fi fi # Check for package PROFILES: if NetCDF is not available, # then delete profiles from the list of available packages. -echo $PACKAGES | grep ' profiles ' > /dev/null 2>&1 -RETVAL=$? -if test "x$RETVAL" = x0 ; then - if test "x$HAVE_NETCDF" != xt ; then +if test "x$HAVE_NETCDF" != xt ; then + echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" = x0 ; then cat </dev/null )` for j in $list_files ; do @@ -2265,7 +2321,7 @@ 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 @@ -2300,7 +2356,7 @@ fi rm -f .links.tmp/foo -if test "x$OPENAD" != x ; then +if test "x$OPENAD" != x ; then OAD_DONT_COMPILE="/dev/null" OAD_DONT_TRANSFORM="/dev/null" OAD_KEEP_ORIGINAL="/dev/null" @@ -2353,7 +2409,7 @@ deplist= sfiles=`( cd $d; echo *.[h,c,F] *.flow )` sfiles=`( echo $sfiles; cd $d; echo *.F90 )` - if test "x$OPENAD" != x ; then + if test "x$OPENAD" != x ; then sfiles=`( echo $sfiles | grep -v _cb2m\. )` fi for sf in $sfiles ; do @@ -2393,27 +2449,27 @@ F) echo " \\" >> F77srclist.tmp printf " $sf" >> F77srclist.tmp - if test "x$OPENAD" != x ; then + if test "x$OPENAD" != x ; then basename=${sf%%.F} isAD=`egrep ^$basename.f'[ ]*' adSrcFiles.tmp` - if test -z "$isAD" ; then + if test -z "$isAD" ; then toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE}` - if test -z "$toBeIgnored" ; then + if test -z "$toBeIgnored" ; then echo " \\" >> nonADF77srclist.tmp printf " $sf" >> nonADF77srclist.tmp - else + else echo " not to be compiled : $sf" fi - else # file is initially listed as an AD file we want to exclude it + else # file is initially listed as an AD file we want to exclude it # or we want to retain the untransformed version notToBeTransformed=`egrep ^$basename'[ ]*' ${OAD_DONT_TRANSFORM}` untransformedVersionToBeKept=`egrep ^$basename'[ ]*' ${OAD_KEEP_ORIGINAL}` - if test -n "$notToBeTransformed"; then + if test -n "$notToBeTransformed"; then echo " not to be transformed: $sf" fi if test -n "$untransformedVersionToBeKept" ; then echo " original to be kept : $sf" - fi + fi if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then echo " \\" >> nonADF77srclist.tmp printf " $sf" >> nonADF77srclist.tmp @@ -2462,8 +2518,14 @@ echo "" >> hsrclist.tmp echo "" >> ad_flow_files.tmp +CMDLINE=$0 +for xx in "$@" ; do nw=`echo $xx | wc -w` + if test $nw = '1' ; then CMDLINE="$CMDLINE $xx" + else CMDLINE="$CMDLINE '$xx'" ; fi +done + if test -f $MAKEFILE ; then - mv -f $MAKEFILE "$MAKEFILE.bak" + mv -f $MAKEFILE "$MAKEFILE.old" fi echo " Writing makefile: $MAKEFILE" echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE @@ -2471,7 +2533,7 @@ echo "# This makefile was generated automatically on" >> $MAKEFILE echo "# $THISDATE" >> $MAKEFILE echo "# by the command:" >> $MAKEFILE -echo "# $0 $G2ARGS" >> $MAKEFILE +echo "# $CMDLINE" >> $MAKEFILE echo "# executed by:" >> $MAKEFILE echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE @@ -2482,7 +2544,7 @@ cat >>$MAKEFILE < \$@ .$FS.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< +.F.o: + \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< .F90.$FS90: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .FF90.f$FS90: @@ -2727,7 +2796,7 @@ #=== Automatic Differentiation Rules === #=== for TAMC/TAF ====================== -if test "x$OPENAD" == x ; then +if test "x$OPENAD" = x ; then 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 \$(F77_PP_SRC_FILES) @make \$(FLOFILES) - cat \$(FLOFILES) \$(AD_FILES) > ad_input_code.$FS + cat \$(FLOFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS ad_taf_output.$FS: ad_input_code.$FS \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS @@ -2787,18 +2856,18 @@ cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS \${EXE_AD}: ad_taf_output.o \$(OBJFILES) - \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) + \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) 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) + \$(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 @@ -2826,15 +2895,14 @@ 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) + \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS) 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) - + \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS) # ... SVD ... svdtaf: ad_taf_output.$FS ftl_taf_output.$FS @@ -2862,17 +2930,17 @@ EOF -fi +fi #=== for OpenAD ======================== -if test "x$OPENAD" != x ; then +if test "x$OPENAD" != x ; then # ============ begin OpenAD specific section ============== cat >>$MAKEFILE <>$MAKEFILE < \$@ -f95_test.f90: all_mods.xb.x2w.w2f.pp.f$FS90 \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90) ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90 +f95_test.f90: all_mods.xb.x2w.w2f.pp.f$FS90 \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90) ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90 cat \$^ > \$@ f95_test.out: f95_test_mods.f90 f95_test.f90 f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1 f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1 -AD_OBJ_FILES=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) all_mods.xb.x2w.w2f.pp.o ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.o \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o) +# the file included below is created by the +# postProcessor and its inclusion sets the +# variable POSTPROCESSEDFILES +# used below. Because the file is made during +# make it won't be read until the second (recursive) +# invocation in the rule below +-include postProcess.make + +AD_OBJ_FILES_S1=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) \$(POSTPROCESSEDFILES:.f$FS90=.o) + +AD_OBJ_FILES_S2=\$(AD_OBJ_FILES_S1) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o) + +postProcess.comp: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S1) +ifeq (\$(MAKELEVEL),0) + \$(MAKE) adAll +else + touch \$@ +endif -\$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(AD_OBJ_FILES) - @echo Creating \$@ ... - \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES) \$(LIBS) +\$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.comp \$(AD_OBJ_FILES_S2) +ifeq (\$(MAKELEVEL),1) + \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS) +else + touch \$@ +endif # makefile debug rule openad: ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90 .PHONY: openad -# create the module files -%_mod.FF90 : %.h ../OAD_support/cb2mGetModules.csh ../OAD_support/cb2mGetModules.awk +# create the module files +%_mod.FF90 : %.h ../OAD_support/cb2mGetModules.csh ../OAD_support/cb2mGetModules.awk ../OAD_support/cb2mGetModules.csh $< ../OAD_support/cb2mGetModules.awk -# create the header files -%_mod.h : %.h ../OAD_support/cb2mGetHeaders.csh ../OAD_support/cb2mGetHeaders.awk +# create the header files +%_mod.h : %.h ../OAD_support/cb2mGetHeaders.csh ../OAD_support/cb2mGetHeaders.awk ../OAD_support/cb2mGetHeaders.csh $< ../OAD_support/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES) # change everybody else to use the new module files: @@ -2992,33 +3080,33 @@ @./\$(EXE_AD) > \$@ CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90) -ad_input_code.f$FS90: ../OAD_support/maxMinDefs.f \$(CB2M_AD_FILES) +ad_input_code.f$FS90: \$(CB2M_AD_FILES) cat \$^ > \$@ -# strip all comments and blanks to reduce -# the file size in order to reduce perl's memory requirements -ad_input_code_sf.f$FS90 : ad_input_code.f$FS90 +# strip all comments and blanks to reduce +# the file size in order to reduce perl's memory requirements +ad_input_code_sf.f$FS90 : ad_input_code.f$FS90 cat \$^ | sed -f ../OAD_support/strip.sed | sed -f ../OAD_support/stop2print.sed > \$@ # mfef90 preprocessing -# expand statement functions -# expose mfef90 specific substring handling +# expand statement functions +# expose mfef90 specific substring handling # add the w2f__types module ad_input_code_sf.w2f.f$FS90: ad_input_code_sf.f$FS90 mfef90 whirl2f whirl2f_be w2f__types.f90 - ./mfef90 -r8 -z -F -N132 \$< - mv \$<.B \$(basename \$<).B + ./mfef90 -r8 -z -F -N132 \$< + mv \$<.B \$(basename \$<).B ./whirl2f -openad \$(basename \$<).B cat w2f__types.f90 \$(basename \$<).w2f.f > \$@ # canonicalizer ad_input_code_sf.w2f.pre.f$FS90: ad_input_code_sf.w2f.f$FS90 preProcess.py - ./preProcess.py -H -S \$< -o \$@ + ./preProcess.py --timing --r8 -H -S \$< -o \$@ # F -> WHIRL -# note that the canonicalized version cuts off at col 72 -# doing this also for string constants which is ok as long -# as we are in fixed mode and cut of exactly there. -# Otherwise mfef90 patches in spaces to fill up to 72 (or 132) +# note that the canonicalized version cuts off at col 72 +# doing this also for string constants which is ok as long +# as we are in fixed mode and cut of exactly there. +# Otherwise mfef90 patches in spaces to fill up to 72 (or 132) # characters respectively. ad_input_code_sf.w2f.pre.B: ad_input_code_sf.w2f.pre.f$FS90 mfef90 ./mfef90 -r8 -z -F \$< @@ -3034,11 +3122,11 @@ # XAIF' -> WHIRL' ad_input_code_sf.w2f.pre.xb.x2w.B : ad_input_code_sf.w2f.pre.xb.xaif xaif2whirl - ./xaif2whirl --debug 1 --structured ad_input_code_sf.w2f.pre.B \$< + ./xaif2whirl --debug 1 ad_input_code_sf.w2f.pre.B \$< # WHIRL' -> F' ad_input_code_sf.w2f.pre.xb.x2w.w2f.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.B whirl2f whirl2f_be - ./whirl2f -FLIST:ftn_file=\$@ -openad \$< + ./whirl2f -FLIST:ftn_file=\$@ -openad \$< # insert template directives ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.f$FS90 ../OAD_support/insertTemplateDir.bash @@ -3046,40 +3134,29 @@ PPEXTRAS=\$(wildcard ../OAD_support/ad_template.*.F) ../OAD_support/ad_inline.F # postprocess F' -ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.pp.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90 multi-pp.pl \$(PPEXTRAS:.F=.f) - perl multi-pp.pl -inline=../OAD_support/ad_inline.f \$< - # the postprocessor still gets the name wrong - cat \$<.pp | sed 's/RETURN//' > \$@ - -# extract all transformed modules -all_mods.xb.x2w.w2f.pp.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.pp.f$FS90 - cat \$< | sed -n '/MODULE /,/END MODULE/p' > \$@ - -# remove the transformed globals module from the -# transformed ad_input_code file -# and remove for now the duplicate variables -# and fix 2 data statements -ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.pp.f$FS90 - cat \$< | sed '/MODULE /,/END MODULE/d' | sed '/^ INTEGER(w2f__i4) DOLOOP_UB/d' > \$@ +postProcess.tag: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90 postProcess.py \$(PPEXTRAS:.F=.f) + # the target is a placeholder to signal execution of the rule + touch \$@ + # this step also creates the file postProcess.make but we cannot + # name it as the target or else make will try to remake it for + # the include directive above for any rule, e.g. make clean + ./postProcess.py --progress --timing --outputFormat=fixed -m r -i ../OAD_support/ad_inline.f --width 4 \$< # setup some links %.xsd: \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ . -mfef90: +mfef90: \$(LN) \${OPEN64ROOT}/crayf90/sgi/mfef90 . # link the support files: -\$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES): +\$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES): \$(LN) ../OAD_support/\$@ . -whirl2xaif xaif2whirl: - \$(LN) \${OPENADFORTTK}/bin/\$@ . - -%.pl: +whirl2xaif xaif2whirl: \$(LN) \${OPENADFORTTK}/bin/\$@ . -preProcess.py: +preProcess.py postProcess.py: \$(LN) \${OPENADFORTTK_BASE}/tools/SourceProcessing/\$@ . whirl2f whirl2f_be: @@ -3088,6 +3165,8 @@ oadDriver: \$(LN) \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver \$@ +AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.make postProcess.tag postProcess.comp \$(PPEXTRAS:.F=.f) + # ============ end OpenAD specific section ============== EOF @@ -3131,7 +3210,7 @@ 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" +$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 @@ -3148,9 +3227,8 @@ $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 +if test "x$DUMPSTATE" = xt ; then printf "" > genmake_state for i in $gm_state ; do t1="t2=\$$i"