automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: explicit rules bloat reduction


From: Alexandre Duret-Lutz
Subject: FYI: explicit rules bloat reduction
Date: Thu, 01 Jan 2004 19:53:56 +0100
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

I'm checking this in.  This removes the .o/.obj explicit rules
when compiling libtool object and vice versa.

I would like to do this for implicit rules too, but this will
require more work.

The reason I've decided to pass %transform all along (instead of
a $libtool boolean, say) is that it can help adding further
options in the future.

2004-01-01  Alexandre Duret-Lutz  <address@hidden>

        Do not output .lo rules for programs and static libraries objects,
        and do not output .o/.obj rules for libtool libraries.  This is
        about explicit rules only, not inference rules.
        * automake.in (handle_single_transform_list): Rename as ...
        (handle_single_transform): ... this.  Take a single file
        to transform (it was only called this way) and accept a new
        %transform argument.  Fill %lang_specific_files with list
        references instead of strings, and append %transform to each
        of these lists.
        (define_objects_from_sources, handle_source_transform):
        Take a %transform argument, and forward it to &handle_single_transform.
        (handle_languages): Adjust to the new format of
        %lang_specific_files, and honor its %transform part.
        (handle_programs, handle_libraries, handle_ltlibraries): Override
        %NONLIBTOOL% and %LIBTOOL% while calling handle_source_transform.
        (make_paragraphs): Define %NONLIBTOOL% by default.  Make sure
        %transform settings override global settings.
        * lib/am/depend2.am (%OBJ%, %OBJOBJ%): Define only if %NONLIBTOOL%.
        * tests/libtool3.test: Augment to check Makefile.ins for unneeded
        rules.
        Suggested by Thomas Fitzsimmons.

Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.259
diff -u -r1.259 NEWS
--- NEWS        30 Dec 2003 23:49:57 -0000      1.259
+++ NEWS        1 Jan 2004 18:51:49 -0000
@@ -1,9 +1,19 @@
 New in 1.8a:
 
-* Inference rules are used to compile sources in subdirectories when the
-  `subdir-objects' option is used and no per-target flags are used.  This
-  should reduce the size of some projects a lot, because Automake used to
-  output an explicit rule for each such object in the past.
+* Makefile.in bloat reduction.
+
+  - Inference rules are used to compile sources in subdirectories when
+    the `subdir-objects' option is used and no per-target flags are
+    used.  This should reduce the size of some projects a lot, because
+    Automake used to output an explicit rule for each such object in
+    the past.
+
+  - Automake no longer outputs three rules (.o, .obj, .lo) for each
+    object that must be built with explicit rules.  It just outputs
+    the rules required to build the kind of object considered: either
+    the two .o and .obj rules for usual objects, or the .lo rule for
+    libtool objects.
+
 
 New in 1.8:
 
Index: THANKS
===================================================================
RCS file: /cvs/automake/automake/THANKS,v
retrieving revision 1.232
diff -u -r1.232 THANKS
--- THANKS      26 Dec 2003 03:57:59 -0000      1.232
+++ THANKS      1 Jan 2004 18:51:50 -0000
@@ -223,6 +223,7 @@
 Tatu Ylonen            address@hidden
 The Crimson Binome     address@hidden
 Thien-Thi Nguyen       address@hidden
+Thomas Fitzsimmons     address@hidden
 Thomas Gagne           address@hidden
 Thomas Morgan          address@hidden
 Thomas Tanner          address@hidden
Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1531
diff -u -r1.1531 automake.in
--- automake.in 1 Jan 2004 17:34:17 -0000       1.1531
+++ automake.in 1 Jan 2004 18:51:56 -0000
@@ -1134,7 +1134,7 @@
        my %seen_files = ();
        foreach my $file (@{$lang_specific_files{$lang->name}})
        {
-           my ($derived, $source, $obj, $myext) = split (' ', $file);
+           my ($derived, $source, $obj, $myext, %file_transform) = @$file;
 
            # We might see a given object twice, for instance if it is
            # used under different conditions.
@@ -1215,7 +1215,7 @@
            # and another time we simply remove `$U'.
            #
            # Note that at this point $source (as computed by
-           # &handle_single_transform_list) is `sub/foo$U.c'.
+           # &handle_single_transform) is `sub/foo$U.c'.
            # This can be confusing: it can be used as-is when
            # subdir-objects is set, otherwise you have to know
            # it really means `foo_.c' or `sub/foo.c'.
@@ -1250,7 +1250,8 @@
 
                                     COMPILE   => $obj_compile,
                                     LTCOMPILE => $obj_ltcompile,
-                                    -o        => $output_flag);
+                                    -o        => $output_flag,
+                                    %file_transform);
                    $obj =~ s/\$U//g;
                    $depbase =~ s/\$U//g;
                    $source =~ s/\$U//g;
