--- MITgcm/tools/genmake2 2006/10/23 19:40:43 1.156 +++ MITgcm/tools/genmake2 2008/11/06 11:56:20 1.175 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.156 2006/10/23 19:40:43 heimbach Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.175 2008/11/06 11:56:20 cnh Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -325,7 +325,7 @@ #================================================================ # look for possible C compilers - tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc" + tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc" p_CC= for c in $tmp ; do rm -f ./genmake_hello.c ./genmake_hello @@ -364,7 +364,7 @@ #================================================================ # look for possible FORTRAN compilers - tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran" + tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 gfortran g95" p_FC= for c in $tmp ; do rm -f ./hello.f ./hello @@ -601,6 +601,8 @@ -gsl | --gsl Use GSL to control floating point rounding and precision + -devel | --devel + Add additional warning and debugging flags for development -mpi | --mpi Include MPI header files and link to MPI libraries @@ -744,7 +746,9 @@ *curtim = *curtim/1.E6; } EOF - make genmake_tc_1.o >> genmake_warnings 2>&1 + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -754,7 +758,9 @@ print *," HELLO WORLD", wtime end EOF - $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1 + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 RET_F=$? test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1 RETVAL=$? @@ -801,7 +807,9 @@ return; } EOF - make genmake_tc_1.o >> genmake_warnings 2>&1 + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -849,7 +857,9 @@ return; } EOF - make genmake_tc_1.o >> genmake_warnings 2>&1 + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -893,7 +903,9 @@ *nbyte = -1; } EOF - make genmake_tc_1.o >> genmake_tc.log 2>&1 + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> genmake_warnings + $COMM >> genmake_tc.log 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -983,6 +995,21 @@ if test "x$RET_COMPILE" = x0 ; then LIBS="$LIBS -lnetcdf" HAVE_NETCDF=t + else + # 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=$? + cat genmake_tnc.log >> genmake_warnings + if test "x$RET_COMPILE" = x0 ; then + LIBS="$LIBS -lnetcdff -lnetcdf" + HAVE_NETCDF=t + fi fi fi rm -f genmake_tnc* @@ -1018,6 +1045,7 @@ INCLUDES="-I. $INCLUDES" FFLAGS= FOPTIM= +FEXTRAFLAGS= CFLAGS= KFLAGS1= KFLAGS2= @@ -1036,6 +1064,7 @@ PCL= HPMT= GSL= +DEVEL= HAVE_TEST_L= # DEFINES checked by test compilation or command-line @@ -1094,10 +1123,10 @@ # The following state can be set directly by command-line switches gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE" -gm_s2="FC CPP IEEE TS PAPIS PCLS PAPI PCL HPMT GSL MPI JAM DUMPSTATE STANDARDDIRS" +gm_s2="FC CPP IEEE TS PAPIS PCLS PAPI PCL HPMT GSL DEVEL MPI JAM 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_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM FEXTRAFLAGS" gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS" gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE" gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF" @@ -1124,12 +1153,6 @@ 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 printf " getting local config information: " if test -f $gm_local ; then echo "using $gm_local" @@ -1292,6 +1315,9 @@ -gsl | --gsl) GSL=true ;; + -devel | --devel) + DEVEL=true ;; + -mpi | --mpi) MPI=true ;; -mpi=* | --mpi=*) @@ -1340,12 +1366,11 @@ 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 - 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 " and send an email to MITgcm-support@mitgcm.org if you need help." + echo "WARNING: ignore \"./.genmakerc\" and continue." echo fi @@ -1542,6 +1567,7 @@ 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" @@ -1553,6 +1579,7 @@ 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" @@ -1564,6 +1591,7 @@ fi INCLUDES="$INCLUDES $PCLINC" LIBS="$LIBS $PCLLIB" + PACKAGES="$PACKAGES showflops" fi if test ! "x$PAPI" = x ; then if test ! "x$PAPIS" = x ; then @@ -1943,8 +1971,8 @@ rm -f ./.tmp_pack echo " packages are: $PACKAGES" -# Check availability of NetCDF and then either build the MNC template -# files or delete mnc from the list of available 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 RETVAL=$? if test "x$RETVAL" = x0 ; then @@ -1978,13 +2006,38 @@ fi fi +# Check for package PROFILES: if NetCDF is not available, +# then delete profiles from the list of available packages. +echo $PACKAGES | grep ' profiles ' > /dev/null 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + if test "x$HAVE_NETCDF" != xt ; then + cat <> 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 done rm -rf .links.tmp @@ -2410,7 +2467,7 @@ KFLAGS1 = ${KFLAGS1} KFLAGS2 = ${KFLAGS2} # Optim./debug for FC -FFLAGS = ${FFLAGS} +FFLAGS = ${FFLAGS} ${FEXTRAFLAGS} FOPTIM = ${FOPTIM} # Optim./debug for FC F90FLAGS = ${F90FLAGS} @@ -2436,9 +2493,10 @@ echo 'F77FILES = $(SRCFILES:.F=.'$FS')' >> $MAKEFILE echo 'F90FILES = $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE +echo 'FLOFILES = $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE echo >> $MAKEFILE echo '.SUFFIXES:' >> $MAKEFILE -echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE +echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90 .flowdir .flow' >> $MAKEFILE rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc rm -f ad_flow_files.inc @@ -2458,6 +2516,7 @@ libmitgcmuv.a: \$(OBJFILES) ar rcv libmitgcmuv.a \$(OBJFILES) + ar d libmitgcmuv.a main.o links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES) @@ -2468,18 +2527,22 @@ @\$(EXECUTABLE) > \$@ clean: - -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template + -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template + -rm -rf *.o + -rm -rf *.$FS *.flowdir Clean: @make clean @make cleanlinks -rm -f \$(SPECIAL_FILES) - -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak + -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log f90mkdepend.log *.bak + -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log CLEAN: @make Clean -find \$(EXEDIR) -name "*.meta" -exec rm {} \; -find \$(EXEDIR) -name "*.data" -exec rm {} \; -find \$(EXEDIR) -name "fort.*" -exec rm {} \; -rm -f \$(EXECUTABLE) \$(EXE_AD) *.txt STD* *diagnostics.log datetime + -rm -f *_MIT_CE_000.opt0000 costfunction*0000 -rm -rf mnc_test_* #eh3 Makefile: makefile @@ -2538,12 +2601,14 @@ \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .$FS.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< -.F90.$FS90: - \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.$FS90.o: +.F.o: + \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< +.F90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .c.o: \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$< +.flow.flowdir: + \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain .F.p: @@ -2596,15 +2661,17 @@ 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.$FS + @make \$(FLOFILES) + cat \$(FLOFILES) \$(AD_FILES) > 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.$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) @@ -2638,10 +2705,12 @@ 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.$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)