Subject: [PATCH] gnu: make-glibc-locales: Add patch to fix glibc-locales build for glibc 2.29.
From: Kei Kebreau <[email-masked]>
To: [email-masked]
Cc: Kei Kebreau <[email-masked]>, [email-masked]
Date: Thu, 4 Jul 2019 07:39:06 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

The patch for glibc 2.28 and earlier replaces the same content, but the context
in the patch is different enough to fail to merge.

* gnu/packages/base.scm (make-glibc-locales)[source]: Add patch.
* gnu/packages/patches/glibc-locales-2.29.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/base.scm                         | 10 +++++-
 gnu/packages/patches/glibc-locales-2.29.patch | 32 +++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/glibc-locales-2.29.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index bac1a92741..84c6190bd1 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -867,6 +867,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/glibc-hurd-magic-pid.patch		\
   %D%/packages/patches/glibc-ldd-x86_64.patch			\
   %D%/packages/patches/glibc-locales.patch			\
+  %D%/packages/patches/glibc-locales-2.29.patch			\
   %D%/packages/patches/glibc-o-largefile.patch			\
   %D%/packages/patches/glibc-reinstate-prlimit64-fallback.patch	\
   %D%/packages/patches/glibc-vectorized-strcspn-guards.patch	\
diff --git a/gnu/packages/base.scm b/gnu/packages/base.scm
index f26145cb0b..d6df023f26 100644
--- a/gnu/packages/base.scm
+++ b/gnu/packages/base.scm
@@ -999,7 +999,15 @@ with the Linux kernel.")
     (inherit glibc)
     (name "glibc-locales")
     (source (origin (inherit (package-source glibc))
-                    (patches (cons (search-patch "glibc-locales.patch")
+                    ;; The patch for glibc 2.28 and earlier replaces the same
+                    ;; content, but the context in the patch is different
+                    ;; enough to fail to merge.
+                    (patches (cons (search-patch
+                                    (if (< 2.29
+                                           (string->number
+                                            (package-version glibc)))
+                                        "glibc-locales.patch"
+                                        "glibc-locales-2.29.patch"))
                                    (origin-patches (package-source glibc))))))
     (synopsis "All the locales supported by the GNU C Library")
     (description
diff --git a/gnu/packages/patches/glibc-locales-2.29.patch b/gnu/packages/patches/glibc-locales-2.29.patch
new file mode 100644
index 0000000000..9329a09063
--- /dev/null
+++ b/gnu/packages/patches/glibc-locales-2.29.patch
@@ -0,0 +1,32 @@
+This patch allows us to use glibc's build system to build locales
+in a package separate from glibc.
+
+  1. Use 'localedef' from $PATH since we are not rebuilding it.
+  2. Use '--no-archive' to avoid building the big locale archive, and
+     because the already-built 'localedef' would want to write it
+     to '/run/current-system/locale', which is not possible.
+  3. Pass $(inst_complocaledir)/$$locale to install files in the right
+     place, and because otherwise, 'localedef' fails with:
+     "cannot write output files to `(null)'".
+
+diff -ru glibc-2.29-old/localedata/Makefile glibc-2.29-new/localedata/Makefile
+--- glibc-2.29-old/localedata/Makefile	2019-01-31 11:45:36.000000000 -0500
++++ glibc-2.29-new/localedata/Makefile	2019-07-03 22:48:35.662015071 -0400
+@@ -385,7 +385,7 @@
+ 
+ # Sometimes the whole collection of locale files should be installed.
+ LOCALEDEF=I18NPATH=. GCONV_PATH=$(common-objpfx)iconvdata LC_ALL=C \
+-$(rtld-prefix) $(common-objpfx)locale/localedef
++  localedef --no-archive
+ install-locales: install-locale-archive
+ 
+ # Create and install the locale-archive file.
+@@ -414,7 +414,7 @@
+ 	input=`echo $$locale | sed 's/\([^.]*\)[^@]*\(.*\)/\1\2/'`; \
+ 	$(LOCALEDEF) $$flags --alias-file=../intl/locale.alias \
+ 		     -i locales/$$input -f charmaps/$$charset \
+-		     $(addprefix --prefix=,$(install_root)) $$locale \
++		     $(addprefix --prefix=,$(install_root)) $(inst_complocaledir)/$$locale \
+ 	&& echo ' done';
+ endef
+ 
-- 
2.22.0