summaryrefslogtreecommitdiffstats
path: root/meta/classes/libc-package.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/libc-package.bbclass')
-rw-r--r--meta/classes/libc-package.bbclass390
1 files changed, 390 insertions, 0 deletions
diff --git a/meta/classes/libc-package.bbclass b/meta/classes/libc-package.bbclass
new file mode 100644
index 0000000000..c1bc399c18
--- /dev/null
+++ b/meta/classes/libc-package.bbclass
@@ -0,0 +1,390 @@
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
10GLIBC_INTERNAL_USE_BINARY_LOCALE ?= "ondevice"
11
12python __anonymous () {
13 enabled = d.getVar("ENABLE_BINARY_LOCALE_GENERATION", True)
14
15 pn = d.getVar("PN", True)
16 if pn.endswith("-initial"):
17 enabled = False
18
19 if enabled and int(enabled):
20 import re
21
22 target_arch = d.getVar("TARGET_ARCH", True)
23 binary_arches = d.getVar("BINARY_LOCALE_ARCHES", True) or ""
24 use_cross_localedef = d.getVar("LOCALE_GENERATION_WITH_CROSS-LOCALEDEF", True) or ""
25
26 for regexp in binary_arches.split(" "):
27 r = re.compile(regexp)
28
29 if r.match(target_arch):
30 depends = d.getVar("DEPENDS", True)
31 if use_cross_localedef == "1" :
32 depends = "%s cross-localedef-native" % depends
33 else:
34 depends = "%s qemu-native" % depends
35 d.setVar("DEPENDS", depends)
36 d.setVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", "compile")
37 break
38
39 # try to fix disable charsets/locales/locale-code compile fail
40 if bb.utils.contains('DISTRO_FEATURES', 'libc-charsets', True, False, d) and \
41 bb.utils.contains('DISTRO_FEATURES', 'libc-locales', True, False, d) and \
42 bb.utils.contains('DISTRO_FEATURES', 'libc-locale-code', True, False, d):
43 d.setVar('PACKAGE_NO_GCONV', '0')
44 else:
45 d.setVar('PACKAGE_NO_GCONV', '1')
46}
47
48OVERRIDES_append = ":${TARGET_ARCH}-${TARGET_OS}"
49
50do_configure_prepend() {
51 if [ -e ${S}/elf/ldd.bash.in ]; then
52 sed -e "s#@BASH@#/bin/sh#" -i ${S}/elf/ldd.bash.in
53 fi
54}
55
56
57
58# indentation removed on purpose
59locale_base_postinst() {
60#!/bin/sh
61
62if [ "x$D" != "x" ]; then
63 exit 1
64fi
65
66rm -rf ${TMP_LOCALE}
67mkdir -p ${TMP_LOCALE}
68if [ -f ${localedir}/locale-archive ]; then
69 cp ${localedir}/locale-archive ${TMP_LOCALE}/
70fi
71localedef --inputfile=${datadir}/i18n/locales/%s --charmap=%s --prefix=/tmp/locale %s
72mkdir -p ${localedir}/
73mv ${TMP_LOCALE}/locale-archive ${localedir}/
74rm -rf ${TMP_LOCALE}
75}
76
77# indentation removed on purpose
78locale_base_postrm() {
79#!/bin/sh
80
81rm -rf ${TMP_LOCALE}
82mkdir -p ${TMP_LOCALE}
83if [ -f ${localedir}/locale-archive ]; then
84 cp ${localedir}/locale-archive ${TMP_LOCALE}/
85fi
86localedef --delete-from-archive --inputfile=${datadir}/locales/%s --charmap=%s --prefix=/tmp/locale %s
87mv ${TMP_LOCALE}/locale-archive ${localedir}/
88rm -rf ${TMP_LOCALE}
89}
90
91
92TMP_LOCALE="/tmp/locale${localedir}"
93LOCALETREESRC ?= "${PKGD}"
94
95do_prep_locale_tree() {
96 treedir=${WORKDIR}/locale-tree
97 rm -rf $treedir
98 mkdir -p $treedir/${base_bindir} $treedir/${base_libdir} $treedir/${datadir} $treedir/${localedir}
99 tar -cf - -C ${LOCALETREESRC}${datadir} -p i18n | tar -xf - -C $treedir/${datadir}
100 # unzip to avoid parsing errors
101 for i in $treedir/${datadir}/i18n/charmaps/*gz; do
102 gunzip $i
103 done
104 tar -cf - -C ${LOCALETREESRC}${base_libdir} -p . | tar -xf - -C $treedir/${base_libdir}
105 if [ -f ${STAGING_DIR_NATIVE}${prefix_native}/lib/libgcc_s.* ]; then
106 tar -cf - -C ${STAGING_DIR_NATIVE}/${prefix_native}/${base_libdir} -p libgcc_s.* | tar -xf - -C $treedir/${base_libdir}
107 fi
108 install -m 0755 ${LOCALETREESRC}${bindir}/localedef $treedir/${base_bindir}
109}
110
111do_collect_bins_from_locale_tree() {
112 treedir=${WORKDIR}/locale-tree
113
114 parent=$(dirname ${localedir})
115 mkdir -p ${PKGD}/$parent
116 tar -cf - -C $treedir/$parent -p $(basename ${localedir}) | tar -xf - -C ${PKGD}$parent
117}
118
119inherit qemu
120
121python package_do_split_gconvs () {
122 import re
123 if (d.getVar('PACKAGE_NO_GCONV', True) == '1'):
124 bb.note("package requested not splitting gconvs")
125 return
126
127 if not d.getVar('PACKAGES', True):
128 return
129
130 mlprefix = d.getVar("MLPREFIX", True) or ""
131
132 bpn = d.getVar('BPN', True)
133 libdir = d.getVar('libdir', True)
134 if not libdir:
135 bb.error("libdir not defined")
136 return
137 datadir = d.getVar('datadir', True)
138 if not datadir:
139 bb.error("datadir not defined")
140 return
141
142 gconv_libdir = base_path_join(libdir, "gconv")
143 charmap_dir = base_path_join(datadir, "i18n", "charmaps")
144 locales_dir = base_path_join(datadir, "i18n", "locales")
145 binary_locales_dir = d.getVar('localedir', True)
146
147 def calc_gconv_deps(fn, pkg, file_regex, output_pattern, group):
148 deps = []
149 f = open(fn, "rb")
150 c_re = re.compile('^copy "(.*)"')
151 i_re = re.compile('^include "(\w+)".*')
152 for l in f.readlines():
153 m = c_re.match(l) or i_re.match(l)
154 if m:
155 dp = legitimize_package_name('%s%s-gconv-%s' % (mlprefix, bpn, m.group(1)))
156 if not dp in deps:
157 deps.append(dp)
158 f.close()
159 if deps != []:
160 d.setVar('RDEPENDS_%s' % pkg, " ".join(deps))
161 if bpn != 'glibc':
162 d.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc'))
163
164 do_split_packages(d, gconv_libdir, file_regex='^(.*)\.so$', output_pattern=bpn+'-gconv-%s', \
165 description='gconv module for character set %s', hook=calc_gconv_deps, \
166 extra_depends=bpn+'-gconv')
167
168 def calc_charmap_deps(fn, pkg, file_regex, output_pattern, group):
169 deps = []
170 f = open(fn, "rb")
171 c_re = re.compile('^copy "(.*)"')
172 i_re = re.compile('^include "(\w+)".*')
173 for l in f.readlines():
174 m = c_re.match(l) or i_re.match(l)
175 if m:
176 dp = legitimize_package_name('%s%s-charmap-%s' % (mlprefix, bpn, m.group(1)))
177 if not dp in deps:
178 deps.append(dp)
179 f.close()
180 if deps != []:
181 d.setVar('RDEPENDS_%s' % pkg, " ".join(deps))
182 if bpn != 'glibc':
183 d.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc'))
184
185 do_split_packages(d, charmap_dir, file_regex='^(.*)\.gz$', output_pattern=bpn+'-charmap-%s', \
186 description='character map for %s encoding', hook=calc_charmap_deps, extra_depends='')
187
188 def calc_locale_deps(fn, pkg, file_regex, output_pattern, group):
189 deps = []
190 f = open(fn, "rb")
191 c_re = re.compile('^copy "(.*)"')
192 i_re = re.compile('^include "(\w+)".*')
193 for l in f.readlines():
194 m = c_re.match(l) or i_re.match(l)
195 if m:
196 dp = legitimize_package_name(mlprefix+bpn+'-localedata-%s' % m.group(1))
197 if not dp in deps:
198 deps.append(dp)
199 f.close()
200 if deps != []:
201 d.setVar('RDEPENDS_%s' % pkg, " ".join(deps))
202 if bpn != 'glibc':
203 d.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc'))
204
205 do_split_packages(d, locales_dir, file_regex='(.*)', output_pattern=bpn+'-localedata-%s', \
206 description='locale definition for %s', hook=calc_locale_deps, extra_depends='')
207 d.setVar('PACKAGES', d.getVar('PACKAGES') + ' ' + d.getVar('MLPREFIX') + bpn + '-gconv')
208
209 use_bin = d.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", True)
210
211 dot_re = re.compile("(.*)\.(.*)")
212
213 # Read in supported locales and associated encodings
214 supported = {}
215 with open(base_path_join(d.getVar('WORKDIR', True), "SUPPORTED")) as f:
216 for line in f.readlines():
217 try:
218 locale, charset = line.rstrip().split()
219 except ValueError:
220 continue
221 supported[locale] = charset
222
223 # GLIBC_GENERATE_LOCALES var specifies which locales to be generated. empty or "all" means all locales
224 to_generate = d.getVar('GLIBC_GENERATE_LOCALES', True)
225 if not to_generate or to_generate == 'all':
226 to_generate = supported.keys()
227 else:
228 to_generate = to_generate.split()
229 for locale in to_generate:
230 if locale not in supported:
231 if '.' in locale:
232 charset = locale.split('.')[1]
233 else:
234 charset = 'UTF-8'
235 bb.warn("Unsupported locale '%s', assuming encoding '%s'" % (locale, charset))
236 supported[locale] = charset
237
238 def output_locale_source(name, pkgname, locale, encoding):
239 d.setVar('RDEPENDS_%s' % pkgname, 'localedef %s-localedata-%s %s-charmap-%s' % \
240 (mlprefix+bpn, legitimize_package_name(locale), mlprefix+bpn, legitimize_package_name(encoding)))
241 d.setVar('pkg_postinst_%s' % pkgname, d.getVar('locale_base_postinst', True) \
242 % (locale, encoding, locale))
243 d.setVar('pkg_postrm_%s' % pkgname, d.getVar('locale_base_postrm', True) % \
244 (locale, encoding, locale))
245
246 def output_locale_binary_rdepends(name, pkgname, locale, encoding):
247 m = re.match("(.*)\.(.*)", name)
248 if m:
249 libc_name = "%s.%s" % (m.group(1), m.group(2).lower())
250 else:
251 libc_name = name
252 d.setVar('RDEPENDS_%s' % pkgname, legitimize_package_name('%s-binary-localedata-%s' \
253 % (mlprefix+bpn, libc_name)))
254
255 commands = {}
256
257 def output_locale_binary(name, pkgname, locale, encoding):
258 treedir = base_path_join(d.getVar("WORKDIR", True), "locale-tree")
259 ldlibdir = base_path_join(treedir, d.getVar("base_libdir", True))
260 path = d.getVar("PATH", True)
261 i18npath = base_path_join(treedir, datadir, "i18n")
262 gconvpath = base_path_join(treedir, "iconvdata")
263 outputpath = base_path_join(treedir, binary_locales_dir)
264
265 use_cross_localedef = d.getVar("LOCALE_GENERATION_WITH_CROSS-LOCALEDEF", True) or "0"
266 if use_cross_localedef == "1":
267 target_arch = d.getVar('TARGET_ARCH', True)
268 locale_arch_options = { \
269 "arm": " --uint32-align=4 --little-endian ", \
270 "armeb": " --uint32-align=4 --big-endian ", \
271 "aarch64_be": " --uint32-align=4 --big-endian ", \
272 "sh4": " --uint32-align=4 --big-endian ", \
273 "powerpc": " --uint32-align=4 --big-endian ", \
274 "powerpc64": " --uint32-align=4 --big-endian ", \
275 "mips": " --uint32-align=4 --big-endian ", \
276 "mips64": " --uint32-align=4 --big-endian ", \
277 "mipsel": " --uint32-align=4 --little-endian ", \
278 "mips64el":" --uint32-align=4 --little-endian ", \
279 "i586": " --uint32-align=4 --little-endian ", \
280 "i686": " --uint32-align=4 --little-endian ", \
281 "x86_64": " --uint32-align=4 --little-endian " }
282
283 if target_arch in locale_arch_options:
284 localedef_opts = locale_arch_options[target_arch]
285 else:
286 bb.error("locale_arch_options not found for target_arch=" + target_arch)
287 raise bb.build.FuncFailed("unknown arch:" + target_arch + " for locale_arch_options")
288
289 localedef_opts += " --force --old-style --no-archive --prefix=%s \
290 --inputfile=%s/%s/i18n/locales/%s --charmap=%s %s/%s" \
291 % (treedir, treedir, datadir, locale, encoding, outputpath, name)
292
293 cmd = "PATH=\"%s\" I18NPATH=\"%s\" GCONV_PATH=\"%s\" cross-localedef %s" % \
294 (path, i18npath, gconvpath, localedef_opts)
295 else: # earlier slower qemu way
296 qemu = qemu_target_binary(d)
297 localedef_opts = "--force --old-style --no-archive --prefix=%s \
298 --inputfile=%s/i18n/locales/%s --charmap=%s %s" \
299 % (treedir, datadir, locale, encoding, name)
300
301 qemu_options = d.getVar("QEMU_OPTIONS_%s" % d.getVar('PACKAGE_ARCH', True), True)
302 if not qemu_options:
303 qemu_options = d.getVar('QEMU_OPTIONS', True)
304
305 cmd = "PSEUDO_RELOADED=YES PATH=\"%s\" I18NPATH=\"%s\" %s -L %s \
306 -E LD_LIBRARY_PATH=%s %s %s/bin/localedef %s" % \
307 (path, i18npath, qemu, treedir, ldlibdir, qemu_options, treedir, localedef_opts)
308
309 commands["%s/%s" % (outputpath, name)] = cmd
310
311 bb.note("generating locale %s (%s)" % (locale, encoding))
312
313 def output_locale(name, locale, encoding):
314 pkgname = d.getVar('MLPREFIX') + 'locale-base-' + legitimize_package_name(name)
315 d.setVar('ALLOW_EMPTY_%s' % pkgname, '1')
316 d.setVar('PACKAGES', '%s %s' % (pkgname, d.getVar('PACKAGES', True)))
317 rprovides = ' %svirtual-locale-%s' % (mlprefix, legitimize_package_name(name))
318 m = re.match("(.*)_(.*)", name)
319 if m:
320 rprovides += ' %svirtual-locale-%s' % (mlprefix, m.group(1))
321 d.setVar('RPROVIDES_%s' % pkgname, rprovides)
322
323 if use_bin == "compile":
324 output_locale_binary_rdepends(name, pkgname, locale, encoding)
325 output_locale_binary(name, pkgname, locale, encoding)
326 elif use_bin == "precompiled":
327 output_locale_binary_rdepends(name, pkgname, locale, encoding)
328 else:
329 output_locale_source(name, pkgname, locale, encoding)
330
331 if use_bin == "compile":
332 bb.note("preparing tree for binary locale generation")
333 bb.build.exec_func("do_prep_locale_tree", d)
334
335 utf8_only = int(d.getVar('LOCALE_UTF8_ONLY', True) or 0)
336 encodings = {}
337 for locale in to_generate:
338 charset = supported[locale]
339 if utf8_only and charset != 'UTF-8':
340 continue
341
342 m = dot_re.match(locale)
343 if m:
344 base = m.group(1)
345 else:
346 base = locale
347
348 # Precompiled locales are kept as is, obeying SUPPORTED, while
349 # others are adjusted, ensuring that the non-suffixed locales
350 # are utf-8, while the suffixed are not.
351 if use_bin == "precompiled":
352 output_locale(locale, base, charset)
353 else:
354 if charset == 'UTF-8':
355 output_locale(base, base, charset)
356 else:
357 output_locale('%s.%s' % (base, charset), base, charset)
358
359 if use_bin == "compile":
360 makefile = base_path_join(d.getVar("WORKDIR", True), "locale-tree", "Makefile")
361 m = open(makefile, "w")
362 m.write("all: %s\n\n" % " ".join(commands.keys()))
363 for cmd in commands:
364 m.write(cmd + ":\n")
365 m.write("\t" + commands[cmd] + "\n\n")
366 m.close()
367 d.setVar("B", os.path.dirname(makefile))
368 d.setVar("EXTRA_OEMAKE", "${PARALLEL_MAKE}")
369 bb.note("Executing binary locale generation makefile")
370 bb.build.exec_func("oe_runmake", d)
371 bb.note("collecting binary locales from locale tree")
372 bb.build.exec_func("do_collect_bins_from_locale_tree", d)
373 do_split_packages(d, binary_locales_dir, file_regex='(.*)', \
374 output_pattern=bpn+'-binary-localedata-%s', \
375 description='binary locale definition for %s', extra_depends='', allow_dirs=True)
376 elif use_bin == "precompiled":
377 do_split_packages(d, binary_locales_dir, file_regex='(.*)', \
378 output_pattern=bpn+'-binary-localedata-%s', \
379 description='binary locale definition for %s', extra_depends='', allow_dirs=True)
380 else:
381 bb.note("generation of binary locales disabled. this may break i18n!")
382
383}
384
385# We want to do this indirection so that we can safely 'return'
386# from the called function even though we're prepending
387python populate_packages_prepend () {
388 bb.build.exec_func('package_do_split_gconvs', d)
389}
390