Subject: Re: bug#27188: lex/yacc with subdir-objects and --disable-dependency-tracking broken

From: Mathieu Lirzin <[email-masked]>
Date: Mon, 05 Jun 2017 01:15:30 +0200

Hello,

Nick Brown <[email-masked]> writes:

> By default Debian dh passes --disable-dependacy-tracking when building.
> If the package rules also adds --builddirectory to use out of source builds
> (eg. "dh $@ --builddirectory=build --parallel --with autoreconf"), and the
> package happens to be using subdir-objects automake option and generated source
> files from lex/yacc then the build will fail.
>
> Eg.
>
> mkdir build
> ../configure --disable-dependency-tracking --disable-silent-rules
> make
>
> /bin/bash ../ylwrap ../src/scanner.ll lex.yy.c src/scanner.cc -- flex
> ../ylwrap: line 206: ../src/scanner.cc: No such file or directory
> Makefile:422: recipe for target 'src/scanner.cc' failed
> make: *** [src/scanner.cc] Error 1

This seems like a known bug since 2011, that would be nice to fix.
There is already an "expected fail" test case for the issue you have
described.  The commit 40c34328d1e5d3ab6885f046ce27517332413c13 which
has intentionaly make the test fail has the following ChangeLog:

+2011-10-20  Stefano Lattarini  <[email-masked]>
+
+	deps: partially revert commit `v1.11-512-geeee551'
+	This change partly reverts commit "Create subdirs for generated
+	sources even when not dep tracking", of 2011-04-02.
+	That commit had caused the bugs #8485 and #8526.  Since we are
+	nearing the bug-fixing automake release 1.11.2, the safest policy
+	at the moment is to just revert the problematic hunks: an older,
+	known bug is better than a regression.
+	* automake.in (handle_single_transform): Don't add a dirstamp
+	dependency, even when $object is derived and lands in a subdir.
+	* tests/Makefile.am (XFAIL_TESTS): Add lex-subobj-nodep.test,
+	remove yacc-dist-nobuild-subdir.test.

This seems to imply that this has not been fixed because of time
constraints before a release.  Can you investigate more to see if your
patch doesn't reintroduce problems from bugs #8485 and #8526?

>
> A simple patch to lex.am and yacc.am fixes this.
>
>>>From bd6971224f304c8f5951afca620f33c25248b446 Mon Sep 17 00:00:00 2001
> From: Nicholas Brown <[email-masked]>
> Date: Fri, 4 Dec 2015 10:49:18 +0000
> Subject: [PATCH] yacc and lex built objects without dependancy tracking
>
> ---
>  lib/am/lex.am  | 1 +
>  lib/am/yacc.am | 1 +
>  2 files changed, 2 insertions(+)
>
> diff --git a/lib/am/lex.am b/lib/am/lex.am
> index d7ddc77..6357507 100644
> --- a/lib/am/lex.am
> +++ b/lib/am/lex.am
> @@ -23,6 +23,7 @@ endif %?MAINTAINER-MODE%
>  
>  ?GENERIC?%EXT%%DERIVED-EXT%:
>  ?!GENERIC?%OBJ%: %SOURCE%
> +?SUBDIROBJ?	%SILENT%test -d $(dir $@) || $(MKDIR_P) $(dir $@)

I suspect the '$(dir ..)' syntax is not portable.  Hopefully there
should be a alternative.  Can you look into it? 

>  ?GENERIC?	%VERBOSE%$(am__skiplex) $(SHELL) $(YLWRAP) %SOURCE% $(LEX_OUTPUT_ROOT).c %OBJ% -- %COMPILE%
>  ?!GENERIC?	%VERBOSE% \
>  ?!GENERIC??DIST_SOURCE?	$(am__skiplex) \
> diff --git a/lib/am/yacc.am b/lib/am/yacc.am
> index 2b3f92a..2c33023 100644
> --- a/lib/am/yacc.am
> +++ b/lib/am/yacc.am
> @@ -43,6 +43,7 @@ endif %?FIRST%
>  
>  ?GENERIC?%EXT%%DERIVED-EXT%:
>  ?!GENERIC?%OBJ%: %SOURCE%
> +?SUBDIROBJ?	%SILENT%test -d $(dir $@) || $(MKDIR_P) $(dir $@)
>  ?GENERIC?	%VERBOSE%$(am__skipyacc) $(SHELL) $(YLWRAP) %SOURCE% y.tab.c %OBJ% y.tab.h `echo %OBJ% | $(am__yacc_c2h)` y.output %BASE%.output -- %COMPILE%
>  ?!GENERIC?	%VERBOSE% \
>  ?!GENERIC??DIST_SOURCE?	$(am__skipyacc) \

Thank you for you patch.

-- 
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37