@@ -1275,7 +1276,8 @@
 
                             COMPILE   => $obj_compile,
                             LTCOMPILE => $obj_ltcompile,
-                            -o        => $output_flag);
+                            -o        => $output_flag,
+                            %file_transform);
        }
 
        # The rest of the loop is done once per language.
@@ -1387,20 +1389,23 @@
 
 
 # @OBJECTS
-# handle_single_transform_list ($VAR, $TOPPARENT, $DERIVED, $OBJ, @FILES)
-# -----------------------------------------------------------------------
+# handle_single_transform ($VAR, $TOPPARENT, $DERIVED, $OBJ, $FILE, %TRANSFORM)
+# -----------------------------------------------------------------------------
 # Does much of the actual work for handle_source_transform.
 # Arguments are:
 #   $VAR is the name of the variable that the source filenames come from
 #   $TOPPARENT is the name of the _SOURCES variable which is being processed
 #   $DERIVED is the name of resulting executable or library
 #   $OBJ is the object extension (e.g., `$U.lo')
-#   @FILES is the list of source files to transform
+#   $FILE the source file to transform
+#   %TRANSFORM contains extras arguments to pass to file_contents
+#     when producing explicit rules
 # Result is a list of the names of objects
 # %linkers_used will be updated with any linkers needed
-sub handle_single_transform_list ($$$$@)
+sub handle_single_transform ($$$$$%)
 {
-    my ($var, $topparent, $derived, $obj, @files) = @_;
+    my ($var, $topparent, $derived, $obj, $_file, %transform) = @_;
+    my @files = ($_file);
     my @result = ();
     my $nonansi_obj = $obj;
     $nonansi_obj =~ s/\$U//g;
@@ -1585,32 +1590,34 @@
                    $obj_sans_ext .= '$U';
                  }
 
-               my $val = ("$full_ansi $obj_sans_ext "
-                          # Only use $this_obj_ext in the derived
-                          # source case because in the other case we
-                          # *don't* want $(OBJEXT) to appear here.
-                          . ($derived_source ? $this_obj_ext : '.o'));
+               my @specifics = ($full_ansi, $obj_sans_ext,
+                                # Only use $this_obj_ext in the derived
+                                # source case because in the other case we
+                                # *don't* want $(OBJEXT) to appear here.
+                                ($derived_source ? $this_obj_ext : '.o'));
 
                # If we renamed the object then we want to use the
                # per-executable flag name.  But if this is simply a
                # subdir build then we still want to use the AM_ flag
                # name.
                if ($renamed)
-               {
-                   $val = "$derived $val";
+                 {
+                   unshift @specifics, $derived;
                    $aggregate = $derived;
-               }
+                 }
                else
-               {
-                   $val = "AM $val";
-               }
+                 {
+                   unshift @specifics, 'AM';
+                 }
 
-               # Each item on this list is a string consisting of
-               # four space-separated values: the derived flag prefix
+               # Each item on this list is a reference to a list consisting
+               # of four values followed by additional transform flags for
+               # file_contents.   The four values are the derived flag prefix
                # (e.g. for `foo_CFLAGS', it is `foo'), the name of the
                # source file, the base name of the output file, and
                # the extension for the object file.
-                push (@{$lang_specific_files{$lang->name}}, $val);
+                push (@{$lang_specific_files{$lang->name}},
+                     address@hidden, %transform]);
             }
         }
         elsif ($extension eq $nonansi_obj)
@@ -1737,8 +1744,8 @@
 
 # $LINKER
 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
-#                              $OBJ, $PARENT, $TOPPARENT, $WHERE)
-# ---------------------------------------------------------------------
+#                              $OBJ, $PARENT, $TOPPARENT, $WHERE, %TRANSFORM)
+# ---------------------------------------------------------------------------
 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
 #
 # Arguments are:
@@ -1751,12 +1758,15 @@
 #   $OBJ is the object extension (i.e. either `.o' or `.lo').
 #   $TOPPARENT is the _SOURCES variable being processed.
 #   $WHERE context into which this definition is done
