--- MITgcm/tools/genmake2 2003/11/11 20:38:27 1.29 +++ MITgcm/tools/genmake2 2003/11/13 22:03:39 1.35 @@ -1,6 +1,6 @@ -#!/bin/bash +#!/bin/sh # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.29 2003/11/11 20:38:27 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.35 2003/11/13 22:03:39 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -104,6 +104,16 @@ CPP="cpp -traditional -P" fi + # makedepend is not always available + 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' + fi + fi + # look for possible fortran compilers tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95" p_FC= @@ -206,7 +216,7 @@ cat $1 | sed -e 's/#.*$//g' \ | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \ > ./.pd_tmp - source ./.pd_tmp + . ./.pd_tmp rm -f ./.pd_tmp echo -n "PNAME = "${} @@ -264,24 +274,84 @@ exit 1 } -#eh3 # This is the generic configuration. -#eh3 set LN = ( 'ln -s' ) -#eh3 set CPP = ( '/lib/cpp -P' ) -#eh3 set S64 = ( '$(TOOLSDIR)/set64bitConst.sh' ) -#eh3 set KPP = ( ) -#eh3 set FC = ( 'f77' ) -#eh3 set LINK = $FC -#eh3 set MAKEDEPEND = ( 'makedepend' ) -#eh3 set INCLUDES = ( -I. ) -#eh3 set FFLAGS = ( ) -#eh3 set FOPTIM = ( ) -#eh3 set CFLAGS = ( ) -#eh3 set KFLAGS1 = ( ) -#eh3 set KFLAGS2 = ( ) -#eh3 set LIBS = ( ) -#eh3 set KPPFILES = ( ) -#eh3 if (! $?NOOPTFILES ) set NOOPTFILES = ( ) -#eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = ( ) +# Build a CPP macro to automate calling C routines from FORTRAN +get_fortran_c_namemangling() { + default_nm="#define FC_NAMEMANGLE(X) X ## _" + + cat > genmake_test.c < genmake_test.log 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 ; then + cat genmake_test.log >> genmake_errors + FC_NAMEMANGLE=$default_nm + echo + echo "WARNING: C test compile fails -- please see \"genmake_errors\"" + echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" + echo "WARNING: Please contact if you need help here." + return 1 + fi + c_tcall=`nm genmake_test.o | grep tcall | cut -d ' ' -f 3` + RETVAL=$? + if test "x$RETVAL" != x0 ; then + FC_NAMEMANGLE=$default_nm + echo + echo "WARNING: The \"nm\" command failed." + echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" + echo "WARNING: Please contact if you need help here." + return 1 + fi + cat > genmake_tcomp.f < genmake_tcomp.log 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 ; then + cat genmake_tcomp.log >> genmake_errors + FC_NAMEMANGLE=$default_nm + echo + echo "WARNING: FORTRAN test compile fails -- please see \"genmake_errors\"" + echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" + echo "WARNING: Please contact if you need help here." + return 1 + fi + f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3` + RETVAL=$? + if test "x$RETVAL" != x0 ; then + FC_NAMEMANGLE=$default_nm + echo + echo "WARNING: The \"nm\" command failed." + echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" + echo "WARNING: Please contact if you need help here." + return 1 + fi + + c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'` + f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'` + c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'` + f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'` + + nmangle="X" + if test "x$c_a" != "x$f_a" ; then + comm="echo x$f_a | sed -e 's|x$c_a||'" + a=`eval $comm` + nmangle="$a ## $nmangle" + fi + if test "x$c_b" != "x$f_b" ; then + comm="echo x$f_b | sed -e 's|x$c_b||'" + b=`eval $comm` + nmangle="$nmangle ## $b" + fi + + FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle" + + # cleanup the testing files + rm -f genmake_tcomp.* genmake_test.* +} # Set defaults here COMMANDL="$0 $@" @@ -292,7 +362,8 @@ KPP= FC= LINK= -DEFINES="-DWORDLENGTH=4" +# DEFINES="-DWORDLENGTH=4" +DEFINES= PACKAGES= ENABLE= DISABLE= @@ -379,14 +450,14 @@ gm_local="genmake_local" for i in . $MODS ; do if test -r $i/$gm_local ; then - source $i/$gm_local + . $i/$gm_local break fi done echo -n " getting local config information: " if test -e $gm_local ; then echo "using $gm_local" - source $gm_local + . $gm_local # echo "DISABLE=$DISABLE" # echo "ENABLE=$ENABLE" else @@ -590,7 +661,7 @@ if test "x$OPTFILE" != xNONE ; then if test -f "$OPTFILE" -a -r "$OPTFILE" ; then echo " using OPTFILE=\"$OPTFILE\"" - source "$OPTFILE" + . "$OPTFILE" RETVAL=$? if test "x$RETVAL" != x0 ; then echo -n "Error: failed to source OPTFILE \"$OPTFILE\"" @@ -617,7 +688,7 @@ if test "x${AD_OPTFILE}" != xNONE ; then if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then echo " using AD_OPTFILE=\"$AD_OPTFILE\"" - source "$AD_OPTFILE" + . "$AD_OPTFILE" RETVAL=$? if test "x$RETVAL" != x0 ; then echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\"" @@ -633,8 +704,8 @@ fi fi -# Check that FC, LINK, CPP, and S64 are defined. If not, complain -# and abort! +# Check that FC, LINK, CPP, S64, and LN are defined. If not, +# complain and abort! if test "x$FC" = x ; then cat <&2 @@ -660,6 +731,7 @@ 1) within the options file ("CPP=...") as specified by "-of=OPTFILE" 2) the "./genmake_local" file + 3) with the CPP environment variable EOF exit 1 @@ -669,7 +741,22 @@ if test "x$MAKEDEPEND" = x ; then MAKEDEPEND=makedepend fi +if test "x$LN" = x ; then + LN="ln -s" +fi +echo "test" > genmake_test_ln +$LN genmake_test_ln genmake_tlink +RETVAL=$? +if test "x$RETVAL" != x0 ; then + cat <&2 +Error: The command "ln -s" failed -- please specify a working soft-link + command in the optfile. + +EOF + exit 1 +fi +rm -f genmake_test_ln genmake_tlink printf "\n=== Checking system libraries ===\n" echo -n " Do we have the system() command using $FC... " @@ -711,46 +798,18 @@ fi rm -f genmake_tcomp* -echo -n " The name mangling convention for $FC is... " +echo " The name mangling convention for $FC is... " +#FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _" if test "x$FC_NAMEMANGLE" = x ; then - FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _" -fi -cat > genmake_tcomp.f < genmake_tcomp.log 2>&1 -RETVAL=$? -if test "x$RETVAL" != x0 ; then - cat genmake_tcomp.log >> genmake_errors - echo - echo "WARNING: test compile fails -- please see \"genmake_errors\"" - echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" - echo "WARNING: Please contact if you need help here." -else - tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3` - RETVAL=$? - if test "x$RETVAL" != x0 ; then - echo - echo "WARNING: The \"nm\" command failed." - echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" - echo "WARNING: Please contact if you need help here." - else - t0=`echo $tcall | sed -e 's|_tcall|_ ## X|g'` - nmres=`echo $t0 | sed -e 's|tcall_|X ## _|g'` - FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmres" - echo "'$FC_NAMEMANGLE'" - fi + get_fortran_c_namemangling fi +echo " '$FC_NAMEMANGLE'" echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h fi -rm -f genmake_tcomp* printf "\n=== Setting defaults ===\n" @@ -842,7 +901,7 @@ echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\"" exit 1 fi -source ./.pd_tmp +. ./.pd_tmp rm -f ./.pd_tmp # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"