--- MITgcm/tools/genmake2 2004/02/24 19:00:32 1.67 +++ MITgcm/tools/genmake2 2011/01/15 19:16:32 1.219 @@ -1,6 +1,7 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.67 2004/02/24 19:00:32 adcroft Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.219 2011/01/15 19:16:32 jmc Exp $ +# $Name: $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -8,25 +9,194 @@ # modified by aja 01/00 # rewritten in bash by eh3 08/03 +# Explain usage +usage() { +cat < /dev/null 2>&1 RETVAL=$? if test "x${RETVAL}" = x0 ; then - echo -n "Error: In $file there is an illegal line: " + printf "Error: In $file there is an illegal line: " grep -i "$strng" $file - return 1 + exit 99 fi return 0 } @@ -48,7 +218,6 @@ # the package list. expand_pkg_groups() { new_packages= - PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups" if test -r $PKG_GROUPS ; then cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp @@ -59,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" @@ -67,68 +236,316 @@ done PACKAGES=$new_packages rm -f ./p[1,2].tmp + return $matched else echo "Warning: can't read package groups definition file: $PKG_GROUPS" fi } -# Guess possible config options for this host -find_possible_configs() { +# Check for broken environments (eg. cygwin, MacOSX w/HFS+) that +# cannot distinguish [*.F/*.F90] from [*.f/*.f90] files. +check_for_broken_Ff() { + # Do we have defaults for $FS and/or $FS90 ? + tfs=f + tfs9=f90 + if test "x$FS" != x ; then + tfs="$FS" + fi + if test "x$FS90" != x ; then + tfs9="$FS90" + fi - 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/'` - PLATFORM=$tmp2 - OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")` - echo " The platform appears to be: $PLATFORM" - - echo "test" > test - ln -s ./test link + # First check the ability to create a *.F/.f pair. + cat <> genmake_hello.F + program hello + write(*,*) 'hi' + stop + end +EOF + cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1 RETVAL=$? - if test "x${RETVAL}" = x0 ; then - LN="ln -s" - else - echo "Error: \"ln -s\" does not appear to work on this system!" - echo " For help, please contact ." - exit 1 + if test "x$RETVAL" != x0 ; then + if test "x$FS" = x ; then + FS='for' + FS90='fr9' + check_for_broken_Ff + else + cat <&1 +ERROR: Your file system cannot distinguish between *.F and *.f files + (fails the "cp" test) and this program cannot find a suitable + replacement extension. Please try a different build environment or + contact the list for help. + +EOF + exit -1 + fi + return fi - rm -f test link + rm -f genmake_hello.* - if test "x$CPP" = x ; then - CPP="cpp -traditional -P" + # Check the ability of ${MAKE} and ${LN} to use the current set + # of extensions. + cat <> genmake_hello.F + program hello + write(*,*) 'hi' + stop + end +EOF + test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst" + cat <> $MAKEFILE +.SUFFIXES: +.SUFFIXES: .$tfs .F +.F.$tfs: + $LN \$< \$@ +EOF + $MAKE "genmake_hello."$tfs > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then + if test "x$FS" = x ; then + FS='for' + FS90='fr9' + check_for_broken_Ff + else + cat <&1 +ERROR: Your file system cannot distinguish between *.F and *.f files + (fails the "make/ln" test) and this program cannot find a suitable + replacement extension. Please try a different build environment or + contact the list for help. + +EOF + exit -1 + return + fi fi + rm -f genmake_hello.* $MAKEFILE + test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE + + # If we make it here, use the extensions + FS=$tfs + FS90=$tfs9 + return +} + +look_for_makedepend() { - # makedepend is not always available + # The "original" makedepend is part of the Imake system that is + # most often distributed with XFree86 or with an XFree86 source + # package. As a result, many machines (eg. generic Linux) do not + # have a system-default "makedepend" available. For those + # systems, we have two fall-back options: + # + # 1) a makedepend implementation shipped with the cyrus-imapd + # package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/ + # + # 2) a known-buggy xmakedpend shell script + # + # So the choices are, in order: + # + # 1) use the user-specified program + # 2) use a system-wide default + # 3) locally build and use the cyrus implementation + # 4) fall back to the buggy local xmakedpend script + # + echo >> $LOGFILE + echo "running: look_for_makedepend()" >> $LOGFILE + if test "x${MAKEDEPEND}" != x ; then + echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1 + RETVAL=$? + if test x"$RETVAL" = x0 ; then + build_cyrus_makedepend + RETVAL=$? + if test "x$RETVAL" != x0 ; then + echo "WARNING: unable to build cyrus-makedepend. Try 'makedepend'" + MAKEDEPEND= + fi + else + echo " --> MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE + fi + fi if test "x${MAKEDEPEND}" = x ; then - which makedepend >& /dev/null - RETVAL=$? - if test "x${RETVAL}" = x1 ; then - echo " makedepend was not found. Using xmakedpend instead." - MAKEDEPEND='$(TOOLSDIR)/xmakedepend' - fi + which makedepend > /dev/null 2>&1 + RV0=$? + test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst" + # echo 'MAKEFILE="'$MAKEFILE'"' + cat <> $MAKEFILE +# THIS IS A TEST MAKEFILE GENERATED BY "genmake2" +# +# Some "makedepend" implementations will die if they cannot +# find a Makefile -- so this file is here to gives them an +# empty one to find and parse. +EOF + cat <> genmake_tc.f + program test + write(*,*) 'test' + stop + end +EOF + makedepend genmake_tc.f > /dev/null 2>&1 + RV1=$? + test -f $MAKEFILE && rm -f $MAKEFILE + test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE + if test "x${RV0}${RV1}" = x00 ; then + MAKEDEPEND=makedepend + echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE + else + echo " system-default makedepend not found. 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 + fi + fi fi +} - # look for possible fortran compilers - tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95" - p_FC= +build_cyrus_makedepend() { + echo >> $LOGFILE + echo "running: build_cyrus_makedepend()" >> $LOGFILE + rm -f ./genmake_cy_md + ( + cd $ROOTDIR/tools/cyrus-imapd-makedepend \ + && ./configure > /dev/null 2>&1 \ + && make > /dev/null 2>&1 + if test -x ./makedepend.exe ; then + $LN ./makedepend.exe ./makedepend + fi + ./makedepend ifparser.c > /dev/null 2>&1 \ + && echo "true" + ) > ./genmake_cy_md + grep true ./genmake_cy_md > /dev/null 2>&1 + RETVAL=$? + rm -f ./genmake_cy_md + if test "x$RETVAL" = x0 ; then + MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend' + echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE + return 0 + else + echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE + return 1 + fi +} + +build_embed_encode() +{ + printf " building the embed-encode utility... " + if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then + if test ! -d "$ROOTDIR/tools/embed_encode" ; then + echo + echo " Error: can't locate \"$ROOTDIR/tools/embed_encode\"" + echo + EMBED_SRC=f + return 1 + fi + clist="cc gcc c89 $CC" + for ic in $clist ; do + comm="$ic -o encode_files encode_files.c" + ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" = x0 ; then + echo "OK" + DEFINES="$DEFINES -DHAVE_EMBED_SRC" + return 0 + fi + done + echo + echo " Error: unable to build $ROOTDIR/embed_encode/encode_files" + echo " so it has been disabled" + echo + EMBED_SRC=f + return 1 + fi + echo "OK" + DEFINES="$DEFINES -DHAVE_EMBED_SRC" +} + +# 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 + tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc" + p_CC= for c in $tmp ; do - rm -f ./hello.f ./hello - cat >> hello.f <> $LOGFILE + $COMM >> $LOGFILE 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + echo " $c test successful" >> $LOGFILE + p_CC="$p_CC $c" + fi + done + rm -f ./genmake_hello.c ./genmake_hello + if test "x${p_CC}" = x ; then + cat 1>&2 < 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 + 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= + rm -f ./genmake_hello.f + cat >> 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` @@ -200,7 +614,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 @@ -210,7 +624,6 @@ # fi # rm -f test.f out # fi - } # Parse the package dependency information @@ -219,173 +632,86 @@ # 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 - - echo -n "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 - c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3` + c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3` 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 - cat > genmake_tcomp.f < 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 - f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3` + f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3` RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm - 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 @@ -411,10 +737,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 @@ -431,32 +760,203 @@ *curtim = *curtim/1.E6; } EOF - make genmake_tc_1.o >> genmake_tc.log 2>&1 + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RET_C=$? - cat < genmake_tc_2.f + cat < genmake_tc_2.$FS program hello - Real*8 wtime + REAL*8 wtime external cloc call cloc(wtime) print *," HELLO WORLD", wtime - end program hello + end EOF - $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1 + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 RET_F=$? - test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 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 +#include +#include +#include +#include +#include + +int * ip; + +static void killhandler( + unsigned int sn, siginfo_t si, struct ucontext *sc ) +{ + *ip = *ip + 1; + return; +} + +void FC_NAMEMANGLE(sigreg) (int * aip) +{ + struct sigaction s; + ip = aip; + s.sa_flags = SA_SIGINFO; + s.sa_sigaction = (void *)killhandler; + if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) { + printf("Sigaction returned error = %d\n", errno); + exit(0); + } + return; } +EOF + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 + RET_C=$? + cat < genmake_tc_2.$FS + program hello + integer anint + common /iv/ anint + external sigreg + call sigreg(anint) + end +EOF + cat genmake_tc_2.$FS >> $LOGFILE + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + 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" + return + fi + 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 +#include +#include +#include +void FC_NAMEMANGLE(setrlstk) () +{ + struct rlimit rls; + rls.rlim_cur = RLIM_INFINITY; + rls.rlim_max = RLIM_INFINITY; + setrlimit(RLIMIT_STACK, &rls); + return; +} +EOF + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> $LOGFILE + $COMM >> $LOGFILE 2>&1 + RET_C=$? + cat < genmake_tc_2.$FS + program hello + external setrlstk + call setrlstk() + end +EOF + cat genmake_tc_2.$FS >> $LOGFILE + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + 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 +#include +#include +#include +#include +#include +void FC_NAMEMANGLE(tfsize) ( int *nbyte ) +{ + char name[512]; + struct stat astat; + name[0] = 'a'; name[1] = '\0'; + if (! stat(name, &astat)) + *nbyte = (int)(astat.st_size); + else + *nbyte = -1; +} +EOF + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> $LOGFILE + $COMM >> genmake_tc.log 2>&1 + RET_C=$? + cat < genmake_tc_2.$FS + program hello + integer nbyte + call tfsize(nbyte) + print *," HELLO WORLD", nbyte + end +EOF + cat genmake_tc_2.$FS >> $LOGFILE + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> $LOGFILE + $COMM >> genmake_tc.log 2>&1 + 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 +} check_netcdf_libs() { + if test ! "x$SKIP_NETCDF_CHECK" = x ; then + return + fi + echo >> $LOGFILE + echo "running: check_netcdf_libs()" >> $LOGFILE cat < genmake_tnc.F program fgennc #include "netcdf.inc" +EOF + if test ! "x$MPI" = x ; then + echo '#include "mpif.h"' >> genmake_tnc.F + fi + cat <> genmake_tnc.F integer iret, ncid, xid iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid) IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) @@ -466,33 +966,76 @@ IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) end EOF - $CPP genmake_tnc.F > genmake_tnc.f \ - && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1 + echo "=== genmake_tnc.F >>>" > genmake_tnc.log + cat 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 + eval $COMM > genmake_tnc.$FS 2>/dev/null && RET_CPP=t + if test "x$RET_CPP" = xf ; then + echo " WARNING: CPP failed to pre-process the netcdf test." \ + >> genmake_tnc.log + echo " Please check that \$INCLUDES is properly set." \ + >> genmake_tnc.log + fi + echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log + echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log + $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=$? - test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1 - RETVAL=$? - if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + cat genmake_tnc.log >> $LOGFILE + + #EH3 Remove test program execution for machines that either disallow + #EH3 execution or cannot support it (eg. cross-compilers) + #EH3 + #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1 + #EH3 RETVAL=$? + #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + + if test "x$RET_COMPILE" = x0 ; then HAVE_NETCDF=t + echo "check_netcdf: successful" >> $LOGFILE else # try again with "-lnetcdf" added to the libs - $CPP genmake_tnc.F > genmake_tnc.f \ - && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \ - $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1 + 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 + cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \ + && $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=$? - test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1 - RETVAL=$? - if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + 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 - cat genmake_tnc.log >> genmake_warnings + # try again with "-lnetcdff" added to the libs + 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 + cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \ + && $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=$? + 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 ############################################################################### @@ -504,38 +1047,61 @@ LN= S64= KPP= -FC= -CPP= +#FC= +#CC=gcc +#CPP= LINK= DEFINES= PACKAGES= ENABLE= DISABLE= -MAKEFILE= -MAKEDEPEND= -PDEPEND= -DUMPSTATE=t -PDEFAULT= +# MAKEFILE= +# MAKEDEPEND= +PKG_DEPEND= +PKG_GROUPS= +DUMPSTATE=f OPTFILE= -INCLUDES="-I." +INCLUDES="-I. $INCLUDES" FFLAGS= FOPTIM= +FEXTRAFLAGS= +USE_EXTENDED_SRC= +EXTENDED_SRC_FLAG= +GET_FC_VERSION= CFLAGS= KFLAGS1= KFLAGS2= +#LDADD= LIBS= KPPFILES= NOOPTFILES= NOOPTFLAGS= MPI= MPIPATH= +OMP= +OMPFLAG= +USE_R4= +TS= +PAPIS= +PCLS= +FOOLAD= +PAPI= +PCL= +HPMT= +GSL= +DEVEL= +HAVE_TEST_L= -# DEFINES checked by test compilation +# DEFINES checked by test compilation or command-line HAVE_SYSTEM= HAVE_FDATE= FC_NAMEMANGLE= HAVE_CLOC= +# HAVE_SETRLSTK= +HAVE_STAT= HAVE_NETCDF= +HAVE_ETIME= +IGNORE_TIME= MODS= TOOLSDIR= @@ -543,12 +1109,17 @@ INCLUDEDIRS= STANDARDDIRS="USE_THE_DEFAULT" +G2ARGS= +BASH= PWD=`pwd` -MAKE=make -AWK=awk -THISHOSTNAME=`hostname` +test "x$MAKE" = x && MAKE=make +test "x$AWK" = x && AWK=awk +EMBED_SRC= +THISHOST=`hostname` THISCWD=`pwd` THISDATE=`date` +THISUSER=`echo $USER` +THISVER= MACHINE=`uname -a` EXECUTABLE= EXEHOOK= @@ -558,6 +1129,8 @@ if test "x$MITGCM_IEEE" != x ; then IEEE=$MITGCM_IEEE fi +FS= +FS90= AUTODIFF_PKG_USED=f AD_OPTFILE= @@ -572,17 +1145,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 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 " -gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS" -gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE 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" +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" @@ -596,23 +1168,21 @@ 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" -for i in . $MODS ; do - if test -r $i/$gm_local ; then - . $i/$gm_local - break - fi -done -echo -n " getting local config information: " -if test -e $gm_local ; then +printf " getting local config information: " +if test -f $gm_local ; then echo "using $gm_local" . $gm_local # echo "DISABLE=$DISABLE" @@ -621,19 +1191,12 @@ echo "none found" 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 +#echo "$0::$1:$2:$3:$4:$5:$6:$7:" #parse_options ac_prev= -for ac_option ; do +for ac_option in "$@" ; do + + G2ARGS="$G2ARGS \"$ac_option\"" # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then @@ -641,9 +1204,9 @@ ac_prev= continue fi - + ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` - + case $ac_option in -help | --help | -h | --h) @@ -662,20 +1225,30 @@ 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 ;; -make=* | --make=* | -m=* | --m=*) MAKE=$ac_optarg ;; + -bash | --bash) + ac_prev=BASH ;; + -bash=* | --bash=*) + BASH=$ac_optarg ;; + + -makedepend | --makedepend | -md | --md) + ac_prev=MAKEDEPEND ;; + -makedepend=* | --makedepend=* | -md=* | --md=*) + MAKEDEPEND=$ac_optarg ;; + -makefile | --makefile | -ma | --ma) ac_prev=MAKEFILE ;; -makefile=* | --makefile=* | -ma=* | --ma=*) @@ -717,27 +1290,67 @@ # ac_prev=cpp ;; # -cpp=* | --cpp=*) # CPP=$ac_optarg ;; - + + -cc | --cc) + ac_prev=CC ;; + -cc=* | --cc=*) + CC=$ac_optarg ;; + -fortran | --fortran | -fc | --fc) ac_prev=FC ;; -fc=* | --fc=*) FC=$ac_optarg ;; + -fs | --fs) + ac_prev=FS ;; + -fs=* | --fs=*) + FS=$ac_optarg ;; + + -fs90 | --fs90) + ac_prev=FS90 ;; + -fs90=* | --fs90=*) + FS90=$ac_optarg ;; + -ieee | --ieee) IEEE=true ;; -noieee | --noieee) IEEE= ;; + -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 ) + USE_R4=true ;; + + -ts | --ts) + TS=true ;; + -papis | --papis) + PAPIS=true ;; + -pcls | --pcls) + PCLS=true ;; + -foolad | --foolad) + FOOLAD=true ;; + -papi | --papi) + PAPI=true ;; + -pcl | --pcl) + PCL=true ;; + -hpmt | --hpmt) + HPMT=true ;; + + -gsl | --gsl) + GSL=true ;; + + -devel | --devel) + DEVEL=true ;; + -mpi | --mpi) MPI=true ;; -mpi=* | --mpi=*) 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 ;; @@ -751,6 +1364,12 @@ ac_prev=TAMC_EXTRA ;; -tamc_extra=* | --tamc_extra=*) TAMC_EXTRA=$ac_optarg ;; + + -ignoretime | -ignore_time | --ignoretime | --ignore_time) + IGNORE_TIME="-DIGNORE_TIME" ;; + + -es | --es | -embed-source | --embed-source) + EMBED_SRC=t ;; -*) echo "Error: unrecognized option: "$ac_option @@ -763,30 +1382,31 @@ ;; esac - + done if test -f ./.genmakerc ; then echo echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\"" - echo " file. This file format is no longer supported. Please see:" - echo + echo " file. This file format is no longer supported. For directions on" + echo " how to setup and use the new \"genmake2\" script, please see:" 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 " for directions on how to setup and use the new \"genmake2\" input" - echo " files and send an email to MITgcm-support@mitgcm.org if you want help." - echo fi +# Find the MITgcm ${ROOTDIR} if test "x${ROOTDIR}" = x ; then - if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then + tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'` + if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then ROOTDIR=".." else for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then ROOTDIR=$d - echo -n "Warning: ROOTDIR was not specified but there appears to be" - echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it." + printf "Warning: ROOTDIR was not specified ;" + echo " try using a local copy of MITgcm found at \"$ROOTDIR\"" break fi done @@ -803,12 +1423,27 @@ exit 1 fi +# Find the MITgcm ${THISVER} +version_file="${ROOTDIR}/doc/tag-index" +if test -f $version_file ; then + 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})" + rm -f ./BUILD_INFO.h + fi +fi + +if test "x$MAKEFILE" = x ; then + MAKEFILE="Makefile" +fi + echo " getting OPTFILE information: " if test "x${OPTFILE}" = x ; then if test "x$MITGCM_OF" = x ; then 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 @@ -819,11 +1454,11 @@ . "$OPTFILE" RETVAL=$? if test "x$RETVAL" != x0 ; then - echo -n "Error: failed to source OPTFILE \"$OPTFILE\"" + printf "Error: failed to source OPTFILE \"$OPTFILE\"" echo "--please check that variable syntax is bash-compatible" exit 1 fi - if test "x$DUMPSTATE" != xf ; then + if test "x$DUMPSTATE" = xt ; then cp -f $OPTFILE "genmake_optfile" fi else @@ -846,11 +1481,11 @@ . "$AD_OPTFILE" RETVAL=$? if test "x$RETVAL" != x0 ; then - echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\"" + printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\"" echo "--please check that variable syntax is bash-compatible" exit 1 fi - if test "x$DUMPSTATE" != xf ; then + if test "x$DUMPSTATE" = xt ; then cp -f $AD_OPTFILE "genmake_ad_optfile" fi else @@ -859,8 +1494,15 @@ fi fi -# Check that FC, LINK, CPP, S64, LN, and MAKE are defined. If not, +#==================================================================== +# Set default values if not set by the optfile +# +# Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not, # either set defaults or complain and abort! +if test ! "x$BASH" = x ; then + # add a trailing space so that it works within the Makefile syntax (see below) + BASH="$BASH " +fi if test "x$FC" = x ; then cat <&2 @@ -871,6 +1513,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 + look_for_C_compilers +fi + if test "x$LINK" = x ; then LINK=$FC fi @@ -878,11 +1530,11 @@ MAKE="make" fi if test "x$CPP" = x ; then - CPP=cpp + CPP="cpp -traditional -P" fi #EH3 === UGLY === -# The following an ugly little hack to check for $CPP in /lib/ and it -# should eventually be replaced with a more general function that +# The following is an ugly little hack to check for $CPP in /lib/ and +# it should eventually be replaced with a more general function that # searches a combo of the user's path and a list of "usual suspects" # to find the correct location for binaries such as $CPP. for i in " " "/lib/" ; do @@ -905,9 +1557,10 @@ else rm -f test_cpp fi -if test "x$MAKEDEPEND" = x ; then - MAKEDEPEND=makedepend -fi + +look_for_makedepend + +# Check that soft-link command is set and usable if test "x$LN" = x ; then LN="ln -s" fi @@ -917,27 +1570,132 @@ 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 exit 1 fi +test -L genmake_tlink > /dev/null 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + HAVE_TEST_L=t +fi rm -f genmake_test_ln genmake_tlink +# Check for broken *.F/*.f handling and fix if possible +check_for_broken_Ff + if test ! "x$MPI" = x ; then echo " Turning on MPI cpp macros" - DEFINES="$DEFINS -DALLOW_USE_MPI -DALWAYS_USE_MPI" + 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" + if test ! "x$FOOLAD" = x ; then + DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP" + else + DEFINES="$DEFINES -DTIME_PER_TIMESTEP" + fi + PACKAGES="$PACKAGES showflops" +fi +if test ! "x$PAPIS" = x ; then + echo " Turning on PAPI flop summary per timestep" + echo " Please make sure PAPIINC, PAPILIB are defined" + if test ! "x$FOOLAD" = x ; then + DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP" + else + DEFINES="$DEFINES -DUSE_PAPI_FLOPS" + fi + INCLUDES="$INCLUDES $PAPIINC" + LIBS="$LIBS $PAPILIB" + PACKAGES="$PACKAGES showflops" +fi +if test ! "x$PCLS" = x ; then + echo " Turning on PCL counter summary per timestep" + echo " Please make sure PCLINC, PCLLIB are defined" + if test ! "x$FOOLAD" = x ; then + DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP" + else + DEFINES="$DEFINES -DUSE_PCL_FLOPS" + fi + INCLUDES="$INCLUDES $PCLINC" + LIBS="$LIBS $PCLLIB" + PACKAGES="$PACKAGES showflops" +fi +if test ! "x$PAPI" = x ; then + if test ! "x$PAPIS" = x ; then + echo " PAPI performance analysis and flop summary per timestep cannot co-exist!" + echo " Sticking with PAPI flop summary per timestep!" + else + echo " Turning on performance analysis with PAPI" + echo " Please make sure PAPIINC, PAPILIB are defined" + DEFINES="$DEFINES -DUSE_PAPI" + INCLUDES="$INCLUDES $PAPIINC" + LIBS="$LIBS $PAPILIB" + fi +fi +if test ! "x$PCL" = x ; then + if test ! "x$PCLS" = x ; then + echo " PCL performance analysis and flop summary per timestep cannot co-exist!" + echo " Sticking with PCL flop summary per timestep!" + else + echo " Turning on performance analysis with PCL" + echo " Please make sure PCLINC, PCLLIB are defined" + DEFINES="$DEFINES -DUSE_PCL" + INCLUDES="$INCLUDES $PCLINC" + LIBS="$LIBS $PCLLIB" + fi +fi +if test ! "x$HPMT" = x ; then + if test ! "x$PAPI" = x ; then + echo " PAPI and the HPM Toolkit cannot co-exist!" + echo " Sticking with PAPI!" + else if test ! "x$PCL" = x ; then + echo " PCL and the HPM Toolkit cannot co-exist!" + echo " Sticking with PCL!" + else + echo " Turning on performance analysis with the HPM Toolkit" + echo " Please make sure HPMTINC, HPMTLIB are defined" + DEFINES="$DEFINES -DUSE_LIBHPM" + INCLUDES="$INCLUDES $HPMTINC" + LIBS="$LIBS $HPMTLIB" + fi + fi +fi +if test ! "x$GSL" = x ; then + echo " Turning on use of GSL to control floating point calculations" + echo " Please make sure GSLINC, GSLLIB are defined" + DEFINES="$DEFINES -DUSE_GSL_IEEE" + INCLUDES="$INCLUDES $GSLINC" + LIBS="$LIBS $GSLLIB" +fi +#- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS : +if test ! "x$USE_EXTENDED_SRC" = x ; then + FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG" + F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG" fi printf "\n=== Checking system libraries ===\n" -echo -n " Do we have the system() command using $FC... " -cat > genmake_tcomp.f < genmake_tcomp.$FS < genmake_tcomp.log 2>&1 +$FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_SYSTEM=t @@ -949,69 +1707,128 @@ fi rm -f genmake_tcomp* -echo -n " Do we have the fdate() command using $FC... " -cat > genmake_tcomp.f < genmake_tcomp.$FS < genmake_tcomp.log 2>&1 +$FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_FDATE=t DEFINES="$DEFINES -DHAVE_FDATE" echo "yes" else - HAVE_FDATE= + HAVE_FDATE= + echo "no" +fi +rm -f genmake_tcomp* + +printf " Do we have the etime() command using $FC... " +cat > genmake_tcomp.$FS < genmake_tcomp.log 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + HAVE_ETIME=t + DEFINES="$DEFINES -DHAVE_ETIME" + echo "yes" +else + HAVE_ETIME= + echo "no" +fi +rm -f genmake_tcomp* + +printf " Can we call simple C routines (here, \"cloc()\") using $FC... " +check_HAVE_CLOC +if test "x$HAVE_CLOC" != x ; then + echo "yes" +else + echo "no" + if test "x$EMBED_SRC" = xt ; then + echo " WARNING: you requested file embedding but it has" + echo " been disabled since C code cannot be called" + EMBED_SRC= + fi +fi +rm -f genmake_t* + +printf " Can we unlimit the stack size using $FC... " +check_HAVE_SETRLSTK +if test "x$HAVE_SETRLSTK" = xt ; then + echo "yes" +else + echo "no" +fi +rm -f genmake_t* + +printf " Can we register a signal handler using $FC... " +check_HAVE_SIGREG +if test "x$HAVE_SIGREG" = xt ; then + echo "yes" +else echo "no" fi -rm -f genmake_tcomp* +rm -f genmake_t* -echo -n " Can we call simple C routines (here, \"cloc()\") using $FC... " -check_HAVE_CLOC -if test "x$HAVE_CLOC" != x ; then +printf " Can we use stat() through C calls... " +check_HAVE_STAT +if test "x$HAVE_STAT" != x ; then echo "yes" else echo "no" fi rm -f genmake_t* -echo -n " Can we create NetCDF-enabled binaries... " +printf " Can we create NetCDF-enabled binaries... " check_netcdf_libs if test "x$HAVE_NETCDF" != x ; then echo "yes" else echo "no" fi +DEFINES="$DEFINES $IGNORE_TIME" +if test "x$EMBED_SRC" = xt ; then + build_embed_encode +fi +if test "x$EMBED_SRC" = xt ; then + ENABLE="$ENABLE embed_files" +fi printf "\n=== Setting defaults ===\n" -echo -n " Adding MODS directories: " +printf " Adding MODS directories: " for d in $MODS ; do if test ! -d $d ; then echo echo "Error: MODS directory \"$d\" not found!" exit 1 else - echo -n " $d" + printf "$d " SOURCEDIRS="$SOURCEDIRS $d" INCLUDEDIRS="$INCLUDEDIRS $d" fi done echo -if test "x$MAKEFILE" = x ; then - MAKEFILE="Makefile" -fi -if test "x${PLATFORM}" = x ; then - PLATFORM=$p_PLATFORM -fi +#if test "x${PLATFORM}" = x ; then +# PLATFORM=$p_PLATFORM +#fi if test "x${EXEDIR}" = x ; then - if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then + tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'` + if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then EXEDIR=../exe else EXEDIR=. @@ -1030,18 +1847,55 @@ exit 1 fi if test "x$S64" = x ; then - S64='$(TOOLSDIR)/set64bitConst.sh' + echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + S64='$(TOOLSDIR)/set64bitConst.sh' + else + echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + S64='$(TOOLSDIR)/set64bitConst.csh' + else + cat < /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 @@ -1052,89 +1906,111 @@ fi fi -#same for exch2 -if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then - echo " Making source files in exch2 from templates" - ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1 - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - rm -f make_exch2.errors - else - echo "Error: problem encountered while building source files in exch2:" - cat make_exch2.errors 1>&2 - exit 1 +#same for pkg/exch2 and pkg/regrid +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 clean_old && $MAKE \ + ) > make_${pdir}.errors 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + rm -f make_${pdir}.errors + else + echo "Error: problem encountered while building source files in pkg/${pdir}:" + cat make_${pdir}.errors 1>&2 + exit 1 + fi fi -fi +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 - echo -n "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" - expand_pkg_groups - 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 +for i in `grep "-" ./.tmp_pack` ; do + j=`echo $i | sed 's/[-]//'` + DISABLE="$DISABLE $j" +done pack= for p in $PACKAGES ; do addit="t" @@ -1151,28 +2027,97 @@ echo " applying ENABLE settings" echo "" > ./.tmp_pack PACKAGES="$PACKAGES $ENABLE" +# Test if each explicitly referenced package exists for i in $PACKAGES ; do - if test ! -d "$ROOTDIR/pkg/$i" ; then - echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\"" - exit 1 + j=`echo $i | sed 's/[-+]//'` + if test ! -d "$ROOTDIR/pkg/$j" ; then + echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'" + exit 1 fi echo $i >> ./.tmp_pack done -pack=`cat ./.tmp_pack | sort | uniq` -rm -f ./.tmp_pack PACKAGES= -for i in $pack ; do +for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do PACKAGES="$PACKAGES $i" done -echo " packages are: $PACKAGES" +rm -f ./.tmp_pack +echo " packages are: $PACKAGES" + +# 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 +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 + 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 + DISABLE="$DISABLE mnc" + fi + fi +fi + +# Check for package PROFILES: if NetCDF is not available, +# then delete profiles from the list of available packages. +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 2>&1 -RETVAL=$? -if test "x$RETVAL" = x0 ; then - ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1 - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - rm -f make_mnc.errors - else - echo "Error: problem encountered while building source files in pkg/mnc:" - cat make_mnc.errors 1>&2 - exit 1 - fi - if test "x$HAVE_NETCDF" != xt ; then - cat </dev/null )` for j in $list_files ; do - cat $i/$j >> ad_files + cat $i/$j >> adSrcFiles.tmp 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 +fi echo echo "=== Creating the Makefile ===" echo " setting INCLUDES" for i in $INCLUDEDIRS ; do - if ! test -d $i ; then -# INCLUDES="$INCLUDES -I$i" -# else + if test ! -d $i ; then echo "Warning: can't find INCLUDEDIRS=\"$i\"" fi done +if test ! "x$DIVA" = x ; then + echo " Creating the pseudo-MPI include directory" + INCLUDES="-I./mpi_headers $INCLUDES" + rm -rf ./mpi_headers + mkdir -p ./mpi_headers + + if test "x$MPIINCLUDEDIR" = x ; then + if test "x$MPIHOME" = x ; then + MPIHOME='/usr' + fi + MPIINCLUDEDIR='$MPIHOME/include' + fi + + if test -r $MPIINCLUDEDIR/mpif.h ; then + for i in $MPI_HEADER_FILES; do + cp -p $MPIINCLUDEDIR/$i ./mpi_headers + done + + perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h + else + echo " We cannot create a copy of mpif.h!" +# exit -1 + fi +fi + echo " Determining the list of source and include files" rm -rf .links.tmp mkdir .links.tmp +touch .links.tmp/foo +if test ! -r ".links.tmp/foo" ; then + echo + echo "ERROR : something is wrong with your directory permissions or" + echo " your user file-creation mask (\"umask\") since creating a" + echo " sub-dir, touch-ing a file within it, and then reading it is" + echo " not working. Please try setting your umask to something" + echo " sane such as:" + echo + echo " umask 0002" + echo + echo " and please verify that you have the proper permissions for" + echo " creating sub-directories and then reading files created" + echo " within them." + echo + exit 1 +fi +rm -f .links.tmp/foo + +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" + echo " looking for dontCompile file: " + for i in "." $MODS ; do + if test -r $i"/dontCompile" ; then + OAD_DONT_COMPILE=$i"/dontCompile" + echo " found $OAD_DONT_COMPILE" + break + fi + done + echo " looking for dontTransform file: " + for i in "." $MODS ; do + if test -r $i"/dontTransform" ; then + OAD_DONT_TRANSFORM=$i"/dontTransform" + echo " found $OAD_DONT_TRANSFORM" + break + fi + done + echo " looking for keepOriginal file: " + for i in "." $MODS ; do + if test -r $i"/keepOriginal" ; then + OAD_KEEP_ORIGINAL=$i"/keepOriginal" + echo " found $OAD_KEEP_ORIGINAL" + break + fi + done + echo " looking for cb2mFiles: " + for i in "." $MODS ; do + if test -r $i"/cb2mFiles" ; then + OAD_CB2M_FILES=$i"/cb2mFiles" + echo " found $OAD_CB2M_FILES" + break + fi + done + echo " OpenAD exceptions: " +fi + echo "# This section creates symbolic links" > srclinks.tmp echo "" >> srclinks.tmp -echo -n 'SRCFILES = ' > srclist.inc -echo -n 'CSRCFILES = ' > csrclist.inc -echo -n 'F90SRCFILES = ' > f90srclist.inc -echo -n 'HEADERFILES = ' > hlist.inc -echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc +printf '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 alldirs="$SOURCEDIRS $INCLUDEDIRS ." for d in $alldirs ; do deplist= sfiles=`( cd $d; echo *.[h,c,F] *.flow )` sfiles=`( echo $sfiles; cd $d; echo *.F90 )` + if test "x$OPENAD" != x ; then + sfiles=`( echo $sfiles | grep -v _cb2m\. )` + fi for sf in $sfiles ; do if test ! -r ".links.tmp/$sf" ; then if test -f "$d/$sf" ; then + ignore_f=f case $d/$sf in ./$PACKAGES_DOT_H) + ignore_f=t ;; ./AD_CONFIG.h) + ignore_f=t ;; ./FC_NAMEMANGLE.h) + ignore_f=t + ;; + ./BUILD_INFO.h) + ignore_f=t + ;; + ./EMBEDDED_FILES.h) + ignore_f=t ;; *) - touch .links.tmp/$sf - deplist="$deplist $sf" + # For the local directory *ONLY*, + # ignore all soft-links + if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then + ignore_f=t + else + touch .links.tmp/$sf + deplist="$deplist $sf" + fi ;; esac - extn=`echo $sf | $AWK -F '.' '{print $NF}'` - case $extn in - F) - echo " \\" >> srclist.inc - echo -n " $sf" >> srclist.inc + 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 + basename=${sf%%.F} + isAD=`egrep ^$basename.f'[ ]*' adSrcFiles.tmp` + if test -z "$isAD" ; then + toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE}` + if test -z "$toBeIgnored" ; then + echo " \\" >> nonADF77srclist.tmp + printf " $sf" >> nonADF77srclist.tmp + else + echo " not to be compiled : $sf" + fi + 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 + echo " not to be transformed: $sf" + fi + if test -n "$untransformedVersionToBeKept" ; then + echo " original to be kept : $sf" + fi + if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then + echo " \\" >> nonADF77srclist.tmp + printf " $sf" >> nonADF77srclist.tmp + fi + fi + fi ;; F90) - echo " \\" >> f90srclist.inc - echo -n " $sf" >> f90srclist.inc + echo " \\" >> F90srclist.tmp + printf " $sf" >> F90srclist.tmp ;; c) - echo " \\" >> csrclist.inc - echo -n " $sf" >> csrclist.inc + echo " \\" >> csrclist.tmp + printf " $sf" >> csrclist.tmp ;; h) - echo " \\" >> hlist.inc - echo -n " $sf" >> hlist.inc + echo " \\" >> hsrclist.tmp + printf " $sf" >> hsrclist.tmp ;; - flow) - echo " \\" >> ad_flow_files.inc - echo -n " $sf" >> ad_flow_files.inc + flow) + echo " \\" >> ad_flow_files.tmp + printf " $sf" >> ad_flow_files.tmp ;; - esac + esac + fi fi fi done if test "x$deplist" != x ; then - echo "" >> srclinks.tmp + if test "$d" != "." ; then + echo "" >> srclinks.tmp echo "# These files are linked from $d" >> srclinks.tmp echo "$deplist :" >> srclinks.tmp - printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp +# 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 + fi fi done rm -rf .links.tmp -echo "" >> srclist.inc -echo "" >> csrclist.inc -echo "" >> f90srclist.inc -echo "" >> hlist.inc -echo "" >> ad_flow_files.inc +echo "" >> F77srclist.tmp +echo "" >> nonADF77srclist.tmp +echo "" >> csrclist.tmp +echo "" >> F90srclist.tmp +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 -e $MAKEFILE ; then - mv -f $MAKEFILE "$MAKEFILE.bak" +if test -f $MAKEFILE ; then + mv -f $MAKEFILE "$MAKEFILE.old" fi echo " Writing makefile: $MAKEFILE" echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE @@ -1478,9 +2547,9 @@ echo "# This makefile was generated automatically on" >> $MAKEFILE echo "# $THISDATE" >> $MAKEFILE echo "# by the command:" >> $MAKEFILE -echo "# $0 $@" >> $MAKEFILE +echo "# $CMDLINE" >> $MAKEFILE echo "# executed by:" >> $MAKEFILE -echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE +echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE EXE_AD=$EXECUTABLE"_ad" EXE_FTL=$EXECUTABLE"_ftl" @@ -1489,7 +2558,7 @@ cat >>$MAKEFILE <>$MAKEFILE +else + echo "EMBEDDED_FILES = " >>$MAKEFILE +fi + cat >>$MAKEFILE <> $MAKEFILE -cat csrclist.inc >> $MAKEFILE -cat f90srclist.inc >> $MAKEFILE -cat hlist.inc >> $MAKEFILE -cat ad_flow_files.inc >> $MAKEFILE -echo >> $MAKEFILE -echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE -echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE -echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE +cat F77srclist.tmp >> $MAKEFILE +cat nonADF77srclist.tmp >> $MAKEFILE +cat csrclist.tmp >> $MAKEFILE +cat F90srclist.tmp >> $MAKEFILE +cat hsrclist.tmp >> $MAKEFILE +cat ad_flow_files.tmp >> $MAKEFILE -rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc -rm -f ad_flow_files.inc +rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp -cat >>$MAKEFILE <> $MAKEFILE -.SUFFIXES: -.SUFFIXES: .o .f .p .F .c .F90 .f90 +# add definitions for preprocessed sources +# and note that not all systems allow case sensitive extensions +# hence the $FS and $FS90 here. +# for fixed format f90 files we use ff90 or FF90 resp +# but these are not expected to be the original source files + +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 >> $MAKEFILE +echo '.SUFFIXES:' >> $MAKEFILE +echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE + +cat >>$MAKEFILE <> \$(MAKEFILE) + -rm -f makedepend.out + +lib: libmitgcmuv.a + +libmitgcmuv.a: \$(OBJFILES) + ar rcv libmitgcmuv.a \$(OBJFILES) + ar d libmitgcmuv.a main.o -links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES) +links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES) -small_f: \$(F77FILES) \$(F90FILES) +small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES) output.txt: \$(EXECUTABLE) @printf 'running ... ' @\$(EXECUTABLE) > \$@ +# remove most of the files that "make" generates clean: - -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} *.template + -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template + -rm -rf *.o + -rm -rf *.$FS *.flowdir + -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input* + +# remove most of the files that "make" and "make depend" generate Clean: @make clean @make cleanlinks - -rm -f \$(SPECIAL_FILES) - -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak + -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 + +# remove also the executable, files that "genmake2" generates (except Makefile) +# and output from a run (plus log files from testreport) CLEAN: @make Clean + -rm -f \$(EXECUTABLE) \$(EXE_AD) *.bak + -rm -f $LOGFILE genmake_state genmake_*optfile + -rm -f SIZE.h.mpi genmake.tr_log make.tr_log -find \$(EXEDIR) -name "*.meta" -exec rm {} \; -find \$(EXEDIR) -name "*.data" -exec rm {} \; -find \$(EXEDIR) -name "fort.*" -exec rm {} \; - -rm -f \$(EXECUTABLE) output.txt + -rm -f *.txt STD* *diagnostics.log datetime + -rm -f *_MIT_CE_000.opt0000 costfunction*0000 + -rm -rf mnc_test_* -#eh3 Makefile: makefile makefile: - $THIS_SCRIPT $@ + $THIS_SCRIPT $G2ARGS cleanlinks: -find . -type l -exec rm {} \; -# Special targets ($SPECIAL_FILES) which are create by make +# Special targets (SPECIAL_FILES) which are created by make ${PACKAGES_DOT_H}: @echo Creating \$@ ... - @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@ + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@ AD_CONFIG.h: @echo Creating \$@ ... - @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > \$@ + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > \$@ FC_NAMEMANGLE.h: @echo Creating \$@ ... echo "$FC_NAMEMANGLE" > \$@ -# The normal chain of rules is ( .F - .f - .o ) -.F.f: +BUILD_INFO.h: + @echo Creating \$@ ... +EOF + +test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE +test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE +test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE +test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE + +if test "x$EMBED_SRC" = xt ; then + cat >>$MAKEFILE <>$MAKEFILE < \$@ -.f.o: +.$FS.o: + \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< +.F.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< -.F90.f90: +.F90.$FS90: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.f90.o: +.FF90.f$FS90: + \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ +.$FS90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< +.f$FS90.o: + cp \$< \$(basename \$<).f90 + \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename \$<).f90 .c.o: - \$(CC) \$(CFLAGS) -c \$< + \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$< +.flow.flowdir: + \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -# Special exceptions that use the ( .F - .p - .f - .o ) rule-chain +# Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain .F.p: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.p.f: +.p.$FS: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< +EOF + #========================================= #=== Automatic Differentiation Rules === +#=== for TAMC/TAF ====================== + +if test "x$OPENAD" = x ; then + +cat >>$MAKEFILE <> $MAKEFILE done echo " Add the source list for AD code generation" echo >> $MAKEFILE -echo -n "AD_FILES = " >> $MAKEFILE -AD_FILES=`cat ad_files` +printf "AD_FILES = " >> $MAKEFILE +AD_FILES=`cat adSrcFiles.tmp` for i in $AD_FILES ; do echo " \\" >> $MAKEFILE - echo -n " $i" >> $MAKEFILE + printf " $i" >> $MAKEFILE done echo >> $MAKEFILE -rm -f ad_files +rm -f adSrcFiles.tmp cat >>$MAKEFILE < ad_config.template +ad_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES) \$(AD_FLOW_FILES) + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ad_config.template cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h -rm -f ad_config.template - @make \$(F77FILES) - @make \$(AD_FLOW_FILES) - cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f - -ad_taf_output.f: ad_input_code.f - \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f - cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f + @make \$(F77_PP_SRC_FILES) + @make \$(FLOFILES) + 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 + ls -l ad_input_code_ad.$FS + cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS adtafonly: - \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f - cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f - -ad_taf: ad_taf_output.o \$(OBJFILES) - \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) - -ad_tamc_output.f: ad_input_code.f - \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f - cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f + \$(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 + +\${EXE_AD}: ad_taf_output.o \$(OBJFILES) + \$(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 # ... FTL ... ftlall: ftl_taf -ftltaf: ftl_taf_output.f -ftltamc: ftl_tamc_output.f +ftltaf: ftl_taf_output.$FS +ftltamc: ftl_tamc_output.$FS -ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES) - @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template +ftl_input_code.$FS: \$(AD_FILES) \$(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 \$(F77FILES) + @make \$(F77_PP_SRC_FILES) @make \$(AD_FLOW_FILES) - cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f + cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS -ftl_taf_output.f: ftl_input_code.f - \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f - cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f +ftl_taf_output.$FS: ftl_input_code.$FS + \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS + ls -l ftl_input_code_ftl.$FS + cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS ftltafonly: - \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f - cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f + \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS + ls -l ftl_input_code_ftl.$FS + cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS ftl_taf: ftl_taf_output.o \$(OBJFILES) - \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS) + \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS) -ftl_tamc_output.f: ftl_input_code.f - \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f - cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f +ftl_tamc_output.$FS: ftl_input_code.$FS + \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS + cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS ftl_tamc: ftl_tamc_output.o \$(OBJFILES) - \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS) - + \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS) # ... SVD ... -svdtaf: ad_taf_output.f ftl_taf_output.f -svdall: svd_taf +svdtaf: ad_taf_output.$FS ftl_taf_output.$FS + @echo "--->>> Only ran TAF to generate SVD code! <<<---" + @echo "--->>> Do make svdall afterwards to compile. <<<---" +svdall: svd_touch svd_taf -svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES) +svd_taf: \$(OBJFILES) \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS) + @echo "--->>> Only COMPILE svd code! <<<---" + @echo "--->>> Assumes you previously <<<---" + @echo "--->>> did make svdtaf <<<---" + +svd_touch: + @echo "--->>> Only COMPILE svd code! <<<---" + @echo "--->>> Assumes you previously <<<---" + @echo "--->>> did make svdtaf <<<---" + touch ad_taf_output.$FS ftl_taf_output.$FS + \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS + \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS + @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template + cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h + -rm -f ftl_config.template -#========================================= +EOF + +fi + +#=== for OpenAD ======================== + +if test "x$OPENAD" != x ; then + +# ============ begin OpenAD specific section ============== + +cat >>$MAKEFILE <> $MAKEFILE +printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE +for i in `cat ${OAD_CB2M_FILES}` ; do + echo " \\" >> $MAKEFILE + printf " $i" >> $MAKEFILE +done +echo >> $MAKEFILE + +echo " Add the source list for AD code generation" +echo >> $MAKEFILE +printf "AD_FILES = " >> $MAKEFILE +for i in `cat ${OAD_CB2M_FILES}` ; do + echo " \\" >> $MAKEFILE + printf " ${i}_mod.f$FS90" >> $MAKEFILE +done +AD_FILES=`cat adSrcFiles.tmp` +for i in $AD_FILES ; do + basename=${i%%.f} + toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}` + if test -z "$toBeIgnored" ; then + echo " \\" >> $MAKEFILE + printf " $i" >> $MAKEFILE + fi +done +echo >> $MAKEFILE +rm -f adSrcFiles.tmp + +cat >>$MAKEFILE <> \$(MAKEFILE) + -rm -f makedepend.out + +OPENAD_SUPPORT_F90_SRC_FILES = \ +w2f__types.F90 \ +OAD_active.F90 \ +OAD_cp.F90 \ +OAD_rev.F90 \ +OAD_tape.F90 + +OPENAD_SUPPORT_C_SRC_FILES = \ +iaddr.c \ +timeRatio.c + +f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90) + cat \$^ > \$@ + +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 + +# 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)) 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 + ../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} + +# makefile debug rule +small_f: \$(CB2M_F90_PP_SRC_FILES) +.PHONY: small_f + +ad_output.txt: \$(EXE_AD) + @printf 'linking data files ... ' + \$(LN) -f ../input_ad/data* ../input_ad/eedata . + \$(LN) -f ../../global_ocean.90x40x15/input/*.bin . + @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 \$@ + +# 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 \$@ + +# WHIRL -> XAIF +ad_input_code_sf.w2f.pre.xaif : ad_input_code_sf.w2f.pre.B whirl2xaif + ./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 + +# 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 \$< + +# 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 \$< + +# 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 \$< \$@ + +PPEXTRAS=\$(wildcard ../OAD_support/ad_template.*.F) ../OAD_support/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 + 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: + \$(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 \$@ + +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 +fi + +#========================================= + if test "x$EXEHOOK" != x ; then printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE fi @@ -1779,7 +3201,7 @@ if test "x$RETVAL" != x0 ; then echo "Error: unable to add file \"$i\" to the exceptions list" fi - echo "$base.f: $base.p" >> $MAKEFILE + echo "$base.$FS: $base.p" >> $MAKEFILE done echo " Making list of NOOPTFILES" @@ -1789,7 +3211,7 @@ if test "x$RETVAL" != x0 ; then echo "Error: unable to add file \"$i\" to the exceptions list" fi - echo "$base.o: $base.f" >> $MAKEFILE + echo "$base.o: $base.$FS" >> $MAKEFILE printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE done @@ -1803,7 +3225,7 @@ printf "\n=== Done ===\n" # Create special header files -$TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp" +$BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp" if test ! -f $PACKAGES_DOT_H ; then mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H else @@ -1817,13 +3239,12 @@ fi fi if test ! -f AD_CONFIG.h ; then - $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > AD_CONFIG.h + $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > AD_CONFIG.h fi - # Write the "state" for future records -if test "x$DUMPSTATE" != xf ; then - echo -n "" > genmake_state +if test "x$DUMPSTATE" = xt ; then + printf "" > genmake_state for i in $gm_state ; do t1="t2=\$$i" eval $t1