* automake.in (rule_define): Don't diagnose duplicate user rules.
authorAlexandre Duret-Lutz <adl@gnu.org>
Thu, 19 Sep 2002 08:59:49 +0000 (08:59 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Thu, 19 Sep 2002 08:59:49 +0000 (08:59 +0000)
* tests/phony.test, tests/percent2.test: New files.
* tests/Makefile.am (TESTS): Add them.

ChangeLog
automake.in
tests/Makefile.am
tests/Makefile.in
tests/percent2.test [new file with mode: 0755]
tests/phony.test [new file with mode: 0755]

index 9dccc4e..62aa813 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2002-09-19  Alexandre Duret-Lutz  <duret_g@epita.fr>
 
+       * automake.in (rule_define): Don't diagnose duplicate user rules.
+       * tests/phony.test, tests/percent2.test: New files.
+       * tests/Makefile.am (TESTS): Add them.
+
        * automake.in (require_variables): Search variable definitions
        in any condition implied by $cond.
        * tests/cond25.test: New file.
index 2e88206..a8c9800 100755 (executable)
@@ -7382,7 +7382,7 @@ sub register_suffix_rule ($$$)
 # rule_define ($TARGET, $SOURCE, $OWNER, $COND, $WHERE)
 # -----------------------------------------------------
 # Define a new rule.  $TARGET is the rule name.  $SOURCE
-# si the filename the rule comes from.  $OWNER is the
+# is the filename the rule comes from.  $OWNER is the
 # owener of the rule (TARGET_AUTOMAKE or TARGET_USER).
 # $COND is the condition string under which the rule is defined.
 # $WHERE is where the rule is defined (file name and/or line number).
@@ -7413,6 +7413,11 @@ sub rule_define ($$$$$)
 
   $target = $noexe;
 
+  # A GNU make-style pattern rule has a single "%" in the target name.
+  msg ('portability', $where,
+       "`%'-style pattern rules are a GNU make extension")
+    if $target =~ /^[^%]*%[^%]*$/;
+
   # Diagnose target redefinitions.
   if (exists $target_source{$target}{$cond})
     {
@@ -7433,9 +7438,27 @@ sub rule_define ($$$$$)
        {
          if ($oldowner eq TARGET_USER)
            {
-             msg ('syntax', $where, "redefinition of `$target'$condmsg...");
-             msg_cond_target ('syntax', $cond, $target,
-                              "... `$target' previously defined here.");
+             # Ignore `%'-style pattern rules.  We'd need the
+             # dependencies to detect duplicates, and they are
+             # already diagnosed as unportable by -Wportability.
+             if ($target !~ /^[^%]*%[^%]*$/)
+               {
+                 ## FIXME: Presently we can't diagnose duplcate user rules
+                 ## because we doesn't distinguish rules with commands
+                 ## from rules that only add dependencies.  E.g.,
+                 ##   .PHONY: foo
+                 ##   .PHONY: bar
+                 ## is legitimate. (This is phony.test.)
+
+                 # msg ('syntax', $where,
+                 #      "redefinition of `$target'$condmsg...");
+                 # msg_cond_target ('syntax', $cond, $target,
+                 #                "... `$target' previously defined here.");
+               }
+             # Return so we don't redefine the rule in our tables,
+             # don't check for ambiguous conditional, etc.  The rule
+             # will be output anyway beauce &read_am_file ignore the
+             # return code.
              return ();
            }
          else
@@ -7477,11 +7500,6 @@ sub rule_define ($$$$$)
       prog_error ("Unreachable place reached.");
     }
 
-  # A GNU make-style pattern rule has a single "%" in the target name.
-  msg ('portability', $where,
-       "`%'-style pattern rules are a GNU make extension")
-    if $target =~ /^[^%]*%[^%]*$/;
-
   # Conditions for which the rule should be defined.
   my @conds = $cond;
 
@@ -7751,9 +7769,9 @@ sub read_am_file ($)
            # Found a rule.
            $prev_state = IN_RULE_DEF;
 
-           # For TARGET_USER rules, rule_define won't reject a rule
-           # without diagnosic an error.  So we go on and ignore the
-           # return value.
+           # For now we have to output all definitions of user rules
+           # and can't diagnose duplicates (see the comment in
+           # rule_define). So we go on and ignore the return value.
            rule_define ($1, $amfile, TARGET_USER, $cond || 'TRUE', $here);
 
            check_variable_expansions ($_, $here);
index ef561ae..333ef33 100644 (file)
@@ -274,6 +274,8 @@ output5.test \
 package.test \
 parse.test \
 percent.test \
+percent2.test \
+phony.test \
 pluseq.test \
 pluseq2.test \
 pluseq3.test \
index fba3673..c961b33 100644 (file)
@@ -365,6 +365,8 @@ output5.test \
 package.test \
 parse.test \
 percent.test \
+percent2.test \
+phony.test \
 pluseq.test \
 pluseq2.test \
 pluseq3.test \
diff --git a/tests/percent2.test b/tests/percent2.test
new file mode 100755 (executable)
index 0000000..c8b6273
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+# Copyright (C) 2002  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 autoconf; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Another test for -Wportability warning about %-style rules, plus
+# make sure we don't warn about duplicate definition for
+# `${ARCH}/%.$(OBJEXT):'.
+# Report from Ralf Corsepius.
+
+. ./defs
+
+set -e
+
+cat >>Makefile.am << 'EOF'
+${ARCH}/%.$(OBJEXT): %.S
+       test -d ${ARCH} || mkdir ${ARCH}
+       ${CCASCOMPILE} -o $@ -c $<
+
+${ARCH}/%.$(OBJEXT): %.c
+       test -d ${ARCH} || mkdir ${ARCH}
+       ${COMPILE} -o $@ -c $<
+EOF
+
+$ACLOCAL
+$AUTOMAKE 2>stderr && exit 1
+cat stderr
+grep '%.*pattern.*rules' stderr
+
+# No error otherwise.
+$AUTOMAKE -Wno-portability
diff --git a/tests/phony.test b/tests/phony.test
new file mode 100755 (executable)
index 0000000..16af5eb
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+# Copyright (C) 2002  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 autoconf; 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 .PHONY can be given depenencies several times.
+# From Ralf Corsepius.
+
+. ./defs
+
+set -e
+
+cat >Makefile.am << 'EOF'
+.PHONY: foo
+.PHONY: bar
+EOF
+
+$ACLOCAL
+$AUTOMAKE