--- MITgcm/tools/genmake2 2003/10/01 18:44:48 1.11.2.1 +++ MITgcm/tools/genmake2 2003/10/02 14:42:04 1.11.2.6 @@ -1,6 +1,6 @@ #!/bin/bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.11.2.1 2003/10/01 18:44:48 adcroft Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.11.2.6 2003/10/02 14:42:04 edhill Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -11,34 +11,61 @@ # Search for particular CPP #cmds associated with packages # usage: test_for_package_in_cpp_options CPP_file package_name test_for_package_in_cpp_options() { - cpp_options=$1 - pkg=$2 - grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1 - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg" - exit 99 - fi - grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1 - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg" - exit 99 - fi - grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1 - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg" - exit 99 - fi - grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1 - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg" - exit 99 + cpp_options=$1 + pkg=$2 + grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg" + exit 99 + fi + grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg" + exit 99 + fi + grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg" + exit 99 + fi + grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg" + exit 99 fi } +# Read the $ROOTDIR/pkg/pkg_groups file and expand any references to +# the package list. +expand_pkg_groups() { + new_packages= + PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups" + if test -r $PKG_GROUPS ; then + cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp + cat ./p1.tmp | awk '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp + matched=0 + for i in $PACKAGES ; do + line=`grep $i ./p2.tmp` + RETVAL=$? + if test "x$RETVAL" = x0 ; then + matched=1 + replace=`echo $line | awk '{ $1=""; $2=""; print $0 }'` + echo " replacing \"$i\" with: $replace" + new_packages="$new_packages $replace" + else + new_packages="$new_packages $i" + fi + done + PACKAGES=$new_packages + rm -f ./p[1,2].tmp + else + echo "Warning: can't read package groups definition file: $PKG_GROUPS" + fi +} # Guess possible config options for this host find_possible_configs() { @@ -634,8 +661,19 @@ source ./.pd_tmp rm -f ./.pd_tmp +# Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups" +# file should eventually be added so that, for convenience, one can +# specify groups of packages using names like "ocean" and "atmosphere". echo -n " checking default package list: " if test "x${PDEFAULT}" = x ; then + for i in "." $MODS ; do + if test -r $i"/packages.conf" ; then + PDEFAULT=$i"/packages.conf" + break + fi + done +fi +if test "x${PDEFAULT}" = x ; then PDEFAULT="$ROOTDIR/pkg/pkg_default" fi if test "x${PDEFAULT}" = xNONE ; then @@ -657,7 +695,9 @@ for i in $def ; do PACKAGES="$PACKAGES $i" done - echo " packages are: $PACKAGES" + echo " before group expansion packages are: $PACKAGES" + expand_pkg_groups + echo " after group expansion packages are: $PACKAGES" fi fi @@ -794,21 +834,16 @@ # Create a list of #define and #undef to enable/disable packages PACKAGES_DOT_H=PACKAGES.h -if test -e $PACKAGES_DOT_H ; then - if test ! -e $PACKAGES_DOT_H.bak ; then - cp -f $PACKAGES_DOT_H $PACKAGES_DOT_H.bak - fi - cat $PACKAGES_DOT_H \ - | awk 'BEGIN{p=1;} ($1=="C===" && $2=="GENMAKE"){p=0;} {if (p==1) print $0}' \ - > $PACKAGES_DOT_H.tmp -fi -cat <>$PACKAGES_DOT_H.tmp +cat <$PACKAGES_DOT_H".tmp" C=== GENMAKE v2 === C The following defines have been set by GENMAKE, so please do not C edit anything below these comments. In general, you should C add or remove packages by re-running genmake with different C "-enable" and/or "-disable" options. +#ifndef PACKAGES_H +#define PACKAGES_H + C Packages disabled by genmake: EOF # The following UGLY HACK sets multiple "#undef"s and it needs to go @@ -828,7 +863,7 @@ done if test "x$has_pack" = xf ; then undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'` - echo "#undef $undef" >> $PACKAGES_DOT_H.tmp + echo "#undef $undef" >> $PACKAGES_DOT_H".tmp" # DEFINES="$DEFINES -U$undef" #EH3 WARNING : This is an UGLY HACK that needs to be removed!!! @@ -848,27 +883,43 @@ fi fi done -cat <>$PACKAGES_DOT_H.tmp +cat <>$PACKAGES_DOT_H".tmp" C Packages enabled by genmake: EOF for i in $PACKAGES ; do def=`echo "ALLOW_$i" | awk '{print toupper($0)}'` - echo "#define $def" >> $PACKAGES_DOT_H.tmp - DEFINES="$DEFINES -D$def" + echo "#define $def" >> $PACKAGES_DOT_H".tmp" +#eh3 DEFINES="$DEFINES -D$def" #EH3 WARNING : This is an UGLY HACK that needs to be removed!!! case $i in aim_v23) - echo "#define ALLOW_AIM" >> $PACKAGES_DOT_H.tmp - DEFINES="$DEFINES -DALLOW_AIM" + echo "#define ALLOW_AIM" >> $PACKAGES_DOT_H".tmp" + DEFINES="$DEFINES -DALLOW_AIM" echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)" ;; esac #EH3 WARNING : This is an UGLY HACK that needs to be removed!!! done -mv -f $PACKAGES_DOT_H.tmp $PACKAGES_DOT_H +cat <>$PACKAGES_DOT_H".tmp" + +#endif /* PACKAGES_H */ +EOF + +if test ! -f $PACKAGES_DOT_H ; then + mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H +else + cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H + RETVAL=$? + if test "x$RETVAL" = x0 ; then + rm -f $PACKAGES_DOT_H".tmp" + else + mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak" + mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H + fi +fi echo " Adding STANDARDDIRS" BUILDDIR=${BUILDDIR:-.} @@ -892,7 +943,8 @@ fi done -echo " Searching for CPP_OPTIONS.h (macros and flags for configuring the model):" +echo " Searching for CPP_OPTIONS.h in order to warn about the presence" +echo " of \"#define ALLOW_PKGNAME\"-type statements:" CPP_OPTIONS= spaths=". $INCLUDEDIRS" for i in $spaths ; do @@ -901,9 +953,6 @@ if test -f $try -a -r $try ; then echo " found CPP_OPTIONS=\"$try\"" CPP_OPTIONS="$try" -#aja if test "x$i" != "x." ; then -#aja cp -f $CPP_OPTIONS . -#aja fi break fi done @@ -983,8 +1032,6 @@ echo "" >> f90srclist.inc echo "" >> hlist.inc -echo $DEFINES - if test -e $MAKEFILE ; then mv -f $MAKEFILE "$MAKEFILE.bak" fi @@ -1106,7 +1153,7 @@ Clean: @make clean @make cleanlinks - -rm -f Makefile.bak gm_state gm_optfile make.log PACKAGES.h* + -rm -f Makefile.bak gm_state gm_optfile make.log CLEAN: @make Clean -find \$(EXEDIR) -name "*.meta" -exec rm {} \;