--- MITgcm/tools/genmake2 2012/01/17 22:55:39 1.228 +++ MITgcm/tools/genmake2 2014/01/25 18:25:49 1.264 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.228 2012/01/17 22:55:39 jmc Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.264 2014/01/25 18:25:49 jmc Exp $ # $Name: $ # # Makefile generator for MITgcm UV codes @@ -17,139 +17,143 @@ where [OPTIONS] can be: -help | --help | -h | --h - Print this help message and exit. + Print this help message and exit. + + -oad | --oad + Generate a Makefile for an OpenAD built -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME - Use "NAME" as the adoptfile. By default, the file at - "tools/adjoint_options/adjoint_default" will be used. + Use "NAME" as the adoptfile. By default, the file at + "tools/adjoint_options/adjoint_oad" (for OpenAD built) or + "tools/adjoint_options/adjoint_default" will be used. -nooptfile | --nooptfile -optfile NAME | --optfile NAME | -of NAME | --of NAME -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME - Use "NAME" as the optfile. By default, an attempt will be - made to find an appropriate "standard" optfile in the - tools/build_options/ directory. + Use "NAME" as the optfile. By default, an attempt will be + made to find an appropriate "standard" optfile in the + tools/build_options/ directory. -pdepend NAME | --pdepend NAME -pdepend=NAME | --pdepend=NAME - Get package dependency information from "NAME". + Get package dependency information from "NAME". -pgroups NAME | --pgroups NAME -pgroups=NAME | --pgroups=NAME - Get the package groups information from "NAME". + Get the package groups information from "NAME". -bash NAME - Explicitly specify the Bourne or BASH shell to use + Explicitly specify the Bourne or BASH shell to use -make NAME | -m NAME --make=NAME | -m=NAME - Use "NAME" for the MAKE program. The default is "make" but - many platforms, "gmake" is the preferred choice. + Use "NAME" for the MAKE program. The default is "make" but + many platforms, "gmake" is the preferred choice. -makefile NAME | -mf NAME --makefile=NAME | -mf=NAME - Call the makefile "NAME". The default is "Makefile". + Call the makefile "NAME". The default is "Makefile". -makedepend NAME | -md NAME --makedepend=NAME | -md=NAME - Use "NAME" for the MAKEDEPEND program. + Use "NAME" for the MAKEDEPEND program. -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME - Specify the location of the MITgcm ROOTDIR as "NAME". - By default, genamke will try to find the location by - looking in parent directories (up to the 5th parent). + Specify the location of the MITgcm ROOTDIR as "NAME". + By default, genamke will try to find the location by + looking in parent directories (up to the 5th parent). -mods NAME | --mods NAME | -mo NAME | --mo NAME -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME - Here, "NAME" specifies a list of directories that are - used for additional source code. Files found in the - "mods list" are given preference over files of the same - name found elsewhere. + Here, "NAME" specifies a list of directories that are + used for additional source code. Files found in the + "mods list" are given preference over files of the same + name found elsewhere. -disable NAME | --disable NAME -disable=NAME | --disable=NAME - Here "NAME" specifies a list of packages that we don't - want to use. If this violates package dependencies, - genamke will exit with an error message. + Here "NAME" specifies a list of packages that we don't + want to use. If this violates package dependencies, + genamke will exit with an error message. -enable NAME | --enable NAME -enable=NAME | --enable=NAME - Here "NAME" specifies a list of packages that we wish - to specifically enable. If this violates package - dependencies, genamke will exit with an error message. + Here "NAME" specifies a list of packages that we wish + to specifically enable. If this violates package + dependencies, genamke will exit with an error message. -standarddirs NAME | --standarddirs NAME -standarddirs=NAME | --standarddirs=NAME - Here, "NAME" specifies a list of directories to be - used as the "standard" code. + Here, "NAME" specifies a list of directories to be + used as the "standard" code. -fortran NAME | --fortran NAME | -fc NAME | --fc NAME -fc=NAME | --fc=NAME - Use "NAME" as the fortran compiler. By default, genmake - will search for a working compiler by trying a list of - "usual suspects" such as g77, f77, etc. + Use "NAME" as the fortran compiler. By default, genmake + will search for a working compiler by trying a list of + "usual suspects" such as g77, f77, etc. -cc NAME | --cc NAME | -cc=NAME | --cc=NAME - Use "NAME" as the C compiler. By default, genmake - will search for a working compiler by trying a list of - "usual suspects" such as gcc, c89, cc, etc. + Use "NAME" as the C compiler. By default, genmake + will search for a working compiler by trying a list of + "usual suspects" such as gcc, c89, cc, etc. -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 - Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW) - *only* works if CPP_EEOPTIONS.h allows this. + Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW) + *only* works if CPP_EEOPTIONS.h allows this. -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. + 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 + Produce timing information per timestep -papis | --papis - Produce summary MFlop/s (and IPC) with PAPI per timestep + Produce summary MFlop/s (and IPC) with PAPI per timestep -pcls | --pcls - Produce summary MFlop/s etc. with PCL per timestep + Produce summary MFlop/s etc. with PCL per timestep -foolad | --foolad - Fool the AD code generator + Fool the AD code generator -papi | --papi - Performance analysis with PAPI + Performance analysis with PAPI -pcl | --pcl - Performance analysis with PCL + Performance analysis with PCL -hpmt | --hpmt - Performance analysis with the HPM Toolkit + Performance analysis with the HPM Toolkit -ieee | --ieee - use IEEE numerics. Note that this option *only* works - if it is supported by the OPTFILE that is being used. + use IEEE numerics. Note that this option *only* works + if it is supported by the OPTFILE that is being used. -devel | --devel - Add additional warning and debugging flags for development - (if supported by the OPTFILE); also switch to IEEE numerics. + Add additional warning and debugging flags for development + (if supported by the OPTFILE); also switch to IEEE numerics. -gsl | --gsl - Use GSL to control floating point rounding and precision + Use GSL to control floating point rounding and precision -mpi | --mpi - Include MPI header files and link to MPI libraries + Include MPI header files and link to MPI libraries -mpi=PATH | --mpi=PATH - Include MPI header files and link to MPI libraries using MPI_ROOT - set to PATH. i.e. Include files from \$PATH/include, link to libraries - from \$PATH/lib and use binaries from \$PATH/bin. + Include MPI header files and link to MPI libraries using MPI_ROOT + set to PATH. i.e. Include files from \$PATH/include, link to libraries + from \$PATH/lib and use binaries from \$PATH/bin. -omp | --omp - Activate OpenMP code + use Compiler option OMPFLAG + Activate OpenMP code + use Compiler option OMPFLAG -omp=OMPFLAG | --omp=OMPFLAG - Activate OpenMP code + use Compiler option OMPFLAG + Activate OpenMP code + use Compiler option OMPFLAG -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] + Embed a tarball containing the full source code + (including the Makefile, etc.) used to build the + executable [off by default] -ds | --ds - Report genmake internal variables status (DUMPSTATE) - to file "genmake_state" (for debug purpose) + Report genmake internal variables status (DUMPSTATE) + to file "genmake_state" (for debug purpose) While it is most often a single word, the "NAME" variables specified above can in many cases be a space-delimited string such as: @@ -174,28 +178,18 @@ test_for_package_in_cpp_options() { cpp_options=$1 pkg=$2 - 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$" + test_for_string_in_file $cpp_options "^ *# *define *\" + test_for_string_in_file $cpp_options "^ *# *undef *\" + test_for_string_in_file $cpp_options "^ *# *define *\" + test_for_string_in_file $cpp_options "^ *# *undef *\" } # 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[ ]" - 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$" + test_for_string_in_file $cpp_options "^ *# *define *\" + test_for_string_in_file $cpp_options "^ *# *undef *\" } # Search for particular string in a file. Return 1 if detected, 0 if not @@ -203,11 +197,11 @@ test_for_string_in_file() { file=$1 strng=$2 - grep -i "$strng" $file > /dev/null 2>&1 + grep "$strng" $file > /dev/null 2>&1 RETVAL=$? if test "x${RETVAL}" = x0 ; then printf "Error: In $file there is an illegal line: " - grep -i "$strng" $file + grep -i "$strng" $file exit 99 fi return 0 @@ -218,11 +212,11 @@ expand_pkg_groups() { new_packages= if test -r $PKG_GROUPS ; then - cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp - cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp + cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > $TMP.p1 + cat $TMP.p1 | $AWK '(NF>2 && $2==":"){ print $0 }' > $TMP.p2 matched=0 for i in $PACKAGES ; do - line=`grep "^ *$i" ./p2.tmp` + line=`grep "^ *$i" $TMP.p2` RETVAL=$? if test "x$RETVAL" = x0 ; then matched=1 @@ -234,7 +228,7 @@ fi done PACKAGES=$new_packages - rm -f ./p[1,2].tmp + rm -f $TMP.p[1,2] return $matched else echo "Warning: can't read package groups definition file: $PKG_GROUPS" @@ -305,13 +299,12 @@ 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 + echo "ERROR: test: '$MAKE -f $MAKEFILE genmake_hello.$tfs' Failed" + echo " see simple makefile: '$MAKEFILE' (left here)" + echo " Please check (1) your '$MAKE' command, (2) your '$LN' command" + echo " and (3) the allowed sufix '.F' and '.$tfs' in makefile" + echo " or contact the list for help." + echo "" exit -1 return fi @@ -335,15 +328,14 @@ # # 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 + # 2) a local tools/xmakedepend 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 + # 2) use the local xmakedepend script (get all dependencies, but slower) + # 3) use a system-wide default + # 4) locally build and use the cyrus makedepend + # (faster, but can miss some dependencies) # echo >> $LOGFILE echo "running: look_for_makedepend()" >> $LOGFILE @@ -354,7 +346,7 @@ build_cyrus_makedepend RETVAL=$? if test "x$RETVAL" != x0 ; then - echo "WARNING: unable to build cyrus-makedepend. Try 'makedepend'" + echo "WARNING: unable to build cyrus-makedepend. Try other 'makedepend'" MAKEDEPEND= fi else @@ -367,8 +359,6 @@ fi fi 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 @@ -384,22 +374,39 @@ stop end EOF - makedepend genmake_tc.f > /dev/null 2>&1 + $ROOTDIR/tools/xmakedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1 RV1=$? + which makedepend > /dev/null 2>&1 + RV2=$? + if test "x${RV2}" = x0 ; then + makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1 + RV3=$? ; loc_msg='not working.' + else RV3=$RV2 ; loc_msg='not found.' + fi test -f $MAKEFILE && rm -f $MAKEFILE test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE - if test "x${RV0}${RV1}" = x00 ; then + echo " check makedepend (local: $RV1, system: $RV2, $RV3)" + if test "x${RV1}" = x0 ; then + MAKEDEPEND='$(TOOLSDIR)/xmakedepend' + echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE + elif test "x${RV3}" = x0 ; then + echo " local tools/xmakedepend not working. Use system-default makedepend" MAKEDEPEND=makedepend echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE else - echo " system-default makedepend not found. Try to build cyrus-makedepend" + echo " local tools/xmakedepend not working; system-default makedepend $loc_msg" + echo -n " Try to build cyrus-makedepend ..." # Try to build the cyrus implementation build_cyrus_makedepend RETVAL=$? - if test "x$RETVAL" != x0 ; then - echo "WARNING: unable to build cyrus-makedepend. Use local xmakedepend" - MAKEDEPEND='$(TOOLSDIR)/xmakedepend' - echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE + if test "x$RETVAL" = x0 ; then + echo " Works" + else + echo " Fails" ; echo "" >> $LOGFILE + echo "ERROR: no working makedepend found ; look_for_makedepend FAILED" | tee -a $LOGFILE + echo "" + exit -1 + return fi fi fi @@ -412,7 +419,7 @@ ( cd $ROOTDIR/tools/cyrus-imapd-makedepend \ && ./configure > /dev/null 2>&1 \ - && make > /dev/null 2>&1 + && $MAKE > /dev/null 2>&1 if test -x ./makedepend.exe ; then $LN ./makedepend.exe ./makedepend fi @@ -436,13 +443,13 @@ { 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 + 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 + fi clist="cc gcc c89 $CC" for ic in $clist ; do comm="$ic -o encode_files encode_files.c" @@ -450,7 +457,6 @@ RETVAL=$? if test "x$RETVAL" = x0 ; then echo "OK" - DEFINES="$DEFINES -DHAVE_EMBED_SRC" return 0 fi done @@ -462,7 +468,6 @@ return 1 fi echo "OK" - DEFINES="$DEFINES -DHAVE_EMBED_SRC" } # look for possible C compilers @@ -580,8 +585,8 @@ if test "x$OPTFILE" = x ; then OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC if test ! -r $OPTFILE ; then - echo " I looked for the file "$OPTFILE" but did not find it" - fi + echo " I looked for the file "$OPTFILE" but did not find it" + fi fi if test "x$OPTFILE" = x ; then @@ -599,35 +604,81 @@ EOF exit 1 fi +} + +# Do a local copy of MPI headers files (in local dir ./mpi_headers/) after +# checking for additional included headers (in case of chain of included header) +mpi_headers_do_local_copy() { -# # look for possible MPI libraries -# mpi_libs= -# mpi_fort=`which mpif77 2>/dev/null` -# RETVAL=$? -# if test "x${RETVAL}" = x0 ; then -# cat >>test.f < out" -# RETVAL=$? -# if test "x${RETVAL}" = x0 ; then -# a=`cat out` -# for i in $a ; do -# case $i in -# -*) -# mpi_libs="$mpi_libs $i" ;; -# esac -# done -# echo "The MPI libs appear to be:" -# echo " "$mpi_libs -# fi -# rm -f test.f out -# fi + dBug=0 + rm -rf ./mpi_headers + if test -d $MPIINCLUDEDIR ; then + + #----- check for additional headers (chain of included headers) + echo -n ' Check MPI headers ... ' + listIni=$MPI_HEADER_FILES + echo $listIni | grep "\" > /dev/null 2>&1 + outp=$? + #- always check mpif.h (the only mpi-header included in standard MITgcm code) + if test $outp != 0 ; then listIni="mpif.h $listIni" ; fi + if test $dBug = 1 ; then echo "listIni='$listIni'" ; fi + + doCheck=1 ; list2copy='' ; list2check=$listIni + while test $doCheck = 1 ; do + newList='' + for i in $list2check ; do + if test -f $MPIINCLUDEDIR/$i ; then + newInc=`grep '^ *include ' $MPIINCLUDEDIR/$i | \ + sed -e 's/^ *include //' -e 's/\!.*$//' -e "s/'//g" -e 's/\"//g'` + if test $dBug = 1 ; then echo -n "checking $i : newInc='$newInc'" ; fi + for j in $newInc ; do + echo $listIni $list2copy $newList | grep "\<$j\>" > /dev/null 2>&1 + outp=$? + if test $outp != 0 ; then + if test $dBug = 1 ; then echo -n " ; adding $j" ; fi + newList="$newList $j" + fi + done + if test $dBug = 1 ; then echo "" ; fi + fi + done + if test "x$newList" = x ; then doCheck=0 + else list2check=$newList ; list2copy="$list2copy $newList" + fi + done + list2copy="$MPI_HEADER_FILES $list2copy" + if test $dBug = 1 ; then echo "list2copy='$list2copy'" ; fi + + #----- create local mpi_headers dir if we have files to copy + mkListInc=`echo $list2copy | wc -w` + if test $mkListInc != 0 ; then + echo 'create local "./mpi_headers" dir' + mkdir -p ./mpi_headers + INCLUDES="-I./mpi_headers $INCLUDES" + mkListInc=1 + fi + if test "x$LOCAL_MPI_HEADERS" != x ; then mkListInc=0 ; fi + + #----- make local copy and update LOCAL_MPI_HEADERS (if not already set) + for i in $list2copy ; do + if test -f $MPIINCLUDEDIR/$i ; then + cp -p $MPIINCLUDEDIR/$i ./mpi_headers + if test $i = 'mpif.h' ; then + perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h + fi + if test $mkListInc = 2 ; then + LOCAL_MPI_HEADERS="$LOCAL_MPI_HEADERS ./mpi_headers/$i" + fi + if test $mkListInc = 1 ; then + LOCAL_MPI_HEADERS="./mpi_headers/$i" ; mkListInc=2 + fi + fi + done + else + echo "WARNING: MPIINCLUDEDIR='$MPIINCLUDEDIR' is not a directory" + echo "WARNING: => skip checking for MPI headers (no ./mpi_headers dir)" +# exit -1 + fi } # Parse the package dependency information @@ -652,7 +703,7 @@ #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\"" if test ! "x$FC_NAMEMANGLE" = x ; then - return 0 + return 0 fi echo " running: get_fortran_c_namemangling()" >> $LOGFILE @@ -784,7 +835,6 @@ 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 @@ -846,17 +896,12 @@ 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" - return - fi if test ! "x$HAVE_SETRLSTK" = x ; then return fi @@ -894,7 +939,6 @@ 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 @@ -941,7 +985,6 @@ RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_STAT=t - DEFINES="$DEFINES -DHAVE_STAT" fi rm -f genmake_tc* echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE @@ -957,9 +1000,9 @@ program fgennc #include "netcdf.inc" EOF - if test ! "x$MPI" = x ; then - echo '#include "mpif.h"' >> genmake_tnc.F - fi + #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) @@ -1039,6 +1082,148 @@ echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE } +check_lapack_libs() { + if test ! "x$SKIP_LAPACK_CHECK" = x ; then + return + fi + echo >> $LOGFILE + echo "running: check_lapack_libs()" >> $LOGFILE + cat < genmake_tla.F + program fgenla + integer info + integer ipiv( 2 ) + double precision ab( 4, 2 ), b( 2 ) + data ab / 0., 0., 1., 2., 0., 2., 1., 0. / + data b / 1., 1. / + call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info ) + IF (info .NE. 0) write(*,*) 'Error:', info + write(*,*) b + end +EOF + echo "=== genmake_tla.F >>>" > genmake_tla.log + cat genmake_tla.F >> genmake_tla.log + echo "<<< genmake_tla.F ===" >> genmake_tla.log + RET_CPP=f + COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES" + echo "$COMM" >> genmake_tla.log + eval $COMM > genmake_tla.$FS 2>/dev/null && RET_CPP=t + if test "x$RET_CPP" = xf ; then + echo " WARNING: CPP failed to pre-process the lapack test." \ + >> genmake_tla.log + echo " Please check that \$INCLUDES is properly set." \ + >> genmake_tla.log + fi + echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log + echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log + $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \ + && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1 + RET_COMPILE=$? + cat genmake_tla.log >> $LOGFILE + + # test program execution not always possible (see check_netcdf_libs) + # + #test -x ./genmake_tla && ./genmake_tla >> genmake_tla.log 2>&1 + #RETVAL=$? + #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + + if test "x$RET_COMPILE" = x0 ; then + HAVE_LAPACK=t + echo "check_lapack: successful" >> $LOGFILE + else + # try again with "-llapack" added to the libs + echo "==> try again with added '-llapack'" > genmake_tla.log + echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log + echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log + echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log + cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \ + && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \ + && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1 + RET_COMPILE=$? + echo >> $LOGFILE + cat genmake_tla.log >> $LOGFILE + if test "x$RET_COMPILE" = x0 ; then + LIBS="$LIBS -llapack" + HAVE_LAPACK=t + echo "check_lapack: successful" >> $LOGFILE + else + # try again with "-lf77blas -lcblas" added to the libs + echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log + echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log + echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log + echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log + cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \ + && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \ + && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1 + RET_COMPILE=$? + echo >> $LOGFILE + cat genmake_tla.log >> $LOGFILE + if test "x$RET_COMPILE" = x0 ; then + LIBS="$LIBS -llapack -lf77blas -lcblas" + HAVE_LAPACK=t + echo "check_lapack: successful" >> $LOGFILE + else + # try again with "-latlas" added to the libs + echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log + echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log + echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log + echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log + cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \ + && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \ + && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1 + RET_COMPILE=$? + echo >> $LOGFILE + cat genmake_tla.log >> $LOGFILE + if test "x$RET_COMPILE" = x0 ; then + LIBS="$LIBS -llapack -lf77blas -lcblas -latlas" + HAVE_LAPACK=t + echo "check_lapack: successful" >> $LOGFILE + fi + fi + fi + fi + rm -f genmake_tla* + echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE +} + +check_HAVE_FLUSH() { + if test ! "x$SKIP_CHECK_FLUSH" = x ; then + return + fi + echo >> $LOGFILE + echo "running: check_HAVE_FLUSH()" >> $LOGFILE + cat < genmake_tflsh.$FS + program fgenflsh + integer iounit + character*9 fname + iounit = 26 + fname = 'tmp.tflsh' + open(iounit,FILE=fname,STATUS='unknown') + write(iounit,*) 'genmake_tflsh: hello' + call flush(iounit) + close(iounit) + end +EOF + echo "=== genmake_tflsh.$FS >>>" > genmake_tflsh.log + cat genmake_tflsh.$FS >> genmake_tflsh.log + echo "<<< genmake_tflsh.$FS ===" >> genmake_tflsh.log + + echo "$FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS \ " >> genmake_tflsh.log + echo " && $LINK $FFLAGS $FOPTIM -o genmake_tflsh.o $LIBS" >> genmake_tflsh.log + $FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS >> genmake_tflsh.log 2>&1 \ + && $LINK $FFLAGS $FOPTIM -o genmake_tflsh genmake_tflsh.o $LIBS >> genmake_tflsh.log 2>&1 + RET_COMPILE=$? + + if test "x$RET_COMPILE" = x0 ; then + HAVE_FLUSH=t + #cat genmake_tflsh.log >> $LOGFILE + echo " check_HAVE_FLUSH: successful" >> $LOGFILE + else + HAVE_FLUSH=f + cat genmake_tflsh.log >> $LOGFILE + fi + rm -f genmake_tflsh* + echo " --> set HAVE_FLUSH='$HAVE_FLUSH'" >> $LOGFILE +} ############################################################################### # Sequential part of script starts here @@ -1096,6 +1281,9 @@ DEVEL= HAVE_TEST_L= +# comment this line out to enable lapack test +SKIP_LAPACK_CHECK=t + # DEFINES checked by test compilation or command-line HAVE_SYSTEM= HAVE_FDATE= @@ -1106,6 +1294,8 @@ HAVE_NETCDF= HAVE_ETIME= IGNORE_TIME= +HAVE_LAPACK= +HAVE_FLUSH= MODS= TOOLSDIR= @@ -1113,6 +1303,9 @@ INCLUDEDIRS= STANDARDDIRS="USE_THE_DEFAULT" +#- local config file +gm_local="genmake_local" + G2ARGS= BASH= PWD=`pwd` @@ -1136,6 +1329,7 @@ FS90= AUTODIFF_PKG_USED=f +OPENAD= AD_OPTFILE= TAF= AD_TAF_FLAGS= @@ -1148,22 +1342,27 @@ SVD_TAMC_FLAGS= TAMC_EXTRA= +DIVA= +MPIINCLUDEDIR= +MPI_HEADER_FILES= +LOCAL_MPI_HEADERS= + # The following state can be set directly by command-line switches -gm_s1="OPTFILE PKG_DEPEND PKG_GROUPS DISABLE ENABLE MAKEFILE MAKEDEPEND PLATFORM" -gm_s2="FC CC MPI OMP USE_R4 TS PAPIS PCLS PAPI PCL HPMT IEEE DEVEL GSL FEXTRAFLAGS" -gm_s3="ROOTDIR STANDARDDIRS MODS DUMPSTATE" +gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE" +gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4" +gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE" # The following state is not directly set by command-line switches -gm_s4="LN S64 LINK MAKE PACKAGES INCLUDES FFLAGS FOPTIM" +gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM" gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS" -gm_s6="TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK" -gm_s7="PWD THISHOST THISUSER THISDATE THISVER MACHINE" -gm_s8="FC_NAMEMANGLE HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME" +gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK" +gm_s7="TMP THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE" +gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH" # 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" +gm_s10="AUTODIFF_PKG_USED AD_OPTFILE OPENAD TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS" gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS" -gm_s12="TAF_EXTRA TAMC_EXTRA" +gm_s12="TAF_EXTRA TAMC_EXTRA DIVA MPIINCLUDEDIR MPI_HEADER_FILES" gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8" gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12" @@ -1184,16 +1383,6 @@ rm -f genmake_state genmake_*optfile $LOGFILE echo "=== Processing options files and arguments ===" -gm_local="genmake_local" -printf " getting local config information: " -if test -f $gm_local ; then - echo "using $gm_local" - . $gm_local - # echo "DISABLE=$DISABLE" - # echo "ENABLE=$ENABLE" -else - echo "none found" -fi #echo "$0::$1:$2:$3:$4:$5:$6:$7:" #parse_options @@ -1212,79 +1401,81 @@ ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` case $ac_option in - + -help | --help | -h | --h) usage ;; - + -nooptfile | --nooptfile) OPTFILE="NONE" ;; -optfile | --optfile | -of | --of) ac_prev=OPTFILE ;; -optfile=* | --optfile=* | -of=* | --of=*) OPTFILE=$ac_optarg ;; - + + -oad | --oad) + OPENAD="true" ;; -adoptfile | --adoptfile | -adof | --adof) ac_prev=AD_OPTFILE ;; -adoptfile=* | --adoptfile=* | -adof=* | --adof=*) AD_OPTFILE=$ac_optarg ;; - + -pdepend | --pdepend) ac_prev=PKG_DEPEND ;; -pdepend=* | --pdepend=*) PKG_DEPEND=$ac_optarg ;; - + -pgroups | --pgroups) ac_prev=PKG_GROUPS ;; -pgroups=* | --pgroups=*) PKG_GROUPS=$ac_optarg ;; - + -make | --make | -m | --m) ac_prev=MAKE ;; -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) + + -makefile | --makefile | -mf | --mf) ac_prev=MAKEFILE ;; - -makefile=* | --makefile=* | -ma=* | --ma=*) + -makefile=* | --makefile=* | -mf=* | --mf=*) MAKEFILE=$ac_optarg ;; - + -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*) echo "ERROR: The platform option has been removed. Please specify" echo " the build options using the \"optfile\" mechanism." echo usage ;; - + -rootdir | --rootdir | -rd | --rd) ac_prev=ROOTDIR ;; -rootdir=* | --rootdir=* | -rd=* | --rd=*) ROOTDIR=$ac_optarg ;; - + -mods | --mods | -mo | --mo) ac_prev=MODS ;; -mods=* | --mods=* | -mo=* | --mo=*) MODS=$ac_optarg ;; - + -disable | --disable) ac_prev=DISABLE ;; -disable=* | --disable=*) DISABLE=$ac_optarg ;; - + -enable | --enable) ac_prev=ENABLE ;; -enable=* | --enable=*) ENABLE=$ac_optarg ;; - + -standarddirs | --standarddirs) ac_prev=STANDARDDIRS ;; -standarddirs=* | --standarddirs=*) @@ -1294,27 +1485,27 @@ # 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 ;; - + -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 ) USE_R4=true ;; @@ -1322,9 +1513,9 @@ IEEE=true ;; -noieee | --noieee) echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;; - -devel | --devel) + -devel | --devel) IEEE=true ; DEVEL=true ;; - -gsl | --gsl) + -gsl | --gsl) GSL=true ;; -ts | --ts) @@ -1347,21 +1538,21 @@ -mpi=* | --mpi=*) MPIPATH=$ac_optarg MPI=true ;; - - -omp | --omp) - OMP=true ;; + + -omp | --omp) + OMP=true ;; -omp=* | --omp=*) OMPFLAG=$ac_optarg OMP=true ;; - + -ds | --ds) DUMPSTATE=t ;; - + -extra_flag | --extra_flag) ac_prev=FEXTRAFLAGS ;; -extra_flag=* | --extra_flag=*) FEXTRAFLAGS=$ac_optarg ;; - + -taf_extra | --taf_extra) ac_prev=TAF_EXTRA ;; -taf_extra=* | --taf_extra=*) @@ -1371,7 +1562,7 @@ ac_prev=TAMC_EXTRA ;; -tamc_extra=* | --tamc_extra=*) TAMC_EXTRA=$ac_optarg ;; - + -ignoretime | -ignore_time | --ignoretime | --ignore_time) IGNORE_TIME="-DIGNORE_TIME" ;; @@ -1382,16 +1573,36 @@ echo "Error: unrecognized option: "$ac_option usage ;; - + *) echo "Error: unrecognized argument: "$ac_option usage ;; - + esac done +#TMP=./genmk_$$ +#- try to put temporary files in system-local /tmp dir +TMP=/tmp/genmk_$$ +touch $TMP ; retVal=$? +if [ $retVal -eq 0 ] ; then + if test ! -r $TMP ; then TMP=./genmk_$$ ; fi +else + TMP=./genmk_$$ +fi +rm -f $TMP +#echo " temp files: $TMP.*" + +printf " getting local config information: " +if test -f $gm_local ; then + echo "using $gm_local" + . $gm_local +else + echo "none found" +fi + if test -f ./.genmakerc ; then echo echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\"" @@ -1476,10 +1687,12 @@ echo " getting AD_OPTFILE information:" if test "x${AD_OPTFILE}" = x ; then - if test "x$MITGCM_AD_OF" = x ; then + if test "x$MITGCM_AD_OF" != x ; then + AD_OPTFILE=$MITGCM_AD_OF + elif test "x$OPENAD" = x ; then AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default else - AD_OPTFILE=$MITGCM_AD_OF + AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_oad fi fi if test "x${AD_OPTFILE}" != xNONE ; then @@ -1603,7 +1816,9 @@ if test ! "x$MPI" = x ; then echo " Turning on MPI cpp macros" - DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI" + DEFINES="$DEFINES -DALLOW_USE_MPI" +#- To compile code older than checkpoint63s (2012/09/05), un-comment the following line: +# DEFINES="$DEFINES -DALWAYS_USE_MPI" fi if test ! "x$OMP" = x ; then echo " Add OMPFLAG and turn on OpenMP cpp macros" @@ -1620,7 +1835,7 @@ if test ! "x$TS" = x ; then echo " Turning on timing per timestep" if test ! "x$FOOLAD" = x ; then - DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP" + DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP" else DEFINES="$DEFINES -DTIME_PER_TIMESTEP" fi @@ -1656,7 +1871,7 @@ echo " Sticking with PAPI flop summary per timestep!" else echo " Turning on performance analysis with PAPI" - echo " Please make sure PAPIINC, PAPILIB are defined" + echo " Please make sure PAPIINC, PAPILIB are defined" DEFINES="$DEFINES -DUSE_PAPI" INCLUDES="$INCLUDES $PAPIINC" LIBS="$LIBS $PAPILIB" @@ -1668,7 +1883,7 @@ echo " Sticking with PCL flop summary per timestep!" else echo " Turning on performance analysis with PCL" - echo " Please make sure PCLINC, PCLLIB are defined" + echo " Please make sure PCLINC, PCLLIB are defined" DEFINES="$DEFINES -DUSE_PCL" INCLUDES="$INCLUDES $PCLINC" LIBS="$LIBS $PCLLIB" @@ -1678,16 +1893,17 @@ if test ! "x$PAPI" = x ; then echo " PAPI and the HPM Toolkit cannot co-exist!" echo " Sticking with PAPI!" - else if test ! "x$PCL" = x ; then + else + if test ! "x$PCL" = x ; then echo " PCL and the HPM Toolkit cannot co-exist!" echo " Sticking with PCL!" - else + else echo " Turning on performance analysis with the HPM Toolkit" - echo " Please make sure HPMTINC, HPMTLIB are defined" + echo " Please make sure HPMTINC, HPMTLIB are defined" DEFINES="$DEFINES -DUSE_LIBHPM" - INCLUDES="$INCLUDES $HPMTINC" + INCLUDES="$INCLUDES $HPMTINC" LIBS="$LIBS $HPMTLIB" - fi + fi fi fi if test ! "x$GSL" = x ; then @@ -1768,6 +1984,7 @@ printf " Can we call simple C routines (here, \"cloc()\") using $FC... " check_HAVE_CLOC if test "x$HAVE_CLOC" != x ; then + DEFINES="$DEFINES -DHAVE_CLOC" echo "yes" else echo "no" @@ -1782,6 +1999,7 @@ printf " Can we unlimit the stack size using $FC... " check_HAVE_SETRLSTK if test "x$HAVE_SETRLSTK" = xt ; then + DEFINES="$DEFINES -DHAVE_SETRLSTK" echo "yes" else echo "no" @@ -1791,6 +2009,7 @@ printf " Can we register a signal handler using $FC... " check_HAVE_SIGREG if test "x$HAVE_SIGREG" = xt ; then + DEFINES="$DEFINES -DHAVE_SIGREG" echo "yes" else echo "no" @@ -1800,6 +2019,7 @@ printf " Can we use stat() through C calls... " check_HAVE_STAT if test "x$HAVE_STAT" != x ; then + DEFINES="$DEFINES -DHAVE_STAT" echo "yes" else echo "no" @@ -1809,17 +2029,37 @@ printf " Can we create NetCDF-enabled binaries... " check_netcdf_libs if test "x$HAVE_NETCDF" != x ; then + DEFINES="$DEFINES -DHAVE_NETCDF" echo "yes" else echo "no" fi -DEFINES="$DEFINES $IGNORE_TIME" +printf " Can we create LAPACK-enabled binaries... " +check_lapack_libs +if test "x$HAVE_LAPACK" != x ; then + DEFINES="$DEFINES -DHAVE_LAPACK" + echo "yes" +else + echo "no" +fi + +printf " Can we call FLUSH intrinsic subroutine... " +check_HAVE_FLUSH +if test "x$HAVE_FLUSH" = xt ; then + DEFINES="$DEFINES -DHAVE_FLUSH" + echo "yes" +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" +# DEFINES="$DEFINES -DHAVE_EMBED_SRC" fi printf "\n=== Setting defaults ===\n" @@ -1997,7 +2237,7 @@ exit 1 else echo " using PKG_LIST=\"$PKG_LIST\"" - # Strip the comments and add all the names + # Strip the comments and add all the names pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'` RETVAL=$? if test "x${RETVAL}" != x0 ; then @@ -2018,11 +2258,11 @@ fi echo " applying DISABLE settings" -echo "" > ./.tmp_pack +echo "" > $TMP.pack for i in $PACKAGES ; do - echo $i >> ./.tmp_pack + echo $i >> $TMP.pack done -for i in `grep "-" ./.tmp_pack` ; do +for i in `grep "-" $TMP.pack` ; do j=`echo $i | sed 's/[-]//'` DISABLE="$DISABLE $j" done @@ -2040,22 +2280,22 @@ done PACKAGES="$pack" echo " applying ENABLE settings" -echo "" > ./.tmp_pack +echo "" > $TMP.pack PACKAGES="$PACKAGES $ENABLE" # Test if each explicitly referenced package exists for i in $PACKAGES ; do j=`echo $i | sed 's/[-+]//'` if test ! -d "$ROOTDIR/pkg/$j" ; then echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'" - exit 1 + exit 1 fi - echo $i >> ./.tmp_pack + echo $i >> $TMP.pack done PACKAGES= -for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do +for i in `grep -v "-" $TMP.pack | sort | uniq` ; do PACKAGES="$PACKAGES $i" done -rm -f ./.tmp_pack +rm -f $TMP.pack echo " packages are: $PACKAGES" # Check for package MNC: if NetCDF is available, then build the MNC @@ -2092,7 +2332,7 @@ 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 + exit 1 else DISABLE="$DISABLE mnc" fi @@ -2125,6 +2365,23 @@ fi fi +# Make sure the openad package is enabled if using OpenAD +if test "x$OPENAD" != x ; then + echo " $PACKAGES " | grep ' openad ' > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 ; then + cat </dev/null )` for j in $list_files ; do - cat $i/$j >> adSrcFiles.tmp + cat $i/$j >> $TMP.adSrcFiles done done if test ! "x"$FS = "x.f" ; then - cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f - mv -f adSrcFiles.tmp_f adSrcFiles.tmp + cat $TMP.adSrcFiles | sed -e "s/\.f/.$FS/g" > $TMP.adSrcFiles_f + mv -f $TMP.adSrcFiles_f $TMP.adSrcFiles fi echo @@ -2338,36 +2595,20 @@ 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 +if test ! "x$DIVA" = x -a ! "x$MPI" = x ; then + if test ! "x$MPIINCLUDEDIR" = x ; then + # Do a local copy of MPI headers files (in local dir ./mpi_headers/) after + # checking for additional included headers (in case of chain of included + # header); also set LOCAL_MPI_HEADERS (if not already set) + mpi_headers_do_local_copy 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 +rm -rf $TMP.links +mkdir $TMP.links +touch $TMP.links/foo +if test ! -r "$TMP.links/foo" ; then echo echo "ERROR : something is wrong with your directory permissions or" echo " your user file-creation mask (\"umask\") since creating a" @@ -2383,13 +2624,14 @@ echo exit 1 fi -rm -f .links.tmp/foo +rm -f $TMP.links/foo if test "x$OPENAD" != x ; then OAD_DONT_COMPILE="/dev/null" OAD_DONT_TRANSFORM="/dev/null" OAD_KEEP_ORIGINAL="/dev/null" OAD_CB2M_FILES="/dev/null" + OADTOOLS="$TOOLSDIR/OAD_support" echo " looking for dontCompile file: " for i in "." $MODS ; do if test -r $i"/dontCompile" ; then @@ -2425,14 +2667,14 @@ echo " OpenAD exceptions: " fi -echo "# This section creates symbolic links" > srclinks.tmp -echo "" >> srclinks.tmp -printf 'F77_SRC_FILES = ' > F77srclist.tmp -printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp -printf 'C_SRC_FILES = ' > csrclist.tmp -printf 'F90_SRC_FILES = ' > F90srclist.tmp -printf 'H_SRC_FILES = ' > hsrclist.tmp -printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp +echo "# This section creates symbolic links" > $TMP.srclinks +echo "" >> $TMP.srclinks +printf 'F77_SRC_FILES = ' > $TMP.F77srclist +printf 'NON_AD_F77_SRC_FILES = ' > $TMP.nonADF77srclist +printf 'C_SRC_FILES = ' > $TMP.csrclist +printf 'F90_SRC_FILES = ' > $TMP.F90srclist +printf 'H_SRC_FILES = ' > $TMP.hsrclist +printf 'AD_FLOW_FILES = ' > $TMP.ad_flow_files alldirs="$SOURCEDIRS $INCLUDEDIRS ." for d in $alldirs ; do deplist= @@ -2442,50 +2684,57 @@ sfiles=`( echo $sfiles | grep -v _cb2m\. )` fi for sf in $sfiles ; do - if test ! -r ".links.tmp/$sf" ; then + if test ! -r "$TMP.links/$sf" ; then if test -f "$d/$sf" ; then ignore_f=f - case $d/$sf in - ./$PACKAGES_DOT_H) + case $d/$sf in + ./$PACKAGES_DOT_H) ignore_f=t ;; - ./AD_CONFIG.h) + ./AD_CONFIG.h) ignore_f=t ;; - ./FC_NAMEMANGLE.h) + ./FC_NAMEMANGLE.h) ignore_f=t ;; - ./BUILD_INFO.h) + ./BUILD_INFO.h) ignore_f=t ;; - ./EMBEDDED_FILES.h) + ./EMBEDDED_FILES.h) ignore_f=t ;; - *) + *) # 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 + touch $TMP.links/$sf deplist="$deplist $sf" fi ;; - esac + esac if test "x$ignore_f" = xf ; then extn=`echo $sf | $AWK -F. '{print $NF}'` case $extn in F) - echo " \\" >> F77srclist.tmp - printf " $sf" >> F77srclist.tmp - if test "x$OPENAD" != x ; then + echo " \\" >> $TMP.F77srclist + printf " $sf" >> $TMP.F77srclist + if test "x$OPENAD" = x ; then + basename=${sf%%.F} + isAD=`egrep ^$basename.f'[ ]*' $TMP.adSrcFiles` + if test -z "$isAD" ; then + echo " \\" >> $TMP.nonADF77srclist + printf " $sf" >> $TMP.nonADF77srclist + fi + else #- OpenAD case: basename=${sf%%.F} - isAD=`egrep ^$basename.f'[ ]*' adSrcFiles.tmp` + isAD=`egrep ^$basename.f'[ ]*' $TMP.adSrcFiles` if test -z "$isAD" ; then toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE}` if test -z "$toBeIgnored" ; then - echo " \\" >> nonADF77srclist.tmp - printf " $sf" >> nonADF77srclist.tmp + echo " \\" >> $TMP.nonADF77srclist + printf " $sf" >> $TMP.nonADF77srclist else echo " not to be compiled : $sf" fi @@ -2500,27 +2749,27 @@ echo " original to be kept : $sf" fi if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then - echo " \\" >> nonADF77srclist.tmp - printf " $sf" >> nonADF77srclist.tmp + echo " \\" >> $TMP.nonADF77srclist + printf " $sf" >> $TMP.nonADF77srclist fi fi fi ;; F90) - echo " \\" >> F90srclist.tmp - printf " $sf" >> F90srclist.tmp + echo " \\" >> $TMP.F90srclist + printf " $sf" >> $TMP.F90srclist ;; c) - echo " \\" >> csrclist.tmp - printf " $sf" >> csrclist.tmp + echo " \\" >> $TMP.csrclist + printf " $sf" >> $TMP.csrclist ;; h) - echo " \\" >> hsrclist.tmp - printf " $sf" >> hsrclist.tmp + echo " \\" >> $TMP.hsrclist + printf " $sf" >> $TMP.hsrclist ;; - flow) - echo " \\" >> ad_flow_files.tmp - printf " $sf" >> ad_flow_files.tmp + flow) + echo " \\" >> $TMP.ad_flow_files + printf " $sf" >> $TMP.ad_flow_files ;; esac fi @@ -2529,28 +2778,28 @@ done if test "x$deplist" != x ; then if test "$d" != "." ; then - echo "" >> srclinks.tmp - echo "# These files are linked from $d" >> srclinks.tmp - echo "$deplist :" >> srclinks.tmp + echo "" >> $TMP.srclinks + echo "# These files are linked from $d" >> $TMP.srclinks + echo "$deplist :" >> $TMP.srclinks # We need to make sure that the link isn't already there. # This may happen when make thinks that a header file has to be "remade" # because a module it depends on has changed. In this case we do nothing. - printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp + printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> $TMP.srclinks fi fi done -rm -rf .links.tmp -echo "" >> F77srclist.tmp -echo "" >> nonADF77srclist.tmp -echo "" >> csrclist.tmp -echo "" >> F90srclist.tmp -echo "" >> hsrclist.tmp -echo "" >> ad_flow_files.tmp +rm -rf $TMP.links +echo "" >> $TMP.F77srclist +echo "" >> $TMP.nonADF77srclist +echo "" >> $TMP.csrclist +echo "" >> $TMP.F90srclist +echo "" >> $TMP.hsrclist +echo "" >> $TMP.ad_flow_files CMDLINE=$0 for xx in "$@" ; do nw=`echo $xx | wc -w` if test $nw = '1' ; then CMDLINE="$CMDLINE $xx" - else CMDLINE="$CMDLINE '$xx'" ; fi + else CMDLINE="$CMDLINE '$xx'" ; fi done if test -f $MAKEFILE ; then @@ -2584,8 +2833,6 @@ # INCLUDES : Directories searched for header files # DEFINES : Macro definitions for CPP # MAKEDEPEND : Dependency generator -# KPP : Special preprocessor command (specific to platform) -# KFLAGS : Flags for KPP # FC : Fortran compiler command # FFLAGS : Configuration/debugging options for FC # FOPTIM : Optimization options for FC @@ -2599,6 +2846,7 @@ EXEDIR = ${EXEDIR} EXECUTABLE = \$(EXEDIR)/${EXECUTABLE} TOOLSDIR = ${TOOLSDIR} +OADTOOLS = ${OADTOOLS} #eh3 new defines for the adjoint work AUTODIFF = ${ROOTDIR}/pkg/autodiff @@ -2619,11 +2867,12 @@ echo "EMBEDDED_FILES = " >>$MAKEFILE fi +# extract default cpp search path so we can pass it to makedepend +CPPINCLUDES=`cat /dev/null | $CPP -v 2>&1 | awk '/^End of search/{f=0}!/^\#/{if(f){printf " -I%s", $1;}}/^\#include "..." search start/{f=1}'` + cat >>$MAKEFILE <> $MAKEFILE -cat nonADF77srclist.tmp >> $MAKEFILE -cat csrclist.tmp >> $MAKEFILE -cat F90srclist.tmp >> $MAKEFILE -cat hsrclist.tmp >> $MAKEFILE -cat ad_flow_files.tmp >> $MAKEFILE +cat $TMP.F77srclist >> $MAKEFILE +cat $TMP.nonADF77srclist >> $MAKEFILE +cat $TMP.csrclist >> $MAKEFILE +cat $TMP.F90srclist >> $MAKEFILE +cat $TMP.hsrclist >> $MAKEFILE +cat $TMP.ad_flow_files >> $MAKEFILE -rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp +rm -f $TMP.F77srclist $TMP.nonADF77srclist $TMP.csrclist $TMP.F90srclist $TMP.hsrclist $TMP.ad_flow_files echo >> $MAKEFILE @@ -2683,21 +2936,28 @@ echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')' >> $MAKEFILE echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE -echo 'FLOFILES = $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE +echo 'FLOWFILES = $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE echo >> $MAKEFILE echo '.SUFFIXES:' >> $MAKEFILE echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE 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) -f \$(MAKEFILE) \$(EXECUTABLE) + \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES) @echo Creating \$@ ... \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS) depend: - @make -f \$(MAKEFILE) links - \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES) + @\$(MAKE) -f \$(MAKEFILE) links + \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES) \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE) -rm -f makedepend.out @@ -2726,25 +2986,26 @@ # remove most of the files that "make" and "make depend" generate Clean: - @make -f \$(MAKEFILE) clean - @make -f \$(MAKEFILE) cleanlinks + @\$(MAKE) -f \$(MAKEFILE) clean + @\$(MAKE) -f \$(MAKEFILE) cleanlinks -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old - -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log - -rm -f genmake_warnings genmake_errors make.log + -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log # remove also the executable, files that "genmake2" generates (except Makefile) # and output from a run (plus log files from testreport) CLEAN: - @make -f \$(MAKEFILE) Clean - -rm -f \$(EXECUTABLE) \$(EXE_AD) *.bak + @\$(MAKE) -f \$(MAKEFILE) Clean + -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak -rm -f $LOGFILE genmake_state genmake_*optfile -rm -f SIZE.h.mpi genmake.tr_log make.tr_log + -rm -rf mpi_headers mnc_test_* -find \$(EXEDIR) -name "*.meta" -exec rm {} \; -find \$(EXEDIR) -name "*.data" -exec rm {} \; -find \$(EXEDIR) -name "fort.*" -exec rm {} \; - -rm -f *.txt STD* *diagnostics.log datetime + -rm -f *.txt STDOUT.* STDERR.* *diagnostics.log *.[0-9][0-9][0-9][0-9].log + -rm -f datetime costfinal divided.ctrl snapshot* output_adm.txt.diva_* -rm -f *_MIT_CE_000.opt0000 costfunction*0000 - -rm -rf mnc_test_* + -rm -f oad_cp.[0-9][0-9][0-9].????? makefile: $THIS_SCRIPT $G2ARGS @@ -2754,10 +3015,10 @@ # Special targets (SPECIAL_FILES) which are created by make ${PACKAGES_DOT_H}: @echo Creating \$@ ... - @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@ + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@ AD_CONFIG.h: @echo Creating \$@ ... - @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > \$@ + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > \$@ FC_NAMEMANGLE.h: @echo Creating \$@ ... echo "$FC_NAMEMANGLE" > \$@ @@ -2797,16 +3058,19 @@ ## This nullifies any default implicit rules concerning these two file types: ## %.o : %.F +# C preprocessing and replacing the _d in constants: +CPPCMD = cat \$< | ${CPP} \$(DEFINES) \$(INCLUDES) | ${S64} + .F.$FS: - \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ + \$(CPPCMD) > \$@ .$FS.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< .F.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< .F90.$FS90: - \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ + \$(CPPCMD) > \$@ .FF90.f$FS90: - \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ + \$(CPPCMD) > \$@ .$FS90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .f$FS90.o: @@ -2815,11 +3079,11 @@ .c.o: \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$< .flow.flowdir: - \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ + \$(CPPCMD) > \$@ # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain .F.p: - \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ + \$(CPPCMD) > \$@ .p.$FS: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< @@ -2838,6 +3102,7 @@ TAF_EXTRA = ${TAF_EXTRA} TAMC_EXTRA = ${TAMC_EXTRA} +LOCAL_MPI_HEADERS = ${LOCAL_MPI_HEADERS} EOF @@ -2855,30 +3120,38 @@ echo " Add the source list for AD code generation" echo >> $MAKEFILE printf "AD_FILES = " >> $MAKEFILE -AD_FILES=`cat adSrcFiles.tmp` +AD_FILES=`cat $TMP.adSrcFiles` for i in $AD_FILES ; do echo " \\" >> $MAKEFILE printf " $i" >> $MAKEFILE done echo >> $MAKEFILE -rm -f adSrcFiles.tmp +rm -f $TMP.adSrcFiles cat >>$MAKEFILE < ad_config.template +ad_exe_target: + @echo Update AD_CONFIG.h and make \$(EXE_AD) + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template + @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h + @-rm -f ad_config.template + \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD) + +ad_input_code.$FS: \$(AD_FILES) \$(AD_FLOW_FILES) + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h - -rm -f ad_config.template - @make -f \$(MAKEFILE) \$(F77_PP_SRC_FILES) - @make -f \$(MAKEFILE) \$(FLOFILES) - cat \$(FLOFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS + @-rm -f ad_config.template + @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES) + @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES) + cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS ad_taf_output.$FS: ad_input_code.$FS + @-rm -f ad_input_code_ad.$FS ; echo '' \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS ls -l ad_input_code_ad.$FS cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS @@ -2888,8 +3161,8 @@ ls -l ad_input_code_ad.$FS 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) +\$(EXE_AD): \$(SPECIAL_FILES) \$(H_SRC_FILES) ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES) + \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS) ad_tamc_output.$FS: ad_input_code.$FS \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS @@ -2904,33 +3177,41 @@ adtrick: patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff -adobj: ad_taf_output.o \$(OBJFILES) +adobj: ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) # ... FTL ... -ftlall: ftl_taf +ftlall: ftl_exe_target ftltaf: ftl_taf_output.$FS ftltamc: ftl_tamc_output.$FS -ftl_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES) - @$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 -f \$(MAKEFILE) \$(F77_PP_SRC_FILES) - @make -f \$(MAKEFILE) \$(AD_FLOW_FILES) - cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS +ftl_exe_target: + @echo Update AD_CONFIG.h and make \$(EXE_FTL) + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template + @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h + @-rm -f ad_config.template + \$(MAKE) -f \$(MAKEFILE) \$(EXE_FTL) + +ftl_input_code.$FS: \$(AD_FILES) + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template + cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h + @-rm -f ad_config.template + @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES) + @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES) + cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS ftl_taf_output.$FS: ftl_input_code.$FS + @-rm -f ftl_input_code_tl.$FS ; echo '' \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS - ls -l ftl_input_code_ftl.$FS - cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS + ls -l ftl_input_code_tl.$FS + cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS ftltafonly: \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS - ls -l ftl_input_code_ftl.$FS - cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS + ls -l ftl_input_code_tl.$FS + cat ftl_input_code_tl.$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) +\$(EXE_FTL): \$(SPECIAL_FILES) \$(H_SRC_FILES) ftl_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES) + \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) ftl_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS) ftl_tamc_output.$FS: ftl_input_code.$FS \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS @@ -2959,9 +3240,9 @@ 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 + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "SVD version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template + cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h + @-rm -f ad_config.template EOF @@ -3013,7 +3294,7 @@ echo " \\" >> $MAKEFILE printf " ${i}_mod.f$FS90" >> $MAKEFILE done -AD_FILES=`cat adSrcFiles.tmp` +AD_FILES=`cat $TMP.adSrcFiles` for i in $AD_FILES ; do basename=${i%%.f} toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}` @@ -3023,7 +3304,7 @@ fi done echo >> $MAKEFILE -rm -f adSrcFiles.tmp +rm -f $TMP.adSrcFiles cat >>$MAKEFILE <> \$(MAKEFILE) -rm -f makedepend.out @@ -3045,7 +3326,8 @@ OAD_active.F90 \ OAD_cp.F90 \ OAD_rev.F90 \ -OAD_tape.F90 +OAD_tape.F90 \ +revolve.F90 OPENAD_SUPPORT_C_SRC_FILES = \ iaddr.c \ @@ -3061,47 +3343,26 @@ 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 -# 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 +CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90) -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_S1=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) OAD_intrinsics_oad.o \$(CB2M_AD_FILES:.f$FS90=_oad.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)) postProcess.comp \$(AD_OBJ_FILES_S2) -ifeq (\$(MAKELEVEL),1) +\$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2) \$(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 - ../OAD_support/cb2mGetModules.csh $< ../OAD_support/cb2mGetModules.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: -%_cb2m.FF90 : %.F ../OAD_support/cb2mUseModules.bash - ../OAD_support/cb2mUseModules.bash $< ${MPI} +# create sources files modules from header files containing common blocks +%_mod.FF90 : %.h \${OADTOOLS}/cb2mGetModules.csh \${OADTOOLS}/cb2mGetModules.awk + \${OADTOOLS}/cb2mGetModules.csh $< \${OADTOOLS}/cb2mGetModules.awk + +# create new header files with USE statements for the new modules made above +%_mod.h : %.h \${OADTOOLS}/cb2mGetHeaders.csh \${OADTOOLS}/cb2mGetHeaders.awk + \${OADTOOLS}/cb2mGetHeaders.csh $< \${OADTOOLS}/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES) + +# change the include directives of everybody to refer to the new header files with the USE statements +%_cb2m.FF90 : %.F \${OADTOOLS}/cb2mUseModules.bash + \${OADTOOLS}/cb2mUseModules.bash $< ${MPI} # makefile debug rule small_f: \$(CB2M_F90_PP_SRC_FILES) @@ -3114,93 +3375,59 @@ @printf 'running ... ' @./\$(EXE_AD) > \$@ -CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90) 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 - cat \$^ | sed -f ../OAD_support/strip.sed | sed -f ../OAD_support/stop2print.sed > \$@ - -# mfef90 preprocessing -# 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 - ./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 --timing --r8 -H -S \$< -o \$@ +ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES) + \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S -o \$@ \$^ + +# replace stop statements (to avoid the implied unstructured control flow) with print statements +ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90 + cat \$< | sed -f \${OADTOOLS}/stop2print.sed > ad_input_code_sf.pre.s2p.f90 # 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) -# characters respectively. -ad_input_code_sf.w2f.pre.B: ad_input_code_sf.w2f.pre.f$FS90 mfef90 - ./mfef90 -r8 -z -F \$< - mv \$<.B \$@ +ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90 + \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90 # WHIRL -> XAIF -ad_input_code_sf.w2f.pre.xaif : ad_input_code_sf.w2f.pre.B whirl2xaif - ./whirl2xaif -s -n --debug 1 -o \$@ \$< +ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B + \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$< # XAIF -> XAIF' -ad_input_code_sf.w2f.pre.xb.xaif : ad_input_code_sf.w2f.pre.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd oadDriver - ./oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r +ad_input_code_sf.pre.s2p.xb.xaif : ad_input_code_sf.pre.s2p.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd + \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r # XAIF' -> WHIRL' -ad_input_code_sf.w2f.pre.xb.x2w.B : ad_input_code_sf.w2f.pre.xb.xaif xaif2whirl - ./xaif2whirl --debug 1 ad_input_code_sf.w2f.pre.B \$< +ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif + \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.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 \$< +ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B + \${OPEN64ROOT}/whirl2f/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 - ../OAD_support/insertTemplateDir.bash \$< \$@ +ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90 \${OADTOOLS}/insertTemplateDir.bash + \${OADTOOLS}/insertTemplateDir.bash \$< \$@ -PPEXTRAS=\$(wildcard ../OAD_support/ad_template.*.F) ../OAD_support/ad_inline.F +PPEXTRAS=\$(notdir \$(wildcard \${OADTOOLS}/ad_template.*.F)) ad_inline.F # postprocess F' -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 +postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90 + \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i ad_inline.f \$< + # the target is a placeholder to trigger a single 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 --infoUnitFile w2f__types.f90 --outputFormat=fixed -m r -i ../OAD_support/ad_inline.f --width 4 \$< +# put this so make knows about the postprocessing output +OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag -# setup some links +# link the XAIF schema files %.xsd: \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ . -mfef90: - \$(LN) \${OPEN64ROOT}/crayf90/sgi/mfef90 . - # link the support files: -\$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES): - \$(LN) ../OAD_support/\$@ . - -whirl2xaif xaif2whirl: - \$(LN) \${OPENADFORTTK}/bin/\$@ . - -preProcess.py postProcess.py: - \$(LN) \${OPENADFORTTK_BASE}/tools/SourceProcessing/\$@ . - -whirl2f whirl2f_be: - \$(LN) \${OPEN64ROOT}/whirl2f/\$@ . - -oadDriver: - \$(LN) \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver \$@ +\$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES) \$(PPEXTRAS): + \$(LN) \${OADTOOLS}/\$@ . -AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.make postProcess.tag postProcess.comp \$(PPEXTRAS:.F=.f) +AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag # ============ end OpenAD specific section ============== @@ -3236,8 +3463,8 @@ done echo " Add rules for links" -cat srclinks.tmp >> $MAKEFILE -rm -f srclinks.tmp +cat $TMP.srclinks >> $MAKEFILE +rm -f $TMP.srclinks echo " Adding makedepend marker" printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE @@ -3245,7 +3472,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 -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 @@ -3259,7 +3486,7 @@ fi fi if test ! -f AD_CONFIG.h ; then - $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > AD_CONFIG.h + $BASH $TOOLSDIR/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > AD_CONFIG.h fi # Write the "state" for future records