--- MITgcm/tools/genmake2 2003/11/14 05:25:46 1.37 +++ MITgcm/tools/genmake2 2003/11/20 18:29:07 1.42 @@ -1,6 +1,6 @@ #!/bin/sh # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.37 2003/11/14 05:25:46 heimbach Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.42 2003/11/20 18:29:07 adcroft Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -76,17 +76,6 @@ PLATFORM=`echo $tmp3 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'` OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")` echo " The platform appears to be: $PLATFORM" -# if test "x$OFLIST" = x ; then -# echo " No pre-defined options files were found matching this platform" -# echo " but examples for other platforms can be found in:" -# echo " $ROOTDIR/tools/build_options" -# else -# echo " Options files (located in $ROOTDIR/tools/build_options) that" -# echo " may work with this machine are:" -# for i in $OFLIST ; do -# echo " $i" -# done -# fi echo "test" > test ln -s ./test link @@ -225,52 +214,94 @@ # Explain usage usage() { - echo - echo "Usage: "$0" [OPTIONS]" - echo " where [OPTIONS] can be:" - echo - echo " -help | --help | -h | --h" - echo " -nooptfile | --nooptfile" - echo " -optfile NAME | --optfile NAME | -of NAME | --of NAME" - echo " -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME" - echo " -pdepend NAME | --pdepend NAME" - echo " -pdepend=NAME | --pdepend=NAME" - echo " -pdefault NAME | --pdefault NAME" - echo " -pdefault=NAME | --pdefault=NAME" - echo " -make NAME | -m NAME" - echo " --make=NAME | -m=NAME" - echo " -makefile NAME | -mf NAME" - echo " --makefile=NAME | -mf=NAME" - echo " -platform NAME | --platform NAME | -pl NAME | --pl NAME" - echo " -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME" - echo " -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME" - echo " -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME" - echo " -mods NAME | --mods NAME | -mo NAME | --mo NAME" - echo " -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME" - echo " -disable NAME | --disable NAME" - echo " -disable=NAME | --disable=NAME" - echo " -enable NAME | --enable NAME" - echo " -enable=NAME | --enable=NAME" - echo " -standarddirs NAME | --standarddirs NAME" - echo " -standarddirs=NAME | --standarddirs=NAME" - echo " -noopt NAME | --noopt NAME" - echo " -noopt=NAME | --noopt=NAME" -# echo " -cpp NAME | --cpp NAME" -# echo " -cpp=NAME | --cpp=NAME" - echo " -fortran NAME | --fortran NAME | -fc NAME | --fc NAME" - echo " -fc=NAME | --fc=NAME" - echo " -[no]ieee | --[no]ieee" - echo " -[no]mpi | --[no]mpi" - echo " -[no]jam | --[no]jam" - echo - echo " and NAME is a string such as:" - echo - echo " --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'" - echo " -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'" - echo " -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'" - echo - echo " which, depending upon your shell, may need to be single-quoted" - echo " if it contains spaces, dashes, or other special characters." +cat < genmake_test.c < genmake_test.log 2>&1 + $MAKE genmake_test.o >> genmake_warnings 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then - cat genmake_test.log >> genmake_errors FC_NAMEMANGLE=$default_nm - echo - echo "WARNING: C test compile fails -- please see \"genmake_errors\"" - echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" - echo "WARNING: Please contact if you need help here." + cat <> genmake_errors + +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 tcall | cut -d ' ' -f 3` RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm - echo - echo "WARNING: The \"nm\" command failed." - echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" - echo "WARNING: Please contact if you need help here." + cat <> genmake_warnings + +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.log 2>&1 + $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then - cat genmake_tcomp.log >> genmake_errors FC_NAMEMANGLE=$default_nm - echo - echo "WARNING: FORTRAN test compile fails -- please see \"genmake_errors\"" - echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" - echo "WARNING: Please contact if you need help here." + cat <> genmake_warnings + +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. +EOF return 1 fi f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3` RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm - echo - echo "WARNING: The \"nm\" command failed." - echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" - echo "WARNING: Please contact if you need help here." + cat <> genmake_warnings + +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 @@ -353,6 +390,46 @@ rm -f genmake_tcomp.* genmake_test.* } + +check_HAVE_CLOC() { + get_fortran_c_namemangling + cat < genmake_tc_1.c +$FC_NAMEMANGLE +#include +#include +#include +#include +#include +void FC_NAMEMANGLE(cloc) ( double *curtim ) +{ + struct timeval tv1; + gettimeofday(&tv1 , (void *)NULL ); + *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6); + *curtim = *curtim/1.E6; +} +EOF + make genmake_tc_1.o >> genmake_tc.log 2>&1 + RET_C=$? + cat < genmake_tc_2.f + program hello + Real*8 wtime + external cloc + call cloc(wtime) + print *," HELLO WORLD", wtime + end program hello +EOF + $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1 + RET_F=$? + test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1 + RETVAL=$? + if test "x$RETVAL" = x0 ; then + HAVE_CLOC=t + DEFINES="$DEFINES -DHAVE_CLOC" + fi + rm -f genmake_tc* +} + + # Set defaults here COMMANDL="$0 $@" @@ -388,6 +465,7 @@ HAVE_SYSTEM= HAVE_FDATE= FC_NAMEMANGLE= +HAVE_CLOC= MODS= TOOLSDIR= @@ -426,7 +504,7 @@ # The following state can be set directly by command-line switches -gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT" +gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE" gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS" # The following state is not directly set by command-line switches @@ -444,8 +522,17 @@ gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7" gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12" +cat <&2 @@ -722,6 +801,9 @@ if test "x$CPP" = x ; then CPP="cpp" fi +if test "x$MAKE" = x ; then + MAKE="make" +fi echo "#define A a" | $CPP > test_cpp 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then @@ -758,6 +840,7 @@ fi rm -f genmake_test_ln genmake_tlink + printf "\n=== Checking system libraries ===\n" echo -n " Do we have the system() command using $FC... " cat > genmake_tcomp.f < FC_NAMEMANGLE.h.template cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h fi +rm -f genmake_t* printf "\n=== Setting defaults ===\n" @@ -907,7 +992,7 @@ # 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 -n " checking default package list: " +echo " checking default package list: " if test "x${PDEFAULT}" = x ; then for i in "." $MODS ; do if test -r $i"/packages.conf" ; then @@ -920,13 +1005,12 @@ PDEFAULT="$ROOTDIR/pkg/pkg_default" fi if test "x${PDEFAULT}" = xNONE ; then - echo "default packages file disabled" + echo " default packages file disabled" else if test ! -r $PDEFAULT ; then - echo "" echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\"" else - echo " using PDEFAULT=\"$PDEFAULT\"" + echo " using PDEFAULT=\"$PDEFAULT\"" # Strip the comments and add all the names def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'` RETVAL=$? @@ -1413,7 +1497,7 @@ Clean: @make clean @make cleanlinks - -rm -f Makefile.bak genmake_state genmake_*optfile make.log + -rm -f Makefile.bak genmake_state genmake_*optfile genmake_warnings make.log CLEAN: @make Clean -find \$(EXEDIR) -name "*.meta" -exec rm {} \; @@ -1525,6 +1609,10 @@ \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f +ftltafonly: + \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f + cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f + ftl_taf: ftl_taf_output.o \$(OBJFILES) \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS) @@ -1537,21 +1625,11 @@ # ... SVD ... -svd: svd_taf -svd_taf_f: svd_taf_output.f - -svd_input_code.f: \$(SRCFILES) - cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h - @make \$(F77FILES) - @make \$(AD_FLOW_FILES) - cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f - -svd_taf_output.f: svd_input_code.f - \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f - cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f +svdtaf: ad_taf_output.f ftl_taf_output.f +svdall: svd_taf -svd_taf: svd_taf_output.o \$(OBJFILES) - \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS) +svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES) + \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS) #=========================================