Subject: bug#8360: distcheck-hook never called

From: Stefano Lattarini <[email-masked]>
Date: Thu, 1 Sep 2011 20:12:37 +0200

Resurrecting an old thread, for reference see:
  <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8360>

On Saturday 09 April 2011, Ralf Wildenhues wrote:
> Hello Pitamila,
> 
> let's keep the mailing list in Cc:, please.  I would've seen your reply
> earlier then.
> 
> * [email-masked] wrote on Mon, Apr 04, 2011 at 04:02:53PM CEST:
> > ----- "Ralf Wildenhues" a écrit :
> > > 
> > > thanks for the report.
> > 
> > thanks for the support, I hope my answer is not too late.
> 
> There's (almost) never a "too late" when giving useful feedback!
> 
> > > * [email-masked] wrote on Mon, Mar 28, 2011 at 09:17:09AM CEST:
> > > > I'd like to make a rpm buildpackage in my distcheck-hook rule.
> > > > My 'distcheck-hook' rule in my root Makefile.am is never called.
> > > > I tryed to define a 'distcheck-local' too without success.
> > > > Is there something more to know than 14.4 of automake manual?
> > > 
> > > Can you show the Makefile.am file?  distcheck-hook should work.
> > 
> > Find attached the Makefile.am of my doc/ subdir
> > In fact I try to call a clean-local without success (I suppose
> > it's the same bug than my distcheck-local not beeing called
> > in my top Makefile.am)
> 
> Yep.  And you have indeed stumbled over a limitation in automake;
> I could call it a bug, but I'm inclined to document it rather than
> fix it as it is worked around easily.
> 
> Quoting your Makefile.am:
> 
> clean-local	:
> 		-rm -rf html/* html @PACKAGE@.pdf latex/* latex
> 
> There is a literal TAB after 'clean-local'.  automake's parser is pretty
> dumb when it comes to distinguishing rule commands from rule lines from
> variable assignments, mostly because it is hard to get things right when
> hard-core GNU make code is used.
> 
> Anyway, in this case it gets things wrong due to the TAB.  Solution is
> to remove the TAB before the colon, maybe replacing it with a number of
> spaces.  Then everything will work out fine.
> 
I've ended up writing a documentation patch for this, as well for another
unrelated limitation encountered by Roberto Bagnara in an older thread on
the automake list, see:
  <http://lists.gnu.org/archive/html/automake/2010-08/msg00074.html>
Since I was at it, I've written two tests verifying the documented
behaviour.

I will wait a few hours before pushing (to maint), to allow for reviews.

Regards,
  Stefano
From 00e845afb826107a14db247a465eefea728f9bc5 Mon Sep 17 00:00:00 2001
Message-Id: <00e845afb[email-masked]>
From: Stefano Lattarini <[email-masked]>
Date: Thu, 1 Sep 2011 19:17:39 +0200
Subject: [PATCH] docs: report few more automake parsing limitations

Partly motivated by automake bug#8360.

* doc/automake.texi (General Operation): Report few more automake
limitations w.r.t. parsing of unusual makefile constructs.  Related
minor reorderings.
* tests/doc-parsing-buglets-colneq-subst.test: New test.
* tests/doc-parsing-buglets-tabs.test: Likewise.
* tests/Makefile.am (TESTS): Update.
---
 ChangeLog                                   |   11 +++++
 doc/automake.texi                           |   26 +++++++++--
 tests/Makefile.am                           |    2 +
 tests/Makefile.in                           |    2 +
 tests/doc-parsing-buglets-colneq-subst.test |   39 ++++++++++++++++
 tests/doc-parsing-buglets-tabs.test         |   64 +++++++++++++++++++++++++++
 6 files changed, 139 insertions(+), 5 deletions(-)
 create mode 100755 tests/doc-parsing-buglets-colneq-subst.test
 create mode 100755 tests/doc-parsing-buglets-tabs.test

diff --git a/ChangeLog b/ChangeLog
index 7c11ab3..5d0eda1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-09-01  Stefano Lattarini  <[email-masked]>
+
+	docs: report few more automake parsing limitations
+	Partly motivated by automake bug#8360.
+	* doc/automake.texi (General Operation): Report few more automake
+	limitations w.r.t. parsing of unusual makefile constructs.  Related
+	minor reorderings.
+	* tests/doc-parsing-buglets-colneq-subst.test: New test.
+	* tests/doc-parsing-buglets-tabs.test: Likewise.
+	* tests/Makefile.am (TESTS): Update.
+
 2011-08-25  Stefano Lattarini  <[email-masked]>
 
 	tests: list "forgotten" test script in TESTS
diff --git a/doc/automake.texi b/doc/automake.texi
index 49a6cd1..3be8578 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -1813,14 +1813,30 @@ supported.  This operator appends its right hand argument to the variable
 specified on the left.  Automake will translate the operator into
 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
 
-@cindex indentation
-Further note that variable assignments should not be indented with
-@key{TAB} characters, use spaces if necessary.  On the other hand,
-rule commands should be indented with a leading @key{TAB} character.
-
 Automake tries to keep comments grouped with any adjoining rules or
 variable definitions.
 
+@cindex Limitations of automake parser
+@cindex Automake parser, limitations of
+@cindex indentation in Makefile.am
+Generally, Automake is not particularly smart in the parsing of unusual
+Makefile constructs, so you're advised to avoid fancy constructs or
+``creative'' use of whitespaces.
+@c Keep this in sync with doc-parsing-buglets-tabs.test.
+For example, @key{TAB} characters cannot be used between a target name
+and the following ``@code{:}'' character, and variable assignments
+shouldn't be indented with @key{TAB} characters.
+@c Keep this in sync with doc-parsing-buglets-colneq-subst.test.
+Also, using more complex macro in target names can cause trouble:
+
+@example
+% @kbd{cat Makefile.am}
+$(FOO:=x): bar
+% @kbd{automake}
+Makefile.am:1: bad characters in variable name `$(FOO'
+Makefile.am:1: `:='-style assignments are not portable
+@end example
+
 @cindex Make targets, overriding
 @cindex Make rules, overriding
 @cindex Overriding make rules
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a1c67ff..6101460 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -325,6 +325,8 @@ distcheck-configure-flags-subpkg.test \
 distcheck-hook.test \
 distcheck-hook2.test \
 dmalloc.test \
+doc-parsing-buglets-colneq-subst.test \
+doc-parsing-buglets-tabs.test \
 dollar.test \
 dollarvar.test \
 dollarvar2.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 4b2d845..108672d 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -603,6 +603,8 @@ distcheck-configure-flags-subpkg.test \
 distcheck-hook.test \
 distcheck-hook2.test \
 dmalloc.test \
+doc-parsing-buglets-colneq-subst.test \
+doc-parsing-buglets-tabs.test \
 dollar.test \
 dollarvar.test \
 dollarvar2.test \
diff --git a/tests/doc-parsing-buglets-colneq-subst.test b/tests/doc-parsing-buglets-colneq-subst.test
new file mode 100755
index 0000000..685d2b6
--- /dev/null
+++ b/tests/doc-parsing-buglets-colneq-subst.test
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2011 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check a documented limitation of the Automake's Makefile parser
+# w.r.t. POSIX variable substitutions used in the name of targets.
+# See Section "General Operation" in the Automake manual.
+# If you cause some parts of this test to fail, chances are that you've
+# improved the Automake parser ;-)
+# See: <http://lists.gnu.org/archive/html/automake/2010-08/msg00074.html>
+# or: <http://thread.gmane.org/gmane.comp.sysutils.automake.general/11943/focus=11962>
+
+. ./defs || Exit 1
+
+set -e
+
+cat > Makefile.am <<'END'
+$(FOO:=x): bar
+END
+
+$ACLOCAL
+AUTOMAKE_fails
+
+grep 'bad characters.*variable name.*\$(FOO' stderr
+grep ':=.*assignments.*not portable' stderr
+
+:
diff --git a/tests/doc-parsing-buglets-tabs.test b/tests/doc-parsing-buglets-tabs.test
new file mode 100755
index 0000000..eee4a81
--- /dev/null
+++ b/tests/doc-parsing-buglets-tabs.test
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2011 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check the documented limitation of the Automake's Makefile parser w.r.t.
+# use of TAB characters; see Section "General Operation" in the Automake
+# manual, and automake bug#8360.
+# If you cause some parts of this test to fail, chances are that you've
+# improved the Automake parser ;-)
+
+. ./defs || Exit 1
+
+set -e
+
+cat > Makefile.am <<END
+.PHONY: test
+test: all check
+
+fail:
+${tab}@echo "'\$@ recipe executed'"; exit 1
+
+## This won't be recognized as a target+recipe by Automake.
+all-local${tab}:
+${tab}@exit 1
+#check-local :
+#${tab}@exit 1
+
+## This won't be recognized as a target+rdependency by Automake.
+all-local${tab}: fail
+#check-local : fail
+
+just_to_separate: dummy deps
+
+## This won't be recognized as a variable assignment by Automake.
+${tab}bin_PROGRAMS = foo
+END
+
+echo AC_OUTPUT >> configure.in
+
+$ACLOCAL
+$AUTOMAKE
+
+$FGREP '$(EXEEEXT)' Makefile.in && Exit 1
+grep 'all:.*all-local' Makefile.in && Exit 1
+grep "^${tab}bin_PROGRAMS = foo" Makefile.in
+
+$AUTOCONF
+./configure
+
+$MAKE test
+
+:
-- 
1.7.2.3