--- MITgcm/tools/genmake2 2004/01/11 17:02:47 1.59 +++ MITgcm/tools/genmake2 2004/02/24 19:00:32 1.67 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.59 2004/01/11 17:02:47 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.67 2004/02/24 19:00:32 adcroft Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -145,18 +145,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 +505,8 @@ S64= KPP= FC= +CPP= LINK= -# DEFINES="-DWORDLENGTH=4" DEFINES= PACKAGES= ENABLE= @@ -467,12 +527,15 @@ KPPFILES= NOOPTFILES= NOOPTFLAGS= +MPI= +MPIPATH= # DEFINES checked by test compilation HAVE_SYSTEM= HAVE_FDATE= FC_NAMEMANGLE= HAVE_CLOC= +HAVE_NETCDF= MODS= TOOLSDIR= @@ -512,7 +575,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 " @@ -664,6 +727,12 @@ IEEE=true ;; -noieee | --noieee) IEEE= ;; + + -mpi | --mpi) + MPI=true ;; + -mpi=* | --mpi=*) + MPIPATH=$ac_optarg + MPI=true ;; # -jam | --jam) # JAM=1 ;; @@ -805,12 +874,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 +925,10 @@ fi rm -f genmake_test_ln genmake_tlink +if test ! "x$MPI" = x ; then + echo " Turning on MPI cpp macros" + DEFINES="$DEFINS -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 +979,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 +1026,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,7 +1047,7 @@ 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 @@ -971,7 +1061,7 @@ rm -f make_exch2.errors else echo "Error: problem encountered while building source files in exch2:" - cat make_exch2.errors + cat make_exch2.errors 1>&2 exit 1 fi fi @@ -1159,6 +1249,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"