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