From 3a763d27cb5c43312c561ebaf8b9879d93329027 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 1 Jan 2004 18:54:20 +0000 Subject: [PATCH] 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. --- ChangeLog | 22 +++++++++ NEWS | 18 +++++-- THANKS | 1 + automake.in | 114 ++++++++++++++++++++++++++------------------ lib/am/depend2.am | 6 ++- tests/libtool3.test | 16 +++++-- 6 files changed, 120 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index 741aef8c..22fc55f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,27 @@ 2004-01-01 Alexandre Duret-Lutz + 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. + * automake.in, aclocal.in: Bump copyright years. 2003-12-31 Alexandre Duret-Lutz diff --git a/NEWS b/NEWS index f70c7d60..6090d461 100644 --- a/NEWS +++ b/NEWS @@ -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: diff --git a/THANKS b/THANKS index cb6b5b99..4e2b87d3 100644 --- a/THANKS +++ b/THANKS @@ -223,6 +223,7 @@ Tamara L. Dahlgren dahlgren1@llnl.gov Tatu Ylonen ylo@ssh.fi The Crimson Binome steve@nyongwa.montreal.qc.ca Thien-Thi Nguyen ttn@glug.org +Thomas Fitzsimmons fitzsim@redhat.com Thomas Gagne tgagne@ix.netcom.com Thomas Morgan tmorgan@pobox.com Thomas Tanner tanner@ffii.org diff --git a/automake.in b/automake.in index 581688cf..ff444148 100755 --- a/automake.in +++ b/automake.in @@ -1134,7 +1134,7 @@ sub handle_languages 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 @@ sub handle_languages # 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 @@ sub handle_languages 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 @@ sub handle_languages 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 @@ sub check_libobjs_sources # @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 @@ sub handle_single_transform_list ($$$$@) $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}}, + [@specifics, %transform]); } } elsif ($extension eq $nonansi_obj) @@ -1737,8 +1744,8 @@ sub handle_single_transform_list ($$$$@) # $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 @@ sub handle_single_transform_list ($$$$@) # $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 @@ sub define_objects_from_sources ($$$$$$$) # 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 @@ sub define_objects_from_sources ($$$$$$$) } +# 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 @@ sub handle_source_transform 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 @@ sub handle_source_transform %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 @@ sub handle_programs $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 @@ sub handle_libraries # 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 @@ sub handle_ltlibraries "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 @@ sub check_gnits_standards # 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 @@ sub make_paragraphs ($%) { 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 @@ sub make_paragraphs ($%) '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'; diff --git a/lib/am/depend2.am b/lib/am/depend2.am index 24ec0c74..8a26b195 100644 --- a/lib/am/depend2.am +++ b/lib/am/depend2.am @@ -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 @@ else !%?GENERIC% ?!-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: diff --git a/tests/libtool3.test b/tests/libtool3.test index 101a4a63..183bdb68 100755 --- a/tests/libtool3.test +++ b/tests/libtool3.test @@ -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 @@ lib0_la_SOURCES = 0.c 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 @@ zero (void) } END -cat > 1.c << 'END' +cat > sub/1.c << 'END' int zero (); int @@ -79,6 +80,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 $MAKE distcheck -- 2.43.5