scratch/remove-build-tex-prerequisite a378b96aaa8: Remove Emacs build need for tex/texindex being installed

Vincent Belaïche <[email protected]> Fri, 17 Jul 2026 07:59:56 -0400 (EDT)
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: scratch/remove-build-tex-prerequisite
commit a378b96aaa8ce613317e14a8d2f904d1afd77519
Author: Vincent Belaïche <[email protected]>
Commit: Vincent Belaïche <[email protected]>

    Remove Emacs build need for tex/texindex being installed
    
    * doc/translations/README: Add a `Adding new languages' section
    
    * m4/texinfo.m4 (gl_GET_TEXINFO_TEX_VER, gl_GET_TEXINDEX_VER):
      Detect whether tex or texindex are installed and working under
      pipefail regime and set new variable `tex_available' accordingly.
      (gl_SET_DOCLANGS): Do not fallback to default language when
      tex/texindex are not working or not installed.
---
 Makefile.in             | 17 +++++++--
 doc/translations/README | 11 ++++++
 m4/texinfo.m4           | 93 +++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 99 insertions(+), 22 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 24d5584b68f..28a60b40396 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1151,15 +1151,26 @@ $(1)-DOCLANG-$(2): $(1)-common
 	$$(MAKE) -C doc/$$(subst -, DOCLANG=$(2) ,$(1))
 
 endef
+## Languages to build the manuals in doc/$(1) for: the default
+## language, plus every other language in DOCLANGS that has
+## translations for this directory (doc/translations/<lang>/$(1)).
+## Directories without translations for a language must not run a
+## sub-make for it: the doc Makefiles of untranslated directories
+## ignore DOCLANG, so such a sub-make would just repeat the
+## default-language build, and two sub-makes producing the same
+## outputs race under "make -j" (e.g. "cp: cannot create regular
+## file ...: File exists").
+doc_langs = default $(foreach lang,$(filter-out default,$(DOCLANGS)),$(if $(wildcard ${srcdir}/doc/translations/$(lang)/$(1)),$(lang)))
+# $(1) = doc target (e.g. lispintro-info), $(2) = languages to build
 define MAKE_DOC
 # Define a target to which dependencies common to all of the doc files
 # in this directory may be assigned.
 $(1)-common:
-$(1): $$(addprefix $(1)-DOCLANG-,$(DOCLANGS))
+$(1): $$(addprefix $(1)-DOCLANG-,$(2))
 
-$$(foreach lang,$(DOCLANGS),$$(eval $$(call MAKE_DOC_FOR_DOCLANG,$(1),$$(lang))))
+$$(foreach lang,$(2),$$(eval $$(call MAKE_DOC_FOR_DOCLANG,$(1),$$(lang))))
 endef
-$(foreach doc,$(DOCS),$(eval $(call MAKE_DOC,$(doc))))
+$(foreach doc,$(DOCS),$(eval $(call MAKE_DOC,$(doc),$(call doc_langs,$(word 1,$(subst -, ,$(doc)))))))
 
 .PHONY: $(DOCS) docs pdf ps
 .PHONY: info dvi dist html info-dir check-info
diff --git a/doc/translations/README b/doc/translations/README
index 49c63ef62ad..846c9f45768 100644
--- a/doc/translations/README
+++ b/doc/translations/README
@@ -68,6 +68,17 @@ For the pdf output:
 
 ses-fr.pdf will go into the doc/misc directory.
 
+** Adding new languages
+
+For instance to add Japanese (ja):
+
+- add 'ja' to the list into list gl_DOCLANGS_FULL in file EMACS-REPO/m4/texinfo.m4
+- add a subdirectory 'ja' under directory EMACS-REPO/doc/translations/,
+- create a info_common.mk file into each subdirectory
+  EMACS-REPO/doc/translations/ja/TRANSLATED_DIR, eg TRANSLATED_DIR is
+  'misc' if you translate to Japanese a manual from the misc category.
+
+
 * Translating the Emacs manuals
 
 ** Copyright assignment
