summaryrefslogtreecommitdiffstats
path: root/meta/classes/libc-package.bbclass
diff options
context:
space:
mode:
authorNitin A Kamble <nitin.a.kamble@intel.com>2010-08-05 19:38:06 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2010-09-02 09:52:31 +0100
commit561d875404ef1783f94f37314b6e756766db8411 (patch)
tree664f8afe01c9ba8828ab02b19367e97e52dae842 /meta/classes/libc-package.bbclass
parent436d590c4a5b7b5942bac5b51af128bcdd30621f (diff)
downloadpoky-561d875404ef1783f94f37314b6e756766db8411.tar.gz
libc-package.bbclass: merge glibc & eglibc class files
Other enhancements: print qemu's stdio & error on failure glibc: enable locale generation for all arches eglibc: enable binary locale generation for mips And cleanup of code based on the code review. [e]glibc: move common definition in the common file bitbake was complaining about duplicate definition of get_libc_fpu_setting in eglibc.inc & glibc.inc files. And bump PRs Signed-off-by: Nitin A Kamble <nitin.a.kamble@intel.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'meta/classes/libc-package.bbclass')
-rw-r--r--meta/classes/libc-package.bbclass349
1 files changed, 349 insertions, 0 deletions
diff --git a/meta/classes/libc-package.bbclass b/meta/classes/libc-package.bbclass
new file mode 100644
index 0000000000..c0e7176472
--- /dev/null
+++ b/meta/classes/libc-package.bbclass
@@ -0,0 +1,349 @@
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
12inherit qemu
13
14def get_libc_fpu_setting(bb, d):
15 if bb.data.getVar('TARGET_FPU', d, 1) in [ 'soft' ]:
16 return "--without-fp"
17 return ""
18
19OVERRIDES_append = ":${TARGET_ARCH}-${TARGET_OS}"
20
21do_configure_prepend() {
22 sed -e "s#@BASH@#/bin/sh#" -i ${S}/elf/ldd.bash.in
23}
24
25
26
27# indentation removed on purpose
28locale_base_postinst() {
29#!/bin/sh
30
31if [ "x$D" != "x" ]; then
32 exit 1
33fi
34
35rm -rf ${TMP_LOCALE}
36mkdir -p ${TMP_LOCALE}
37if [ -f ${libdir}/locale/locale-archive ]; then
38 cp ${libdir}/locale/locale-archive ${TMP_LOCALE}/
39fi
40localedef --inputfile=${datadir}/i18n/locales/%s --charmap=%s --prefix=/tmp/locale %s
41mkdir -p ${libdir}/locale/
42mv ${TMP_LOCALE}/locale-archive ${libdir}/locale/
43rm -rf ${TMP_LOCALE}
44}
45
46# indentation removed on purpose
47locale_base_postrm() {
48#!/bin/sh
49
50rm -rf ${TMP_LOCALE}
51mkdir -p ${TMP_LOCALE}
52if [ -f ${libdir}/locale/locale-archive ]; then
53 cp ${libdir}/locale/locale-archive ${TMP_LOCALE}/
54fi
55localedef --delete-from-archive --inputfile=${datadir}/locales/%s --charmap=%s --prefix=/tmp/locale %s
56mv ${TMP_LOCALE}/locale-archive ${libdir}/locale/
57rm -rf ${TMP_LOCALE}
58}
59
60
61do_install() {
62 oe_runmake install_root=${D} install
63 for r in ${rpcsvc}; do
64 h=`echo $r|sed -e's,\.x$,.h,'`
65 install -m 0644 ${S}/sunrpc/rpcsvc/$h ${D}/${includedir}/rpcsvc/
66 done
67 install -m 0644 ${WORKDIR}/etc/ld.so.conf ${D}/${sysconfdir}/
68 install -d ${D}${libdir}/locale
69 make -f ${WORKDIR}/generate-supported.mk IN="${S}/localedata/SUPPORTED" OUT="${WORKDIR}/SUPPORTED"
70 # get rid of some broken files...
71 for i in ${GLIBC_BROKEN_LOCALES}; do
72 grep -v $i ${WORKDIR}/SUPPORTED > ${WORKDIR}/SUPPORTED.tmp
73 mv ${WORKDIR}/SUPPORTED.tmp ${WORKDIR}/SUPPORTED
74 done
75 rm -f ${D}{sysconfdir}/rpc
76 rm -f ${D}${includedir}/scsi/sg.h
77 rm -f ${D}${includedir}/scsi/scsi_ioctl.h
78 rm -f ${D}${includedir}/scsi/scsi.h
79 rm -rf ${D}${datadir}/zoneinfo
80 rm -rf ${D}${libexecdir}/getconf
81}
82
83TMP_LOCALE="/tmp/locale${libdir}/locale"
84
85do_prep_locale_tree() {
86 treedir=${WORKDIR}/locale-tree
87 rm -rf $treedir
88 mkdir -p $treedir/bin $treedir/lib $treedir/${datadir} $treedir/${libdir}/locale
89 cp -pPR ${PKGD}${datadir}/i18n $treedir/${datadir}/i18n
90 # unzip to avoid parsing errors
91 for i in $treedir/${datadir}/i18n/charmaps/*gz; do
92 gunzip $i
93 done
94 cp -pPR ${PKGD}${base_libdir}/* $treedir/lib
95 if [ -f ${STAGING_DIR_NATIVE}${prefix_native}/lib/libgcc_s.* ]; then
96 cp -pPR ${STAGING_DIR_NATIVE}/${prefix_native}/lib/libgcc_s.* $treedir/lib
97 fi
98 install -m 0755 ${PKGD}${bindir}/localedef $treedir/bin
99}
100
101do_collect_bins_from_locale_tree() {
102 treedir=${WORKDIR}/locale-tree
103
104 mkdir -p ${PKGD}${libdir}
105 cp -pPR $treedir/${libdir}/locale ${PKGD}${libdir}
106}
107
108python package_do_split_gconvs () {
109 import os, re
110 if (bb.data.getVar('PACKAGE_NO_GCONV', d, 1) == '1'):
111 bb.note("package requested not splitting gconvs")
112 return
113
114 if not bb.data.getVar('PACKAGES', d, 1):
115 return
116
117 bpn = bb.data.getVar('BPN', d, 1)
118 libdir = bb.data.getVar('libdir', d, 1)
119 if not libdir:
120 bb.error("libdir not defined")
121 return
122 datadir = bb.data.getVar('datadir', d, 1)
123 if not datadir:
124 bb.error("datadir not defined")
125 return
126
127 gconv_libdir = base_path_join(libdir, "gconv")
128 charmap_dir = base_path_join(datadir, "i18n", "charmaps")
129 locales_dir = base_path_join(datadir, "i18n", "locales")
130 binary_locales_dir = base_path_join(libdir, "locale")
131
132 def calc_gconv_deps(fn, pkg, file_regex, output_pattern, group):
133 deps = []
134 f = open(fn, "r")
135 c_re = re.compile('^copy "(.*)"')
136 i_re = re.compile('^include "(\w+)".*')
137 for l in f.readlines():
138 m = c_re.match(l) or i_re.match(l)
139 if m:
140 dp = legitimize_package_name('%s-gconv-%s' % (bpn, m.group(1)))
141 if not dp in deps:
142 deps.append(dp)
143 f.close()
144 if deps != []:
145 bb.data.setVar('RDEPENDS_%s' % pkg, " ".join(deps), d)
146 if bpn != 'glibc':
147 bb.data.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc'), d)
148
149 do_split_packages(d, gconv_libdir, file_regex='^(.*)\.so$', output_pattern=bpn+'-gconv-%s', \
150 description='gconv module for character set %s', hook=calc_gconv_deps, \
151 extra_depends=bpn+'-gconv')
152
153 def calc_charmap_deps(fn, pkg, file_regex, output_pattern, group):
154 deps = []
155 f = open(fn, "r")
156 c_re = re.compile('^copy "(.*)"')
157 i_re = re.compile('^include "(\w+)".*')
158 for l in f.readlines():
159 m = c_re.match(l) or i_re.match(l)
160 if m:
161 dp = legitimize_package_name('%s-charmap-%s' % (bpn, m.group(1)))
162 if not dp in deps:
163 deps.append(dp)
164 f.close()
165 if deps != []:
166 bb.data.setVar('RDEPENDS_%s' % pkg, " ".join(deps), d)
167 if bpn != 'glibc':
168 bb.data.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc'), d)
169
170 do_split_packages(d, charmap_dir, file_regex='^(.*)\.gz$', output_pattern=bpn+'-charmap-%s', \
171 description='character map for %s encoding', hook=calc_charmap_deps, extra_depends='')
172
173 def calc_locale_deps(fn, pkg, file_regex, output_pattern, group):
174 deps = []
175 f = open(fn, "r")
176 c_re = re.compile('^copy "(.*)"')
177 i_re = re.compile('^include "(\w+)".*')
178 for l in f.readlines():
179 m = c_re.match(l) or i_re.match(l)
180 if m:
181 dp = legitimize_package_name(bpn+'-localedata-%s' % m.group(1))
182 if not dp in deps:
183 deps.append(dp)
184 f.close()
185 if deps != []:
186 bb.data.setVar('RDEPENDS_%s' % pkg, " ".join(deps), d)
187 if bpn != 'glibc':
188 bb.data.setVar('RPROVIDES_%s' % pkg, pkg.replace(bpn, 'glibc'), d)
189
190 do_split_packages(d, locales_dir, file_regex='(.*)', output_pattern=bpn+'-localedata-%s', \
191 description='locale definition for %s', hook=calc_locale_deps, extra_depends='')
192 bb.data.setVar('PACKAGES', bb.data.getVar('PACKAGES', d) + ' ' + bpn + '-gconv', d)
193
194 use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1)
195
196 dot_re = re.compile("(.*)\.(.*)")
197
198#GLIBC_GENERATE_LOCALES var specifies which locales to be supported, empty or "all" means all locales
199 if use_bin != "precompiled":
200 supported = bb.data.getVar('GLIBC_GENERATE_LOCALES', d, 1)
201 if not supported or supported == "all":
202 f = open(base_path_join(bb.data.getVar('WORKDIR', d, 1), "SUPPORTED"), "r")
203 supported = f.readlines()
204 f.close()
205 else:
206 supported = supported.split()
207 supported = map(lambda s:s.replace(".", " ") + "\n", supported)
208 else:
209 supported = []
210 full_bin_path = bb.data.getVar('PKGD', d, True) + binary_locales_dir
211 for dir in os.listdir(full_bin_path):
212 dbase = dir.split(".")
213 d2 = " "
214 if len(dbase) > 1:
215 d2 = "." + dbase[1].upper() + " "
216 supported.append(dbase[0] + d2)
217
218 # Collate the locales by base and encoding
219 utf8_only = int(bb.data.getVar('LOCALE_UTF8_ONLY', d, 1) or 0)
220 encodings = {}
221 for l in supported:
222 l = l[:-1]
223 (locale, charset) = l.split(" ")
224 if utf8_only and charset != 'UTF-8':
225 continue
226 m = dot_re.match(locale)
227 if m:
228 locale = m.group(1)
229 if not encodings.has_key(locale):
230 encodings[locale] = []
231 encodings[locale].append(charset)
232
233 def output_locale_source(name, pkgname, locale, encoding):
234 bb.data.setVar('RDEPENDS_%s' % pkgname, 'localedef %s-localedata-%s %s-charmap-%s' % \
235 (bpn, legitimize_package_name(locale), bpn, legitimize_package_name(encoding)), d)
236 bb.data.setVar('pkg_postinst_%s' % pkgname, bb.data.getVar('locale_base_postinst', d, 1) \
237 % (locale, encoding, locale), d)
238 bb.data.setVar('pkg_postrm_%s' % pkgname, bb.data.getVar('locale_base_postrm', d, 1) % \
239 (locale, encoding, locale), d)
240
241 def output_locale_binary_rdepends(name, pkgname, locale, encoding):
242 m = re.match("(.*)_(.*)", name)
243 if m:
244 libc_name = "%s.%s" % (m.group(1), m.group(2).lower().replace("-",""))
245 else:
246 libc_name = name
247 bb.data.setVar('RDEPENDS_%s' % pkgname, legitimize_package_name('%s-binary-localedata-%s' \
248 % (bpn, libc_name)), d)
249 rprovides = (bb.data.getVar('RPROVIDES_%s' % pkgname, d, True) or "").split()
250 rprovides.append(legitimize_package_name('%s-binary-localedata-%s' % (bpn, libc_name)))
251 bb.data.setVar('RPROVIDES_%s' % pkgname, " ".join(rprovides), d)
252
253 def output_locale_binary(name, pkgname, locale, encoding):
254 qemu = qemu_target_binary(d)
255
256 treedir = base_path_join(bb.data.getVar("WORKDIR", d, 1), "locale-tree")
257 ldlibdir = "%s/lib" % treedir
258 path = bb.data.getVar("PATH", d, 1)
259 i18npath = base_path_join(treedir, datadir, "i18n")
260
261 localedef_opts = "--force --old-style --no-archive --prefix=%s \
262 --inputfile=%s/i18n/locales/%s --charmap=%s %s" \
263 % (treedir, datadir, locale, encoding, name)
264
265 qemu_options = bb.data.getVar("QEMU_OPTIONS_%s" % bb.data.getVar('PACKAGE_ARCH', d, 1), d, 1)
266 if not qemu_options:
267 qemu_options = bb.data.getVar('QEMU_OPTIONS', d, 1)
268
269 cmd = "PATH=\"%s\" I18NPATH=\"%s\" %s -L %s \
270 -E LD_LIBRARY_PATH=%s %s %s/bin/localedef %s" % \
271 (path, i18npath, qemu, treedir, ldlibdir, qemu_options, treedir, localedef_opts)
272 bb.note("generating locale %s (%s)" % (locale, encoding))
273 import subprocess
274 process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
275 if process.wait() != 0:
276 bb.note("cmd:")
277 bb.note(cmd)
278 bb.note("stdout:")
279 bb.note(process.stdout.read())
280 bb.note("stderr:")
281 bb.note(process.stderr.read())
282 raise bb.build.FuncFailed("localedef returned an error")
283
284 def output_locale(name, locale, encoding):
285 pkgname = 'locale-base-' + legitimize_package_name(name)
286 bb.data.setVar('ALLOW_EMPTY_%s' % pkgname, '1', d)
287 bb.data.setVar('PACKAGES', '%s %s' % (pkgname, bb.data.getVar('PACKAGES', d, 1)), d)
288 rprovides = ' virtual-locale-%s' % legitimize_package_name(name)
289 m = re.match("(.*)_(.*)", name)
290 if m:
291 rprovides += ' virtual-locale-%s' % m.group(1)
292 bb.data.setVar('RPROVIDES_%s' % pkgname, rprovides, d)
293
294 if use_bin == "compile":
295 output_locale_binary_rdepends(name, pkgname, locale, encoding)
296 output_locale_binary(name, pkgname, locale, encoding)
297 elif use_bin == "precompiled":
298 output_locale_binary_rdepends(name, pkgname, locale, encoding)
299 else:
300 output_locale_source(name, pkgname, locale, encoding)
301
302 if use_bin == "compile":
303 bb.note("preparing tree for binary locale generation")
304 bb.build.exec_func("do_prep_locale_tree", d)
305
306 # Reshuffle names so that UTF-8 is preferred over other encodings
307 non_utf8 = []
308 for l in encodings.keys():
309 if len(encodings[l]) == 1:
310 output_locale(l, l, encodings[l][0])
311 if encodings[l][0] != "UTF-8":
312 non_utf8.append(l)
313 else:
314 if "UTF-8" in encodings[l]:
315 output_locale(l, l, "UTF-8")
316 encodings[l].remove("UTF-8")
317 else:
318 non_utf8.append(l)
319 for e in encodings[l]:
320 output_locale('%s.%s' % (l, e), l, e)
321
322 if non_utf8 != [] and use_bin != "precompiled":
323 bb.note("the following locales are supported only in legacy encodings:")
324 bb.note(" " + " ".join(non_utf8))
325
326 if use_bin == "compile":
327 bb.note("collecting binary locales from locale tree")
328 bb.build.exec_func("do_collect_bins_from_locale_tree", d)
329 do_split_packages(d, binary_locales_dir, file_regex='(.*)', \
330 output_pattern=bpn+'-binary-localedata-%s', \
331 description='binary locale definition for %s', extra_depends='', allow_dirs=True)
332 elif use_bin == "precompiled":
333 do_split_packages(d, binary_locales_dir, file_regex='(.*)', \
334 output_pattern=bpn+'-binary-localedata-%s', \
335 description='binary locale definition for %s', extra_depends='', allow_dirs=True)
336 else:
337 bb.note("generation of binary locales disabled. this may break i18n!")
338
339}
340
341# We want to do this indirection so that we can safely 'return'
342# from the called function even though we're prepending
343python populate_packages_prepend () {
344 if bb.data.getVar('DEBIAN_NAMES', d, 1):
345 bpn = bb.data.getVar('BPN', d, 1)
346 bb.data.setVar('PKG_'+bpn, 'libc6', d)
347 bb.data.setVar('PKG_'+bpn+'-dev', 'libc6-dev', d)
348 bb.build.exec_func('package_do_split_gconvs', d)
349}