--- MITgcm/tools/genmake2 2004/04/07 20:28:09 1.75 +++ MITgcm/tools/genmake2 2004/07/12 15:49:08 1.84 @@ -1,6 +1,6 @@ -#! /usr/bin/env bash +#! /usr/bin/env sh # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.75 2004/04/07 20:28:09 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.84 2004/07/12 15:49:08 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -76,73 +76,89 @@ # 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 + # First check the ability to create a *.F/.f pair. - cat <> ./hello.F + cat <> genmake_hello.F program hello write(*,*) 'hi' stop end EOF - cp ./hello.F ./hello.f + cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then - FEXT='fp' - F90EXT='fp90' + 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 ./hello.f + rm -f genmake_hello.* - # Then check the ability of ${MAKE} to use the two. + # 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 -e Makefile && mv -f Makefile Makefile.bak cat <> Makefile +%.$tfs : %.F .SUFFIXES: -hello.f: hello.F - cp -f hello.F hello.f +genmake_hello.$tfs: genmake_hello.F + $LN genmake_hello.F genmake_hello.$tfs EOF - ( $MAKE hello.f ) > /dev/null 2>&1 + $MAKE "genmake_hello."$tfs > /dev/null 2>&1 RETVAL=$? - if test "x$RETVAL" != x0 -o ! -f ./hello.f ; then - FEXT='fp' - F90EXT='fp90' - return + if test "x$RETVAL" != x0 -o ! -e "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 ./hello.f ./hello.F Makefile + rm -f genmake_hello.* Makefile test -e Makefile && mv -f Makefile.bak Makefile - # Both tests passed, so use the default. - FEXT='F' - F90EXT='F90' + # If we make it here, use the extensions + FS=$tfs + FS90=$tfs9 + return } -# Guess possible config options for this host -find_possible_configs() { - - 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 - OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")` - echo " The platform appears to be: $PLATFORM" - - echo "test" > test - ln -s ./test link - 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 - fi - rm -f test link - - if test "x$CPP" = x ; then - CPP="cpp -traditional -P" - fi +look_for_makedepend() { # The "original" makedepend is part of the Imake system that is # most often distributed with XFree86 or with an XFree86 source @@ -164,8 +180,16 @@ # if test "x${MAKEDEPEND}" = x ; then which makedepend > /dev/null 2>&1 - RETVAL=$? - if test ! "x${RETVAL}" = x0 ; then + RV0=$? + cat <> genmake_tc.f + program test + write(*,*) 'test' + stop + end +EOF + makedepend genmake_tc.f > /dev/null 2>&1 + RV1=$? + if test ! "x${RV0}${RV1}" = x00 ; then echo " a system-default makedepend was not found." # Try to build the cyrus impl @@ -173,8 +197,11 @@ ( cd $ROOTDIR/tools/cyrus-imapd-makedepend \ && ./configure > /dev/null 2>&1 \ - && make > /dev/null 2>&1 \ - && ./makedepend ifparser.c > /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 @@ -187,6 +214,40 @@ rm -f ./genmake_cy_md fi fi +} + + +# Guess possible config options for this host +find_possible_configs() { + + 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" + + echo "test" > test + ln -s ./test link + 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 + fi + rm -f test link + + if test "x$CPP" = x ; then + CPP="cpp -traditional -P" + fi + + look_for_makedepend # look for possible fortran compilers tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95" @@ -316,6 +377,11 @@ -help | --help | -h | --h Print this help message and exit. + -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME + -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME + Use "NAME" as the adoptfile. By default, the file at + "tools/adjoint_options/adjoint_default" will be used. + -nooptfile | --nooptfile -optfile NAME | --optfile NAME | -of NAME | --of NAME -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME @@ -622,6 +688,7 @@ FC_NAMEMANGLE= HAVE_CLOC= HAVE_NETCDF= +HAVE_ETIME= MODS= TOOLSDIR= @@ -646,8 +713,8 @@ if test "x$MITGCM_IEEE" != x ; then IEEE=$MITGCM_IEEE fi -FEXT= -F90EXT= +FS= +FS90= AUTODIFF_PKG_USED=f AD_OPTFILE= @@ -672,7 +739,7 @@ gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS" gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE" gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF" -gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE" +gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE 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" @@ -825,6 +892,16 @@ -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) @@ -935,9 +1012,7 @@ fi # Check for broken systems that cannot correctly distinguish *.F and *.f files -if test "x$FEXT" = x -a "x$F90EXT" = x ; then - check_for_broken_Ff -fi +# check_for_broken_Ff echo " getting AD_OPTFILE information: " if test "x${AD_OPTFILE}" = x ; then @@ -992,8 +1067,8 @@ CPP=cpp 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 @@ -1016,9 +1091,7 @@ else rm -f test_cpp fi -if test "x$MAKEDEPEND" = x ; then - MAKEDEPEND=makedepend -fi +look_for_makedepend if test "x$LN" = x ; then LN="ln -s" fi @@ -1036,6 +1109,9 @@ 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="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI" @@ -1081,6 +1157,28 @@ fi rm -f genmake_tcomp* +printf " Do we have the etime() command using $FC... " +cat > genmake_tcomp.f < 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 @@ -1698,13 +1796,12 @@ cat hlist.inc >> $MAKEFILE cat ad_flow_files.inc >> $MAKEFILE echo >> $MAKEFILE -echo 'F77FILES = $(SRCFILES:.'$FEXT'=.f)' >> $MAKEFILE -echo 'F90FILES = $(F90SRCFILES:.'$F90EXT'=.f90)' >> $MAKEFILE -echo 'OBJFILES = $(SRCFILES:.'$FEXT'=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.'$F90EXT'=.o)' >> $MAKEFILE +echo 'F77FILES = $(SRCFILES:.F=.'$FS')' >> $MAKEFILE +echo 'F90FILES = $(F90SRCFILES:.F=.'$FS90')' >> $MAKEFILE +echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE echo >> $MAKEFILE echo '.SUFFIXES:' >> $MAKEFILE -echo '.SUFFIXES: .o .f .p .'$FEXT' .c .'$F90EXT' .f90' >> $MAKEFILE - +echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc rm -f ad_flow_files.inc @@ -1716,7 +1813,7 @@ \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS) depend: @make links - \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES) + \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES) \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE) -rm -f makedepend.out @@ -1729,7 +1826,7 @@ @\$(EXECUTABLE) > \$@ clean: - -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} *.template + -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template Clean: @make clean @make cleanlinks @@ -1740,7 +1837,7 @@ -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 \$(EXECUTABLE) output.txt STD* #eh3 Makefile: makefile makefile: @@ -1759,22 +1856,25 @@ @echo Creating \$@ ... echo "$FC_NAMEMANGLE" > \$@ -# The normal chain of rules is ( .$FEXT - .f - .o ) -.$FEXT.f: +# The normal chain of rules is ( .F - .$FS - .o ) + +%.o : %.F + +.F.$FS: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.f.o: +.$FS.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< -.$F90EXT.f90: +.F90.$FS90: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.f90.o: +.$FS90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .c.o: \$(CC) \$(CFLAGS) -c \$< -# Special exceptions that use the ( .$FEXT - .p - .f - .o ) rule-chain -.$FEXT.p: +# Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain +.F.p: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.p.f: +.p.$FS: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< #========================================= @@ -1899,7 +1999,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" @@ -1909,7 +2009,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