+#   %TRANSFORM extra arguments to pass to file_contents when producing
+#     rules
 #
 # Result is a pair ($LINKER, $OBJVAR):
 #    $LINKER is a boolean, true if a linker is needed to deal with the objects
-sub define_objects_from_sources ($$$$$$$)
+sub define_objects_from_sources ($$$$$$$%)
 {
-  my ($var, $objvar, $nodefine, $one_file, $obj, $topparent, $where) = @_;
+  my ($var, $objvar, $nodefine, $one_file,
+      $obj, $topparent, $where, %transform) = @_;
 
   my $needlinker = "";
 
@@ -1765,8 +1775,9 @@
      # The transform code to run on each filename.
      sub {
        my ($subvar, $val, $cond, $full_cond) = @_;
-       my @trans = &handle_single_transform_list ($subvar, $topparent,
-                                                 $one_file, $obj, $val);
+       my @trans = handle_single_transform ($subvar, $topparent,
+                                           $one_file, $obj, $val,
+                                           %transform);
        $needlinker = "true" if @trans;
        return @trans;
      });
@@ -1775,18 +1786,22 @@
 }
 
 
+# handle_source_transform ($CANON_TARGET, $TARGET, $OBJEXT, $WHERE, %TRANSFORM)
+# -----------------------------------------------------------------------------
 # Handle SOURCE->OBJECT transform for one program or library.
 # Arguments are:
-#   canonical (transformed) name of object to build
-#   actual name of object to build
+#   canonical (transformed) name of target to build
+#   actual target of object to build
 #   object extension (i.e. either `.o' or `$o'.
+#   location of the source variable
+#   extra arguments to pass to file_contents when producing rules
 # Return result is name of linker variable that must be used.
 # Empty return means just use `LINK'.
-sub handle_source_transform
+sub handle_source_transform ($$$$%)
 {
     # one_file is canonical name.  unxformed is given name.  obj is
     # object extension.
-    my ($one_file, $unxformed, $obj, $where) = @_;
+    my ($one_file, $unxformed, $obj, $where, %transform) = @_;
 
     my ($linker) = '';
 
@@ -1834,7 +1849,8 @@
            define_objects_from_sources ($varname,
                                         $xpfx . $one_file . '_OBJECTS',
                                         $prefix =~ /EXTRA_/,
-                                        $one_file, $obj, $varname, $where);
+                                        $one_file, $obj, $varname, $where,
+                                        %transform);
     }
     if ($needlinker)
     {
@@ -1866,10 +1882,10 @@
 
        %linkers_used = ();
        my (@result) =
-         &handle_single_transform_list ($one_file . '_SOURCES',
-                                        $one_file . '_SOURCES',
-                                        $one_file, $obj,
-                                        $default_source);
+         handle_single_transform ($one_file . '_SOURCES',
+                                  $one_file . '_SOURCES',
+                                  $one_file, $obj,
+                                  $default_source, %transform);
        $linker ||= &resolve_linker (%linkers_used);
        define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @result);
     }
@@ -2187,7 +2203,8 @@
       $where->push_context ("while processing program `$one_file'");
       $where->set (INTERNAL->get);
 
