glibc-package.bbclass : added KaeilOS hack supporting glibc 2.9
[openembedded.git] / recipes / 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
18 # Binary locales are generated at build time if ENABLE_BINARY_LOCALE_GENERATION
19 # is set. The idea is to avoid running localedef on the target (at first boot)
20 # to decrease initial boot time and avoid localedef being killed by the OOM
21 # killer which used to effectively break i18n on machines with < 128MB RAM.
22
23 # default to disabled until qemu works for everyone
24 ENABLE_BINARY_LOCALE_GENERATION ?= "0"
25
26 # BINARY_LOCALE_ARCHES is a space separated list of regular expressions
27 BINARY_LOCALE_ARCHES ?= "arm.* i[3-6]86 x86_64 powerpc"
28
29 # Set this to zero if you don't want ldconfig in the output package
30 USE_LDCONFIG ?= "1"
31
32 PACKAGES = "glibc-dbg glibc catchsegv sln nscd ldd localedef glibc-utils glibc-dev glibc-doc glibc-locale libsegfault glibc-extra-nss glibc-thread-db glibc-pcprofile"
33 PACKAGES_DYNAMIC = "glibc-gconv-* glibc-charmap-* glibc-localedata-* locale-base-* glibc-binary-localedata-*"
34
35 INSANE_SKIP_glibc-dbg = True
36
37 libc_baselibs = "${base_libdir}/libcrypt*.so.* ${base_libdir}/libcrypt-*.so ${base_libdir}/libc*.so.* ${base_libdir}/libc-*.so ${base_libdir}/libm*.so.* ${base_libdir}/libm-*.so ${base_libdir}/ld*.so.* ${base_libdir}/ld-*.so ${base_libdir}/libpthread*.so.* ${base_libdir}/libpthread-*.so ${base_libdir}/libresolv*.so.* ${base_libdir}/libresolv-*.so ${base_libdir}/librt*.so.* ${base_libdir}/librt-*.so ${base_libdir}/libutil*.so.* ${base_libdir}/libutil-*.so ${base_libdir}/libnsl*.so.* ${base_libdir}/libnsl-*.so ${base_libdir}/libnss_files*.so.* ${base_libdir}/libnss_files-*.so ${base_libdir}/libnss_compat*.so.* ${base_libdir}/libnss_compat-*.so ${base_libdir}/libnss_dns*.so.* ${base_libdir}/libnss_dns-*.so ${base_libdir}/libdl*.so.* ${base_libdir}/libdl-*.so ${base_libdir}/libanl*.so.* ${base_libdir}/libanl-*.so ${base_libdir}/libBrokenLocale*.so.* ${base_libdir}/libBrokenLocale-*.so"
38
39 FILES_${PN} = "${libc_baselibs} ${libexecdir}/* ${datadir}/zoneinfo ${@base_conditional('USE_LDCONFIG', '1', '${base_sbindir}/ldconfig', '', d)}"
40 FILES_ldd = "${bindir}/ldd"
41 FILES_libsegfault = "${base_libdir}/libSegFault*"
42 FILES_glibc-extra-nss = "${base_libdir}/libnss*"
43 FILES_sln = "${base_sbindir}/sln"
44 FILES_glibc-dev_append = " ${libdir}/*.o ${bindir}/rpcgen"
45 FILES_nscd = "${sbindir}/nscd* ${sysconfdir}/nscd* ${sysconfdir}/init.d/nscd*"
46 FILES_glibc-utils = "${bindir}/* ${sbindir}/*"
47 FILES_glibc-gconv = "${libdir}/gconv/*"
48 FILES_${PN}-dbg += " ${libdir}/gconv/.debug ${libexecdir}/*/.debug"
49 FILES_catchsegv = "${bindir}/catchsegv"
50 RDEPENDS_catchsegv = "libsegfault"
51 FILES_glibc-pcprofile = "${base_libdir}/libpcprofile.so"
52 FILES_glibc-thread-db = "${base_libdir}/libthread_db*"
53 FILES_localedef = "${bindir}/localedef"
54 RPROVIDES_glibc-dev += "libc-dev"
55
56 DESCRIPTION_sln = "glibc: create symbolic links between files"
57 DESCRIPTION_nscd = "glibc: name service cache daemon for passwd, group, and hosts"
58 DESCRIPTION_glibc-extra-nss = "glibc: nis, nisplus and hesiod search services"
59 DESCRIPTION_ldd = "glibc: print shared library dependencies"
60 DESCRIPTION_localedef = "glibc: compile locale definition files"
61 DESCRIPTION_glibc-utils = "glibc: misc utilities like iconf, local, gencat, tzselect, rpcinfo, ..."
62
63 INITSCRIPT_NAME = "nscd"
64 INITSCRIPT_PACKAGES = "nscd"
65 INITSCRIPT_PARAMS = "start 40 S . stop 40 0 6 1 ."
66 inherit update-rc.d
67
68 def get_glibc_fpu_setting(bb, d):
69     if bb.data.getVar('TARGET_FPU', d, 1) in [ 'soft' ]:
70         return "--without-fp"
71     return ""
72
73 EXTRA_OECONF += "${@get_glibc_fpu_setting(bb, d)}"
74 EXTRA_OEMAKE += "rootsbindir=${base_sbindir}"
75
76 OVERRIDES_append = ":${TARGET_ARCH}-${TARGET_OS}"
77
78 do_install() {
79         oe_runmake install_root=${D} install
80         for r in ${rpcsvc}; do
81                 h=`echo $r|sed -e's,\.x$,.h,'`
82                 install -m 0644 ${S}/sunrpc/rpcsvc/$h ${D}/${includedir}/rpcsvc/
83         done
84         install -d ${D}${libdir}/locale
85         make -f ${WORKDIR}/generate-supported.mk IN="${S}/localedata/SUPPORTED" OUT="${WORKDIR}/SUPPORTED"
86         # get rid of some broken files...
87         for i in ${GLIBC_BROKEN_LOCALES}; do
88                 grep -v $i ${WORKDIR}/SUPPORTED > ${WORKDIR}/SUPPORTED.tmp
89                 mv ${WORKDIR}/SUPPORTED.tmp ${WORKDIR}/SUPPORTED
90         done
91         rm -f ${D}{sysconfdir}/rpc
92         install -d ${D}${sysconfdir}/init.d
93         install -m 0644 ${S}/nscd/nscd.conf ${D}${sysconfdir}/
94         install ${S}/nscd/nscd.init ${D}${sysconfdir}/init.d/nscd
95 }
96
97 TMP_LOCALE="/tmp/locale${libdir}/locale"
98
99 locale_base_postinst() {
100 #!/bin/sh
101
102 if [ "x$D" != "x" ]; then
103   exit 1
104 fi
105
106 rm -rf ${TMP_LOCALE}
107 mkdir -p ${TMP_LOCALE}
108 if [ -f ${libdir}/locale/locale-archive ]; then
109         cp ${libdir}/locale/locale-archive ${TMP_LOCALE}/
110 fi
111 localedef --inputfile=${datadir}/i18n/locales/%s --charmap=%s --prefix=/tmp/locale %s
112 mkdir -p ${libdir}/locale/
113 mv ${TMP_LOCALE}/locale-archive ${libdir}/locale/
114 rm -rf ${TMP_LOCALE}
115 }
116
117 locale_base_postrm() {
118 #!/bin/sh
119
120 rm -rf ${TMP_LOCALE}
121 mkdir -p ${TMP_LOCALE}
122 if [ -f ${libdir}/locale/locale-archive ]; then
123         cp ${libdir}/locale/locale-archive ${TMP_LOCALE}/
124 fi
125 localedef --delete-from-archive --inputfile=${datadir}/locales/%s --charmap=%s --prefix=/tmp/locale %s
126 mv ${TMP_LOCALE}/locale-archive ${libdir}/locale/
127 rm -rf ${TMP_LOCALE}
128 }
129
130 python __anonymous () {
131     enabled = bb.data.getVar("ENABLE_BINARY_LOCALE_GENERATION", d, 1)
132
133     if enabled and int(enabled):
134         import re
135
136         target_arch = bb.data.getVar("TARGET_ARCH", d, 1)
137         binary_arches = bb.data.getVar("BINARY_LOCALE_ARCHES", d, 1) or ""
138
139         for regexp in binary_arches.split(" "):
140             r = re.compile(regexp)
141
142             if r.match(target_arch):
143                 depends = bb.data.getVar("DEPENDS", d, 1)
144                 depends = "%s qemu-native" % depends
145                 bb.data.setVar("DEPENDS", depends, d)
146                 bb.data.setVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", "1", d)
147                 break
148 }
149
150 do_prep_locale_tree() {
151         treedir=${WORKDIR}/locale-tree
152         rm -rf $treedir
153         mkdir -p $treedir/bin $treedir/lib $treedir/${datadir} $treedir/${libdir}/locale
154         cp -pPR ${D}${datadir}/i18n $treedir/${datadir}/i18n
155         # unzip to avoid parsing errors
156         for i in $treedir/${datadir}/i18n/charmaps/*gz; do 
157                 gunzip $i
158         done
159         ls -d ${D}${base_libdir}/* | xargs -iBLAH cp -pPR BLAH $treedir/lib
160         if [ -f ${CROSS_DIR}/${TARGET_SYS}/lib/libgcc_s.so ]; then
161                 cp -pPR ${CROSS_DIR}/${TARGET_SYS}/lib/libgcc_s.so $treedir/lib
162         fi
163         if [ -f ${CROSS_DIR}/${TARGET_SYS}/lib/libgcc_s.so.* ]; then
164                 cp -pPR ${CROSS_DIR}/${TARGET_SYS}/lib/libgcc_s.so.* $treedir/lib
165         fi
166         install -m 0755 ${D}${bindir}/localedef $treedir/bin
167 }
168
169 do_collect_bins_from_locale_tree() {
170         treedir=${WORKDIR}/locale-tree
171
172         mkdir -p ${D}${libdir}
173         cp -pPR $treedir/${libdir}/locale ${D}${libdir}
174 }
175
176 python package_do_split_gconvs () {
177         import os, re
178         if (bb.data.getVar('PACKAGE_NO_GCONV', d, 1) == '1'):
179                 bb.note("package requested not splitting gconvs")
180                 return
181
182         if not bb.data.getVar('PACKAGES', d, 1):
183                 return
184
185         libdir = bb.data.getVar('libdir', d, 1)
186         if not libdir:
187                 bb.error("libdir not defined")
188                 return
189         datadir = bb.data.getVar('datadir', d, 1)
190         if not datadir:
191                 bb.error("datadir not defined")
192                 return
193
194         gconv_libdir = base_path_join(libdir, "gconv")
195         charmap_dir = base_path_join(datadir, "i18n", "charmaps")
196         locales_dir = base_path_join(datadir, "i18n", "locales")
197         binary_locales_dir = base_path_join(libdir, "locale")
198
199         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')
200
201         do_split_packages(d, charmap_dir, file_regex='^(.*)\.gz$', output_pattern='glibc-charmap-%s', description='character map for %s encoding', extra_depends='')
202
203         def calc_locale_deps(fn, pkg, file_regex, output_pattern, group):
204                 deps = []
205                 f = open(fn, "r")
206                 c_re = re.compile('^copy "(.*)"')
207                 i_re = re.compile('^include "(\w+)".*')
208                 for l in f.readlines():
209                         m = c_re.match(l) or i_re.match(l)
210                         if m:
211                                 dp = legitimize_package_name('glibc-localedata-%s' % m.group(1))
212                                 if not dp in deps:
213                                         deps.append(dp)
214                 f.close()
215                 if deps != []:
216                         bb.data.setVar('RDEPENDS_%s' % pkg, " ".join(deps), d)
217
218         do_split_packages(d, locales_dir, file_regex='(.*)', output_pattern='glibc-localedata-%s', description='locale definition for %s', hook=calc_locale_deps, extra_depends='')
219         bb.data.setVar('PACKAGES', bb.data.getVar('PACKAGES', d) + ' glibc-gconv', d)
220
221         supported = bb.data.getVar('GLIBC_GENERATE_LOCALES', d, 1)
222         if not supported or supported == "all":
223             f = open(base_path_join(bb.data.getVar('WORKDIR', d, 1), "SUPPORTED"), "r")
224             supported = f.readlines()
225             f.close()
226         else:
227             supported = supported.split()
228             supported = map(lambda s:s.replace(".", " ") + "\n", supported)
229
230         dot_re = re.compile("(.*)\.(.*)")
231
232         # Collate the locales by base and encoding
233         utf8_only = int(bb.data.getVar('LOCALE_UTF8_ONLY', d, 1) or 0)
234         encodings = {}
235         for l in supported:
236                 l = l[:-1]
237                 (locale, charset) = l.split(" ")
238                 if utf8_only and charset != 'UTF-8':
239                         continue
240                 m = dot_re.match(locale)
241                 if m:
242                         locale = m.group(1)
243                 if not encodings.has_key(locale):
244                         encodings[locale] = []
245                 encodings[locale].append(charset)
246
247         def output_locale_source(name, locale, encoding):
248                 pkgname = 'locale-base-' + legitimize_package_name(name)
249
250                 bb.data.setVar('RDEPENDS_%s' % pkgname, 'localedef glibc-localedata-%s glibc-charmap-%s' % (legitimize_package_name(locale), legitimize_package_name(encoding)), d)
251                 rprovides = 'virtual-locale-%s' % legitimize_package_name(name)
252                 m = re.match("(.*)_(.*)", name)
253                 if m:
254                         rprovides += ' virtual-locale-%s' % m.group(1)
255                 bb.data.setVar('RPROVIDES_%s' % pkgname, rprovides, d)
256                 bb.data.setVar('PACKAGES', '%s %s' % (pkgname, bb.data.getVar('PACKAGES', d, 1)), d)
257                 bb.data.setVar('ALLOW_EMPTY_%s' % pkgname, '1', d)
258                 bb.data.setVar('pkg_postinst_%s' % pkgname, bb.data.getVar('locale_base_postinst', d, 1) % (locale, encoding, locale), d)
259                 bb.data.setVar('pkg_postrm_%s' % pkgname, bb.data.getVar('locale_base_postrm', d, 1) % (locale, encoding, locale), d)
260
261         def output_locale_binary(name, locale, encoding):
262                 target_arch = bb.data.getVar("TARGET_ARCH", d, 1)
263                 if target_arch in ("i486", "i586", "i686"):
264                         target_arch = "i386"
265                 elif target_arch == "powerpc":
266                         target_arch = "ppc"
267
268                 # This is a hack till linux-libc-headers gets patched for the missing arm syscalls and all arm device kernels as well
269                 if bb.data.getVar("DISTRO_NAME", d, 1) == "Angstrom":
270                         kernel_ver = "2.6.24"
271                 elif bb.data.getVar("DISTRO_NAME", d, 1) == "KaeilOS":
272                         kernel_ver = "2.6.24"
273                 else:
274                         kernel_ver = bb.data.getVar("OLDEST_KERNEL", d, 1)
275
276                 if kernel_ver is None:
277                         qemu = "qemu-%s  -s 1048576" % target_arch
278                 else:
279                         qemu = "qemu-%s  -s 1048576 -r %s" % (target_arch, kernel_ver)
280                 pkgname = 'locale-base-' + legitimize_package_name(name)
281                 m = re.match("(.*)\.(.*)", name)
282                 if m:
283                         glibc_name = "%s.%s" % (m.group(1), m.group(2).lower().replace("-",""))
284                 else:
285                         glibc_name = name
286                 bb.data.setVar('RDEPENDS_%s' % pkgname, legitimize_package_name('glibc-binary-localedata-%s' % glibc_name), d)
287                 rprovides = 'virtual-locale-%s' % legitimize_package_name(name)
288                 m = re.match("(.*)_(.*)", name)
289                 if m:
290                         rprovides += ' virtual-locale-%s' % m.group(1)
291                 bb.data.setVar('RPROVIDES_%s' % pkgname, rprovides, d)
292                 bb.data.setVar('ALLOW_EMPTY_%s' % pkgname, '1', d)
293                 bb.data.setVar('PACKAGES', '%s %s' % (pkgname, bb.data.getVar('PACKAGES', d, 1)), d)
294
295                 treedir = base_path_join(bb.data.getVar("WORKDIR", d, 1), "locale-tree")
296                 ldlibdir = "%s/lib" % treedir
297                 path = bb.data.getVar("PATH", d, 1)
298                 i18npath = base_path_join(treedir, datadir, "i18n")
299
300                 localedef_opts = "--force --old-style --no-archive --prefix=%s --inputfile=%s/i18n/locales/%s --charmap=%s %s" % (treedir, datadir, locale, encoding, name)
301
302                 qemu_options = bb.data.getVar("QEMU_OPTIONS_%s" % bb.data.getVar('PACKAGE_ARCH', d, 1), d, 1)
303                 if not qemu_options:
304                         qemu_options = bb.data.getVar('QEMU_OPTIONS', d, 1)
305                 
306                 cmd = "PATH=\"%s\" I18NPATH=\"%s\" %s -L %s -E LD_LIBRARY_PATH=%s %s %s/bin/localedef %s" % (path, i18npath, qemu, treedir, ldlibdir, qemu_options, treedir, localedef_opts)
307                 bb.note("generating locale %s (%s)" % (locale, encoding))
308                 if os.system(cmd):
309                         raise bb.build.FuncFailed("localedef returned an error (command was %s)." % cmd)
310
311         def output_locale(name, locale, encoding):
312                 use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1)
313                 if use_bin:
314                         output_locale_binary(name, locale, encoding)
315                 else:
316                         output_locale_source(name, locale, encoding)
317
318         use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1)
319         if use_bin:
320                 bb.note("preparing tree for binary locale generation")
321                 bb.build.exec_func("do_prep_locale_tree", d)
322
323         # Reshuffle names so that UTF-8 is preferred over other encodings
324         non_utf8 = []
325         for l in encodings.keys():
326                 if len(encodings[l]) == 1:
327                         output_locale(l, l, encodings[l][0])
328                         if encodings[l][0] != "UTF-8":
329                                 non_utf8.append(l)
330                 else:
331                         if "UTF-8" in encodings[l]:
332                                 output_locale(l, l, "UTF-8")
333                                 encodings[l].remove("UTF-8")
334                         else:
335                                 non_utf8.append(l)
336                         for e in encodings[l]:
337                                 output_locale('%s.%s' % (l, e), l, e)
338
339         if non_utf8 != []:
340                 bb.note("the following locales are supported only in legacy encodings:")
341                 bb.note("  " + " ".join(non_utf8))
342
343         use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1)
344         if use_bin:
345                 bb.note("collecting binary locales from locale tree")
346                 bb.build.exec_func("do_collect_bins_from_locale_tree", d)
347                 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)
348         else:
349                 bb.note("generation of binary locales disabled. this may break i18n!")
350
351 }
352
353 # We want to do this indirection so that we can safely 'return'
354 # from the called function even though we're prepending
355 python populate_packages_prepend () {
356         if bb.data.getVar('DEBIAN_NAMES', d, 1):
357                 bb.data.setVar('PKG_glibc', 'libc6', d)
358                 bb.data.setVar('PKG_glibc-dev', 'libc6-dev', d)
359         bb.build.exec_func('package_do_split_gconvs', d)
360 }