--- MITgcm/tools/genmake2 2004/03/16 18:20:34 1.73 +++ MITgcm/tools/genmake2 2004/04/07 20:28:09 1.75 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.73 2004/03/16 18:20:34 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.75 2004/04/07 20:28:09 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -67,11 +67,54 @@ done PACKAGES=$new_packages rm -f ./p[1,2].tmp + return $matched else echo "Warning: can't read package groups definition file: $PKG_GROUPS" fi } +# Check for broken environments (eg. cygwin, MacOSX w/HFS+) that +# cannot distinguish [*.F/*.F90] from [*.f/*.f90] files. +check_for_broken_Ff() { + # First check the ability to create a *.F/.f pair. + cat <> ./hello.F + program hello + write(*,*) 'hi' + stop + end +EOF + cp ./hello.F ./hello.f + RETVAL=$? + if test "x$RETVAL" != x0 ; then + FEXT='fp' + F90EXT='fp90' + return + fi + rm -f ./hello.f + + # Then check the ability of ${MAKE} to use the two. + test -e Makefile && mv -f Makefile Makefile.bak + cat <> Makefile +.SUFFIXES: +hello.f: hello.F + cp -f hello.F hello.f +EOF + ( $MAKE hello.f ) > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 -o ! -f ./hello.f ; then + FEXT='fp' + F90EXT='fp90' + return + fi + rm -f ./hello.f ./hello.F Makefile + test -e Makefile && mv -f Makefile.bak Makefile + + # Both tests passed, so use the default. + FEXT='F' + F90EXT='F90' +} + + # Guess possible config options for this host find_possible_configs() { @@ -496,7 +539,7 @@ check_netcdf_libs() { - cat < genmake_tnc.F + cat < genmake_tnc.for program fgennc #include "netcdf.inc" integer iret, ncid, xid @@ -508,7 +551,7 @@ IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) end EOF - $CPP genmake_tnc.F > genmake_tnc.f \ + $CPP genmake_tnc.for > 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 @@ -517,7 +560,7 @@ HAVE_NETCDF=t else # try again with "-lnetcdf" added to the libs - $CPP genmake_tnc.F > genmake_tnc.f \ + $CPP genmake_tnc.for > genmake_tnc.f \ && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \ $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1 RET_COMPILE=$? @@ -603,6 +646,8 @@ if test "x$MITGCM_IEEE" != x ; then IEEE=$MITGCM_IEEE fi +FEXT= +F90EXT= AUTODIFF_PKG_USED=f AD_OPTFILE= @@ -889,6 +934,11 @@ fi fi +# Check for broken systems that cannot correctly distinguish *.F and *.f files +if test "x$FEXT" = x -a "x$F90EXT" = x ; then + check_for_broken_Ff +fi + echo " getting AD_OPTFILE information: " if test "x${AD_OPTFILE}" = x ; then if test "x$MITGCM_AD_OF" = x ; then @@ -1190,12 +1240,19 @@ PACKAGES="$PACKAGES $i" done echo " before group expansion packages are: $PACKAGES" - expand_pkg_groups + while ! expand_pkg_groups; do echo > /dev/null; done echo " after group expansion packages are: $PACKAGES" fi fi echo " applying DISABLE settings" +for i in $PACKAGES ; do + echo $i >> ./.tmp_pack +done +for i in `grep "-" ./.tmp_pack` ; do + j=`echo $i | sed 's/[-]//'` + DISABLE="$DISABLE $j" +done pack= for p in $PACKAGES ; do addit="t" @@ -1212,19 +1269,20 @@ echo " applying ENABLE settings" echo "" > ./.tmp_pack PACKAGES="$PACKAGES $ENABLE" +# Test if each explicitly referenced package exists for i in $PACKAGES ; do - if test ! -d "$ROOTDIR/pkg/$i" ; then + j=`echo $i | sed 's/[-+]//'` + if test ! -d "$ROOTDIR/pkg/$j" ; then echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\"" - exit 1 + exit 1 fi echo $i >> ./.tmp_pack done -pack=`cat ./.tmp_pack | sort | uniq` -rm -f ./.tmp_pack PACKAGES= -for i in $pack ; do +for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do PACKAGES="$PACKAGES $i" done +rm -f ./.tmp_pack echo " packages are: $PACKAGES" echo " applying package dependency rules" @@ -1639,19 +1697,19 @@ cat f90srclist.inc >> $MAKEFILE cat hlist.inc >> $MAKEFILE cat ad_flow_files.inc >> $MAKEFILE -echo >> $MAKEFILE -echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE -echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE -echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE +echo >> $MAKEFILE +echo 'F77FILES = $(SRCFILES:.'$FEXT'=.f)' >> $MAKEFILE +echo 'F90FILES = $(F90SRCFILES:.'$F90EXT'=.f90)' >> $MAKEFILE +echo 'OBJFILES = $(SRCFILES:.'$FEXT'=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.'$F90EXT'=.o)' >> $MAKEFILE +echo >> $MAKEFILE +echo '.SUFFIXES:' >> $MAKEFILE +echo '.SUFFIXES: .o .f .p .'$FEXT' .c .'$F90EXT' .f90' >> $MAKEFILE rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc rm -f ad_flow_files.inc cat >>$MAKEFILE < \$@ -# The normal chain of rules is ( .F - .f - .o ) -.F.f: +# The normal chain of rules is ( .$FEXT - .f - .o ) +.$FEXT.f: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .f.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< -.F90.f90: +.$F90EXT.f90: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .f90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .c.o: \$(CC) \$(CFLAGS) -c \$< -# Special exceptions that use the ( .F - .p - .f - .o ) rule-chain -.F.p: +# Special exceptions that use the ( .$FEXT - .p - .f - .o ) rule-chain +.$FEXT.p: \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .p.f: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<