-      my $linker = &handle_source_transform ($xname, $one_file, $obj, $where);
+      my $linker = &handle_source_transform ($xname, $one_file, $obj, $where,
+                                            NONLIBTOOL => 1, LIBTOOL => 0);
 
       if (var ($xname . "_LDADD"))
        {
@@ -2314,7 +2331,8 @@
       # Make sure we at look at this.
       set_seen ($xlib . '_DEPENDENCIES');
 
-      &handle_source_transform ($xlib, $onelib, $obj, $where);
+      &handle_source_transform ($xlib, $onelib, $obj, $where,
+                               NONLIBTOOL => 1, LIBTOOL => 0);
 
       # If the resulting library lies into a subdirectory,
       # make sure this directory will exist.
@@ -2451,7 +2469,8 @@
                  "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
 
 
-      my $linker = &handle_source_transform ($xlib, $onelib, $obj, $where);
+      my $linker = &handle_source_transform ($xlib, $onelib, $obj, $where,
+                                            NONLIBTOOL => 0, LIBTOOL => 1);
 
       # Determine program to use for link.
       my $xlink;
@@ -4788,7 +4807,7 @@
 # file is to be dealt with, LANG_IGNORE otherwise.
 
 # Much of the actual processing is handled in
-# handle_single_transform_list.  These functions exist so that
+# handle_single_transform.  These functions exist so that
 # auxiliary information can be recorded for a later cleanup pass.
 # Note that the calls to these functions are computed, so don't bother
 # searching for their precise names in the source.
@@ -5808,12 +5827,11 @@
 {
   my ($file, %transform) = @_;
 
-  # Complete %transform with global options and make it a Perl
-  # $command.
+  # Complete %transform with global options and make it a Perl $command.
+  # Note that %transform goes last, so it overrides global options.
   my $command =
     "s/$IGNORE_PATTERN//gm;"
-    . transform (%transform,
-                'CYGNUS'      => !! option 'cygnus',
+    . transform ('CYGNUS'      => !! option 'cygnus',
                 'MAINTAINER-MODE'
                 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
 
@@ -5835,7 +5853,9 @@
                 'HOST'     => $seen_canonical,
                 'TARGET'   => $seen_canonical == AC_CANONICAL_SYSTEM,
 
-                'LIBTOOL'      => !! var ('LIBTOOL'))
+                'LIBTOOL'      => !! var ('LIBTOOL'),
+                'NONLIBTOOL'   => 1,
+                %transform)
     # We don't need more than two consecutive new-lines.
     . 's/\n{3,}/\n\n/g';
 
Index: lib/am/depend2.am
===================================================================
RCS file: /cvs/automake/automake/lib/am/depend2.am,v
retrieving revision 1.57
diff -u -r1.57 depend2.am
--- lib/am/depend2.am   30 Dec 2003 23:49:58 -0000      1.57
+++ lib/am/depend2.am   1 Jan 2004 18:52:04 -0000
@@ -1,6 +1,6 @@
 ## automake - create Makefile.in from Makefile.am
-## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-## Free Software Foundation, Inc.
+## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+## 2003, 2004  Free Software Foundation, Inc.
 
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -59,6 +59,7 @@
 ## line and is therefore easier to spot.  (We need an extra line when
 ## depbase is used.)
 
+if %?NONLIBTOOL%
 ?GENERIC?%EXT%.o:
 ?!GENERIC?%OBJ%: %SOURCE%
 if %FASTDEP%
@@ -106,6 +107,7 @@
 ?!-o?  %COMPILE% %-c% `if test -f '%SOURCE%'; then $(CYGPATH_W) '%SOURCE%'; 
else $(CYGPATH_W) '$(srcdir)/%SOURCE%'; fi`
 endif !%?GENERIC%
 endif !%FASTDEP%
+endif %?NONLIBTOOL%
 
 if %?LIBTOOL%
 ?GENERIC?%EXT%.lo:
Index: tests/libtool3.test
===================================================================
RCS file: /cvs/automake/automake/tests/libtool3.test,v
retrieving revision 1.4
diff -u -r1.4 libtool3.test
--- tests/libtool3.test 14 Nov 2003 21:25:58 -0000      1.4
+++ tests/libtool3.test 1 Jan 2004 18:52:05 -0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2002  Free Software Foundation, Inc.
+# Copyright (C) 2002, 2004  Free Software Foundation, Inc.
 #
 # This file is part of GNU Automake.
 #
@@ -19,6 +19,7 @@
 # Boston, MA 02111-1307, USA.
 
 # Try to build and package a program linked to a Libtool library.
+# Also make sure we do not bloat the Makefile with unneeded rules.
 
 required='libtoolize gcc'
 . ./defs || exit 1
@@ -37,11 +38,11 @@
 liba_liba_la_SOURCES = liba/a.c
 
 bin_PROGRAMS = 1
-1_SOURCES = 1.c
+1_SOURCES = sub/1.c
 1_LDADD = lib0.la $(top_builddir)/liba/liba.la
 END
 
-mkdir liba
+mkdir liba sub
 
 cat > 0.c << 'END'
 int
@@ -51,7 +52,7 @@
 }
 END
 
-cat > 1.c << 'END'
+cat > sub/1.c << 'END'
 int zero ();
 
 int
@@ -78,6 +79,13 @@
 $ACLOCAL
 $AUTOCONF
 $AUTOMAKE --add-missing --copy
+
+# We need explicit rules to build 1.o and a.lo.  Make sure
+# Automake did not output additional rules for 1.lo and and a.lo.
+$FGREP '1.o:' Makefile.in
+$FGREP '1.lo:' Makefile.in && exit 1
+$FGREP 'a.o:' Makefile.in && exit 1
+$FGREP 'a.lo:' Makefile.in
 
 ./configure
 $MAKE
-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]