--- MITgcm/tools/genmake2 2012/09/06 22:54:19 1.239 +++ MITgcm/tools/genmake2 2013/01/24 19:07:04 1.248 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.239 2012/09/06 22:54:19 jmc Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.248 2013/01/24 19:07:04 jmc Exp $ # $Name: $ # # Makefile generator for MITgcm UV codes @@ -907,9 +907,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) @@ -1092,6 +1092,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 @@ -1149,6 +1188,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= @@ -1160,6 +1202,7 @@ HAVE_ETIME= IGNORE_TIME= HAVE_LAPACK= +HAVE_FLUSH= MODS= TOOLSDIR= @@ -1213,9 +1256,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" @@ -1659,6 +1702,8 @@ if test ! "x$MPI" = x ; then echo " Turning on MPI cpp macros" 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" @@ -1883,8 +1928,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 @@ -2482,6 +2536,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 @@ -2896,16 +2959,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: @@ -2914,11 +2980,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) \$< @@ -2976,7 +3042,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 @@ -2994,7 +3060,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 @@ -3024,7 +3090,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 @@ -3042,7 +3108,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 @@ -3184,16 +3250,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) @@ -3215,7 +3281,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 @@ -3238,13 +3304,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 @@ -3256,7 +3322,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)