Rewrote dependency handling
authorTom Tromey <tromey@redhat.com>
Thu, 5 Sep 1996 03:02:31 +0000 (03:02 +0000)
committerTom Tromey <tromey@redhat.com>
Thu, 5 Sep 1996 03:02:31 +0000 (03:02 +0000)
ChangeLog
NEWS
TODO
automake.in
depend.am
depend2.am
lib/am/depend.am
lib/am/depend2.am
tests/block.test

index ac34763..096f09c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,33 @@
 Wed Sep  4 11:36:06 1996  Tom Tromey  <tromey@creche.cygnus.com>
 
+       * automake.in (handle_source_transform): .deps no longer in
+       srcdir.
+       (handle_lib_objects): Ditto.
+       (handle_dist_worker): Pass --build-dir to automake.
+       ($build_directory): New global.
+       (parse_arguments): Handle --build-dir.
+       (initialize_global_constants): Include --build-dir in help.
+       (scan_dependency_file): New sub.
+       (handle_dependencies): Use it.  Also, use $build_directory.
+       (initialize_global_constants): Added --srcdir-name.
+       (parse_arguments): Ditto.
+       (handle_dist_worker): Ditto.
+       ($srcdir_name): New global.
+       ($srcdir_rx): New global.
+       (parse_arguments): Set it.
+
+       * depend2.am: Removed all mention of $(srcdir).
+
+       * depend.am (MKDEP): Use gcc -M, not gcc -MM.
+       Removed all mention of $(srcdir); dependencies now put into build
+       dir.
+
+       * depend2.am ($(srcdir)/.deps/%.P): Fixed computation of `top'.
+       Don't do work silently.
+
        * automake.in (handle_merge_targets): Error if invalid uninstall
        targets are given.
+       (read_am_file): Fix for test block.test.
 
 Tue Sep  3 18:50:32 1996  Tom Tromey  <tromey@creche.cygnus.com>
 
diff --git a/NEWS b/NEWS
index 171b134..325f176 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ New in 1.1d:
 * Random files listed in AC_OUTPUT now removed by "make clean"
 * Will compute _DEPENDENCIES variables automatically if not supplied
 * Will interpolate $(...) and ${...} when examining contents of a variable
+* .deps files now in build directory, not source directory; dependency
+  handling generally rewritten
 \f
 New in 1.0:
 * Bug fixes
diff --git a/TODO b/TODO
index b75cab0..fe12ec4 100644 (file)
--- a/TODO
+++ b/TODO
@@ -349,6 +349,7 @@ document *not* putting config.h into _SOURCES
 
 document variable scanning: $() and ${} interpolation
 
+document --build-dir
 
 ================================================================
 
index 78426fe..9e7ebf5 100755 (executable)
@@ -99,6 +99,16 @@ $output_directory = '.';
 # Relative location of top build directory.
 $top_builddir = '';
 
+# Absolute location of top build directory.
+$build_directory = '';
+
+# Name of srcdir as given in build directory's Makefile.  For
+# dependencies only.
+$srcdir_name = '';
+
+# Regular expression derived from srcdir_name.
+$srcdir_rx = '';
+
 # List of Makefile.am's to process.
 @input_files = ();
 
@@ -261,6 +271,30 @@ sub parse_arguments
            shift (@arglist);
            $am_dir = $arglist[0];
        }
+       elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
+       {
+           # Must end in /.
+           $build_directory = $1 . '/';
+       }
+       elsif ($arglist[0] eq '--build-dir')
+       {
+           &require_argument (@arglist);
+           shift (@arglist);
+           # Must end in /.
+           $build_directory = $arglist[0] . '/';
+       }
+       elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
+       {
+           $srcdir_name = $1;
+           ($srcdir_rx = $srcdir_name) =~ s/(\W)/\\$1/g;
+       }
+       elsif ($arglist[0] eq '--srcdir-name')
+       {
+           &require_argument (@arglist);
+           shift (@arglist);
+           $srcdir_name = $arglist[0];
+           ($srcdir_rx = $srcdir_name) =~ s/(\W)/\\$1/g;
+       }
        elsif ($arglist[0] =~ /^--strictness=(.+)$/)
        {
            &set_strictness ($1);
@@ -812,7 +846,7 @@ sub handle_source_transform
                # Transform .o or $o file into .P file (for automatic
                # dependency code).
                s/$objpat$/.P/g;
-               $dep_files{'$(srcdir)/.deps/' . $_} = 1;
+               $dep_files{'.deps/' . $_} = 1;
            }
 
            &pretty_print ($one_file . "_OBJECTS =", "", @result)
@@ -867,7 +901,7 @@ sub handle_lib_objects
                if ($iter ne 'alloca.c')
                {
                    ($rewrite = $iter) =~ s/\.c$/.P/;
-                   $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
+                   $dep_files{'.deps/' . $rewrite} = 1;
                    &require_file_with_line ($var, $FOREIGN, $iter);
                }
            }
@@ -877,7 +911,7 @@ sub handle_lib_objects
            &am_line_error ($var,
                            "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
                if ! defined $libsources{'alloca.c'};
-           $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
+           $dep_files{'.deps/alloca.P'} = 1;
            &require_file_with_line ($var, $FOREIGN, 'alloca.c');
        }
     }
@@ -1430,9 +1464,9 @@ sub handle_dist_worker
                (
                 # We need an absolute path for --output-dir.  Thus the
                 # weirdness.
-                '      distdir=`cd $(distdir) && pwd` \\
+                '      here=`pwd`; distdir=`cd $(distdir) && pwd` \\
          && cd $(srcdir) \\
-         && automake --include-deps --output-dir=$$distdir --strictness='
+         && automake --include-deps --build-dir=$$here --srcdir-name=$(srcdir) --output-dir=$$distdir --strictness='
                 # Set strictness of output.
                 . $strictness_name . "\n"
                 );
@@ -1627,6 +1661,70 @@ distcheck: dist
     &handle_dist_worker;
 }
 
+# Scan a single dependency file and rewrite the dependencies as
+# appropriate.  Essentially this means:
+# * Clean out absolute dependencies which are not desirable.
+# * Rewrite other dependencies to be relative to $(top_srcdir).
+sub scan_dependency_file
+{
+    local ($depfile) = @_;
+
+    if (! open (DEP_FILE, $depfile))
+    {
+       &am_error ("couldn't open \`$depfile': $!");
+       return;
+    }
+    print "automake: reading $depfile\n" if $verbose;
+
+    local ($first_line) = 1;
+    local ($target, @dependencies);
+    local ($one_dep, $xform);
+
+    while (<DEP_FILE>)
+    {
+       next if (/$WHITE_PATTERN/o);
+       chop;
+       s/\\$//;
+
+       if ($first_line)
+       {
+           if (! /([^:]+):(.+)$/)
+           {
+               &am_error ("\`$depfile' has incorrect format");
+               close (DEP_FILE);
+               return;
+           }
+
+           $target = $1;
+           $_ = $2;
+
+           $first_line = 0;
+       }
+
+       foreach $one_dep (split (' ', $_))
+       {
+           if ($one_dep =~ /^$srcdir_rx\//o)
+           {
+               ($xform = $one_dep) =~ s/^$srcdir_rx/\$(top_srcdir)/o;
+               push (@dependencies, $xform);
+           }
+           elsif ($one_dep =~ /^\//)
+           {
+               # Absolute path; ignore.
+           }
+           else
+           {
+               # Anything else is assumed to be correct.
+               push (@dependencies, $one_dep);
+           }
+       }
+    }
+
+    &pretty_print_rule ($target, "\t", @dependencies);
+
+    close (DEP_FILE);
+}
+
 # Handle auto-dependency code.
 sub handle_dependencies
 {
@@ -1661,25 +1759,20 @@ sub handle_dependencies
     }
     else
     {
-       # Include any auto-generated deps that are present.
-       if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
+       # FIXME consider requiring --build-dir here.  What about case
+       # where this is done via an option?
+
+       # Include any auto-generated deps that are present.  Note that
+       # $build_directory ends in a "/".
+       if (-d ($build_directory . $relative_dir . "/.deps")
+           && -f ($build_directory . $relative_dir . "/.deps/.P"))
        {
            local ($depfile);
-           local ($gpat) = $relative_dir . "/.deps/*.P";
+           local ($gpat) = $build_directory . $relative_dir . "/.deps/*.P";
 
            foreach $depfile (<${gpat}>)
            {
-               if (! open (DEP_FILE, $depfile))
-               {
-                   &am_error ("couldn't open \`$depfile': $!");
-                   next;
-               }
-               print "automake: reading $depfile\n" if $verbose;
-
-               # Slurp entire file.
-               $output_rules .= join ('', <DEP_FILE>);
-
-               close (DEP_FILE);
+               &scan_dependency_file ($depfile);
            }
 
            $output_rules .= "\n";
@@ -2882,8 +2975,9 @@ sub read_am_file
        elsif (/$COMMENT_PATTERN/o)
        {
            # Stick comments before the incoming macro or rule.  Make
-           # sure a blank line preceeds comments.
+           # sure a blank line preceeds first block of comments.
            $spacing = "\n" unless $blank;
+           $blank = 1;
            $comment .= $spacing . $_;
            $spacing = '';
        }
@@ -3056,6 +3150,7 @@ sub initialize_global_constants
 
     $USAGE = "\
   --amdir=DIR           directory storing config files
+  --build-dir=DIR       directory where build being done (for dependencies)
   --foreign             same as --strictness=foreign
   --gnits               same as --strictness=gnits
   --gnu                 same as --strictness=gnu
@@ -3067,6 +3162,7 @@ sub initialize_global_constants
                         put generated Makefile.in's into DIR
   -s LEVEL, --strictness=LEVEL
                         set strictness level.  LEVEL is foreign, gnu, gnits
+  --srcdir-name=DIR     name used for srcdir (for dependencies)
   -v, --verbose         verbosely list files processed
   --version             print version number, then exit\n";
 
index 246b066..32ffb04 100644 (file)
--- a/depend.am
+++ b/depend.am
 ## on GNU make and gcc.  It is only included in the generated
 ## Makefile.in if `automake' is not passed the `--include-deps' flag.
 
