--- MITgcm/tools/genmake2 2004/07/21 16:34:46 1.89 +++ MITgcm/tools/genmake2 2004/10/05 16:10:31 1.104 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.89 2004/07/21 16:34:46 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.104 2004/10/05 16:10:31 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -124,10 +124,10 @@ 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 +.SUFFIXES: .$tfs .F +.F.$tfs: + $LN \$< \$@ EOF $MAKE "genmake_hello."$tfs > /dev/null 2>&1 RETVAL=$? @@ -195,30 +195,48 @@ echo " a system-default makedepend was not found." # Try to build the cyrus implementation - 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 + build_cyrus_makedepend RETVAL=$? - if test "x$RETVAL" = x0 ; then - MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend' - else + 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() { @@ -251,7 +269,47 @@ look_for_makedepend - # look for possible fortran compilers + #================================================================ + # 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 </dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3` RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm @@ -536,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 @@ -613,6 +676,7 @@ check_netcdf_libs() { + echo "" > genmake_tnc.log cat < genmake_tnc.for program fgennc #include "netcdf.inc" @@ -625,23 +689,30 @@ IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) end EOF - #echo "$CPP $DEFINES $INCLUDES" - $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f \ - && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1 + #echo "$CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f" + #echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.f" + #echo "$LINK -o genmake_tnc.o $LIBS" + $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null \ + && $FC $FFLAGS $FOPTIM -c genmake_tnc.f >> genmake_tnc.log 2>&1 \ + && $LINK -o genmake_tnc genmake_tnc.o $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 + + #EH3 Remove test program execution for machines that either disallow + #EH3 execution or cannot support it (eg. cross-compilers) + #EH3 + #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1 + #EH3 RETVAL=$? + #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then + + if test "x$RET_COMPILE" = x0 ; then HAVE_NETCDF=t else # try again with "-lnetcdf" added to the libs - $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f \ - && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \ - $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1 + $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null \ + && $FC $FFLAGS $FOPTIM -c genmake_tnc.f >> genmake_tnc.log 2>&1 \ + && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> 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 + if test "x$RET_COMPILE" = x0 ; then LIBS="$LIBS -lnetcdf" HAVE_NETCDF=t else @@ -665,6 +736,7 @@ S64= KPP= FC= +#CC=gcc CPP= LINK= DEFINES= @@ -672,7 +744,7 @@ ENABLE= DISABLE= MAKEFILE= -MAKEDEPEND= +#MAKEDEPEND= PDEPEND= DUMPSTATE=t PDEFAULT= @@ -710,9 +782,11 @@ PWD=`pwd` MAKE=make AWK=awk -THISHOSTNAME=`hostname` +THISHOST=`hostname` THISCWD=`pwd` THISDATE=`date` +THISUSER=`echo $USER` +THISVER= MACHINE=`uname -a` EXECUTABLE= EXEHOOK= @@ -746,7 +820,7 @@ # The following state is not directly set by command-line switches gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM " gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS" -gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE" +gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE" gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF" gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME" @@ -787,7 +861,7 @@ echo "none found" fi -# echo "$0::$1:$2:$3:$4:$5:$6:$7:" +#echo "$0::$1:$2:$3:$4:$5:$6:$7:" #OPTIONS= #n=0 #for i ; do @@ -799,7 +873,7 @@ #done #parse_options ac_prev= -for ac_option in $@ ; do +for ac_option in "$@" ; do G2ARGS="$G2ARGS \"$ac_option\"" @@ -895,7 +969,12 @@ # 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=*) @@ -966,6 +1045,7 @@ echo fi +# Find the MITgcm ${ROOTDIR} if test "x${ROOTDIR}" = x ; 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 @@ -992,6 +1072,11 @@ exit 1 fi +# Find the MITgcm ${THISVER} +if test -f "${ROOTDIR}/doc/tag-index" ; then + THISVER=`grep checkpoint ${ROOTDIR}/doc/tag-index | head -1` +fi + echo " getting OPTFILE information: " if test "x${OPTFILE}" = x ; then if test "x$MITGCM_OF" = x ; then @@ -1051,7 +1136,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) @@ -1067,6 +1152,16 @@ EOF exit 1 fi +if test "x$CC" = x ; then + CC=cc +# 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 @@ -1250,7 +1345,30 @@ exit 1 fi if test "x$S64" = x ; then - S64='$(TOOLSDIR)/set64bitConst.sh' + echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + S64='$(TOOLSDIR)/set64bitConst.sh' + else + echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + S64='$(TOOLSDIR)/set64bitConst.csh' + else + cat < /dev/null 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + if test "x$HAVE_NETCDF" != xt ; then + cat < 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 + fi +fi + echo " applying package dependency rules" ck= while test "x$ck" != xtt ; do @@ -1479,33 +1632,6 @@ 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 <> $MAKEFILE echo "# $0 $G2ARGS" >> $MAKEFILE echo "# executed by:" >> $MAKEFILE -echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE +echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE EXE_AD=$EXECUTABLE"_ad" EXE_FTL=$EXECUTABLE"_ftl" @@ -1754,7 +1882,7 @@ DISABLED_PACKAGES = ${DISABLED_PACKAGES} # These files are created by Makefile -SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h +SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h EOF @@ -1773,6 +1901,8 @@ FC = ${FC} # Fortran compiler F90C = ${F90C} +# C compiler +CC = ${CC} # Link editor LINK = ${LINK} ${LDADD} @@ -1856,7 +1986,7 @@ cleanlinks: -find . -type l -exec rm {} \; -# Special targets ($SPECIAL_FILES) which are create by make +# Special targets (SPECIAL_FILES) which are create by make ${PACKAGES_DOT_H}: @echo Creating \$@ ... @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@ @@ -1867,9 +1997,21 @@ @echo Creating \$@ ... echo "$FC_NAMEMANGLE" > \$@ +BUILD_INFO.h: + @echo Creating \$@ ... +EOF + +test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE +test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE +test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE +test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE + +cat >>$MAKEFILE < \$@