diff mbox

[v2,2/2] DocBook: Use a fixed encoding for output

Message ID 1443398992.2517.13.camel@decadent.org.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Ben Hutchings Sept. 28, 2015, 12:09 a.m. UTC
Currently the encoding of documents generated by DocBook depends on
the current locale.  Make the output reproducible independently of
the locale, by setting the encoding to UTF-8 (LC_CTYPE=C.UTF-8) by
preference, or ASCII (LC_CTYPE=C) as a fallback.

LC_CTYPE can normally be overridden by LC_ALL, but the top-level
Makefile unsets that.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
v2: Rebase on 4.3-rc3.
    Add an explanatory comment to check-lc_type.c.

 Documentation/DocBook/Makefile |  6 ++++++
 Makefile                       |  2 +-
 scripts/Makefile               |  7 +++++--
 scripts/check-lc_ctype.c       | 11 +++++++++++
 4 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 scripts/check-lc_ctype.c

Comments

Jonathan Corbet Sept. 28, 2015, 7:33 a.m. UTC | #1
On Mon, 28 Sep 2015 01:09:52 +0100
Ben Hutchings <ben@decadent.org.uk> wrote:

> Currently the encoding of documents generated by DocBook depends on
> the current locale.  Make the output reproducible independently of
> the locale, by setting the encoding to UTF-8 (LC_CTYPE=C.UTF-8) by
> preference, or ASCII (LC_CTYPE=C) as a fallback.
> 
> LC_CTYPE can normally be overridden by LC_ALL, but the top-level
> Makefile unsets that.

Applied to the docs tree (part 1 went in a few weeks ago).  Added
check-lc_ctype to scripts/.gitignore while I was at it.

Thanks,

jon
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 93eff64..d254496 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -69,6 +69,12 @@  installmandocs: mandocs
 KERNELDOCXMLREF = $(srctree)/scripts/kernel-doc-xml-ref
 KERNELDOC       = $(srctree)/scripts/kernel-doc
 DOCPROC         = $(objtree)/scripts/docproc
+CHECK_LC_CTYPE = $(objtree)/scripts/check-lc_ctype
+
+# Use a fixed encoding - UTF-8 if the C library has support built-in
+# or ASCII if not
+LC_CTYPE := $(call try-run, LC_CTYPE=C.UTF-8 $(CHECK_LC_CTYPE),C.UTF-8,C)
+export LC_CTYPE
 
 XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
 XMLTOFLAGS += --skip-validation
diff --git a/Makefile b/Makefile
index 84f4b31..d23d2e9 100644
--- a/Makefile
+++ b/Makefile
@@ -1336,7 +1336,7 @@  $(help-board-dirs): help-%:
 # Documentation targets
 # ---------------------------------------------------------------------------
 %docs: scripts_basic FORCE
-	$(Q)$(MAKE) $(build)=scripts build_docproc
+	$(Q)$(MAKE) $(build)=scripts build_docproc build_check-lc_ctype
 	$(Q)$(MAKE) $(build)=Documentation/DocBook $@
 
 else # KBUILD_EXTMOD
diff --git a/scripts/Makefile b/scripts/Makefile
index 1b26617..fd0d53d 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -7,6 +7,7 @@ 
 # conmakehash:   Create chartable
 # conmakehash:	 Create arrays for initializing the kernel console tables
 # docproc:       Used in Documentation/DocBook
+# check-lc_ctype: Used in Documentation/DocBook
 
 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 
@@ -27,14 +28,16 @@  HOSTLOADLIBES_extract-cert = -lcrypto
 always		:= $(hostprogs-y) $(hostprogs-m)
 
 # The following hostprogs-y programs are only build on demand
-hostprogs-y += unifdef docproc
+hostprogs-y += unifdef docproc check-lc_ctype
 
 # These targets are used internally to avoid "is up to date" messages
-PHONY += build_unifdef build_docproc
+PHONY += build_unifdef build_docproc build_check-lc_ctype
 build_unifdef: $(obj)/unifdef
 	@:
 build_docproc: $(obj)/docproc
 	@:
+build_check-lc_ctype: $(obj)/check-lc_ctype
+	@:
 
 subdir-$(CONFIG_MODVERSIONS) += genksyms
 subdir-y                     += mod
diff --git a/scripts/check-lc_ctype.c b/scripts/check-lc_ctype.c
new file mode 100644
index 0000000..9097ff5
--- /dev/null
+++ b/scripts/check-lc_ctype.c
@@ -0,0 +1,11 @@ 
+/*
+ * Check that a specified locale works as LC_CTYPE.  Used by the
+ * DocBook build system to probe for C.UTF-8 support.
+ */
+
+#include <locale.h>
+
+int main(void)
+{
+	return !setlocale(LC_CTYPE, "");
+}