Many bug fixes
diff --git a/ChangeLog b/ChangeLog
index 0bd67ec..0efde9e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+Wed Feb  7 18:00:29 1996  Tom Tromey  <tromey@creche.cygnus.com>
+
+	* automake.in (handle_source_transform): All dep_files are
+	relative to $(srcdir).
+	(handle_libraries): Ditto.
+	(scan_configure): Test for AC_PROG_INSTALL as well as
+	fp_PROG_INSTALL.  Don't error here.
+	(seen_prog_install): Now global.
+	(scripts_installed): New global.
+	(handle_scripts): Set it.
+	Give error if appropriate install macro not seen.
+	(handle_subdirs): Ensure $seen_gettext before requiring
+	gettext-specific files.
+
+        From Jim Meyering:
+	* automake.in (handle_source_transform): Use \W when quoting
+	regexp.  When blah_SOURCES not explicitly defined, still create
+	entry in %deps.
+	* depend.am ($(srcdir)/.deps/%.P): Don't use \< in regexp.
+	* subdirs.am (maintainer-clean-recursive): Now depends on
+	$(CONFIG_HEADER) and Makefile.
+
+	* automake.in (handle_source_transform): Skip macro references.
+
 Mon Feb  5 14:58:58 1996  Tom Tromey  <tromey@creche.cygnus.com>
 
 	* automake.in (handle_texinfo): Include "rm" when deleting files.
diff --git a/NEWS b/NEWS
index 9339983..78237d8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,13 @@
 New in 0.29:
-* Bug fixes
+* Many bug fixes
 * More sophisticated configure.in scanning; now understands ALLOCA and
   LIBOBJS directly, handles AC_CONFIG_HEADER more precisely, etc.
 * TEXINFOS and MANS now obsolete; use info_TEXINFOS and man_MANS instead.
 * CONFIG_HEADER variable now obsolete
 * Can handle multiple Texinfo sources
 * Allow hierarchies deeper than 2.  From Gord Matzigkeit.
+* HEADERS variable no longer needed; now can put .h files directly into
+  foo_SOURCES variable.
 
 New in 0.28:
 * Added --gnu and --gnits options
diff --git a/TODO b/TODO
index d506d28..b425968 100644
--- a/TODO
+++ b/TODO
@@ -8,6 +8,8 @@
 Handle MAINT_CHARSET.  Use recode in dist target.  Handle dist-zoo and
 dist-zip.
 
+If AC_PATH_X given, add extra stuff to generated Makefile.in.
+
 Add support for html via an option.  Use texi2html.  Use
 "html_TEXINFOS", and htmldir = .../html.  Include html files in
 distribution.  Also allow "html_DATA", for raw .html files.
@@ -20,6 +22,8 @@
 a potential bug: configure puts "blah.o" into LIBOBJS, thus implying
 these files can't be de-ansified.  Not a problem?
 
+consider automatically adding -I$(srcdir) to INCLUDES.
+
 In general most .am files should be merged into automake.  For
 instance all the "clean" targets could be merged by keeping lists of
 things to be removed.  This would be a lot nicer looking.  Note that
@@ -57,10 +61,6 @@
 'maintainer-clean' should "rm -rf .deps".  Ditto distclean
 Should look for clean-local targets in Makefile.am.
 
-If 'foo' is in SCRIPTS, and 'foo.in' exists, generate code to rebuild
-by running configure.  Also, ensure that 'foo' is listed in AC_OUTPUT
-line.
-
 Think about writing a small tool to guess what the local Makefile.am
 should look like.
 
@@ -80,8 +80,8 @@
 check
 
 look in configure.in's AC_OUTPUT command and include those files in
-distribution.  Or consider new CONFIGURED_FILES macro that lists files
-generated by config.status.
+distribution.  Make sure to support the ":" notation.  automatically
+regenerate all files listed in AC_OUTPUT line.
 
 Auto-distribute "ChangeLog.[0-9]+"?
 
