--- MITgcm/tools/genmake2 2003/12/06 23:33:10 1.56 +++ MITgcm/tools/genmake2 2004/02/28 05:01:12 1.70 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.56 2003/12/06 23:33:10 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.70 2004/02/28 05:01:12 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -100,13 +100,47 @@ CPP="cpp -traditional -P" fi - # makedepend is not always available + # 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 RETVAL=$? - if test "x${RETVAL}" = x1 ; then - echo " makedepend was not found. Using xmakedpend instead." - MAKEDEPEND='$(TOOLSDIR)/xmakedepend' + 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 fi @@ -145,18 +179,27 @@ echo " "$p_FC if test "x$FC" = x ; then FC=`echo $p_FC | $AWK '{print $1}'` + echo " Setting FORTRAN compiler to: "$FC fi fi - for i in $p_FC ; do - p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i - if test -r $p_OF ; then - OPTFILE=$p_OF - echo " The options file: $p_OF" - echo " appears to match so we'll use it." - break - fi - done + if test "x$OPTFILE" = x ; then + OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC + if test ! -r $OPTFILE ; then + echo " I looked for the file "$OPTFILE" but did not find it" + fi + fi +# echo " The options file: $p_OF" +# echo " appears to match so we'll use it." +# for i in $p_FC ; do +#p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i +#if test -r $p_OF ; then +# OPTFILE=$p_OF +# echo " The options file: $p_OF" +# echo " appears to match so we'll use it." +# break +#fi +# done if test "x$OPTFILE" = x ; then cat 1>&2 < genmake_tnc.F + program fgennc +#include "netcdf.inc" + integer iret, ncid, xid + iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid) + IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) + iret = nf_def_dim(ncid, 'X', 11, xid) + IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) + iret = nf_close(ncid) + IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) + end +EOF + $CPP genmake_tnc.F > genmake_tnc.f \ + && $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 + RETVAL=$? + if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + HAVE_NETCDF=t + else + # try again with "-lnetcdf" added to the libs + $CPP genmake_tnc.F > genmake_tnc.f \ + && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \ + $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1 + RET_COMPILE=$? + test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1 + RETVAL=$? + if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + LIBS="$LIBS -lnetcdf" + HAVE_NETCDF=t + else + cat genmake_tnc.log >> genmake_warnings + fi + fi + rm -f genmake_tnc* +} + + + +############################################################################### +# Sequential part of script starts here +############################################################################### + # Set defaults here COMMANDL="$0 $@" @@ -445,8 +543,8 @@ S64= KPP= FC= +CPP= LINK= -# DEFINES="-DWORDLENGTH=4" DEFINES= PACKAGES= ENABLE= @@ -463,22 +561,26 @@ CFLAGS= KFLAGS1= KFLAGS2= +#LDADD= LIBS= KPPFILES= NOOPTFILES= NOOPTFLAGS= +MPI= +MPIPATH= # DEFINES checked by test compilation HAVE_SYSTEM= HAVE_FDATE= FC_NAMEMANGLE= HAVE_CLOC= +HAVE_NETCDF= MODS= TOOLSDIR= SOURCEDIRS= INCLUDEDIRS= -STANDARDDIRS= +STANDARDDIRS="USE_THE_DEFAULT" PWD=`pwd` MAKE=make @@ -512,7 +614,7 @@ # 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 IEEE MPI JAM DUMPSTATE STANDARDDIRS" +gm_s2="FC CPP IEEE 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 " @@ -613,6 +715,11 @@ -make=* | --make=* | -m=* | --m=*) MAKE=$ac_optarg ;; + -makedepend | --makedepend | -md | --md) + ac_prev=MAKEDEPEND ;; + -makedepend=* | --makedepend=* | -md=* | --md=*) + MAKEDEPEND=$ac_optarg ;; + -makefile | --makefile | -ma | --ma) ac_prev=MAKEFILE ;; -makefile=* | --makefile=* | -ma=* | --ma=*) @@ -664,6 +771,12 @@ IEEE=true ;; -noieee | --noieee) IEEE= ;; + + -mpi | --mpi) + MPI=true ;; + -mpi=* | --mpi=*) + MPIPATH=$ac_optarg + MPI=true ;; # -jam | --jam) # JAM=1 ;; @@ -805,12 +918,21 @@ if test "x$LINK" = x ; then LINK=$FC fi -if test "x$CPP" = x ; then - CPP="cpp" -fi if test "x$MAKE" = x ; then MAKE="make" fi +if test "x$CPP" = x ; then + 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 +# 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 + echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP +done +#EH3 === UGLY === echo "#define A a" | $CPP > test_cpp 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then @@ -847,6 +969,10 @@ fi rm -f genmake_test_ln genmake_tlink +if test ! "x$MPI" = x ; then + echo " Turning on MPI cpp macros" + DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI" +fi printf "\n=== Checking system libraries ===\n" echo -n " Do we have the system() command using $FC... " @@ -897,6 +1023,14 @@ fi rm -f genmake_t* +echo -n " Can we create NetCDF-enabled binaries... " +check_netcdf_libs +if test "x$HAVE_NETCDF" != x ; then + echo "yes" +else + echo "no" +fi + printf "\n=== Setting defaults ===\n" echo -n " Adding MODS directories: " @@ -936,7 +1070,7 @@ TOOLSDIR="$ROOTDIR/tools" fi if test ! -d ${TOOLSDIR} ; then - echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!" + echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!" exit 1 fi if test "x$S64" = x ; then @@ -957,11 +1091,25 @@ rm -f make_eesupp.errors else echo "Error: problem encountered while building source files in eesupp:" - cat make_eesupp.errors + cat make_eesupp.errors 1>&2 exit 1 fi fi +#same for exch2 +if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then + echo " Making source files in exch2 from templates" + ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + rm -f make_exch2.errors + else + echo "Error: problem encountered while building source files in exch2:" + cat make_exch2.errors 1>&2 + exit 1 + fi +fi + printf "\n=== Determining package settings ===\n" if test "x${PDEPEND}" = x ; then tmp=$ROOTDIR"/pkg/pkg_depend" @@ -1145,6 +1293,32 @@ fi done +# Build MNC templates and check for ability to build and use NetCDF +echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + rm -f make_mnc.errors + else + echo "Error: problem encountered while building source files in pkg/mnc:" + cat make_mnc.errors 1>&2 + exit 1 + fi + if test "x$HAVE_NETCDF" != xt ; then + cat < /dev/null 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then rm -f $PACKAGES_DOT_H".tmp"