automake
[Top][All Lists]
Advanced

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

Re: .PHONY and 1.6d & Custom make rules


From: Alexandre Duret-Lutz
Subject: Re: .PHONY and 1.6d & Custom make rules
Date: Thu, 19 Sep 2002 10:59:32 +0200
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-debian-linux-gnu)

>>> "Ralf" == Ralf Corsepius <address@hidden> writes:

[...]

 Ralf> automake-1.6d complains about this:

 Ralf> # cat Makefile.am
 Ralf> .PHONY: foo
 Ralf> .PHONY: bar

 Ralf> # automake
 Ralf> Makefile.am:2: redefinition of `.PHONY'...
 Ralf> Makefile.am:1: ... `.PHONY' previously defined here.

[...]

 Ralf> Using custom compilations rules in a Makefile.am:

 Ralf> # cat Makefile.am:
 Ralf> ${ARCH}/%.$(OBJEXT): %.S
 Ralf> test -d ${ARCH} || mkdir ${ARCH}
 Ralf> ${CCASCOMPILE} -o $@ -c $<

 Ralf> ${ARCH}/%.$(OBJEXT): %.c
 Ralf> test -d ${ARCH} || mkdir ${ARCH}
 Ralf> ${COMPILE} -o $@ -c $<

 Ralf> # autoreconf -fi
 Ralf> autoreconf: `aclocal.m4' is unchanged
 Ralf> Makefile.am:5: redefinition of `${ARCH}/%.$(OBJEXT)'...
 Ralf> Makefile.am:1: ... `${ARCH}/%.$(OBJEXT)' previously defined here.

Thanks a lot.  I'm installing the following patch (it addresses
both errors).  Automake doesn't record enough informations to
diagnose duplicates in user rules, so let's disable this
diagnostic until the internal handling of rules is improved.

 Ralf> 1. automake-1.6.3 and previous versions did not complain.
 Ralf> 2. automake's complaint is wrong. These are two different make rules.

 Ralf> Could it be that automake-1.6d is confused about variables (VAR=..) and
 Ralf> rules (VAR: ...)?

It just that make doesn't now anything about non-POSIX `%'-style
pattern rules.  This looks like duplicate rules for target 
`${ARCH}/%.$(OBJEXT)' if you ignore what `%' means.

2002-09-19  Alexandre Duret-Lutz  <address@hidden>

        * automake.in (rule_define): Don't diagnose duplicate user rules.
        * tests/phony.test, tests/percent2.test: New files.
        * tests/Makefile.am (TESTS): Add them.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1358
diff -u -r1.1358 automake.in
--- automake.in 19 Sep 2002 07:59:36 -0000      1.1358
+++ automake.in 19 Sep 2002 08:57:54 -0000
@@ -7382,7 +7382,7 @@
 # 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 @@
 
   $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 @@
        {
          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 @@
       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 @@
            # 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: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.441
diff -u -r1.441 Makefile.am
--- tests/Makefile.am   19 Sep 2002 07:59:37 -0000      1.441
+++ tests/Makefile.am   19 Sep 2002 08:57:56 -0000
@@ -274,6 +274,8 @@
 package.test \
 parse.test \
 percent.test \
+percent2.test \
+phony.test \
 pluseq.test \
 pluseq2.test \
 pluseq3.test \
Index: tests/percent2.test
===================================================================
RCS file: tests/percent2.test
diff -N tests/percent2.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/percent2.test 19 Sep 2002 08:57:56 -0000
@@ -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
Index: tests/phony.test
===================================================================
RCS file: tests/phony.test
diff -N tests/phony.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/phony.test    19 Sep 2002 08:57:56 -0000
@@ -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
-- 
Alexandre Duret-Lutz





reply via email to

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