-MKDEP = gcc -MM $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
+MKDEP = gcc -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
 
 ## We use ".P" as the name of our placeholder because it can't be
 ## duplicated by any C source file.  (Well, there could be ".c", but
 ## no one does that in practice)
--include $(srcdir)/.deps/.P
-$(srcdir)/.deps/.P: $(BUILT_SOURCES)
-       cd $(srcdir) && test -d .deps || mkdir .deps
+-include .deps/.P
+.deps/.P: $(BUILT_SOURCES)
+       test -d .deps || mkdir .deps
 ## Use ":" here and not "echo timestamp".  Otherwise GNU Make barfs:
 ## .deps/.P:1: *** missing separator.  Stop.
 ## Actually, use a plain "echo" and not ":".  Why?  From the Autoconf
@@ -38,7 +38,7 @@ $(srcdir)/.deps/.P: $(BUILT_SOURCES)
        echo > $@
 
 -include $(DEP_FILES)
-$(DEP_FILES): $(srcdir)/.deps/.P
+$(DEP_FILES): .deps/.P
 
 mostlyclean-depend:
 
@@ -47,4 +47,4 @@ clean-depend:
 distclean-depend:
 
 maintainer-clean-depend:
-       rm -rf $(srcdir)/.deps
+       rm -rf .deps
index 39cdc1d..ec6f31b 100644 (file)
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 ## 02111-1307, USA.
-$(srcdir)/.deps/%.P: $(srcdir)/%@EXT@
-       @echo "mkdeps $< > $@"
-## 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.  Need "//*" in
-## regexps because otherwise the regexp will fail when srcdir=. and
-## the path to the file is relative (eg ../lib/error.c matches "./*").
-       @top=`echo $(srcdir) | sed 's,^$(top_srcdir),,;s,[^/],,g;s,/,../,g'` ; \
-       re=`echo "s,^$(srcdir)//*,,g;s, $(srcdir)//*, ,g;s,$(top_srcdir)//*,$$top,g" | sed 's,\.,\\\\.,g'`; \
-         $(@MKDEP@) $< | sed "$$re" > $@-tmp
-       @if test -n "$o"; then                  \
+.deps/%.P: $(srcdir)/%@EXT@
+       $(@MKDEP@) $< > $@-tmp
+## FIXME shouldn't do this for languages other than C.
+       if test -n "$o"; then                   \
          sed 's/\.o:/$$o:/' $@-tmp > $@;       \
          rm $@-tmp;                            \
        else                                    \
