Dear Recipient,

Your bug #9859 filed against automake has been resolved. Thank you for reporting. Please see the attached patch.

--
With Valediction,
Kamila Szewczyk (https://iczelia.net)
From 7872790c899ea30084219ae47ad278ae2431f841 Mon Sep 17 00:00:00 2001
From: Kamila Szewczyk <[email protected]>
Date: Sun, 18 Oct 2026 16:52:49 +0200
Subject: [PATCH] fix lex/yacc support bug; create output dirs before
 generating sources

resolves #27188 (of #9859).

* lib/am/lex.am: create output directories before generating sources.
* lib/am/yacc.am: ditto
* NEWS: mention that
* t/yacc-subobj-nodep.sh: regression test.
* t/lex-subobj-nodep.sh: ditto.
* t/list-of-tests.mk: deregister t/lex-subobj-nodep.sh as xfail, register t/yacc-subobj-nodep.sh.
---
 NEWS                   |  4 +++
 lib/am/lex.am          |  1 +
 lib/am/yacc.am         |  1 +
 t/lex-subobj-nodep.sh  | 15 +++++++---
 t/list-of-tests.mk     |  2 +-
 t/yacc-subobj-nodep.sh | 68 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 86 insertions(+), 5 deletions(-)
 create mode 100644 t/yacc-subobj-nodep.sh

diff --git a/NEWS b/NEWS
index bdae8429f..97879bf9e 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,10 @@ New in 1.20 (????-??-??):
 
 * Bugs fixed
 
+  - Lex and yacc rules now create output directories before generating
+    sources, fixing out-of-tree builds with subdir-objects and
+    --disable-dependency-tracking.  (bug#27188, Debian bug#807050)
+
   - configure now refuses a source directory path ($srcdir) containing
     ';' or '|', reporting "unsafe srcdir value", as it already did for
     characters such as '$' and '&'.  Such a path used to fail later
diff --git a/lib/am/lex.am b/lib/am/lex.am
index 0d71b47eb..597505dac 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%
+	@$(MKDIR_P) $(@D)
 ?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 824ae9967..2e5e67fb4 100644
--- a/lib/am/yacc.am
+++ b/lib/am/yacc.am
@@ -43,6 +43,7 @@ endif %?FIRST%
 
 ?GENERIC?%EXT%%DERIVED-EXT%:
 ?!GENERIC?%OBJ%: %SOURCE%
+	@$(MKDIR_P) $(@D)
 ?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) \
diff --git a/t/lex-subobj-nodep.sh b/t/lex-subobj-nodep.sh
index b53efee58..26cfaf5f5 100644
--- a/t/lex-subobj-nodep.sh
+++ b/t/lex-subobj-nodep.sh
@@ -16,12 +16,15 @@
 
 # Ensure subdirs for subdir scanners are generated when subdir-objects
 # are used, even when dependency tracking is disabled.
+# Cover C and C++ output, including an explicit rule for a nodist_ source.
+# https://bugs.gnu.org/27188; https://bugs.debian.org/807050
 
-required='cc lex'
+required='cc c++ lex'
 . test-init.sh
 
 cat >>configure.ac <<\END
 AC_PROG_CC
+AC_PROG_CXX
 AC_PROG_LEX
 AC_OUTPUT
 END
@@ -30,13 +33,15 @@ cat >Makefile.am <<\END
 AUTOMAKE_OPTIONS = subdir-objects
 AM_LFLAGS = --never-interactive
 
-bin_PROGRAMS = p1 p2
+bin_PROGRAMS = p1 p2 p3
 p1_SOURCES = sub1/s1.l
 p2_SOURCES = sub2/s2.l
 p2_CPPFLAGS = -DWHATEVER
+p3_SOURCES =
+nodist_p3_SOURCES = sub3/s3.ll
 END
 
-mkdir sub1 sub2
+mkdir sub1 sub2 sub3
 
 cat >sub1/s1.l <<\END
 %%
@@ -57,6 +62,7 @@ int yywrap(void)
 END
 
 cp sub1/s1.l sub2/s2.l
+cp sub1/s1.l sub3/s3.ll
 
 $ACLOCAL
 $AUTOCONF
@@ -66,7 +72,8 @@ cd build
 ../configure --disable-dependency-tracking
 $MAKE sub1/s1.c
 $MAKE sub2/s2.c
-rm -rf sub1 sub2
+$MAKE sub3/s3.cc
+rm -rf sub1 sub2 sub3
 $MAKE
 
 :
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index 385115e79..7e0293706 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -43,7 +43,6 @@ t/instdir-ltlib.sh \
 t/java-nobase.sh \
 t/objext-pr10128.sh \
 t/remake-timing-bug-pr8365.sh \
-t/lex-subobj-nodep.sh \
 t/remake-am-pr10111.sh \
 t/remake-m4-pr10111.sh \
 $(perl_fake_XFAIL_TESTS)
@@ -1350,6 +1349,7 @@ t/yacc-mix-c-cxx.sh \
 t/yacc-nodist.sh \
 t/yacc-pr204.sh \
 t/yacc-subdir.sh \
+t/yacc-subobj-nodep.sh \
 t/yacc-vpath.sh \
 t/yacc-weirdnames.sh \
 t/yflags-cmdline-override.sh \
diff --git a/t/yacc-subobj-nodep.sh b/t/yacc-subobj-nodep.sh
new file mode 100644
index 000000000..c71108360
--- /dev/null
+++ b/t/yacc-subobj-nodep.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2011-2026 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 <https://www.gnu.org/licenses/>.
+
+# Ensure subdir parsers and headers can be generated in a VPATH build
+# with dependency tracking disabled.  Cover both suffix and explicit rules.
+# https://bugs.gnu.org/27188; https://bugs.debian.org/807050
+
+required='cc c++ yacc'
+. test-init.sh
+
+cat >>configure.ac <<\END
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_YACC
+AC_OUTPUT
+END
+
+cat >Makefile.am <<\END
+AUTOMAKE_OPTIONS = subdir-objects
+AM_YFLAGS = -d
+bin_PROGRAMS = p1 p2
+p1_SOURCES = sub1/parse.y
+p2_SOURCES =
+nodist_p2_SOURCES = sub2/parse.yy
+END
+
+mkdir sub1 sub2
+cat >sub1/parse.y <<\END
+%{
+int yylex (void) { return 0; }
+void yyerror (const char *s) {}
+%}
+%%
+start: ;
+%%
+int main (void) { return yyparse (); }
+END
+cp sub1/parse.y sub2/parse.yy
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+mkdir build
+cd build
+../configure --disable-dependency-tracking
+$MAKE sub1/parse.c
+$MAKE sub2/parse.cc
+test -f sub1/parse.h
+test -f sub2/parse.hh
+rm -rf sub1 sub2
+$MAKE
+./p1
+./p2
+
+:
-- 
2.53.0

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to