diff --git a/m4/texinfo.m4 b/m4/texinfo.m4
index 231d0b35736..0fbcbd1f0b6 100644
--- a/m4/texinfo.m4
+++ b/m4/texinfo.m4
@@ -68,26 +68,63 @@ dnl language/encoding corresponding locale is not installer nor active.
 dnl See texinfo version 836b8924560.
 m4_define([gl_TEXINFO_TEX_MINVER],[[20260426.12]])dnl
 m4_define([gl_TEXINDEX_MINVER],[[7.1]])dnl
+dnl gl_TEXINFO_INDEXING_IS_LOCALE_DEPENDANT
+dnl when tex tools are installed & working and that their version suggest that
+dnl the PDF/PS/DVI compilation may be broken by UTF-8 encoded manual sources
+dnl when the locale is not UTF-8, DOCLANGS is restricted to default language.
 m4_define([gl_TEXINFO_INDEXING_IS_LOCALE_DEPENDANT],[dnl
 [DOCLANGS='default'
 gl_fn_doclangs_info () {]
   AC_MSG_WARN([texinfo.tex/texindex versions suggest that indexing is locale dependant, manual compilation is restricted to lang 'default', override this by setting DOCLANGS in the environment])
 [}]])dnl
+dnl gl_GET_TEXINFO_TEX_VER
+dnl Test tex is installed and read the texinfo version into variable texinfo_tex_ver
 m4_define([gl_GET_TEXINFO_TEX_VER],[dnl
-[texinfo_tex_ver=`tex -jobname=conftest '\nonstopmode\input texinfo.tex @typeout{TEXINFO_TEX_VER=@texinfoversion}@bye' | awk 'BEGIN{R=1;FS="="};]gl_dollar[1=="TEXINFO_TEX_VER" { gsub("-","");print ]gl_dollar[2; R=0; exit}; END{ exit R}'`
-if test $? -ne 0; then
-   texinfo_tex_ver_ver=0.0
-   gl_fn_doclangs_info () {]
-     AC_MSG_WARN([Can't find texinfo.tex version, check tex and texinfo.tex are installed.])
-[  }
+[if false | true; then nopipefail=true; set -o pipefail; else nopipefail=false; fi
+if texinfo_tex_ver=`tex -jobname=conftest '\nonstopmode\input texinfo.tex @typeout{TEXINFO_TEX_VER=@texinfoversion}@bye' 2>/dev/null | awk 'BEGIN{R=1;FS="="};]gl_dollar[1=="TEXINFO_TEX_VER" { gsub("-","");print ]gl_dollar[2; R=0; exit}; END{ if(R) {print "notfound"}}'`; then
+  if test "$texinfo_tex_ver" == "notfound"; then
+     texinfo_tex_ver=0.0
+     gl_fn_texinfo_info () {]
+        AC_MSG_WARN([Can't find texinfo.tex version, check tex and texinfo.tex are installed.])[
+     }
+  fi
+else
+   texinfo_tex_ver=0.0
+   tex_available=false
+   gl_fn_texinfo_info () {]
+      AC_MSG_NOTICE([tex not installed or not working.])[
+   }
 fi
+if $nopipefail; then set +o pipefail; fi
 ]])dnl
+dnl gl_GET_TEXINDEX_VER
+dnl Test texindex is installed and read its vrson into variable texindex_ver
+dnl Test is not carried out when tex_available is false
+dnl texindex exiting in error will set tex_available to false
 m4_define([gl_GET_TEXINDEX_VER],[dnl
-[texindex_ver=`texindex --version | awk 'BEGIN { R=1};NR==1 && ]gl_dollar[1 == "texindex"{ print $NF; R=0; exit}; {exit}; END { exit R}'`
-if test $? -ne 0; then
-   texindex_ver=0.0]
-   AC_MSG_WARN([Can't find texindex version, check texindex is installed.])
-[fi
+[if $tex_available; then
+  if false | true; then nopipefail=true; set -o pipefail; else nopipefail=false; fi
+  if texindex_ver=`texindex --version 2> /dev/null | awk 'BEGIN { R=1};NR==1 && ]gl_dollar[1 == "texindex"{ print $NF; R=0; exit}; {exit}; END { if (R) { print "notfound"}}'`; then
+    if test "$texindex_ver" == "notfound"; then
+      texindex_ver=0.0
+      gl_fn_texindex_info () {]
+        AC_MSG_WARN([Can't find texindex version, check texindex is installed.])[
+      }
+    fi
+  else
+    tex_available=false
+    texindex_ver=0.0
+    gl_fn_texindex_info () {]
+      AC_MSG_NOTICE([texindex not installed or not working.])[
+    }
+  fi
+  if $nopipefail; then set +o pipefail; fi
+else
+  texindex_ver=0.0
+  gl_fn_texindex_info () {]
+    AC_MSG_NOTICE([Not testing texindex version for tex not installed or not working])[
+  }
+fi
 ]
 ])dnl
 AC_DEFUN([gl_TEXINFO_VERSION_COMPARE],[dnl
@@ -95,22 +132,40 @@ AC_REQUIRE([AS_VERSION_COMPARE])
 AS_VERSION_COMPARE([$1],[$2],[gl_TEXINFO_INDEXING_IS_LOCALE_DEPENDANT()],[$3],[$3])dnl
 ])dnl
 dnl gl_SET_DOCLANGS
+dnl DOCLANGS is restricted to default when tex/texindex are installed but their
+dnl version do not guarantee that index compilation won't break on an UTF-8 encoded
+dnl manual. Old version of texindex may derive the locale from the environment rather
+dnl than from the @documentencoding statement and break multibyte characters into
+dnl incorrect UTF-8 byte sequences.
+dnl The rationale is that default language is assumed not to use UTF-8 encoding
+dnl whereas translations may use it.
+dnl If ever you wish an UTF-8 encoded English manual to contain some symbol or
+dnl emoji, then create an English translation of a default manual without the symbols.
 AC_DEFUN([gl_SET_DOCLANGS],[dnl
 AC_REQUIRE([gl_TEXINFO_VERSION_COMPARE])
 AC_ARG_VAR([DOCLANGS],[languages for which manuals are compiled, languages supported: ]gl_DOCLANGS_FULL()[, list is space separated])
 AC_MSG_CHECKING([for DOCLANGS derivation from texinfo.tex/texindex versions])
 dnl By default nothing to inform about
-[gl_fn_doclangs_info () { :; }]
+[gl_fn_texinfo_info () { :; }
+gl_fn_texindex_info () { :; }
+gl_fn_doclangs_info () { :; }
+tex_available=true;]
 gl_GET_TEXINFO_TEX_VER()
 gl_GET_TEXINDEX_VER()
-gl_TEXINFO_VERSION_COMPARE([$texinfo_tex_ver],[gl_TEXINFO_TEX_MINVER()],[dnl
-  gl_TEXINFO_VERSION_COMPARE([$texindex_ver],[gl_TEXINDEX_MINVER()],[dnl
-  [DOCLANGS=']gl_DOCLANGS_FULL()['
-  gl_fn_doclangs_info () {]
-    AC_MSG_NOTICE([texinfo.tex/texindex versions suggest that indexing is not locale dependant])
-  [}]])
-])
+[if $tex_available; then]
+  gl_TEXINFO_VERSION_COMPARE([$texinfo_tex_ver],[gl_TEXINFO_TEX_MINVER()],[dnl
+    gl_TEXINFO_VERSION_COMPARE([$texindex_ver],[gl_TEXINDEX_MINVER()],[dnl
+    [DOCLANGS=']gl_DOCLANGS_FULL()['
+    gl_fn_doclangs_info () {]
+      AC_MSG_NOTICE([texinfo.tex/texindex versions suggest that indexing is not locale dependant])
+   [}]])
+])[
+else
+  DOCLANGS=']gl_DOCLANGS_FULL()['
+fi]
 AC_MSG_RESULT([[']$DOCLANGS[']])
+gl_fn_texinfo_info
+gl_fn_texindex_info
 gl_fn_doclangs_info
 AC_SUBST([DOCLANGS])
 ])