index 246b066..32ffb04 100644 (file)
 ## on GNU make and gcc.  It is only included in the generated
 ## Makefile.in if `automake' is not passed the `--include-deps' flag.
 
-MKDEP = gcc -MM $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
+MKDEP = gcc -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
 
 ## We use ".P" as the name of our placeholder because it can't be
 ## duplicated by any C source file.  (Well, there could be ".c", but
 ## no one does that in practice)
--include $(srcdir)/.deps/.P
-$(srcdir)/.deps/.P: $(BUILT_SOURCES)
-       cd $(srcdir) && test -d .deps || mkdir .deps
+-include .deps/.P
+.deps/.P: $(BUILT_SOURCES)
+       test -d .deps || mkdir .deps
 ## Use ":" here and not "echo timestamp".  Otherwise GNU Make barfs:
 ## .deps/.P:1: *** missing separator.  Stop.
 ## Actually, use a plain "echo" and not ":".  Why?  From the Autoconf
@@ -38,7 +38,7 @@ $(srcdir)/.deps/.P: $(BUILT_SOURCES)
        echo > $@
 
 -include $(DEP_FILES)
-$(DEP_FILES): $(srcdir)/.deps/.P
+$(DEP_FILES): .deps/.P
 
 mostlyclean-depend:
 
