--- MITgcm/tools/genmake2 2004/03/12 15:50:06 1.72 +++ MITgcm/tools/genmake2 2004/07/30 15:59:33 1.92 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.72 2004/03/12 15:50:06 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.92 2004/07/30 15:59:33 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -67,11 +67,176 @@ done PACKAGES=$new_packages rm -f ./p[1,2].tmp + return $matched else echo "Warning: can't read package groups definition file: $PKG_GROUPS" fi } +# 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 <> genmake_hello.F + program hello + write(*,*) 'hi' + stop + end +EOF + cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 ; 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 "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 genmake_hello.* + + # 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 -f Makefile && mv -f Makefile Makefile.bak + cat <> Makefile +%.$tfs : %.F +.SUFFIXES: +genmake_hello.$tfs: genmake_hello.F + $LN genmake_hello.F genmake_hello.$tfs +EOF + $MAKE "genmake_hello."$tfs > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 -o ! -f "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 genmake_hello.* Makefile + test -f Makefile && mv -f Makefile.bak Makefile + + # If we make it here, use the extensions + FS=$tfs + FS90=$tfs9 + return +} + + +look_for_makedepend() { + + # The "original" makedepend is part of the Imake system that is + # most often distributed with XFree86 or with an XFree86 source + # package. As a result, many machines (eg. generic Linux) do not + # have a system-default "makedepend" available. For those + # systems, we have two fall-back options: + # + # 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 + # + # 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 + # + if test "x${MAKEDEPEND}" = x ; then + which makedepend > /dev/null 2>&1 + 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 + MAKEDEPEND=makedepend + else + echo " a system-default makedepend was not found." + + # Try to build the cyrus implementation + build_cyrus_makedepend + RETVAL=$? + if test "x$RETVAL" != x0 ; then + MAKEDEPEND='$(TOOLSDIR)/xmakedepend' + fi + rm -f ./genmake_cy_md + fi + else + # echo "MAKEDEPEND=${MAKEDEPEND}" + echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1 + RETVAL=$? + if test x"$RETVAL" = x0 ; then + build_cyrus_makedepend + fi + fi +} + + +build_cyrus_makedepend() { + rm -f ./genmake_cy_md + ( + cd $ROOTDIR/tools/cyrus-imapd-makedepend \ + && ./configure > /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 + RETVAL=$? + rm -f ./genmake_cy_md + if test "x$RETVAL" = x0 ; then + MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend' + return 0 + else + echo "WARNING: unable to build cyrus-imapd-makedepend" + return 1 + fi +} + # Guess possible config options for this host find_possible_configs() { @@ -82,6 +247,7 @@ 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" @@ -101,51 +267,49 @@ CPP="cpp -traditional -P" fi - # The "original" makedepend is part of the Imake system that is - # most often distributed with XFree86 or with an XFree86 source - # package. As a result, many machines (eg. generic Linux) do not - # have a system-default "makedepend" available. For those - # systems, we have two fall-back options: - # - # 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 - # - # 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 - # - if test "x${MAKEDEPEND}" = x ; then - which makedepend > /dev/null 2>&1 - RETVAL=$? - if test ! "x${RETVAL}" = x0 ; then - echo " a system-default makedepend was not found." - - # Try to build the cyrus impl - rm -f ./genmake_cy_md - ( - cd $ROOTDIR/tools/cyrus-imapd-makedepend \ - && ./configure > /dev/null 2>&1 \ - && make > /dev/null 2>&1 \ - && ./makedepend ifparser.c > /dev/null 2>&1 \ - && echo "true" - ) > ./genmake_cy_md - grep true ./genmake_cy_md > /dev/null 2>&1 - RETVAL=$? - if test "x$RETVAL" = x0 ; then - MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend' - else - MAKEDEPEND='$(TOOLSDIR)/xmakedepend' - fi - rm -f ./genmake_cy_md - fi + look_for_makedepend + + #================================================================ + # look for possible C compilers + tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc" + p_CC= + for c in $tmp ; do + rm -f ./genmake_hello.c ./genmake_hello + cat >> genmake_hello.c << EOF +#include +int main(int argc, char **argv) { + printf("Hello!\n"); + return 0; +} +EOF + $c -o genmake_hello genmake_hello.c > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + p_CC="$p_CC $c" + fi + done + rm -f ./genmake_hello.c ./genmake_hello + if test "x${p_CC}" = x ; then + cat 1>&2 < genmake_test.c </dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3` RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm @@ -419,7 +599,7 @@ EOF return 1 fi - f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3` + f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3` RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm @@ -496,7 +676,8 @@ check_netcdf_libs() { - cat < genmake_tnc.F + echo "" > genmake_tnc.log + cat < genmake_tnc.for program fgennc #include "netcdf.inc" integer iret, ncid, xid @@ -508,7 +689,8 @@ IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) end EOF - $CPP genmake_tnc.F > genmake_tnc.f \ + #echo "$CPP $DEFINES $INCLUDES" + $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null \ && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1 RET_COMPILE=$? test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1 @@ -517,7 +699,7 @@ HAVE_NETCDF=t else # try again with "-lnetcdf" added to the libs - $CPP genmake_tnc.F > genmake_tnc.f \ + $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null \ && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \ $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1 RET_COMPILE=$? @@ -547,6 +729,7 @@ S64= KPP= FC= +CC= CPP= LINK= DEFINES= @@ -554,7 +737,7 @@ ENABLE= DISABLE= MAKEFILE= -MAKEDEPEND= +#MAKEDEPEND= PDEPEND= DUMPSTATE=t PDEFAULT= @@ -579,6 +762,7 @@ FC_NAMEMANGLE= HAVE_CLOC= HAVE_NETCDF= +HAVE_ETIME= MODS= TOOLSDIR= @@ -586,6 +770,7 @@ INCLUDEDIRS= STANDARDDIRS="USE_THE_DEFAULT" +G2ARGS= BASH= PWD=`pwd` MAKE=make @@ -602,6 +787,8 @@ if test "x$MITGCM_IEEE" != x ; then IEEE=$MITGCM_IEEE fi +FS= +FS90= AUTODIFF_PKG_USED=f AD_OPTFILE= @@ -626,7 +813,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" @@ -656,7 +843,7 @@ fi done printf " getting local config information: " -if test -e $gm_local ; then +if test -f $gm_local ; then echo "using $gm_local" . $gm_local # echo "DISABLE=$DISABLE" @@ -677,7 +864,9 @@ #done #parse_options ac_prev= -for ac_option ; do +for ac_option in $@ ; do + + G2ARGS="$G2ARGS \"$ac_option\"" # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then @@ -771,12 +960,27 @@ # ac_prev=cpp ;; # -cpp=* | --cpp=*) # CPP=$ac_optarg ;; - + + -cc | --cc) + ac_prev=CC ;; + -cc=* | --cc=*) + CC=$ac_optarg ;; + -fortran | --fortran | -fc | --fc) ac_prev=FC ;; -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) @@ -833,7 +1037,8 @@ fi if test "x${ROOTDIR}" = x ; then - if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then + tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'` + if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then ROOTDIR=".." else for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do @@ -886,6 +1091,9 @@ fi fi +# Check for broken systems that cannot correctly distinguish *.F and *.f files +# check_for_broken_Ff + echo " getting AD_OPTFILE information: " if test "x${AD_OPTFILE}" = x ; then if test "x$MITGCM_AD_OF" = x ; then @@ -913,7 +1121,7 @@ fi fi -# Check that FC, LINK, CPP, S64, LN, and MAKE are defined. If not, +# Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not, # either set defaults or complain and abort! if test ! "x$BASH" = x ; then # add a trailing space so that it works within the Makefile syntax (see below) @@ -929,6 +1137,16 @@ EOF exit 1 fi +if test "x$CC" = x ; then + cat <&2 + +Error: no C compiler: please specify using one of the following: + 1) within the options file ("CC=...") as specified by "-of=OPTFILE" + 2) the "-cc=XXX" command-line option + 3) the "./genmake_local" file +EOF + exit 1 +fi if test "x$LINK" = x ; then LINK=$FC fi @@ -939,8 +1157,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 @@ -963,9 +1181,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 @@ -983,6 +1199,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" @@ -1028,6 +1247,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 @@ -1069,7 +1310,8 @@ fi if test "x${EXEDIR}" = x ; then - if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then + tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'` + if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then EXEDIR=../exe else EXEDIR=. @@ -1187,12 +1429,20 @@ PACKAGES="$PACKAGES $i" done echo " before group expansion packages are: $PACKAGES" - expand_pkg_groups + RET=1 + while test $RET = 1 ; do expand_pkg_groups; RET=$?; done echo " after group expansion packages are: $PACKAGES" fi fi echo " applying DISABLE settings" +for i in $PACKAGES ; do + echo $i >> ./.tmp_pack +done +for i in `grep "-" ./.tmp_pack` ; do + j=`echo $i | sed 's/[-]//'` + DISABLE="$DISABLE $j" +done pack= for p in $PACKAGES ; do addit="t" @@ -1209,19 +1459,20 @@ echo " applying ENABLE settings" echo "" > ./.tmp_pack PACKAGES="$PACKAGES $ENABLE" +# Test if each explicitly referenced package exists for i in $PACKAGES ; do - if test ! -d "$ROOTDIR/pkg/$i" ; then + j=`echo $i | sed 's/[-+]//'` + if test ! -d "$ROOTDIR/pkg/$j" ; then echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\"" - exit 1 + exit 1 fi echo $i >> ./.tmp_pack done -pack=`cat ./.tmp_pack | sort | uniq` -rm -f ./.tmp_pack PACKAGES= -for i in $pack ; do +for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do PACKAGES="$PACKAGES $i" done +rm -f ./.tmp_pack echo " packages are: $PACKAGES" echo " applying package dependency rules" @@ -1288,7 +1539,8 @@ echo " the dependency rules for \"$dname\"" exit 1 fi - i=$(( $i + 1 )) + i=`echo "$i + 1" | bc -l` + #i=$(( $i + 1 )) done ck=$ck"t" done @@ -1450,9 +1702,7 @@ echo "=== Creating the Makefile ===" echo " setting INCLUDES" for i in $INCLUDEDIRS ; do - if ! test -d $i ; then -# INCLUDES="$INCLUDES -I$i" -# else + if test ! -d $i ; then echo "Warning: can't find INCLUDEDIRS=\"$i\"" fi done @@ -1527,7 +1777,7 @@ echo "" >> hlist.inc echo "" >> ad_flow_files.inc -if test -e $MAKEFILE ; then +if test -f $MAKEFILE ; then mv -f $MAKEFILE "$MAKEFILE.bak" fi echo " Writing makefile: $MAKEFILE" @@ -1536,7 +1786,7 @@ echo "# This makefile was generated automatically on" >> $MAKEFILE echo "# $THISDATE" >> $MAKEFILE echo "# by the command:" >> $MAKEFILE -echo "# $0 $@" >> $MAKEFILE +echo "# $0 $G2ARGS" >> $MAKEFILE echo "# executed by:" >> $MAKEFILE echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE @@ -1600,9 +1850,11 @@ # Special preprocessor (KAP on DECs, FPP on Crays) KPP = ${KPP} # Fortran compiler -FC = ${FC} +FC = ${FC} in # Fortran compiler F90C = ${F90C} +# C compiler +CC = ${CC} # Link editor LINK = ${LINK} ${LDADD} @@ -1636,26 +1888,25 @@ cat f90srclist.inc >> $MAKEFILE cat hlist.inc >> $MAKEFILE cat ad_flow_files.inc >> $MAKEFILE -echo >> $MAKEFILE -echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE -echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE +echo >> $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 .'$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 cat >>$MAKEFILE <> \$(MAKEFILE) -rm -f makedepend.out @@ -1668,7 +1919,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 @@ -1679,11 +1930,11 @@ -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: - $THIS_SCRIPT $@ + $THIS_SCRIPT $G2ARGS cleanlinks: -find . -type l -exec rm {} \; @@ -1698,22 +1949,25 @@ @echo Creating \$@ ... echo "$FC_NAMEMANGLE" > \$@ -# The normal chain of rules is ( .F - .f - .o ) -.F.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 \$< -.F90.f90: +.F90.$FS90: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.f90.o: +.$FS90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .c.o: \$(CC) \$(CFLAGS) -c \$< -# Special exceptions that use the ( .F - .p - .f - .o ) rule-chain +# Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain .F.p: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.p.f: +.p.$FS: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< #========================================= @@ -1838,7 +2092,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" @@ -1848,7 +2102,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