1 /* This function builds just the `lib/locale/locale-archive' file from
2 Glibc and nothing else. If `allLocales' is true, all supported
3 locales are included; otherwise, just the locales listed in
4 `locales'. See localedata/SUPPORTED in the Glibc source tree for
5 the list of all supported locales:
6 https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED
9 { lib, stdenv, buildPackages, callPackage, writeText, glibc
10 , allLocales ? true, locales ? [ "en_US.UTF-8/UTF-8" ]
13 callPackage ./common.nix { inherit stdenv; } {
14 pname = "glibc-locales";
16 builder = ./locales-builder.sh;
20 extraNativeBuildInputs = [ glibc ];
23 (if stdenv.hostPlatform.isLittleEndian
24 then "--little-endian"
29 # Awful hack: `localedef' doesn't allow the path to `locale-archive'
30 # to be overriden, but you *can* specify a prefix, i.e. it will use
31 # <prefix>/<path-to-glibc>/lib/locale/locale-archive. So we use
32 # $TMPDIR as a prefix, meaning that the locale-archive is placed in
33 # $TMPDIR/nix/store/...-glibc-.../lib/locale/locale-archive.
34 LOCALEDEF_FLAGS+=" --prefix=$TMPDIR"
36 mkdir -p $TMPDIR/"${buildPackages.glibc.out}/lib/locale"
38 echo 'C.UTF-8/UTF-8 \' >> ../glibc-2*/localedata/SUPPORTED
40 # Hack to allow building of the locales (needed since glibc-2.12)
41 sed -i -e 's,^$(rtld-prefix) $(common-objpfx)locale/localedef,localedef $(LOCALEDEF_FLAGS),' ../glibc-2*/localedata/Makefile
43 + lib.optionalString (!allLocales) ''
44 # Check that all locales to be built are supported
45 echo -n '${lib.concatMapStrings (s: s + " \\\n") locales}' \
46 | sort -u > locales-to-build.txt
47 cat ../glibc-2*/localedata/SUPPORTED | grep ' \\' \
48 | sort -u > locales-supported.txt
49 comm -13 locales-supported.txt locales-to-build.txt \
50 > locales-unsupported.txt
51 if [[ $(wc -c locales-unsupported.txt) != "0 locales-unsupported.txt" ]]; then
52 cat locales-supported.txt
53 echo "Error: unsupported locales detected:"
54 cat locales-unsupported.txt
55 echo "You should choose from the list above the error."
59 echo SUPPORTED-LOCALES='${toString locales}' > ../glibc-2*/localedata/SUPPORTED
61 make localedata/install-locales \
62 localedir=$out/lib/locale \
67 mkdir -p "$out/lib/locale" "$out/share/i18n"
68 cp -v "$TMPDIR/$NIX_STORE/"*"/lib/locale/locale-archive" "$out/lib/locale"
69 cp -v ../glibc-2*/localedata/SUPPORTED "$out/share/i18n/SUPPORTED"
72 setupHook = writeText "locales-setup-hook.sh"
74 export LOCALE_ARCHIVE=@out@/lib/locale/locale-archive
77 meta.description = "Locale information for the GNU C Library";