2014-11-26 21:49:11 +00:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2024-04-08 13:28:20 +00:00
|
|
|
|
;;; Copyright © 2014-2017, 2019-2021, 2023-2024 Ludovic Courtès <ludo@gnu.org>
|
2018-01-20 06:57:07 +00:00
|
|
|
|
;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
|
2023-06-24 13:17:42 +00:00
|
|
|
|
;;; Copyright © 2023 Janneke Nieuwenhuizen <jannek@gnu.org>
|
2014-11-26 21:49:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (gnu system locale)
|
|
|
|
|
#:use-module (guix gexp)
|
2015-10-30 22:05:52 +00:00
|
|
|
|
#:use-module (guix store)
|
2019-05-13 21:28:32 +00:00
|
|
|
|
#:use-module (guix modules)
|
2014-11-26 21:49:11 +00:00
|
|
|
|
#:use-module (guix records)
|
2015-09-30 15:06:40 +00:00
|
|
|
|
#:use-module (guix packages)
|
2018-01-20 06:57:07 +00:00
|
|
|
|
#:use-module (guix utils)
|
2014-11-26 21:49:11 +00:00
|
|
|
|
#:use-module (gnu packages base)
|
|
|
|
|
#:use-module (gnu packages compression)
|
|
|
|
|
#:use-module (srfi srfi-26)
|
2015-10-30 22:05:52 +00:00
|
|
|
|
#:use-module (ice-9 match)
|
2014-11-26 21:49:11 +00:00
|
|
|
|
#:export (locale-definition
|
|
|
|
|
locale-definition?
|
|
|
|
|
locale-definition-name
|
|
|
|
|
locale-definition-source
|
|
|
|
|
locale-definition-charset
|
|
|
|
|
|
2016-02-10 10:01:54 +00:00
|
|
|
|
locale-name->definition
|
2014-11-26 21:49:11 +00:00
|
|
|
|
locale-directory
|
|
|
|
|
|
2015-10-30 22:05:52 +00:00
|
|
|
|
%default-locale-libcs
|
2019-05-13 21:28:32 +00:00
|
|
|
|
%default-locale-definitions
|
|
|
|
|
|
|
|
|
|
glibc-supported-locales))
|
2014-11-26 21:49:11 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;;
|
|
|
|
|
;;; Locale definitions, and compilation thereof.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(define-record-type* <locale-definition> locale-definition
|
|
|
|
|
make-locale-definition
|
|
|
|
|
locale-definition?
|
|
|
|
|
(name locale-definition-name) ;string--e.g., "fr_FR.utf8"
|
|
|
|
|
(source locale-definition-source) ;string--e.g., "fr_FR"
|
|
|
|
|
(charset locale-definition-charset ;string--e.g., "UTF-8"
|
|
|
|
|
(default "UTF-8")))
|
|
|
|
|
|
2016-02-10 10:01:54 +00:00
|
|
|
|
(define %not-dot
|
|
|
|
|
(char-set-complement (char-set #\.)))
|
|
|
|
|
|
|
|
|
|
(define (denormalize-codeset codeset)
|
|
|
|
|
"Attempt to guess the \"real\" name of CODESET, a normalized codeset as
|
|
|
|
|
defined in (info \"(libc) Using gettextized software\")."
|
|
|
|
|
(cond ((string=? codeset "utf8")
|
|
|
|
|
"UTF-8")
|
|
|
|
|
((string-prefix? "iso8859" codeset)
|
|
|
|
|
(string-append "ISO-8859-" (string-drop codeset 7)))
|
|
|
|
|
((string=? codeset "eucjp")
|
|
|
|
|
"EUC-JP")
|
|
|
|
|
(else ;cross fingers, hope for the best
|
|
|
|
|
codeset)))
|
|
|
|
|
|
|
|
|
|
(define (locale-name->definition name)
|
|
|
|
|
"Return a <locale-definition> corresponding to NAME, guessing the charset,
|
|
|
|
|
or #f on failure."
|
|
|
|
|
(match (string-tokenize name %not-dot)
|
|
|
|
|
((source charset)
|
|
|
|
|
;; XXX: NAME is supposed to use the "normalized codeset", such as "utf8",
|
|
|
|
|
;; whereas the actual name used is different. Add a special case to make
|
|
|
|
|
;; the right guess for UTF-8.
|
|
|
|
|
(locale-definition (name name)
|
|
|
|
|
(source source)
|
|
|
|
|
(charset (denormalize-codeset charset))))
|
|
|
|
|
(_
|
|
|
|
|
#f)))
|
|
|
|
|
|
2015-10-30 22:05:52 +00:00
|
|
|
|
(define* (single-locale-directory locales
|
2019-12-31 08:56:51 +00:00
|
|
|
|
#:key (libc glibc))
|
2015-09-30 15:06:40 +00:00
|
|
|
|
"Return a directory containing all of LOCALES for LIBC compiled.
|
|
|
|
|
|
|
|
|
|
Because locale data formats are incompatible when switching from one libc to
|
|
|
|
|
another, locale data is put in a sub-directory named after the 'version' field
|
|
|
|
|
of LIBC."
|
2015-10-30 22:05:52 +00:00
|
|
|
|
(define version
|
2018-01-20 06:57:07 +00:00
|
|
|
|
(version-major+minor (package-version libc)))
|
2015-10-30 22:05:52 +00:00
|
|
|
|
|
2014-11-26 21:49:11 +00:00
|
|
|
|
(define build
|
2019-06-06 11:36:51 +00:00
|
|
|
|
(with-imported-modules (source-module-closure
|
|
|
|
|
'((gnu build locale)))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (gnu build locale))
|
|
|
|
|
|
|
|
|
|
(mkdir #$output)
|
|
|
|
|
(mkdir (string-append #$output "/" #$version))
|
|
|
|
|
|
|
|
|
|
;; 'localedef' executes 'gzip' to access compressed locale sources.
|
|
|
|
|
(setenv "PATH"
|
2020-05-14 21:20:14 +00:00
|
|
|
|
(string-append #+gzip "/bin:" #+libc "/bin"))
|
2019-06-06 11:36:51 +00:00
|
|
|
|
|
|
|
|
|
(setvbuf (current-output-port) 'line)
|
|
|
|
|
(setvbuf (current-error-port) 'line)
|
|
|
|
|
(for-each (lambda (locale codeset name)
|
|
|
|
|
(build-locale locale
|
|
|
|
|
#:codeset codeset
|
|
|
|
|
#:name name
|
|
|
|
|
#:directory
|
|
|
|
|
(string-append #$output "/" #$version)))
|
|
|
|
|
'#$(map locale-definition-source locales)
|
|
|
|
|
'#$(map locale-definition-charset locales)
|
|
|
|
|
'#$(map locale-definition-name locales)))))
|
2014-11-26 21:49:11 +00:00
|
|
|
|
|
2017-07-17 21:38:23 +00:00
|
|
|
|
(computed-file (string-append "locale-" version) build))
|
2014-11-26 21:49:11 +00:00
|
|
|
|
|
2015-10-30 22:05:52 +00:00
|
|
|
|
(define* (locale-directory locales
|
|
|
|
|
#:key (libcs %default-locale-libcs))
|
|
|
|
|
"Return a locale directory containing all of LOCALES for each libc package
|
|
|
|
|
listed in LIBCS.
|
|
|
|
|
|
|
|
|
|
It is useful to list more than one libc when willing to support
|
|
|
|
|
already-installed packages built against a different libc since the locale
|
|
|
|
|
data format changes between libc versions."
|
|
|
|
|
(match libcs
|
|
|
|
|
((libc)
|
|
|
|
|
(single-locale-directory locales #:libc libc))
|
|
|
|
|
((libcs ..1)
|
2017-07-17 21:38:23 +00:00
|
|
|
|
(let ((dirs (map (lambda (libc)
|
|
|
|
|
(single-locale-directory locales #:libc libc))
|
|
|
|
|
libcs)))
|
|
|
|
|
(computed-file "locale-multiple-versions"
|
|
|
|
|
(with-imported-modules '((guix build union))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build union))
|
|
|
|
|
(union-build #$output (list #$@dirs))))
|
|
|
|
|
#:options '(#:local-build? #t
|
|
|
|
|
#:substitutable? #f))))))
|
2015-10-30 22:05:52 +00:00
|
|
|
|
|
|
|
|
|
(define %default-locale-libcs
|
|
|
|
|
;; The libcs for which we build locales by default.
|
2023-06-24 13:17:42 +00:00
|
|
|
|
(if (system-hurd?)
|
|
|
|
|
(list glibc/hurd)
|
2024-04-08 12:51:04 +00:00
|
|
|
|
(list glibc)))
|
2015-10-30 22:05:52 +00:00
|
|
|
|
|
2014-11-26 21:49:11 +00:00
|
|
|
|
(define %default-locale-definitions
|
2024-04-08 13:28:20 +00:00
|
|
|
|
;; Arbitrary set of locales that are built by default. They come as a
|
|
|
|
|
;; "bonus" in addition to that specified in the 'locale' field of the
|
|
|
|
|
;; operating system, for the user's convenience, so they shouldn't take too
|
|
|
|
|
;; much space.
|
2014-11-26 21:49:11 +00:00
|
|
|
|
(letrec-syntax ((utf8-locale (syntax-rules ()
|
|
|
|
|
((_ name*)
|
|
|
|
|
(locale-definition
|
2015-08-29 21:37:33 +00:00
|
|
|
|
;; Note: We choose "utf8", which is the
|
|
|
|
|
;; "normalized codeset".
|
2014-11-26 21:49:11 +00:00
|
|
|
|
(name (string-append name* ".utf8"))
|
|
|
|
|
(source name*)
|
|
|
|
|
(charset "UTF-8")))))
|
|
|
|
|
(utf8-locales (syntax-rules ()
|
|
|
|
|
((_ name ...)
|
|
|
|
|
(list (utf8-locale name) ...)))))
|
2024-04-08 13:28:20 +00:00
|
|
|
|
;; The six UN official languages plus Portuguese, with at most two
|
|
|
|
|
;; variants per language.
|
|
|
|
|
(utf8-locales "ar_DZ"
|
|
|
|
|
"en_GB"
|
|
|
|
|
"en_US"
|
|
|
|
|
"es_AR"
|
|
|
|
|
"es_ES"
|
|
|
|
|
"fr_FR"
|
|
|
|
|
"pt_BR"
|
|
|
|
|
"pt_PT"
|
|
|
|
|
"ru_RU"
|
|
|
|
|
"zh_CN")))
|
2014-11-26 21:49:11 +00:00
|
|
|
|
|
2019-05-13 21:28:32 +00:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Locales supported by glibc.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define* (glibc-supported-locales #:optional (glibc glibc))
|
|
|
|
|
"Return a file-like object that contains a list of locale name/encoding
|
|
|
|
|
pairs such as (\"oc_FR.UTF-8\" . \"UTF-8\"). Each pair corresponds to a
|
|
|
|
|
locale supported by GLIBC."
|
|
|
|
|
(define build
|
|
|
|
|
(with-imported-modules (source-module-closure
|
2019-06-06 11:36:51 +00:00
|
|
|
|
'((guix build gnu-build-system)
|
|
|
|
|
(gnu build locale)))
|
2019-05-13 21:28:32 +00:00
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build gnu-build-system)
|
2019-06-06 11:36:51 +00:00
|
|
|
|
(gnu build locale)
|
2019-05-13 21:28:32 +00:00
|
|
|
|
(ice-9 pretty-print))
|
|
|
|
|
|
|
|
|
|
(define unpack
|
|
|
|
|
(assq-ref %standard-phases 'unpack))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(setenv "PATH"
|
|
|
|
|
(string-append #+(file-append tar "/bin") ":"
|
|
|
|
|
#+(file-append xz "/bin") ":"
|
|
|
|
|
#+(file-append gzip "/bin")))
|
|
|
|
|
(unpack #:source #+(package-source glibc))
|
|
|
|
|
|
|
|
|
|
(let ((locales (call-with-input-file "localedata/SUPPORTED"
|
|
|
|
|
read-supported-locales)))
|
|
|
|
|
(call-with-output-file #$output
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(pretty-print locales port)))))))
|
|
|
|
|
|
|
|
|
|
(computed-file "glibc-supported-locales.scm" build))
|
|
|
|
|
|
2014-11-26 21:49:11 +00:00
|
|
|
|
;;; locale.scm ends here
|