Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # This class knows how to package up [e]glibc. Its shared since prebuild binary toolchains |
| 3 | # may need packaging and its pointless to duplicate this code. |
| 4 | # |
| 5 | # Caller should set GLIBC_INTERNAL_USE_BINARY_LOCALE to one of: |
| 6 | # "compile" - Use QEMU to generate the binary locale files |
| 7 | # "precompiled" - The binary locale files are pregenerated and already present |
| 8 | # "ondevice" - The device will build the locale files upon first boot through the postinst |
| 9 | |
| 10 | GLIBC_INTERNAL_USE_BINARY_LOCALE ?= "ondevice" |
| 11 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | GLIBC_SPLIT_LC_PACKAGES ?= "0" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | python __anonymous () { |
| 15 | enabled = d.getVar("ENABLE_BINARY_LOCALE_GENERATION") |
| 16 | |
| 17 | pn = d.getVar("PN") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | if pn.endswith("-initial"): |
| 19 | enabled = False |
| 20 | |
| 21 | if enabled and int(enabled): |
| 22 | import re |
| 23 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | target_arch = d.getVar("TARGET_ARCH") |
| 25 | binary_arches = d.getVar("BINARY_LOCALE_ARCHES") or "" |
| 26 | use_cross_localedef = d.getVar("LOCALE_GENERATION_WITH_CROSS-LOCALEDEF") or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | |
| 28 | for regexp in binary_arches.split(" "): |
| 29 | r = re.compile(regexp) |
| 30 | |
| 31 | if r.match(target_arch): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 32 | depends = d.getVar("DEPENDS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | if use_cross_localedef == "1" : |
| 34 | depends = "%s cross-localedef-native" % depends |
| 35 | else: |
| 36 | depends = "%s qemu-native" % depends |
| 37 | d.setVar("DEPENDS", depends) |
| 38 | d.setVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", "compile") |
| 39 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | } |
| 41 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 42 | # try to fix disable charsets/locales/locale-code compile fail |
| 43 | PACKAGE_NO_GCONV ?= "0" |
| 44 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | OVERRIDES_append = ":${TARGET_ARCH}-${TARGET_OS}" |
| 46 | |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 47 | locale_base_postinst_ontarget() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 48 | localedef --inputfile=${datadir}/i18n/locales/%s --charmap=%s %s |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 49 | } |
| 50 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | locale_base_postrm() { |
| 52 | #!/bin/sh |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 53 | localedef --delete-from-archive --inputfile=${datadir}/locales/%s --charmap=%s %s |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | LOCALETREESRC ?= "${PKGD}" |
| 57 | |
| 58 | do_prep_locale_tree() { |
| 59 | treedir=${WORKDIR}/locale-tree |
| 60 | rm -rf $treedir |
| 61 | mkdir -p $treedir/${base_bindir} $treedir/${base_libdir} $treedir/${datadir} $treedir/${localedir} |
| 62 | tar -cf - -C ${LOCALETREESRC}${datadir} -p i18n | tar -xf - -C $treedir/${datadir} |
| 63 | # unzip to avoid parsing errors |
| 64 | for i in $treedir/${datadir}/i18n/charmaps/*gz; do |
| 65 | gunzip $i |
| 66 | done |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 67 | # The extract pattern "./l*.so*" is carefully selected so that it will |
| 68 | # match ld*.so and lib*.so*, but not any files in the gconv directory |
| 69 | # (if it exists). This makes sure we only unpack the files we need. |
| 70 | # This is important in case usrmerge is set in DISTRO_FEATURES, which |
| 71 | # means ${base_libdir} == ${libdir}. |
| 72 | tar -cf - -C ${LOCALETREESRC}${base_libdir} -p . | tar -xf - -C $treedir/${base_libdir} --wildcards './l*.so*' |
| 73 | if [ -f ${STAGING_LIBDIR_NATIVE}/libgcc_s.* ]; then |
| 74 | tar -cf - -C ${STAGING_LIBDIR_NATIVE} -p libgcc_s.* | tar -xf - -C $treedir/${base_libdir} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | fi |
| 76 | install -m 0755 ${LOCALETREESRC}${bindir}/localedef $treedir/${base_bindir} |
| 77 | } |
| 78 | |
| 79 | do_collect_bins_from_locale_tree() { |
| 80 | treedir=${WORKDIR}/locale-tree |
| 81 | |
| 82 | parent=$(dirname ${localedir}) |
| 83 | mkdir -p ${PKGD}/$parent |
| 84 | tar -cf - -C $treedir/$parent -p $(basename ${localedir}) | tar -xf - -C ${PKGD}$parent |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 85 | |
| 86 | # Finalize tree by chaning all duplicate files into hard links |
| 87 | cross-localedef-hardlink -c -v ${WORKDIR}/locale-tree |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | inherit qemu |
| 91 | |
| 92 | python package_do_split_gconvs () { |
| 93 | import re |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 94 | if (d.getVar('PACKAGE_NO_GCONV') == '1'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | bb.note("package requested not splitting gconvs") |
| 96 | return |
| 97 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 98 | if not d.getVar('PACKAGES'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 99 | return |
| 100 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 101 | mlprefix = d.getVar("MLPREFIX") or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 103 | bpn = d.getVar('BPN') |
| 104 | libdir = d.getVar('libdir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | if not libdir: |
| 106 | bb.error("libdir not defined") |
| 107 | return |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 108 | datadir = d.getVar('datadir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | if not datadir: |
| 110 | bb.error("datadir not defined") |
| 111 | return |
| 112 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 113 | gconv_libdir = oe.path.join(libdir, "gconv") |
| 114 | charmap_dir = oe.path.join(datadir, "i18n", "charmaps") |
| 115 | locales_dir = oe.path.join(datadir, "i18n", "locales") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 116 | binary_locales_dir = d.getVar('localedir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | |
| 118 | def calc_gconv_deps(fn, pkg, file_regex, output_pattern, group): |
| 119 | deps = [] |
| 120 | f = open(fn, "rb") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 121 | c_re = re.compile(r'^copy "(.*)"') |
| 122 | i_re = re.compile(r'^include "(\w+)".*') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 123 | for l in f.readlines(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 124 | l = l.decode("latin-1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 125 | m = c_re.match(l) or i_re.match(l) |
| 126 | if m: |
| 127 | dp = legitimize_package_name('%s%s-gconv-%s' % (mlprefix, bpn, m.group(1))) |
| 128 | if not dp in deps: |
| 129 | deps.append(dp) |
| 130 | f.close() |
| 131 | if deps != []: |
| 132 | d.setVar('RDEPENDS_%s' % pkg, " ".join(deps)) |
| 133 | if bpn != 'glibc': |
| 134 | d.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc')) |
| 135 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 136 | do_split_packages(d, gconv_libdir, file_regex=r'^(.*)\.so$', output_pattern=bpn+'-gconv-%s', \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | description='gconv module for character set %s', hook=calc_gconv_deps, \ |
| 138 | extra_depends=bpn+'-gconv') |
| 139 | |
| 140 | def calc_charmap_deps(fn, pkg, file_regex, output_pattern, group): |
| 141 | deps = [] |
| 142 | f = open(fn, "rb") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 143 | c_re = re.compile(r'^copy "(.*)"') |
| 144 | i_re = re.compile(r'^include "(\w+)".*') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 | for l in f.readlines(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 146 | l = l.decode("latin-1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 147 | m = c_re.match(l) or i_re.match(l) |
| 148 | if m: |
| 149 | dp = legitimize_package_name('%s%s-charmap-%s' % (mlprefix, bpn, m.group(1))) |
| 150 | if not dp in deps: |
| 151 | deps.append(dp) |
| 152 | f.close() |
| 153 | if deps != []: |
| 154 | d.setVar('RDEPENDS_%s' % pkg, " ".join(deps)) |
| 155 | if bpn != 'glibc': |
| 156 | d.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc')) |
| 157 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 158 | do_split_packages(d, charmap_dir, file_regex=r'^(.*)\.gz$', output_pattern=bpn+'-charmap-%s', \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 159 | description='character map for %s encoding', hook=calc_charmap_deps, extra_depends='') |
| 160 | |
| 161 | def calc_locale_deps(fn, pkg, file_regex, output_pattern, group): |
| 162 | deps = [] |
| 163 | f = open(fn, "rb") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 164 | c_re = re.compile(r'^copy "(.*)"') |
| 165 | i_re = re.compile(r'^include "(\w+)".*') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 166 | for l in f.readlines(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 167 | l = l.decode("latin-1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | m = c_re.match(l) or i_re.match(l) |
| 169 | if m: |
| 170 | dp = legitimize_package_name(mlprefix+bpn+'-localedata-%s' % m.group(1)) |
| 171 | if not dp in deps: |
| 172 | deps.append(dp) |
| 173 | f.close() |
| 174 | if deps != []: |
| 175 | d.setVar('RDEPENDS_%s' % pkg, " ".join(deps)) |
| 176 | if bpn != 'glibc': |
| 177 | d.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc')) |
| 178 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 179 | do_split_packages(d, locales_dir, file_regex=r'(.*)', output_pattern=bpn+'-localedata-%s', \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 180 | description='locale definition for %s', hook=calc_locale_deps, extra_depends='') |
| 181 | d.setVar('PACKAGES', d.getVar('PACKAGES', False) + ' ' + d.getVar('MLPREFIX', False) + bpn + '-gconv') |
| 182 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 183 | use_bin = d.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 184 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 185 | dot_re = re.compile(r"(.*)\.(.*)") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | |
| 187 | # Read in supported locales and associated encodings |
| 188 | supported = {} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 189 | with open(oe.path.join(d.getVar('WORKDIR'), "SUPPORTED")) as f: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 190 | for line in f.readlines(): |
| 191 | try: |
| 192 | locale, charset = line.rstrip().split() |
| 193 | except ValueError: |
| 194 | continue |
| 195 | supported[locale] = charset |
| 196 | |
| 197 | # GLIBC_GENERATE_LOCALES var specifies which locales to be generated. empty or "all" means all locales |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 198 | to_generate = d.getVar('GLIBC_GENERATE_LOCALES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | if not to_generate or to_generate == 'all': |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 200 | to_generate = sorted(supported.keys()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 201 | else: |
| 202 | to_generate = to_generate.split() |
| 203 | for locale in to_generate: |
| 204 | if locale not in supported: |
| 205 | if '.' in locale: |
| 206 | charset = locale.split('.')[1] |
| 207 | else: |
| 208 | charset = 'UTF-8' |
| 209 | bb.warn("Unsupported locale '%s', assuming encoding '%s'" % (locale, charset)) |
| 210 | supported[locale] = charset |
| 211 | |
| 212 | def output_locale_source(name, pkgname, locale, encoding): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 213 | d.setVar('RDEPENDS_%s' % pkgname, '%slocaledef %s-localedata-%s %s-charmap-%s' % \ |
| 214 | (mlprefix, mlprefix+bpn, legitimize_package_name(locale), mlprefix+bpn, legitimize_package_name(encoding))) |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 215 | d.setVar('pkg_postinst_ontarget_%s' % pkgname, d.getVar('locale_base_postinst_ontarget') \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 216 | % (locale, encoding, locale)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 217 | d.setVar('pkg_postrm_%s' % pkgname, d.getVar('locale_base_postrm') % \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 | (locale, encoding, locale)) |
| 219 | |
| 220 | def output_locale_binary_rdepends(name, pkgname, locale, encoding): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 221 | dep = legitimize_package_name('%s-binary-localedata-%s' % (bpn, name)) |
| 222 | lcsplit = d.getVar('GLIBC_SPLIT_LC_PACKAGES') |
| 223 | if lcsplit and int(lcsplit): |
| 224 | d.appendVar('PACKAGES', ' ' + dep) |
| 225 | d.setVar('ALLOW_EMPTY_%s' % dep, '1') |
| 226 | d.setVar('RDEPENDS_%s' % pkgname, mlprefix + dep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 227 | |
| 228 | commands = {} |
| 229 | |
| 230 | def output_locale_binary(name, pkgname, locale, encoding): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 231 | treedir = oe.path.join(d.getVar("WORKDIR"), "locale-tree") |
| 232 | ldlibdir = oe.path.join(treedir, d.getVar("base_libdir")) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 233 | path = d.getVar("PATH") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 234 | i18npath = oe.path.join(treedir, datadir, "i18n") |
| 235 | gconvpath = oe.path.join(treedir, "iconvdata") |
| 236 | outputpath = oe.path.join(treedir, binary_locales_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 237 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 238 | use_cross_localedef = d.getVar("LOCALE_GENERATION_WITH_CROSS-LOCALEDEF") or "0" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | if use_cross_localedef == "1": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 240 | target_arch = d.getVar('TARGET_ARCH') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | locale_arch_options = { \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 242 | "arc": " --uint32-align=4 --little-endian ", \ |
| 243 | "arceb": " --uint32-align=4 --big-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 244 | "arm": " --uint32-align=4 --little-endian ", \ |
| 245 | "armeb": " --uint32-align=4 --big-endian ", \ |
| 246 | "aarch64": " --uint32-align=4 --little-endian ", \ |
| 247 | "aarch64_be": " --uint32-align=4 --big-endian ", \ |
| 248 | "sh4": " --uint32-align=4 --big-endian ", \ |
| 249 | "powerpc": " --uint32-align=4 --big-endian ", \ |
| 250 | "powerpc64": " --uint32-align=4 --big-endian ", \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame^] | 251 | "powerpc64le": " --uint32-align=4 --little-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | "mips": " --uint32-align=4 --big-endian ", \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 253 | "mipsisa32r6": " --uint32-align=4 --big-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 254 | "mips64": " --uint32-align=4 --big-endian ", \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 255 | "mipsisa64r6": " --uint32-align=4 --big-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 256 | "mipsel": " --uint32-align=4 --little-endian ", \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 257 | "mipsisa32r6el": " --uint32-align=4 --little-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 258 | "mips64el":" --uint32-align=4 --little-endian ", \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 259 | "mipsisa64r6el":" --uint32-align=4 --little-endian ", \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 260 | "riscv64": " --uint32-align=4 --little-endian ", \ |
| 261 | "riscv32": " --uint32-align=4 --little-endian ", \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | "i586": " --uint32-align=4 --little-endian ", \ |
| 263 | "i686": " --uint32-align=4 --little-endian ", \ |
| 264 | "x86_64": " --uint32-align=4 --little-endian " } |
| 265 | |
| 266 | if target_arch in locale_arch_options: |
| 267 | localedef_opts = locale_arch_options[target_arch] |
| 268 | else: |
| 269 | bb.error("locale_arch_options not found for target_arch=" + target_arch) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 270 | bb.fatal("unknown arch:" + target_arch + " for locale_arch_options") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 271 | |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 272 | localedef_opts += " --force --no-hard-links --no-archive --prefix=%s \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 | --inputfile=%s/%s/i18n/locales/%s --charmap=%s %s/%s" \ |
| 274 | % (treedir, treedir, datadir, locale, encoding, outputpath, name) |
| 275 | |
| 276 | cmd = "PATH=\"%s\" I18NPATH=\"%s\" GCONV_PATH=\"%s\" cross-localedef %s" % \ |
| 277 | (path, i18npath, gconvpath, localedef_opts) |
| 278 | else: # earlier slower qemu way |
| 279 | qemu = qemu_target_binary(d) |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 280 | localedef_opts = "--force --no-hard-links --no-archive --prefix=%s \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | --inputfile=%s/i18n/locales/%s --charmap=%s %s" \ |
| 282 | % (treedir, datadir, locale, encoding, name) |
| 283 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 284 | qemu_options = d.getVar('QEMU_OPTIONS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 285 | |
| 286 | cmd = "PSEUDO_RELOADED=YES PATH=\"%s\" I18NPATH=\"%s\" %s -L %s \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 287 | -E LD_LIBRARY_PATH=%s %s %s${base_bindir}/localedef %s" % \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 288 | (path, i18npath, qemu, treedir, ldlibdir, qemu_options, treedir, localedef_opts) |
| 289 | |
| 290 | commands["%s/%s" % (outputpath, name)] = cmd |
| 291 | |
| 292 | bb.note("generating locale %s (%s)" % (locale, encoding)) |
| 293 | |
| 294 | def output_locale(name, locale, encoding): |
| 295 | pkgname = d.getVar('MLPREFIX', False) + 'locale-base-' + legitimize_package_name(name) |
| 296 | d.setVar('ALLOW_EMPTY_%s' % pkgname, '1') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 297 | d.setVar('PACKAGES', '%s %s' % (pkgname, d.getVar('PACKAGES'))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 298 | rprovides = ' %svirtual-locale-%s' % (mlprefix, legitimize_package_name(name)) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 299 | m = re.match(r"(.*)_(.*)", name) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 300 | if m: |
| 301 | rprovides += ' %svirtual-locale-%s' % (mlprefix, m.group(1)) |
| 302 | d.setVar('RPROVIDES_%s' % pkgname, rprovides) |
| 303 | |
| 304 | if use_bin == "compile": |
| 305 | output_locale_binary_rdepends(name, pkgname, locale, encoding) |
| 306 | output_locale_binary(name, pkgname, locale, encoding) |
| 307 | elif use_bin == "precompiled": |
| 308 | output_locale_binary_rdepends(name, pkgname, locale, encoding) |
| 309 | else: |
| 310 | output_locale_source(name, pkgname, locale, encoding) |
| 311 | |
| 312 | if use_bin == "compile": |
| 313 | bb.note("preparing tree for binary locale generation") |
| 314 | bb.build.exec_func("do_prep_locale_tree", d) |
| 315 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 316 | utf8_only = int(d.getVar('LOCALE_UTF8_ONLY') or 0) |
| 317 | utf8_is_default = int(d.getVar('LOCALE_UTF8_IS_DEFAULT') or 0) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 318 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 319 | encodings = {} |
| 320 | for locale in to_generate: |
| 321 | charset = supported[locale] |
| 322 | if utf8_only and charset != 'UTF-8': |
| 323 | continue |
| 324 | |
| 325 | m = dot_re.match(locale) |
| 326 | if m: |
| 327 | base = m.group(1) |
| 328 | else: |
| 329 | base = locale |
| 330 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 331 | # Non-precompiled locales may be renamed so that the default |
| 332 | # (non-suffixed) encoding is always UTF-8, i.e., instead of en_US and |
| 333 | # en_US.UTF-8, we have en_US and en_US.ISO-8859-1. This implicitly |
| 334 | # contradicts SUPPORTED. |
| 335 | if use_bin == "precompiled" or not utf8_is_default: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 336 | output_locale(locale, base, charset) |
| 337 | else: |
| 338 | if charset == 'UTF-8': |
| 339 | output_locale(base, base, charset) |
| 340 | else: |
| 341 | output_locale('%s.%s' % (base, charset), base, charset) |
| 342 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 343 | def metapkg_hook(file, pkg, pattern, format, basename): |
| 344 | name = basename.split('/', 1)[0] |
| 345 | metapkg = legitimize_package_name('%s-binary-localedata-%s' % (mlprefix+bpn, name)) |
| 346 | d.appendVar('RDEPENDS_%s' % metapkg, ' ' + pkg) |
| 347 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 348 | if use_bin == "compile": |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 349 | makefile = oe.path.join(d.getVar("WORKDIR"), "locale-tree", "Makefile") |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 350 | with open(makefile, "w") as m: |
| 351 | m.write("all: %s\n\n" % " ".join(commands.keys())) |
| 352 | total = len(commands) |
| 353 | for i, (maketarget, makerecipe) in enumerate(commands.items()): |
| 354 | m.write(maketarget + ":\n") |
| 355 | m.write("\t@echo 'Progress %d/%d'\n" % (i, total)) |
| 356 | m.write("\t" + makerecipe + "\n\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 357 | d.setVar("EXTRA_OEMAKE", "-C %s ${PARALLEL_MAKE}" % (os.path.dirname(makefile))) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 358 | d.setVarFlag("oe_runmake", "progress", "outof:Progress\s(\d+)/(\d+)") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 359 | bb.note("Executing binary locale generation makefile") |
| 360 | bb.build.exec_func("oe_runmake", d) |
| 361 | bb.note("collecting binary locales from locale tree") |
| 362 | bb.build.exec_func("do_collect_bins_from_locale_tree", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 363 | |
| 364 | if use_bin in ('compile', 'precompiled'): |
| 365 | lcsplit = d.getVar('GLIBC_SPLIT_LC_PACKAGES') |
| 366 | if lcsplit and int(lcsplit): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 367 | do_split_packages(d, binary_locales_dir, file_regex=r'^(.*/LC_\w+)', \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 368 | output_pattern=bpn+'-binary-localedata-%s', \ |
| 369 | description='binary locale definition for %s', recursive=True, |
| 370 | hook=metapkg_hook, extra_depends='', allow_dirs=True, match_path=True) |
| 371 | else: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 372 | do_split_packages(d, binary_locales_dir, file_regex=r'(.*)', \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 373 | output_pattern=bpn+'-binary-localedata-%s', \ |
| 374 | description='binary locale definition for %s', extra_depends='', allow_dirs=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 375 | else: |
| 376 | bb.note("generation of binary locales disabled. this may break i18n!") |
| 377 | |
| 378 | } |
| 379 | |
| 380 | # We want to do this indirection so that we can safely 'return' |
| 381 | # from the called function even though we're prepending |
| 382 | python populate_packages_prepend () { |
| 383 | bb.build.exec_func('package_do_split_gconvs', d) |
| 384 | } |