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