From b46aeeae17bb45753c36767f7d8ac7b95ae33dfa Mon Sep 17 00:00:00 2001
From: Carlos O'Donell <carlos@redhat.com>
Date: Thu, 26 Jul 2018 10:14:55 -0400
Subject: [PATCH] Add convenience target 'install-locale-files'.

The convenience install target 'install-locale-files' is created
to allow distributions to install all of the SUPPORTED locales as
files instead of into the locale-archive.

You invoke the new convenience target like this:
make localedata/install-locale-files install_root=<prefix>
---
 ChangeLog           | 12 ++++++++++++
 INSTALL             | 32 ++++++++++++++++++++++++++------
 NEWS                |  7 +++++++
 localedata/Makefile | 26 ++++++++++++++++++++------
 manual/install.texi | 31 ++++++++++++++++++++++++-------
 5 files changed, 89 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8b509d4a34..f52bf6a1a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2018-07-26  Carlos O'Donell <carlos@redhat.com>
+
+	* localedata/Makefile (INSTALL-SUPPORTED-LOCALES): Remove.
+	(INSTALL-SUPPORTED-LOCALE-ARCHIVE): Define.
+	(INSTALL-SUPPORTED-LOCALE-FILES): Define.
+	(install-locales): Depend on install-locale-archive.
+	(install-locale-archive): Define.
+	(install-lcoale-files): Define.
+	(build-one-locale): Define macro.
+	* manual/install.texi (Running make install): Document.
+	* manual/INSTALL: Regenerate.
+
 2018-07-25  Carlos O'Donell <carlos@redhat.com>
 
 	[BZ #23393]
diff --git a/INSTALL b/INSTALL
index 840b862511..1567d7f724 100644
--- a/INSTALL
+++ b/INSTALL
@@ -419,13 +419,33 @@ a pseudoterminal so it can be used by the calling process.  If you are
 using a Linux kernel with the 'devpts' filesystem enabled and mounted at
 '/dev/pts', you don't need this program.
 
-   After installation you might want to configure the timezone and
-locale installation of your system.  The GNU C Library comes with a
-locale database which gets configured with 'localedef'.  For example, to
-set up a German locale with name 'de_DE', simply issue the command
-'localedef -i de_DE -f ISO-8859-1 de_DE'.  To configure all locales that
+   After installation you should configure the timezone and install
+locales for your system.  The time zone configuration ensures that your
+system time matches the time for your current timezone.  The locales
+ensure that the display of information on your system matches the
+expectations of your language and geographic region.
+
+   The GNU C Library is able to use two kinds of localization
+information sources, the first is a locale database named
+'locale-archive' which is generally installed as
+'/usr/lib/locale/locale-archive'.  The locale archive has the benefit of
+taking up less space and being very fast to load, but only if you plan
+to install sixty or more locales.  If you plan to install one or two
+locales you can instead install individual locales into their self-named
+directories e.g.  '/usr/lib/locale/en_US.utf8'.  For example to install
+the German locale using the character set for UTF-8 with name 'de_DE'
+into the locale archive issue the command 'localedef -i de_DE -f UTF-8
+de_DE', and to install just the one locale issue the command 'localedef
+--no-archive -i de_DE -f UTF-8 de_DE'.  To configure all locales that
 are supported by the GNU C Library, you can issue from your build
-directory the command 'make localedata/install-locales'.
+directory the command 'make localedata/install-locales' to install all
+locales into the locale archive or 'make
+localedata/install-locale-files' to install all locales as files in the
+default configured locale installation directory (derived from
+'--prefix' or '--localedir').  To install into an alternative system
+root use 'DESTDIR' e.g.  'make localedata/install-locale-files
+DESTDIR=/opt/glibc', but note that this does not change the configured
+prefix.
 
    To configure the locally used timezone, set the 'TZ' environment
 variable.  The script 'tzselect' helps you to select the right value.
diff --git a/NEWS b/NEWS
index b08fee64a6..5032e1a82b 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,13 @@ Version 2.28
 
 Major new features:
 
+* A new convenience target has been added for distribution maintainers
+  to build and install all locales as directories with files.  The new
+  target is run by issuing the following command in your build tree:
+  'make localedata/install-locale-files', with an optional DESTDIR
+  to set the install root if you wish to install into a non-default
+  configured location.
+
 * The GNU C Library can now be compiled with support for Intel CET, AKA
   Intel Control-flow Enforcement Technology.  When the library is built
   with --enable-cet, the resulting glibc is protected with indirect
diff --git a/localedata/Makefile b/localedata/Makefile
index 13c5423e0e..0eea396ad8 100644
--- a/localedata/Makefile
+++ b/localedata/Makefile
@@ -380,12 +380,18 @@ endif
 
 include SUPPORTED
 
-INSTALL-SUPPORTED-LOCALES=$(addprefix install-, $(SUPPORTED-LOCALES))
+INSTALL-SUPPORTED-LOCALE-ARCHIVE=$(addprefix install-archive-, $(SUPPORTED-LOCALES))
+INSTALL-SUPPORTED-LOCALE-FILES=$(addprefix install-files-, $(SUPPORTED-LOCALES))
 
 # 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
-install-locales: $(INSTALL-SUPPORTED-LOCALES)
+install-locales: install-locale-archive
+
+# Create and install the locale-archive file.
+install-locale-archive: $(INSTALL-SUPPORTED-LOCALE-ARCHIVE)
+# Create and install the locales individually (no archive).
+install-locale-files: $(INSTALL-SUPPORTED-LOCALE-FILES)
 
 install-locales-dir:
 	$(..)./scripts/mkinstalldirs $(inst_complocaledir)
@@ -393,11 +399,10 @@ install-locales-dir:
 # The SHIFT_JIS and SHIFT_JISX0213 character maps are not ASCII compatible,
 # therefore we have to use --no-warnings=ascii to disable the ASCII check.
 # See localedata/gen-locale.sh for the same logic.
-$(INSTALL-SUPPORTED-LOCALES): install-locales-dir
-	@locale=`echo $@ | sed -e 's/^install-//'`; \
+define build-one-locale
+	locale=`echo $@ | sed -e 's/^install-[a-z]*-//'`; \
 	charset=`echo $$locale | sed -e 's,.*/,,'`; \
 	locale=`echo $$locale | sed -e 's,/[^/]*,,'`; \
-	flags="-c"; \
 	if [ "$$charset" = 'SHIFT_JIS' ] \
 	   || [ "$$charset" = 'SHIFT_JISX0213' ]; then \
 	   flags="$$flags --no-warnings=ascii"; \
@@ -410,7 +415,16 @@ $(INSTALL-SUPPORTED-LOCALES): install-locales-dir
 	$(LOCALEDEF) $$flags --alias-file=../intl/locale.alias \
 		     -i locales/$$input -f charmaps/$$charset \
 		     $(addprefix --prefix=,$(install_root)) $$locale \
-	&& echo ' done'; \
+	&& echo ' done';
+endef
+
+$(INSTALL-SUPPORTED-LOCALE-ARCHIVE): install-locales-dir
+	@flags="-c"; \
+	$(build-one-locale)
+
+$(INSTALL-SUPPORTED-LOCALE-FILES): install-locales-dir
+	@flags="-c --no-archive"; \
+	$(build-one-locale)
 
 tst-setlocale-ENV = LC_ALL=ja_JP.EUC-JP
 tst-wctype-ENV = LC_ALL=ja_JP.EUC-JP
diff --git a/manual/install.texi b/manual/install.texi
index a8577dd610..d6301dd382 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -462,13 +462,30 @@ permissions on a pseudoterminal so it can be used by the calling process.
 If you are using a Linux kernel with the @code{devpts} filesystem enabled
 and mounted at @file{/dev/pts}, you don't need this program.
 
-After installation you might want to configure the timezone and locale
-installation of your system.  @Theglibc{} comes with a locale
-database which gets configured with @code{localedef}.  For example, to
-set up a German locale with name @code{de_DE}, simply issue the command
-@samp{localedef -i de_DE -f ISO-8859-1 de_DE}.  To configure all locales
-that are supported by @theglibc{}, you can issue from your build directory the
-command @samp{make localedata/install-locales}.
+After installation you should configure the timezone and install locales
+for your system.  The time zone configuration ensures that your system
+time matches the time for your current timezone.  The locales ensure that
+the display of information on your system matches the expectations of
+your language and geographic region.
+
+@Theglibc{} is able to use two kinds of localization information sources, the
+first is a locale database named @file{locale-archive} which is generally
+installed as @file{/usr/lib/locale/locale-archive}.  The locale archive has the
+benefit of taking up less space and being very fast to load, but only if you
+plan to install sixty or more locales.  If you plan to install one or two
+locales you can instead install individual locales into their self-named
+directories e.g.  @file{/usr/lib/locale/en_US.utf8}.  For example to install
+the German locale using the character set for UTF-8 with name @code{de_DE} into
+the locale archive issue the command @samp{localedef -i de_DE -f UTF-8 de_DE},
+and to install just the one locale issue the command @samp{localedef
+--no-archive -i de_DE -f UTF-8 de_DE}.  To configure all locales that are
+supported by @theglibc{}, you can issue from your build directory the command
+@samp{make localedata/install-locales} to install all locales into the locale
+archive or @samp{make localedata/install-locale-files} to install all locales
+as files in the default configured locale installation directory (derived from
+@samp{--prefix} or @code{--localedir}).  To install into an alternative system
+root use @samp{DESTDIR} e.g. @samp{make localedata/install-locale-files
+DESTDIR=/opt/glibc}, but note that this does not change the configured prefix.
 
 To configure the locally used timezone, set the @code{TZ} environment
 variable.  The script @code{tzselect} helps you to select the right value.
-- 
2.14.4

