--- MITgcm/tools/genmake2 2004/07/12 15:49:08 1.84 +++ MITgcm/tools/genmake2 2004/08/09 02:28:51 1.96 @@ -1,6 +1,6 @@ -#! /usr/bin/env sh +#! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.84 2004/07/12 15:49:08 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.96 2004/08/09 02:28:51 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -122,7 +122,7 @@ stop end EOF - test -e Makefile && mv -f Makefile Makefile.bak + test -f Makefile && mv -f Makefile Makefile.bak cat <> Makefile %.$tfs : %.F .SUFFIXES: @@ -131,7 +131,7 @@ EOF $MAKE "genmake_hello."$tfs > /dev/null 2>&1 RETVAL=$? - if test "x$RETVAL" != x0 -o ! -e "genmake_hello."$tfs ; then + if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then if test "x$FS" = x ; then FS='for' FS90='fr9' @@ -149,7 +149,7 @@ fi fi rm -f genmake_hello.* Makefile - test -e Makefile && mv -f Makefile.bak Makefile + test -f Makefile && mv -f Makefile.bak Makefile # If we make it here, use the extensions FS=$tfs @@ -179,44 +179,64 @@ # 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 + 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 - 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 - 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=$? - if test "x$RETVAL" = x0 ; then - MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend' - else - MAKEDEPEND='$(TOOLSDIR)/xmakedepend' - fi - rm -f ./genmake_cy_md - fi + 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() { @@ -249,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 < genmake_test.c </dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3` RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm @@ -528,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 @@ -605,6 +676,7 @@ check_netcdf_libs() { + echo "" > genmake_tnc.log cat < genmake_tnc.for program fgennc #include "netcdf.inc" @@ -617,8 +689,12 @@ IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) end EOF - $CPP 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 \ + && $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=$? @@ -626,7 +702,7 @@ HAVE_NETCDF=t else # try again with "-lnetcdf" added to the libs - $CPP genmake_tnc.for > 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=$? @@ -656,6 +732,7 @@ S64= KPP= FC= +#CC=gcc CPP= LINK= DEFINES= @@ -663,7 +740,7 @@ ENABLE= DISABLE= MAKEFILE= -MAKEDEPEND= +#MAKEDEPEND= PDEPEND= DUMPSTATE=t PDEFAULT= @@ -769,7 +846,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" @@ -790,7 +867,7 @@ #done #parse_options ac_prev= -for ac_option ; do +for ac_option in $@ ; do G2ARGS="$G2ARGS \"$ac_option\"" @@ -886,7 +963,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=*) @@ -958,7 +1040,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 @@ -1041,7 +1124,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) @@ -1057,6 +1140,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 @@ -1220,7 +1313,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=. @@ -1338,7 +1432,8 @@ PACKAGES="$PACKAGES $i" done echo " before group expansion packages are: $PACKAGES" - while ! expand_pkg_groups; do echo > /dev/null; done + RET=1 + while test $RET = 1 ; do expand_pkg_groups; RET=$?; done echo " after group expansion packages are: $PACKAGES" fi fi @@ -1447,7 +1542,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 @@ -1609,9 +1705,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 @@ -1686,7 +1780,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" @@ -1762,6 +1856,8 @@ FC = ${FC} # Fortran compiler F90C = ${F90C} +# C compiler +CC = ${CC} # Link editor LINK = ${LINK} ${LDADD}