@@ -121,12 +121,6 @@
 	foo_SOURCES = a.c b.c
 Is this worth implementing?
 
-Get the list of Makefiles to create from configure.in AC_OUTPUT
-if none are given.
-	[ right now we look for any Makefile.am's lying around
-	  I think this is better, because it allows use of subdirs
-	  which don't use automake -- eg, stuff from gettext ]
-
 Should libexec programs have the name transform done on them?
 
 Order the output rules sensibly, so FOO_SOURCES and FOO_OBJECTS are
diff --git a/automake.in b/automake.in
index 56e6809..9f998ba 100755
--- a/automake.in
+++ b/automake.in
@@ -97,6 +97,12 @@
 # Whether ud_GNU_GETTEXT has been seen in configure.in.
 $seen_gettext = 0;
 
+# 1 if AC_PROG_INSTALL seen, 2 if fp_PROG_INSTALL seen.
+$seen_prog_install = 0;
+
+# 1 if any scripts installed, 0 otherwise.
+$scripts_installed = 0;
+
 
 
 &initialize_global_constants;
@@ -123,6 +129,10 @@
     }
 }
 
+&am_conf_error ($scripts_installed ? 'fp_PROG_INSTALL' : 'AC_PROG_INSTALL'
+		. " must be used in configure.in")
+    unless $seen_prog_install > $scripts_installed;
+
 exit $exit_status;
 
 
@@ -369,7 +379,7 @@
 {
     local ($one_file, $obj) = @_;
     local ($objpat) = $obj;
-    $objpat =~ s/([.\$])/\\\1/g;
+    $objpat =~ s/(\W)/\\\1/g;
 
     # Look for file_SOURCES and file_OBJECTS.
     if (defined $contents{$one_file . "_SOURCES"})
@@ -381,8 +391,11 @@
 	    local (@result) = ();
 	    foreach (@files)
 	    {
-		# Just skip header files.
+		# Skip header files.
 		next if /\.h$/;
+		# Skip things that look like macro references.
+		next if /^\$\(.*\)$/;
+		next if /^\$\{.*\}$/;
 
 		if (/^(.*)\.[yl]$/)
 		{
@@ -399,7 +412,7 @@
 		# Transform .o or $o file into .P file (for automatic
 		# dependency code).
 		s/$objpat$/.P/g;
-		$dep_files{'.deps/' . $_} = 1;
+		$dep_files{'$(srcdir)/.deps/' . $_} = 1;
 	    }
 
 	    &pretty_print ($one_file . "_OBJECTS =", '', @result);
@@ -419,6 +432,7 @@
 			 . $obj . "\n");
 	push (@sources, $one_file . '.c');
 	push (@objects, $one_file . $obj);
+	$dep_files{'$(srcdir)/.deps/' . $one_file . '.P'} = 1;
     }
 
     if (defined $contents{'CONFIG_HEADER'})
@@ -507,7 +521,7 @@
 			if ($iter ne 'alloca.c')
 			{
 			    ($rewrite = $iter) =~ s/\.c$/.P/;
-			    $dep_files{'.deps/' . $rewrite} = 1;
+			    $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
 			    &require_file ($NORMAL, $iter);
 			}
 		    }
@@ -516,7 +530,7 @@
 		{
 		    &am_error ("\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
 			if ! defined $libsources{'alloca.c'};
-		    $dep_files{'.deps/alloca.P'} = 1;
+		    $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
 		    &require_file ($NORMAL, 'alloca.c');
 		}
 	    }
@@ -548,9 +562,11 @@
 # Handle scripts.
 sub handle_scripts
 {
-    &am_install_var ('-clean',
-		     'scripts', 'SCRIPTS',
-		     'bin', 'sbin', 'libexec', 'noinst');
+    # FIXME can't determine if these scripts are really being
+    # installed or not.
+    $scripts_installed = &am_install_var ('-clean',
+					  'scripts', 'SCRIPTS',
+					  'bin', 'sbin', 'libexec', 'noinst');
 }
 
 # Search a file for a "version.texi" Texinfo include.  Return the name
