]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/glibc/glibc-package.bbclass
glibc: fix locale naming so UTF8 locales are packaged correctly.
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / glibc / glibc-package.bbclass
1 #
2 # For now, we will skip building of a gcc package if it is a uclibc one
3 # and our build is not a uclibc one, and we skip a glibc one if our build
4 # is a uclibc build.
5 #
6 # See the note in gcc/gcc_3.4.0.oe
7 #
8
9 python __anonymous () {
10     import bb, re
11     uc_os = (re.match('.*uclibc$', bb.data.getVar('TARGET_OS', d, 1)) != None)
12     if uc_os:
13         raise bb.parse.SkipPackage("incompatible with target %s" %
14                                    bb.data.getVar('TARGET_OS', d, 1))
15 }
16
17 # Binary locales are generated at build time if ENABLE_BINARY_LOCALE_GENERATION
18 # is set. The idea is to avoid running localedef on the target (at first boot)
19 # to decrease initial boot time and avoid localedef being killed by the OOM
20 # killer which used to effectively break i18n on machines with < 128MB RAM.
21
22 # default to disabled until qemu works for everyone
23 ENABLE_BINARY_LOCALE_GENERATION ?= "0"
24
25 # BINARY_LOCALE_ARCHES is a space separated list of regular expressions
26 BINARY_LOCALE_ARCHES ?= "arm.*"
27
28 PACKAGES = "glibc catchsegv sln nscd ldd localedef glibc-utils glibc-dev glibc-doc glibc-locale libsegfault glibc-extra-nss glibc-thread-db glibc-pcprofile"
29
30 libc_baselibs = "/lib/libc* /lib/libm* /lib/ld* /lib/libpthread* /lib/libresolv* /lib/librt* /lib/libutil* /lib/libnsl* /lib/libnss_files* /lib/libnss_compat* /lib/libnss_dns* /lib/libdl* /lib/libanl* /lib/libBrokenLocale*"
31
32 FILES_${PN} = "${sysconfdir} ${libc_baselibs} /sbin/ldconfig ${libexecdir} ${datadir}/zoneinfo"
33 FILES_ldd = "${bindir}/ldd"
34 FILES_libsegfault = "/lib/libSegFault*"
35 FILES_glibc-extra-nss = "/lib/libnss*"
36 FILES_sln = "/sbin/sln"
37 FILES_glibc-dev_append = " ${libdir}/*.o ${bindir}/rpcgen"
38 FILES_nscd = "${sbindir}/nscd*"
39 FILES_glibc-utils = "${bindir} ${sbindir}"
40 FILES_glibc-gconv = "${libdir}/gconv"
41 FILES_catchsegv = "${bindir}/catchsegv"
42 RDEPENDS_catchsegv = "libsegfault"
43 FILES_glibc-pcprofile = "/lib/libpcprofile.so"
44 FILES_glibc-thread-db = "/lib/libthread_db*"
45 FILES_localedef = "${bindir}/localedef"
46 RPROVIDES_glibc-dev += "libc-dev"
47
48 DESCRIPTION_sln = "glibc: create symbolic links between files"
49 DESCRIPTION_nscd = "glibc: name service cache daemon for passwd, group, and hosts"
50 DESCRIPTION_glibc-extra-nss = "glibc: nis, nisplus and hesiod search services"
51 DESCRIPTION_ldd = "glibc: print shared library dependencies"
52 DESCRIPTION_localedef = "glibc: compile locale definition files"
53 DESCRIPTION_glibc-utils = "glibc: misc utilities like iconf, local, gencat, tzselect, rpcinfo, ..."
54
55 def get_glibc_fpu_setting(bb, d):
56         if bb.data.getVar('TARGET_FPU', d, 1) in [ 'soft' ]:
57                 return "--without-fp"
58         return ""
59
60 EXTRA_OECONF += "${@get_glibc_fpu_setting(bb, d)}"
61
62 OVERRIDES_append = ":${TARGET_ARCH}-${TARGET_OS}"
63 EXTRA_OECONF_append_arm-linuxeabi = " --without-fp"
64
65 do_install() {
66         oe_runmake install_root=${D} install
67         for r in ${rpcsvc}; do
68                 h=`echo $r|sed -e's,\.x$,.h,'`
69                 install -m 0644 ${S}/sunrpc/rpcsvc/$h ${D}/${includedir}/rpcsvc/
70         done
71         install -m 0644 ${WORKDIR}/etc/ld.so.conf ${D}/${sysconfdir}/
72         install -d ${D}${libdir}/locale
73         make -f ${WORKDIR}/generate-supported.mk IN="${S}/localedata/SUPPORTED" OUT="${WORKDIR}/SUPPORTED"
74         # get rid of some broken files...
75         for i in ${GLIBC_BROKEN_LOCALES}; do
76                 grep -v $i ${WORKDIR}/SUPPORTED > ${WORKDIR}/SUPPORTED.tmp
77                 mv ${WORKDIR}/SUPPORTED.tmp ${WORKDIR}/SUPPORTED
78         done
79         rm -f ${D}/etc/rpc
80 }
81
82 TMP_LOCALE="/tmp/locale/${libdir}/locale"
83
84 locale_base_postinst() {
85 #!/bin/sh
86
87 if [ "x$D" != "x" ]; then
88   exit 1
89 fi
90
91 rm -rf ${TMP_LOCALE}
92 mkdir -p ${TMP_LOCALE}
93 if [ -f ${libdir}/locale/locale-archive ]; then
94         cp ${libdir}/locale/locale-archive ${TMP_LOCALE}/
95 fi
96 localedef --inputfile=${datadir}/i18n/locales/%s --charmap=%s --prefix=/tmp/locale %s
97 mv ${TMP_LOCALE}/locale-archive ${libdir}/locale/
98 rm -rf ${TMP_LOCALE}
99 }
100
101 locale_base_postrm() {
102 #!/bin/sh
103
104 rm -rf ${TMP_LOCALE}
105 mkdir -p ${TMP_LOCALE}
106 if [ -f ${libdir}/locale/locale-archive ]; then
107         cp ${libdir}/locale/locale-archive ${TMP_LOCALE}/
108 fi
109 localedef --delete-from-archive --inputfile=${datadir}/locales/%s --charmap=%s --prefix=/tmp/locale %s
110 mv ${TMP_LOCALE}/locale-archive ${libdir}/locale/
111 rm -rf ${TMP_LOCALE}
112 }
113
114 python __anonymous () {
115         enabled = bb.data.getVar("ENABLE_BINARY_LOCALE_GENERATION", d, 1)
116
117         if enabled and int(enabled):
118                 import re
119
120                 target_arch = bb.data.getVar("TARGET_ARCH", d, 1)
121                 binary_arches = bb.data.getVar("BINARY_LOCALE_ARCHES", d, 1) or ""
122
123                 for regexp in binary_arches.split(" "):
124                         r = re.compile(regexp)
125
126                         if r.match(target_arch):
127                                 depends = bb.data.getVar("DEPENDS", d, 1)
128                                 depends = "%s qemu-native" % depends
129                                 bb.data.setVar("DEPENDS", depends, d)
130                                 bb.data.setVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", "1", d)
131                                 break
132 }
133
134 do_prep_locale_tree() {
135         treedir=${WORKDIR}/locale-tree
136         rm -rf $treedir
137         mkdir -p $treedir/bin $treedir/lib $treedir/${datadir} $treedir/${libdir}/locale
138         cp -a ${D}${datadir}/i18n $treedir/${datadir}/i18n
139         # unzip to avoid parsing errors
140         for i in $treedir/${datadir}/i18n/charmaps/*gz; do 
141                 gunzip $i
142         done
143         cp -a ${STAGING_LIBDIR}/* $treedir/lib
144         if [ -f ${CROSS_DIR}/${TARGET_SYS}/lib/libgcc_s.* ]; then
145                 cp -a ${CROSS_DIR}/${TARGET_SYS}/lib/libgcc_s.* $treedir/lib
146         fi
147         install -m 0755 ${D}${bindir}/localedef $treedir/bin
148 }
149
150 do_collect_bins_from_locale_tree() {
151         treedir=${WORKDIR}/locale-tree
152
153         mkdir -p ${D}${libdir}
154         cp -a $treedir/${libdir}/locale ${D}${libdir}
155 }
156
157 python package_do_split_gconvs () {
158         import os, re
159         if (bb.data.getVar('PACKAGE_NO_GCONV', d, 1) == '1'):
160                 bb.note("package requested not splitting gconvs")
161                 return
162
163         if not bb.data.getVar('PACKAGES', d, 1):
164                 return
165
166         libdir = bb.data.getVar('libdir', d, 1)
167         if not libdir:
168                 bb.error("libdir not defined")
169                 return
170         datadir = bb.data.getVar('datadir', d, 1)
171         if not datadir:
172                 bb.error("datadir not defined")
173                 return
174
175         gconv_libdir = os.path.join(libdir, "gconv")
176         charmap_dir = os.path.join(datadir, "i18n", "charmaps")
177         locales_dir = os.path.join(datadir, "i18n", "locales")
178         binary_locales_dir = os.path.join(libdir, "locale")
179
180         do_split_packages(d, gconv_libdir, file_regex='^(.*)\.so$', output_pattern='glibc-gconv-%s', description='gconv module for character set %s', extra_depends='glibc-gconv')
181
182         do_split_packages(d, charmap_dir, file_regex='^(.*)\.gz$', output_pattern='glibc-charmap-%s', description='character map for %s encoding', extra_depends='')
183
184         def calc_locale_deps(fn, pkg, file_regex, output_pattern, group):
185                 deps = []
186                 f = open(fn, "r")
187                 c_re = re.compile('^copy "(.*)"')
188                 i_re = re.compile('^include "(\w+)".*')
189                 for l in f.readlines():
190                         m = c_re.match(l) or i_re.match(l)
191                         if m:
192                                 dp = legitimize_package_name('glibc-localedata-%s' % m.group(1))
193                                 if not dp in deps:
194                                         deps.append(dp)
195                 f.close()
196                 if deps != []:
197                         bb.data.setVar('RDEPENDS_%s' % pkg, " ".join(deps), d)
198
199         do_split_packages(d, locales_dir, file_regex='(.*)', output_pattern='glibc-localedata-%s', description='locale definition for %s', hook=calc_locale_deps, extra_depends='')
200         bb.data.setVar('PACKAGES', bb.data.getVar('PACKAGES', d) + ' glibc-gconv', d)
201
202         f = open(os.path.join(bb.data.getVar('WORKDIR', d, 1), "SUPPORTED"), "r")
203         supported = f.readlines()
204         f.close()
205
206         dot_re = re.compile("(.*)\.(.*)")
207
208         # Collate the locales by base and encoding
209         encodings = {}
210         for l in supported:
211                 l = l[:-1]
212                 (locale, charset) = l.split(" ")
213                 m = dot_re.match(locale)
214                 if m:
215                         locale = m.group(1)
216                 if not encodings.has_key(locale):
217                         encodings[locale] = []
218                 encodings[locale].append(charset)
219
220         def output_locale_source(name, locale, encoding):
221                 pkgname = 'locale-base-' + legitimize_package_name(name)
222
223                 bb.data.setVar('RDEPENDS_%s' % pkgname, 'localedef glibc-localedata-%s glibc-charmap-%s' % (legitimize_package_name(locale), legitimize_package_name(encoding)), d)
224                 rprovides = 'virtual-locale-%s' % legitimize_package_name(name)
225                 m = re.match("(.*)_(.*)", name)
226                 if m:
227                         rprovides += ' virtual-locale-%s' % m.group(1)
228                 bb.data.setVar('RPROVIDES_%s' % pkgname, rprovides, d)
229                 bb.data.setVar('PACKAGES', '%s %s' % (pkgname, bb.data.getVar('PACKAGES', d, 1)), d)
230                 bb.data.setVar('ALLOW_EMPTY_%s' % pkgname, '1', d)
231                 bb.data.setVar('pkg_postinst_%s' % pkgname, bb.data.getVar('locale_base_postinst', d, 1) % (locale, encoding, locale), d)
232                 bb.data.setVar('pkg_postrm_%s' % pkgname, bb.data.getVar('locale_base_postrm', d, 1) % (locale, encoding, locale), d)
233
234         def output_locale_binary(name, locale, encoding):
235                 target_arch = bb.data.getVar("TARGET_ARCH", d, 1)
236                 qemu = "qemu-%s" % target_arch
237                 pkgname = 'locale-base-' + legitimize_package_name(name)
238                 m = re.match("(.*)\.(.*)", name)
239                 if m:
240                         glibc_name = "%s.%s" % (m.group(1), m.group(2).lower().replace("-",""))
241                 else:
242                         glibc_name = name
243                 bb.data.setVar('RDEPENDS_%s' % pkgname, legitimize_package_name('glibc-binary-localedata-%s' % glibc_name), d)
244                 rprovides = 'virtual-locale-%s' % legitimize_package_name(name)
245                 m = re.match("(.*)_(.*)", name)
246                 if m:
247                         rprovides += ' virtual-locale-%s' % m.group(1)
248                 bb.data.setVar('RPROVIDES_%s' % pkgname, rprovides, d)
249                 bb.data.setVar('ALLOW_EMPTY_%s' % pkgname, '1', d)
250                 bb.data.setVar('PACKAGES', '%s %s' % (pkgname, bb.data.getVar('PACKAGES', d, 1)), d)
251
252                 treedir = os.path.join(bb.data.getVar("WORKDIR", d, 1), "locale-tree")
253                 path = bb.data.getVar("PATH", d, 1)
254                 i18npath = os.path.join(treedir, datadir, "i18n")
255
256                 localedef_opts = "--force --old-style --no-archive --prefix=%s --inputfile=%s/i18n/locales/%s --charmap=%s %s" % (treedir, datadir, locale, encoding, name)
257                 cmd = "PATH=\"%s\" I18NPATH=\"%s\" %s -L %s %s/bin/localedef %s" % (path, i18npath, qemu, treedir, treedir, localedef_opts)
258                 bb.note("generating locale %s (%s)" % (locale, encoding))
259                 if os.system(cmd):
260                         raise bb.build.FuncFailed("localedef returned an error.")
261
262         def output_locale(name, locale, encoding):
263                 use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1)
264                 if use_bin:
265                         output_locale_binary(name, locale, encoding)
266                 else:
267                         output_locale_source(name, locale, encoding)
268
269         use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1)
270         if use_bin:
271                 bb.note("preparing tree for binary locale generation")
272                 bb.build.exec_func("do_prep_locale_tree", d)
273
274         # Reshuffle names so that UTF-8 is preferred over other encodings
275         non_utf8 = []
276         for l in encodings.keys():
277                 if len(encodings[l]) == 1:
278                         output_locale(l, l, encodings[l][0])
279                         if encodings[l][0] != "UTF-8":
280                                 non_utf8.append(l)
281                 else:
282                         if "UTF-8" in encodings[l]:
283                                 output_locale(l, l, "UTF-8")
284                                 encodings[l].remove("UTF-8")
285                         else:
286                                 non_utf8.append(l)
287                         for e in encodings[l]:
288                                 output_locale('%s.%s' % (l, e), l, e)
289
290         if non_utf8 != []:
291                 bb.note("the following locales are supported only in legacy encodings:")
292                 bb.note("  " + " ".join(non_utf8))
293
294         use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1)
295         if use_bin:
296                 bb.note("collecting binary locales from locale tree")
297                 bb.build.exec_func("do_collect_bins_from_locale_tree", d)
298                 do_split_packages(d, binary_locales_dir, file_regex='(.*)', output_pattern='glibc-binary-localedata-%s', description='binary locale definition for %s', extra_depends='', allow_dirs=True)
299         else:
300                 bb.note("generation of binary locales disabled. this may break i18n!")
301
302 }
303
304 # We want to do this indirection so that we can safely 'return'
305 # from the called function even though we're prepending
306 python populate_packages_prepend () {
307         if bb.data.getVar('DEBIAN_NAMES', d, 1):
308                 bb.data.setVar('PKG_glibc', 'libc6', d)
309                 bb.data.setVar('PKG_glibc-dev', 'libc6-dev', d)
310         bb.build.exec_func('package_do_split_gconvs', d)
311 }