Subject: [PATCH 1/2] texi: pass automatic -I to dvi & pdf generation

From: Mike Frysinger <[email-masked]>
Date: Mon, 24 Jan 2022 03:10:06 -0500

Fixes automake bug https://bugs.gnu.org/23599.

When generating info/html pages, automake adds -I flags to source
dirs that contain the texi files, but it doesn't do this for dvi or
pdf formats.  Instead, automake has been relying on texi2dvi to use
makeinfo for expanding macros, and it hasn't done that by default in
a long time.

Since adding --expand to the texi2dvi call is undesirable (due to bad
and unpredictable BEHAVIOR), pass those automatic -I flags directly
to TEXI2DVI & TEXI2PDF so they work regardless of --expand behavior.

We have to keep the MAKEINFO= setting around as texi2dvi might itself
fall back to it if the version of tex is old or broken.

* bin/automake.in: Add comment about $makeinfoflags usage.
* lib/am/texibuild.am: Pass %MAKEINFOFLAGS% to TEXI2DVI & TEXI2PDF.
---
 bin/automake.in     |  4 ++++
 lib/am/texibuild.am | 12 ++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/bin/automake.in b/bin/automake.in
index 28e0fe67233b..e0fba69c47e3 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -3131,6 +3131,10 @@ sub output_texinfo_build_rules
   # but just remember that some logic deeper in Automake will not
   # output the same rule twice); while the later need to be output for
   # each Texinfo source.
+  #
+  # NB: The makeinfoflags is currently passed to makeinfo and texi2dvi, so
+  # make sure that it only utilizes compatible flags.  Best to stick to -I.
+  # Changing this requires updating lib/am/texibuild.am.
   my $generic;
   my $makeinfoflags;
   my $sdir = dirname $source;
diff --git a/lib/am/texibuild.am b/lib/am/texibuild.am
index e3d63087a4f9..3f3f00d58df2 100644
--- a/lib/am/texibuild.am
+++ b/lib/am/texibuild.am
@@ -63,7 +63,9 @@ INFO_DEPS += %DEST_INFO_PREFIX%%DEST_SUFFIX%
 ?!GENERIC?%DEST_PREFIX%.dvi: %SOURCE% %DEPS% %DIRSTAMP%
 	%AM_V_TEXI2DVI%TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
 ## Must set MAKEINFO like this so that version.texi will be found even
-## if it is in srcdir (-I $(srcdir) is set in %MAKEINFOFLAGS%).
+## if it is in srcdir (-I $(srcdir) is set in %MAKEINFOFLAGS%), and in case
+## texi2dvi automatically fallsback to using makeinfo for expanding (-E).
+## If texi2dvi doesn't fallback, we also pass %MAKEINFOFLAGS% directly below.
 	MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) %MAKEINFOFLAGS%' \
 ## texi2dvi doesn't silence everything with -q, redirect to /dev/null instead.
 ## We still want -q (%TEXIQUIET%) because it turns on batch mode.
@@ -74,7 +76,7 @@ INFO_DEPS += %DEST_INFO_PREFIX%%DEST_SUFFIX%
 ## avoid hitting a Texinfop bug that could cause low-probability racy
 ## failure when doing parallel builds; see:
 ## https://lists.gnu.org/archive/html/automake-patches/2012-06/msg00073.html
-	$(TEXI2DVI) %TEXIQUIET% --build-dir=$(@:.dvi=.t2d) -o $@ %TEXIDEVNULL% \
+	$(TEXI2DVI) %MAKEINFOFLAGS% %TEXIQUIET% --build-dir=$(@:.dvi=.t2d) -o $@ %TEXIDEVNULL% \
 ?GENERIC?	%SOURCE%
 ?!GENERIC?	`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE%
 
@@ -82,7 +84,9 @@ INFO_DEPS += %DEST_INFO_PREFIX%%DEST_SUFFIX%
 ?!GENERIC?%DEST_PREFIX%.pdf: %SOURCE% %DEPS% %DIRSTAMP%
 	%AM_V_TEXI2PDF%TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
 ## Must set MAKEINFO like this so that version.texi will be found even
-## if it is in srcdir (-I $(srcdir) is set in %MAKEINFOFLAGS%).
+## if it is in srcdir (-I $(srcdir) is set in %MAKEINFOFLAGS%), and in case
+## texi2dvi automatically fallsback to using makeinfo for expanding (-E).
+## If texi2dvi doesn't fallback, we also pass %MAKEINFOFLAGS% directly below.
 	MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) %MAKEINFOFLAGS%' \
 ## texi2pdf doesn't silence everything with -q, redirect to /dev/null instead.
 ## We still want -q (%TEXIQUIET%) because it turns on batch mode.
@@ -93,7 +97,7 @@ INFO_DEPS += %DEST_INFO_PREFIX%%DEST_SUFFIX%
 ## avoid hitting a Texinfop bug that could cause low-probability racy
 ## failure when doing parallel builds; see:
 ## https://lists.gnu.org/archive/html/automake-patches/2012-06/msg00073.html
-	$(TEXI2PDF) %TEXIQUIET% --build-dir=$(@:.pdf=.t2p) -o $@ %TEXIDEVNULL% \
+	$(TEXI2PDF) %MAKEINFOFLAGS% %TEXIQUIET% --build-dir=$(@:.pdf=.t2p) -o $@ %TEXIDEVNULL% \
 ?GENERIC?	%SOURCE%
 ?!GENERIC?	`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE%
 
-- 
2.34.1