@@ -1018,12 +1034,12 @@
 
     &am_conf_error
 	("ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
-	    if $contents{'SUBDIRS'} !~ /\bpo\b/;
+	    if $seen_gettext && $contents{'SUBDIRS'} !~ /\bpo\b/;
     &am_conf_error
 	("ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
-	    if $contents{'SUBDIRS'} !~ /\bintl\b/;
+	    if $seen_gettext && $contents{'SUBDIRS'} !~ /\bintl\b/;
 
-    &require_file ($NORMAL, 'ABOUT-NLS');
+    &require_file ($NORMAL, 'ABOUT-NLS') if $seen_gettext;
 
     return if ! defined $contents{'SUBDIRS'};
 
@@ -1401,7 +1417,6 @@
     %libsources = ();
 
     local ($in_ac_output, @make_list) = 0;
-    local ($seen_prog_install) = 0;
     local ($seen_arg_prog) = 0;
     local ($seen_canonical) = 0;
     while (<CONFIGURE>)
@@ -1498,7 +1513,8 @@
 	# we only really require AC_ARG_PROGRAM if any program is
 	# installed.
 	$seen_make_set = 1 if /AC_PROG_MAKE_SET/;
-	$seen_prog_install = 1 if /fp_PROG_INSTALL/;
+	$seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
+	$seen_prog_install = 2 if ! $seen_prog_install && /fp_PROG_INSTALL/;
 	$seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
     }
 
@@ -1510,8 +1526,6 @@
     &require_file ($NORMAL, 'config.guess', 'config.sub')
 	if $seen_canonical;
 
-    &am_conf_error ("fp_PROG_INSTALL must be used in configure.in")
-	unless $seen_prog_install;
     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
 	unless $seen_arg_prog;
 
diff --git a/automake.texi b/automake.texi
index 3492e90..cd31b47 100644
--- a/automake.texi
+++ b/automake.texi
@@ -180,17 +180,6 @@
 AC_SUBST(VERSION)
 @end example
 
-If your @file{configure.in} uses @samp{AC_CONFIG_HEADER}, then in each
-directory you should define the @samp{CONFIG_HEADER} variable to hold
-the name of the header.
-
-For instance, in cpio's @file{src/Makefile.am}, we see:
-
-@example
-CONFIG_HEADER = ../config.h
-@end example
-
-
 @code{automake} also assumes that your @file{configure} script will
 define the variable @samp{INSTALL_SCRIPT}.  Until this is incorporated
 in @code{autoconf}'s @samp{AC_PROG_INSTALL} macro, you can use this
@@ -209,6 +198,8 @@
 ])
 @end example
 
+@code{automake} requires this macro if you install any scripts.
+Otherwise only @code{AC_PROG_INSTALL} is required.
 
 @code{automake} also assumes your @file{configure.in} calls
 @samp{AC_ARG_PROGRAM}.
@@ -310,11 +301,11 @@
 
 In this simple case, the resulting @file{Makefile.in} will contain code
 to generate a program named @code{hello}.  The variable
-@samp{@var{prog}_SOURCE} is used to specify which source files get built
+@samp{@var{prog}_SOURCES} is used to specify which source files get built
 into an executable:
 
 @example
-hello_SOURCE = hello.c
+hello_SOURCES = hello.c
 @end example
 
 This causes @file{hello.o} to be built from @code{hello.c} at compile
@@ -322,7 +313,7 @@
 
 Multiple programs can be built in a single directory -- simply list them
 all in the @samp{PROGRAMS} definition.  Multiple programs can share a
-single source file.  The source file must be listed in each ``_SOURCE''
+single source file.  The source file must be listed in each ``_SOURCES''
 definition.
 
 Sometimes it is useful to determine the programs that are to be built at
