From 73c74ba0197e6566da6882c87b1adee63e24d75c Mon Sep 17 00:00:00 2001
From: Patrice Dumas <pertusus@free.fr>
Date: Mon, 29 Jan 2024 18:39:44 +0100
Subject: [PATCH] gendocs: get only targetted manual source and includes, when
 possible

* build-aux/gendocs.sh: if makeinfo, based on version, has the
--trace-includes option, gather only the targetted manual srcfile and
the included files obtained with makeinfo --trace-includes. In that
case output include files to tar stdin and use -T-. Bruno Haible for
the version comparison and use of tar.
---
 ChangeLog            |  9 +++++++++
 build-aux/gendocs.sh | 42 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dff23544d0..3ada614959 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-01-29  Patrice Dumas  <pertusus@free.fr>
+
+	gendocs: get only targetted manual source and includes, when possible
+	* build-aux/gendocs.sh: if makeinfo, based on version, has the
+	--trace-includes option, gather only the targetted manual srcfile and
+	the included files obtained with makeinfo --trace-includes. In that
+	case output include files to tar stdin and use -T-. Bruno Haible for
+	the version comparison and use of tar.
+
 2024-01-29  Bruno Haible  <bruno@clisp.org>
 
 	Port FALLTHROUGH to Mac OS X 10.9.
diff --git a/build-aux/gendocs.sh b/build-aux/gendocs.sh
index bdf105e02b..60447d4f5c 100755
--- a/build-aux/gendocs.sh
+++ b/build-aux/gendocs.sh
@@ -422,16 +422,42 @@ d=`dirname $srcfile`
   # file names to be put into the .tar.gz for sources.
   # Omit patterns that do not expand to file names.
   pats=
-  for pat in '*.texinfo' '*.texi' '*.txi' '*.eps'; do
-    for file in $pat; do
-      test "$file" = "$pat" && test ! -e "$file" || pats="$pats $pat"
-      break
+
+  if case `$MAKEINFO --version | sed -e 's/^[^0-9]*//' -e 1q` in \
+       [1-6]* | 7.[01]*) false;; \
+       *) true;; \
+     esac \
+  ; then
+
+    for pat in '*.eps'; do
+      for file in $pat; do
+        test "$file" = "$pat" && test ! -e "$file" || pats="$pats $pat"
+        break
+      done
+    done
+
+    # if $MAKEINFO is recent enough, use --trace-includes on the
+    # $srcfile to get the included files of the targetted manual only
+    base=`basename "$srcfile"`
+
+    cmd="$SETLANG $MAKEINFO $commonarg --trace-includes \"$base\""
+    eval "$cmd" \
+    | tar -czhf "$abs_outdir/$PACKAGE.texi.tar.gz" \
+        --verbatim-files-from -T- -- "$base" $pats \
+        ${source_extra+"$source_extra"} \
+    && ls -l "$abs_outdir/$PACKAGE.texi.tar.gz"
+  else
+    for pat in '*.texinfo' '*.texi' '*.txi' '*.eps'; do
+     for file in $pat; do
+       test "$file" = "$pat" && test ! -e "$file" || pats="$pats $pat"
+       break
+      done
     done
-  done
 
-  tar -czhf "$abs_outdir/$PACKAGE.texi.tar.gz" \
-    -- $pats ${source_extra+"$source_extra"} &&
-  ls -l "$abs_outdir/$PACKAGE.texi.tar.gz"
+    tar -czhf "$abs_outdir/$PACKAGE.texi.tar.gz" \
+       -- $pats ${source_extra+"$source_extra"} \
+    && ls -l "$abs_outdir/$PACKAGE.texi.tar.gz"
+  fi
 ) || exit
 texi_tgz_size=`calcsize "$outdir/$PACKAGE.texi.tar.gz"`
 
-- 
2.39.5