From 542c36fd6dc815eb51cda48e12477e7a4ad33718 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 28 Nov 2002 21:01:51 +0000 Subject: [PATCH] For PR automake/370: * automake.in (handle_languages): Don't prepend $U to $myext since handle_single_transform_list now appends it to $obj. Process the rule twice to handle deansified files in subdirectories. Mark _.c files in subdirectories for cleaning. (handle_single_transform_list): Append $U to $obj_sans_ext if needed: before this dependencies were output foo.Po instead of foo$U.Po. Don't output explicit dependencies for renamed objects or sources in sub-directories: we already output a full compile rule for them. (lang_c_finish): Don't always use the full filename in the .c -> _.c rule. This reverts part of my change of 2002-11-21. * tests/ansi6.test, tests/ansi7.test: Make sure deansified files are created in the right directory, and cleaned. Reported by Kevin Ryde. --- ChangeLog | 18 ++++++++ automake.in | 118 ++++++++++++++++++++++++++++++++++++++--------- tests/ansi6.test | 9 +++- tests/ansi7.test | 15 ++++++ 4 files changed, 138 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 36ddd9eb..48d7c745 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2002-11-28 Alexandre Duret-Lutz + + For PR automake/370: + * automake.in (handle_languages): Don't prepend $U to $myext + since handle_single_transform_list now appends it to $obj. + Process the rule twice to handle deansified files in subdirectories. + Mark _.c files in subdirectories for cleaning. + (handle_single_transform_list): Append $U to $obj_sans_ext if + needed: before this dependencies were output foo.Po instead + of foo$U.Po. Don't output explicit dependencies for renamed + objects or sources in sub-directories: we already output + a full compile rule for them. + (lang_c_finish): Don't always use the full filename in the + .c -> _.c rule. This reverts part of my change of 2002-11-21. + * tests/ansi6.test, tests/ansi7.test: Make sure deansified + files are created in the right directory, and cleaned. + Reported by Kevin Ryde. + 2002-11-25 Jim Meyering * lib/install-sh: Put `$0:' at the beginning of each diagnostic, diff --git a/automake.in b/automake.in index 272033c3..9c040de9 100755 --- a/automake.in +++ b/automake.in @@ -2113,14 +2113,6 @@ sub handle_languages { my ($derived, $source, $obj, $myext) = split (' ', $file); - # For any specially-generated object, we must respect the - # ansi2knr setting so that we don't inadvertently try to - # use the default rule. - if ($lang->ansi && defined $options{'ansi2knr'}) - { - $myext = '$U' . $myext; - } - # We might see a given object twice, for instance if it is # used under different conditions. next if defined $seen_files{$obj}; @@ -2153,9 +2145,100 @@ sub handle_languages unless $depbase eq ''; $depbase .= '$(DEPDIR)/' . basename ($obj); - # Generate a transform which will turn suffix targets in - # depend2.am into real targets for the particular objects we - # are building. + # Support for deansified files in subdirectories is ugly + # enough to deserve an explanation. + # + # A Note about normal ansi2knr processing first. On + # + # AUTOMAKE_OPTIONS = ansi2knr + # bin_PROGRAMS = foo + # foo_SOURCES = foo.c + # + # we generate rules similar to: + # + # foo: foo$U.o; link ... + # foo$U.o: foo$U.c; compile ... + # foo_.c: foo.c; ansi2knr ... + # + # this is fairly compact, and will call ansi2knr depending + # on the value of $U (`' or `_'). + # + # It's harder with subdir sources. On + # + # AUTOMAKE_OPTIONS = ansi2knr + # bin_PROGRAMS = foo + # foo_SOURCES = sub/foo.c + # + # we have to create foo_.c in the current directory. + # (Unless the user asks 'subdir-objects'.) This is important + # in case the same file (`foo.c') is compiled from other + # directories with different cpp options: foo_.c file would + # be preprocessed for only once set of options if it were + # but in the subdirectory. + # + # Because foo$U.o must be build from either foo_.c or + # sub/foo.c we can't be as concise as in the first example. + # Instead we output + # + # foo: foo$U.o; link ... + # foo_.o: foo_.c; compile ... + # foo.o: sub/foo.c; compile ... + # foo_.c: foo.c; ansi2knr ... + # + # This is why we'll now transform $rule_file twice + # if we detect this case. + # A first time we output the compile rule with `$U' + # replaced by `_' and the source directory removed, + # 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'. + # 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'. + my $objdir = dirname ($obj); + my $srcdir = dirname ($source); + if ($lang->ansi && $obj =~ /\$U/) + { + prog_error "`$obj' contains \$U, but `$source' doesn't." + if $source !~ /\$U/; + + (my $source_ = $source) =~ s/\$U/_/g; + # Explicitely clean the _.c files if they are in + # a subdirectory. (In the current directory they get + # erase by a `rm -f *_.c' rule.) + $clean_files{$source_} = MOSTLY_CLEAN + if $srcdir ne '.'; + # Output an additional rule if _.c and .c are not in + # the same directory. (_.c is always in $objdir.) + if ($objdir ne $srcdir) + { + (my $obj_ = $obj) =~ s/\$U/_/g; + (my $depbase_ = $depbase) =~ s/\$U/_/g; + $source_ = basename ($source_); + + $output_rules .= + file_contents ($rule_file, + new Automake::Location, + %transform, + GENERIC => 0, + + DEPBASE => $depbase_, + BASE => $obj_, + SOURCE => $source_, + OBJ => "$obj_$myext", + OBJOBJ => "$obj_.obj", + LTOBJ => "$obj_.lo", + + COMPILE => $obj_compile, + LTCOMPILE => $obj_ltcompile, + -o => $output_flag); + $obj =~ s/\$U//g; + $depbase =~ s/\$U//g; + $source =~ s/\$U//g; + } + } + $output_rules .= file_contents ($rule_file, new Automake::Location, @@ -2330,7 +2413,6 @@ sub handle_single_transform_list ($$$$@) my $directory = $1 || ''; my $base = $2; my $extension = $3; - my $full_ansi = $full; # We'll insert `$U' if needed. # We must generate a rule for the object if it requires its own flags. my $renamed = 0; @@ -2450,9 +2532,11 @@ sub handle_single_transform_list ($$$$@) { my $obj_sans_ext = substr ($object, 0, - length ($this_obj_ext)); + my $full_ansi = $full; if ($lang->ansi && defined $options{'ansi2knr'}) { $full_ansi =~ s/$KNOWN_EXTENSIONS_PATTERN$/\$U$&/; + $obj_sans_ext .= '$U'; } my $val = ("$full_ansi $obj_sans_ext " @@ -2548,13 +2632,6 @@ sub handle_single_transform_list ($$$$@) my @dep_list = (); $object_map{$object} = $full; - # If file is in subdirectory, we need explicit - # dependency. - if ($directory ne '' || $renamed) - { - push (@dep_list, $full_ansi); - } - # If resulting object is in subdir, we need to make # sure the subdir exists at build time. if ($object =~ /\//) @@ -5608,8 +5685,7 @@ sub lang_c_finish # we can't use $< -- some makes only define $< during a # suffix rule. my $ansfile = $de_ansi_files{$base} . $base . '.c'; - my $root = $de_ansi_files{$base} . $base; - $output_rules .= ($root . "_.c: $ansfile \$(ANSI2KNR)\n\t" + $output_rules .= ($base . "_.c: $ansfile \$(ANSI2KNR)\n\t" . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) ' . '`if test -f $(srcdir)/' . $ansfile . '; then echo $(srcdir)/' . $ansfile diff --git a/tests/ansi6.test b/tests/ansi6.test index 735b3a9c..54a908ce 100755 --- a/tests/ansi6.test +++ b/tests/ansi6.test @@ -75,9 +75,16 @@ grep ac_cv_prog_cc_stdc configure ./configure ac_cv_prog_cc_stdc=no $MAKE +test -f hello_.c +test -f dir_.c # Must be in current directory. +test ! -f sub/dir_.c +$MAKE distclean +test ! -f hello_.c +test ! -f dir_.c + # Also run without forcing ansi2knr, so we make sure the # rules work with ANSI compilers. # Report from Andreas Schwab. -$MAKE distclean + ./configure $MAKE diff --git a/tests/ansi7.test b/tests/ansi7.test index 4a4f9bf7..947ba28d 100755 --- a/tests/ansi7.test +++ b/tests/ansi7.test @@ -19,6 +19,7 @@ # Boston, MA 02111-1307, USA. # Check ansi2knr on a source file in subdirectory. +# ansi6.test is the same test without subdir-objects. # From Kevin Ryde. required=gcc @@ -75,3 +76,17 @@ grep ac_cv_prog_cc_stdc configure ./configure ac_cv_prog_cc_stdc=no $MAKE + +test -f hello_.c +test -f sub/dir_.c # Must be in sub directory, unlike ansi6.test. +test ! -f dir_.c +$MAKE distclean +test ! -f hello_.c +test ! -f sub/dir_.c + +# Also run without forcing ansi2knr, so we make sure the +# rules work with ANSI compilers. +# Report from Andreas Schwab. + +./configure +$MAKE -- 2.43.5