diff --git a/depend.am b/depend.am
index c596cc3..18d2d39 100644
--- a/depend.am
+++ b/depend.am
@@ -36,11 +36,12 @@
 
 $(srcdir)/.deps/%.P: $(srcdir)/%.c
 	@echo "mkdeps $< > $@"
-## Need \< in regexp because otherwise when srcdir=. too much can be
-## matched.  Also we regexp-quote srcdir because "." is a matching
-## operator, and commonly appears in filenames.
-	@re=`echo 's,\<$(srcdir),,g' | sed 's/\./\\./g'`; \
-	  $(MKDEP) $< | sed $$re > $@-tmp
+## Use funny regexp because otherwise too much can be matched when
+## srcdir begins with ".".  Can't use \< since sed doesn't recognize
+## "." as a word start.  Regexp-quote srcdir because "." is a matching
+## operator which commonly appears in filenames.
+	@re=`echo 's,^$(srcdir)/*,,g;s, $(srcdir)/*, ,g' | sed 's,\.,\\\\.,g'`; \
+	  $(MKDEP) $< | sed "$$re" > $@-tmp
 	@if test -n "$o"; then			\
 	  sed 's/\.o:/$$o:/' $@-tmp > $@;	\
 	  rm $@-tmp;				\
diff --git a/lib/am/depend.am b/lib/am/depend.am
index c596cc3..18d2d39 100644
--- a/lib/am/depend.am
+++ b/lib/am/depend.am
@@ -36,11 +36,12 @@
 
 $(srcdir)/.deps/%.P: $(srcdir)/%.c
 	@echo "mkdeps $< > $@"
-## Need \< in regexp because otherwise when srcdir=. too much can be
-## matched.  Also we regexp-quote srcdir because "." is a matching
-## operator, and commonly appears in filenames.
-	@re=`echo 's,\<$(srcdir),,g' | sed 's/\./\\./g'`; \
-	  $(MKDEP) $< | sed $$re > $@-tmp
+## Use funny regexp because otherwise too much can be matched when
+## srcdir begins with ".".  Can't use \< since sed doesn't recognize
+## "." as a word start.  Regexp-quote srcdir because "." is a matching
+## operator which commonly appears in filenames.
+	@re=`echo 's,^$(srcdir)/*,,g;s, $(srcdir)/*, ,g' | sed 's,\.,\\\\.,g'`; \
+	  $(MKDEP) $< | sed "$$re" > $@-tmp
 	@if test -n "$o"; then			\
 	  sed 's/\.o:/$$o:/' $@-tmp > $@;	\
 	  rm $@-tmp;				\
diff --git a/lib/am/subdirs.am b/lib/am/subdirs.am
index 85c037a..a335ab6 100644
--- a/lib/am/subdirs.am
+++ b/lib/am/subdirs.am
@@ -28,7 +28,7 @@
 installdirs-recursive install-recursive uninstall-recursive \
 check-recursive installcheck-recursive info-recursive dvi-recursive \
 mostlyclean-recursive clean-recursive distclean-recursive \
-maintainer-clean-recursive:
+maintainer-clean-recursive: $(CONFIG_HEADER) Makefile
 	for subdir in $(SUBDIRS); do		\
 	  target=`echo $@ | sed s/-recursive//`; \
 	  echo making $$target in $$subdir;	\
diff --git a/subdirs.am b/subdirs.am
index 85c037a..a335ab6 100644
--- a/subdirs.am
+++ b/subdirs.am
@@ -28,7 +28,7 @@
 installdirs-recursive install-recursive uninstall-recursive \
 check-recursive installcheck-recursive info-recursive dvi-recursive \
 mostlyclean-recursive clean-recursive distclean-recursive \
-maintainer-clean-recursive:
+maintainer-clean-recursive: $(CONFIG_HEADER) Makefile
 	for subdir in $(SUBDIRS); do		\
 	  target=`echo $@ | sed s/-recursive//`; \
 	  echo making $$target in $$subdir;	\