@@ -47,4 +47,4 @@ clean-depend:
 distclean-depend:
 
 maintainer-clean-depend:
-       rm -rf $(srcdir)/.deps
+       rm -rf .deps
index 39cdc1d..ec6f31b 100644 (file)
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 ## 02111-1307, USA.
-$(srcdir)/.deps/%.P: $(srcdir)/%@EXT@
-       @echo "mkdeps $< > $@"
-## 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.  Need "//*" in
-## regexps because otherwise the regexp will fail when srcdir=. and
-## the path to the file is relative (eg ../lib/error.c matches "./*").
-       @top=`echo $(srcdir) | sed 's,^$(top_srcdir),,;s,[^/],,g;s,/,../,g'` ; \
-       re=`echo "s,^$(srcdir)//*,,g;s, $(srcdir)//*, ,g;s,$(top_srcdir)//*,$$top,g" | sed 's,\.,\\\\.,g'`; \
-         $(@MKDEP@) $< | sed "$$re" > $@-tmp
-       @if test -n "$o"; then                  \
+.deps/%.P: $(srcdir)/%@EXT@
+       $(@MKDEP@) $< > $@-tmp
+## FIXME shouldn't do this for languages other than C.
+       if test -n "$o"; then                   \
          sed 's/\.o:/$$o:/' $@-tmp > $@;       \
          rm $@-tmp;                            \
        else                                    \
index 2ea3918..8ec8c25 100755 (executable)
@@ -1,6 +1,7 @@
 #! /bin/sh
 
 # Make sure block comments are not double-spaced.
+# Report from François Pinard.
 
 . $srcdir/defs || exit 1