2005-03-11  Stepan Kasal  <kasal@ucw.cz>

	* macros2/gnome-autogen.sh (add_to_cm_macrodirs): New function,
	  prevents duplicates.
	(check_m4macros): Look also into the directories listed in the
	  dirlist file; call add_to_cm_macrodirs; at the end, suggest all
	  three alternatives, not only ACLOCAL_FLAGS.
	(sed_ac_config_macro_dir, sed_aclocal_amflags): New variables,
	  contain sed scripts; use them in the main loop to search for
	  AC_CONFIG_MACRO_DIR in configure.ac and for ACLOCAL_AMFLAGS in
	  Makefile.am.

Index: macros2/gnome-autogen.sh
===================================================================
RCS file: /cvs/gnome/gnome-common/macros2/gnome-autogen.sh,v
retrieving revision 1.14
diff -u -r1.14 gnome-autogen.sh
--- macros2/gnome-autogen.sh	11 Feb 2005 08:59:41 -0000	1.14
+++ macros2/gnome-autogen.sh	11 Mar 2005 15:01:58 -0000
@@ -129,16 +129,37 @@
 }
 
 # Usage:
+#     add_to_cm_macrodirs dirname
+# Adds the dir to $cm_macrodirs, if it's not there yet.
+add_to_cm_macrodirs() {
+    case $cm_macrodirs in
+    "$1 "* | *" $1 "* | *" $1") ;;
+    *) cm_macrodirs="$cm_macrodirs $1";;
+    esac
+}
+
+# Usage:
 #     check_m4macros
 # Checks that all the requested macro files are in the aclocal macro path
 # Uses REQUIRED_M4MACROS and ACLOCAL variables.
 check_m4macros() {
     # construct list of macro directories
     cm_macrodirs="`$ACLOCAL --print-ac-dir`"
+    # aclocal also searches a version specific dir, eg. /usr/share/aclocal-1.9
+    # but it contains only Automake's own macros, so can ignore it.
+
+    # Search the dirlist file:
+    if [ -f $cm_macrodirs/dirlist ]; then
+	while read cm_dir; do
+	    add_to_cm_macrodirs "$cm_dir"
+	done <$cm_macrodirs/dirlist
+    fi
+
+    # Parse $ACLOCAL_FLAGS
     set - $ACLOCAL_FLAGS
     while [ $# -gt 0 ]; do
 	if [ "$1" = "-I" ]; then
-	    cm_macrodirs="$cm_macrodirs $2"
+	    add_to_cm_macrodirs "$2"
 	    shift
 	fi
 	shift
@@ -193,14 +214,35 @@
     fi
     if [ "$cm_status" != 0 ]; then
 	printerr "***Error***: some autoconf macros required to build $PKG_NAME"
-	printerr "  were not found in your aclocal path, or some forbidden"
-	printerr "  macros were found.  Perhaps you need to adjust your"
-	printerr "  ACLOCAL_FLAGS?"
+	printerr '  were not found in your aclocal path, or some forbidden'
+	printerr '  macros were found.  Perhaps you need to adjust one of these:'
+	printerr '   - the contents of the file $prefix/share/aclocal/dirlist, or'
+	printerr '   - variable ACLOCAL_AMFLAGS in the top level Makefile.am, or'
+	printerr '   - the environment variable ACLOCAL_FLAGS.'
 	printerr
     fi
     return $cm_status
 }
 
+# Sed command to extract AC_CONFIG_MACRO_DIR:
+sed_ac_config_macro_dir='
+s/^AC_CONFIG_MACRO_DIR(//
+t ok
+d
+:ok
+s/).*//
+s/^ *[[] *//
+s/ *]$ *//
+q'
+
+# Sed command to extract ACLOCAL_AMFLAGS:
+sed_aclocal_amflags='
+s/^ACLOCAL_AMFLAGS[ 	]*=[ 	]*//
+t ok
+d
+:ok
+q'
+
 # try to catch the case where the macros2/ directory hasn't been cleared out.
 forbid_m4macro gnome-cxx-check.m4
 
@@ -361,14 +403,17 @@
 
         # Now run aclocal to pull in any additional macros needed
 
-	# if the AC_CONFIG_MACRO_DIR() macro is used, pass that
+	# If the AC_CONFIG_MACRO_DIR() macro is used, pass that
 	# directory to aclocal.
-	m4dir=`cat "$basename" | grep '^AC_CONFIG_MACRO_DIR' | sed -n -e 's/AC_CONFIG_MACRO_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
+	m4dir=`sed "$sed_ac_config_macro_dir" "$basename"`
 	if [ -n "$m4dir" ]; then
-	    m4dir="-I $m4dir"
+	    ACLOCAL_FLAGS="-I $m4dir $ACLOCAL_FLAGS"
 	fi
+	# And likewise for ACLOCAL_AMFLAGS in the corresponding Makefile.am.
+	ACLOCAL_FLAGS=`sed "$sed_aclocal_amflags" "$basename"`" $ACLOCAL_FLAGS"
+
 	printbold "Running $ACLOCAL..."
-	$ACLOCAL $m4dir $ACLOCAL_FLAGS || exit 1
+	$ACLOCAL $ACLOCAL_FLAGS || exit 1
 
 	if grep "GNOME_AUTOGEN_OBSOLETE" aclocal.m4 >/dev/null; then
 	    printerr "*** obsolete gnome macros were used in $configure_ac"
