--- MITgcm/tools/genmake2 2012/08/28 21:11:22 1.238 +++ MITgcm/tools/genmake2 2013/04/05 21:10:55 1.250 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.238 2012/08/28 21:11:22 jmc Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.250 2013/04/05 21:10:55 jmc Exp $ # $Name: $ # # Makefile generator for MITgcm UV codes @@ -174,28 +174,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,7 +193,7 @@ 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: " @@ -334,15 +324,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 @@ -353,7 +342,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 @@ -366,8 +355,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 @@ -383,22 +370,39 @@ stop end EOF - makedepend -f $MAKEFILE 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 @@ -917,9 +921,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) @@ -1102,6 +1106,45 @@ 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 @@ -1159,6 +1202,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= @@ -1170,6 +1216,7 @@ HAVE_ETIME= IGNORE_TIME= HAVE_LAPACK= +HAVE_FLUSH= MODS= TOOLSDIR= @@ -1223,9 +1270,9 @@ # The following state is not directly set by command-line switches 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 HAVE_LAPACK" +gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK" +gm_s7="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" @@ -1668,7 +1715,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" @@ -1893,8 +1942,17 @@ else echo "no" fi -DEFINES="$DEFINES $IGNORE_TIME" +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 @@ -2492,6 +2550,11 @@ OAD_DONT_TRANSFORM="/dev/null" OAD_KEEP_ORIGINAL="/dev/null" OAD_CB2M_FILES="/dev/null" + OADTOOLS="$TOOLSDIR/OAD_support" + test -f "oadtempflile" && \rm -f "oadtempflile" +cat >> "oadtempflile" <>$MAKEFILE <> \$(MAKEFILE) -rm -f makedepend.out @@ -2906,16 +2973,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: @@ -2924,11 +2994,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) \$< @@ -2986,7 +3056,7 @@ @-rm -f ad_config.template \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD) -ad_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES) \$(AD_FLOW_FILES) +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 @@ -3004,7 +3074,7 @@ 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) +\$(EXE_AD): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ad_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES) \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) ad_tamc_output.$FS: ad_input_code.$FS @@ -3034,7 +3104,7 @@ @-rm -f ad_config.template \$(MAKE) -f \$(MAKEFILE) \$(EXE_FTL) -ftl_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES) +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 @@ -3052,7 +3122,7 @@ ls -l ftl_input_code_ftl.$FS cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS -\${EXE_FTL}: ftl_taf_output.o \$(OBJFILES) +\$(EXE_FTL): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ftl_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES) \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS) ftl_tamc_output.$FS: ftl_input_code.$FS @@ -3168,7 +3238,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 \ @@ -3194,16 +3265,16 @@ \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS) # create sources files modules from header files containing common blocks -%_mod.FF90 : %.h ../OAD_support/cb2mGetModules.csh ../OAD_support/cb2mGetModules.awk - ../OAD_support/cb2mGetModules.csh $< ../OAD_support/cb2mGetModules.awk +%_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 ../OAD_support/cb2mGetHeaders.csh ../OAD_support/cb2mGetHeaders.awk - ../OAD_support/cb2mGetHeaders.csh $< ../OAD_support/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES) +%_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 ../OAD_support/cb2mUseModules.bash - ../OAD_support/cb2mUseModules.bash $< ${MPI} +%_cb2m.FF90 : %.F \${OADTOOLS}/cb2mUseModules.bash + \${OADTOOLS}/cb2mUseModules.bash $< ${MPI} # makefile debug rule small_f: \$(CB2M_F90_PP_SRC_FILES) @@ -3225,7 +3296,7 @@ # 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 ../OAD_support/stop2print.sed > ad_input_code_sf.pre.s2p.f90 + cat \$< | sed -f \${OADTOOLS}/stop2print.sed > ad_input_code_sf.pre.s2p.f90 # F -> WHIRL ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90 @@ -3248,13 +3319,13 @@ \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$< # insert template directives -ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.pre.s2p.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=\$(wildcard \${OADTOOLS}/ad_template.*.F) \${OADTOOLS}/ad_inline.F # postprocess F' 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 ../OAD_support/ad_inline.f \$< + \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i \${OADTOOLS}/ad_inline.f \$< # the target is a placeholder to trigger a single execution of the rule touch \$@ # put this so make knows about the postprocessing output @@ -3266,7 +3337,7 @@ # link the support files: \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES): - \$(LN) ../OAD_support/\$@ . + \$(LN) \${OADTOOLS}/\$@ . AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag \$(PPEXTRAS:.F=.f)