From: Alexandre Duret-Lutz Date: Wed, 16 Apr 2003 19:59:03 +0000 (+0000) Subject: * automake.in (rule_define): If the user tries to override X-Git-Tag: Release-1-7-3b~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=089e43213a17611a7042b87d450f673a752ebefc;p=thirdparty%2Fautomake.git * automake.in (rule_define): If the user tries to override an Automake which has a -local variant, suggest using the -local variant in the -Woverride diagnostic. (handle_factored_dependencies): Register factored rules with rule_define, and define them only in undefined conditions. * tests/Makefile.am (TESTS): Add override.test. * tests/overrid.test: New file. * tests/phony.test: Count the number of .PHONY targets. --- diff --git a/ChangeLog b/ChangeLog index a2a9fe614..4203f403b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2003-04-16 Alexandre Duret-Lutz + + * automake.in (rule_define): If the user tries to override + an Automake which has a -local variant, suggest using the + -local variant in the -Woverride diagnostic. + (handle_factored_dependencies): Register factored + rules with rule_define, and define them only in undefined + conditions. + * tests/Makefile.am (TESTS): Add override.test. + * tests/overrid.test: New file. + * tests/phony.test: Count the number of .PHONY targets. + 2003-04-15 Alexandre Duret-Lutz * lib/am/distdir.am (distuninstallcheck, distcleancheck): Silent diff --git a/automake.in b/automake.in index 32d798cc6..511c11af7 100755 --- a/automake.in +++ b/automake.in @@ -5004,11 +5004,28 @@ sub handle_factored_dependencies unless (@{$dependencies{$_}} || $actions{$_} || $required_targets{$_}); - &pretty_print_rule ("$_:", "\t", - uniq (sort @{$dependencies{$_}})); - $output_rules .= $actions{$_} - if defined $actions{$_}; - $output_rules .= "\n"; + + # Define gathered targets in undefined conditions. + # FIXME: Right now we must handle .PHONY as an exception, + # because people write things like + # .PHONY: myphonytarget + # to append dependencies. This would not work if Automake + # refrained from defining its own .PHONY target as it does + # with other overridden targets. + my @undefined_conds = (TRUE,); + if ($_ ne '.PHONY') + { + @undefined_conds = + rule_define ($_, 'internal', TARGET_AUTOMAKE, TRUE, INTERNAL); + } + my @uniq_deps = uniq (sort @{$dependencies{$_}}); + foreach my $cond (@undefined_conds) + { + my $condstr = $cond->subst_string; + &pretty_print_rule ("$condstr$_:", "$condstr\t", @uniq_deps); + $output_rules .= $actions{$_} if defined $actions{$_}; + $output_rules .= "\n"; + } } } @@ -7196,11 +7213,27 @@ sub rule_define ($$$$$) { if ($oldowner == TARGET_USER) { + # -am targets listed in %dependencies support a -local + # variant. If the user tries to override TARGET or + # TARGET-am for which there exists a -local variant, + # just tell the user to use it. + my $hint = 0; + my $noam = $target; + $noam =~ s/-am$//; + if (exists $dependencies{"$noam-am"}) + { + $hint = "consider using $target-local instead of $target"; + } + msg_cond_target ('override', $cond, $target, "user target `$target' defined here" . "$condmsg...", partial => 1); msg ('override', $where, - "... overrides Automake target `$target' defined here"); + "... overrides Automake target `$target' defined here", + partial => $hint); + msg_cond_target ('override', $cond, $target, $hint) + if $hint; + # Don't overwrite the user definition of TARGET. return (); } diff --git a/tests/Makefile.am b/tests/Makefile.am index fe99435f2..2f7144e92 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -297,6 +297,7 @@ output2.test \ output3.test \ output4.test \ output5.test \ +overrid.test \ package.test \ parse.test \ percent.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 159fb468e..1287edc5c 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -400,6 +400,7 @@ output2.test \ output3.test \ output4.test \ output5.test \ +overrid.test \ package.test \ parse.test \ percent.test \ diff --git a/tests/overrid.test b/tests/overrid.test new file mode 100755 index 000000000..5679c2d2e --- /dev/null +++ b/tests/overrid.test @@ -0,0 +1,67 @@ +#! /bin/sh +# Copyright (C) 2003 Free Software Foundation, Inc. +# +# This file is part of GNU Automake. +# +# GNU Automake is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# GNU Automake is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Automake; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# Make sure automake -Woverride suggests using TARGET-local instead +# of TARGET when possible. + +. ./defs || exit 1 + +set -e + +cat >> configure.in << 'END' +AM_CONDITIONAL([COND]) +END + +cat > Makefile.am << 'END' +install: + : +installcheck: + : +html: + : + +if COND +ps: mine + : +endif +END + +$ACLOCAL +$AUTOMAKE -Wno-override +$AUTOMAKE 2>stderr && exit 1 +cat stderr +grep install-local stderr && exit 1 # There is no such thing as install-local +grep installcheck-local stderr +grep html-local stderr + +# Conditional overrides ought to be diagnosed, but it can't be done yet. +# See the FIXME in rule_define. Once this is fixed, the grep below +# will fail. If you see the failure, it means you fixed Automake. Well done! +# Just strip out the next '&& exit 1' and this comment. +grep ps stderr && exit 1 + +# Test for another issue. Overriding html: should cause only one +# html: rule to be output. +test `grep html: Makefile.in | wc -l` = 1 + +# ps: should be output in two conditions +test `grep ps: Makefile.in | wc -l` = 2 +grep '@COND_TRUE@ps: mine' Makefile.in +grep '@COND_FALSE@ps: ps-am' Makefile.in diff --git a/tests/phony.test b/tests/phony.test index 16af5ebdb..31a6c53aa 100755 --- a/tests/phony.test +++ b/tests/phony.test @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (C) 2002 Free Software Foundation, Inc. +# Copyright (C) 2002, 2003 Free Software Foundation, Inc. # # This file is part of GNU Automake. # @@ -32,3 +32,4 @@ EOF $ACLOCAL $AUTOMAKE +test `$FGREP .PHONY: Makefile.in | wc -l` = 3