diff options
Diffstat (limited to 'meta/classes/glibc-package.bbclass')
| -rw-r--r-- | meta/classes/glibc-package.bbclass | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/meta/classes/glibc-package.bbclass b/meta/classes/glibc-package.bbclass new file mode 100644 index 0000000000..b16daa47f7 --- /dev/null +++ b/meta/classes/glibc-package.bbclass | |||
| @@ -0,0 +1,261 @@ | |||
| 1 | # | ||
| 2 | # This class knows how to package up 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 | |||
| 10 | GLIBC_INTERNAL_USE_BINARY_LOCALE ?= "ondevice" | ||
| 11 | |||
| 12 | 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" | ||
| 13 | PACKAGES_DYNAMIC = "glibc-gconv-* glibc-charmap-* glibc-localedata-* locale-base-* glibc-binary-localedata-*" | ||
| 14 | |||
| 15 | libc_baselibs = "${base_libdir}/libc* ${base_libdir}/libm* ${base_libdir}/ld* ${base_libdir}/libpthread* ${base_libdir}/libresolv* ${base_libdir}/librt* ${base_libdir}/libutil* ${base_libdir}/libnsl* ${base_libdir}/libnss_files* ${base_libdir}/libnss_compat* ${base_libdir}/libnss_dns* ${base_libdir}/libdl* ${base_libdir}/libanl* ${base_libdir}/libBrokenLocale*" | ||
| 16 | |||
| 17 | FILES_glibc = "${sysconfdir} ${libc_baselibs} ${base_sbindir}/ldconfig ${libexecdir}/* ${datadir}/zoneinfo" | ||
| 18 | FILES_ldd = "${bindir}/ldd" | ||
| 19 | FILES_libsegfault = "${base_libdir}/libSegFault*" | ||
| 20 | FILES_glibc-extra-nss = "${base_libdir}/libnss*" | ||
| 21 | FILES_sln = "${base_sbindir}/sln" | ||
| 22 | FILES_glibc-dev_append = " ${libdir}/*.o ${bindir}/rpcgen" | ||
| 23 | FILES_nscd = "${sbindir}/nscd* ${sysconfdir}/nscd* ${sysconfdir}/init.d/nscd*" | ||
| 24 | FILES_glibc-utils = "${bindir}/* ${sbindir}/*" | ||
| 25 | FILES_glibc-gconv = "${libdir}/gconv/*" | ||
| 26 | FILES_glibc-dbg = "${bindir}/.debug ${sbindir}/.debug ${libdir}/.debug \ | ||
| 27 | ${base_bindir}/.debug ${base_sbindir}/.debug ${base_libdir}/.debug \ | ||
| 28 | ${libdir}/gconv/.debug ${libexecdir}/*/.debug" | ||
| 29 | FILES_catchsegv = "${bindir}/catchsegv" | ||
| 30 | RDEPENDS_catchsegv = "libsegfault" | ||
| 31 | FILES_glibc-pcprofile = "${base_libdir}/libpcprofile.so" | ||
| 32 | FILES_glibc-thread-db = "${base_libdir}/libthread_db*" | ||
| 33 | FILES_localedef = "${bindir}/localedef" | ||
| 34 | RPROVIDES_glibc-dev += "libc-dev" | ||
| 35 | |||
| 36 | DESCRIPTION_sln = "glibc: create symbolic links between files" | ||
| 37 | DESCRIPTION_nscd = "glibc: name service cache daemon for passwd, group, and hosts" | ||
| 38 | DESCRIPTION_glibc-extra-nss = "glibc: nis, nisplus and hesiod search services" | ||
| 39 | DESCRIPTION_ldd = "glibc: print shared library dependencies" | ||
| 40 | DESCRIPTION_localedef = "glibc: compile locale definition files" | ||
| 41 | DESCRIPTION_glibc-utils = "glibc: misc utilities like iconf, local, gencat, tzselect, rpcinfo, ..." | ||
| 42 | |||
| 43 | TMP_LOCALE="/tmp/locale${libdir}/locale" | ||
| 44 | |||
| 45 | locale_base_postinst() { | ||
| 46 | #!/bin/sh | ||
| 47 | |||
| 48 | if [ "x$D" != "x" ]; then | ||
| 49 | exit 1 | ||
| 50 | fi | ||
| 51 | |||
| 52 | rm -rf ${TMP_LOCALE} | ||
| 53 | mkdir -p ${TMP_LOCALE} | ||
| 54 | if [ -f ${libdir}/locale/locale-archive ]; then | ||
| 55 | cp ${libdir}/locale/locale-archive ${TMP_LOCALE}/ | ||
| 56 | fi | ||
| 57 | localedef --inputfile=${datadir}/i18n/locales/%s --charmap=%s --prefix=/tmp/locale %s | ||
| 58 | mkdir -p ${libdir}/locale/ | ||
| 59 | mv ${TMP_LOCALE}/locale-archive ${libdir}/locale/ | ||
| 60 | rm -rf ${TMP_LOCALE} | ||
| 61 | } | ||
| 62 | |||
| 63 | locale_base_postrm() { | ||
| 64 | #!/bin/sh | ||
| 65 | |||
| 66 | rm -rf ${TMP_LOCALE} | ||
| 67 | mkdir -p ${TMP_LOCALE} | ||
| 68 | if [ -f ${libdir}/locale/locale-archive ]; then | ||
| 69 | cp ${libdir}/locale/locale-archive ${TMP_LOCALE}/ | ||
| 70 | fi | ||
| 71 | localedef --delete-from-archive --inputfile=${datadir}/locales/%s --charmap=%s --prefix=/tmp/locale %s | ||
| 72 | mv ${TMP_LOCALE}/locale-archive ${libdir}/locale/ | ||
| 73 | rm -rf ${TMP_LOCALE} | ||
| 74 | } | ||
| 75 | |||
| 76 | do_prep_locale_tree() { | ||
| 77 | treedir=${WORKDIR}/locale-tree | ||
| 78 | rm -rf $treedir | ||
| 79 | mkdir -p $treedir/bin $treedir/lib $treedir/${datadir} $treedir/${libdir}/locale | ||
| 80 | cp -pPR ${PKGD}${datadir}/i18n $treedir/${datadir}/i18n | ||
| 81 | # unzip to avoid parsing errors | ||
| 82 | for i in $treedir/${datadir}/i18n/charmaps/*gz; do | ||
| 83 | gunzip $i | ||
| 84 | done | ||
| 85 | cp -pPR ${PKGD}${base_libdir}/* $treedir/lib | ||
| 86 | if [ -f ${CROSS_DIR}/${TARGET_SYS}/lib/libgcc_s.* ]; then | ||
| 87 | cp -pPR ${CROSS_DIR}/${TARGET_SYS}/lib/libgcc_s.* $treedir/lib | ||
| 88 | fi | ||
| 89 | install -m 0755 ${PKGD}${bindir}/localedef $treedir/bin | ||
| 90 | } | ||
| 91 | |||
| 92 | do_collect_bins_from_locale_tree() { | ||
| 93 | treedir=${WORKDIR}/locale-tree | ||
| 94 | |||
| 95 | mkdir -p ${PKGD}${libdir} | ||
| 96 | cp -pPR $treedir/${libdir}/locale ${PKGD}${libdir} | ||
| 97 | } | ||
| 98 | |||
| 99 | python package_do_split_gconvs () { | ||
| 100 | import os, re | ||
| 101 | if (bb.data.getVar('PACKAGE_NO_GCONV', d, 1) == '1'): | ||
| 102 | bb.note("package requested not splitting gconvs") | ||
| 103 | return | ||
| 104 | |||
| 105 | if not bb.data.getVar('PACKAGES', d, 1): | ||
| 106 | return | ||
| 107 | |||
| 108 | libdir = bb.data.getVar('libdir', d, 1) | ||
| 109 | if not libdir: | ||
| 110 | bb.error("libdir not defined") | ||
| 111 | return | ||
| 112 | datadir = bb.data.getVar('datadir', d, 1) | ||
| 113 | if not datadir: | ||
| 114 | bb.error("datadir not defined") | ||
| 115 | return | ||
| 116 | |||
| 117 | gconv_libdir = base_path_join(libdir, "gconv") | ||
| 118 | charmap_dir = base_path_join(datadir, "i18n", "charmaps") | ||
| 119 | locales_dir = base_path_join(datadir, "i18n", "locales") | ||
| 120 | binary_locales_dir = base_path_join(libdir, "locale") | ||
| 121 | |||
| 122 | 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') | ||
| 123 | |||
| 124 | do_split_packages(d, charmap_dir, file_regex='^(.*)\.gz$', output_pattern='glibc-charmap-%s', description='character map for %s encoding', extra_depends='') | ||
| 125 | |||
| 126 | def calc_locale_deps(fn, pkg, file_regex, output_pattern, group): | ||
| 127 | deps = [] | ||
| 128 | f = open(fn, "r") | ||
| 129 | c_re = re.compile('^copy "(.*)"') | ||
| 130 | i_re = re.compile('^include "(\w+)".*') | ||
| 131 | for l in f.readlines(): | ||
| 132 | m = c_re.match(l) or i_re.match(l) | ||
| 133 | if m: | ||
| 134 | dp = legitimize_package_name('glibc-localedata-%s' % m.group(1)) | ||
| 135 | if not dp in deps: | ||
| 136 | deps.append(dp) | ||
| 137 | f.close() | ||
| 138 | if deps != []: | ||
| 139 | bb.data.setVar('RDEPENDS_%s' % pkg, " ".join(deps), d) | ||
| 140 | |||
| 141 | do_split_packages(d, locales_dir, file_regex='(.*)', output_pattern='glibc-localedata-%s', description='locale definition for %s', hook=calc_locale_deps, extra_depends='') | ||
| 142 | bb.data.setVar('PACKAGES', bb.data.getVar('PACKAGES', d) + ' glibc-gconv', d) | ||
| 143 | |||
| 144 | f = open(os.path.join(bb.data.getVar('WORKDIR', d, 1), "SUPPORTED"), "r") | ||
| 145 | supported = f.readlines() | ||
| 146 | f.close() | ||
| 147 | |||
| 148 | dot_re = re.compile("(.*)\.(.*)") | ||
| 149 | |||
| 150 | # Collate the locales by base and encoding | ||
| 151 | utf8_only = int(bb.data.getVar('LOCALE_UTF8_ONLY', d, 1) or 0) | ||
| 152 | encodings = {} | ||
| 153 | for l in supported: | ||
| 154 | l = l[:-1] | ||
| 155 | (locale, charset) = l.split(" ") | ||
| 156 | if utf8_only and charset != 'UTF-8': | ||
| 157 | continue | ||
| 158 | m = dot_re.match(locale) | ||
| 159 | if m: | ||
| 160 | locale = m.group(1) | ||
| 161 | if not encodings.has_key(locale): | ||
| 162 | encodings[locale] = [] | ||
| 163 | encodings[locale].append(charset) | ||
| 164 | |||
| 165 | def output_locale_source(name, locale, encoding): | ||
| 166 | pkgname = 'locale-base-' + legitimize_package_name(name) | ||
| 167 | |||
| 168 | bb.data.setVar('RDEPENDS_%s' % pkgname, 'localedef glibc-localedata-%s glibc-charmap-%s' % (legitimize_package_name(locale), legitimize_package_name(encoding)), d) | ||
| 169 | rprovides = 'virtual-locale-%s' % legitimize_package_name(name) | ||
| 170 | m = re.match("(.*)_(.*)", name) | ||
| 171 | if m: | ||
| 172 | rprovides += ' virtual-locale-%s' % m.group(1) | ||
| 173 | bb.data.setVar('RPROVIDES_%s' % pkgname, rprovides, d) | ||
| 174 | bb.data.setVar('PACKAGES', '%s %s' % (pkgname, bb.data.getVar('PACKAGES', d, 1)), d) | ||
| 175 | bb.data.setVar('ALLOW_EMPTY_%s' % pkgname, '1', d) | ||
| 176 | bb.data.setVar('pkg_postinst_%s' % pkgname, bb.data.getVar('locale_base_postinst', d, 1) % (locale, encoding, locale), d) | ||
| 177 | bb.data.setVar('pkg_postrm_%s' % pkgname, bb.data.getVar('locale_base_postrm', d, 1) % (locale, encoding, locale), d) | ||
| 178 | |||
| 179 | def output_locale_binary(name, locale, encoding): | ||
| 180 | target_arch = bb.data.getVar("TARGET_ARCH", d, 1) | ||
| 181 | qemu = "qemu-%s" % target_arch | ||
| 182 | pkgname = 'locale-base-' + legitimize_package_name(name) | ||
| 183 | m = re.match("(.*)\.(.*)", name) | ||
| 184 | if m: | ||
| 185 | glibc_name = "%s.%s" % (m.group(1), m.group(2).lower().replace("-","")) | ||
| 186 | else: | ||
| 187 | glibc_name = name | ||
| 188 | bb.data.setVar('RDEPENDS_%s' % pkgname, legitimize_package_name('glibc-binary-localedata-%s' % glibc_name), d) | ||
| 189 | rprovides = 'virtual-locale-%s' % legitimize_package_name(name) | ||
| 190 | m = re.match("(.*)_(.*)", name) | ||
| 191 | if m: | ||
| 192 | rprovides += ' virtual-locale-%s' % m.group(1) | ||
| 193 | bb.data.setVar('RPROVIDES_%s' % pkgname, rprovides, d) | ||
| 194 | bb.data.setVar('ALLOW_EMPTY_%s' % pkgname, '1', d) | ||
| 195 | bb.data.setVar('PACKAGES', '%s %s' % (pkgname, bb.data.getVar('PACKAGES', d, 1)), d) | ||
| 196 | |||
| 197 | treedir = base_path_join(bb.data.getVar("WORKDIR", d, 1), "locale-tree") | ||
| 198 | path = bb.data.getVar("PATH", d, 1) | ||
| 199 | i18npath = base_path_join(treedir, datadir, "i18n") | ||
| 200 | |||
| 201 | localedef_opts = "--force --old-style --no-archive --prefix=%s --inputfile=%s/i18n/locales/%s --charmap=%s %s" % (treedir, datadir, locale, encoding, name) | ||
| 202 | |||
| 203 | qemu_options = bb.data.getVar("QEMU_OPTIONS_%s" % bb.data.getVar('PACKAGE_ARCH', d, 1), d, 1) | ||
| 204 | if not qemu_options: | ||
| 205 | qemu_options = bb.data.getVar('QEMU_OPTIONS', d, 1) | ||
| 206 | |||
| 207 | cmd = "PATH=\"%s\" I18NPATH=\"%s\" %s -L %s %s %s/bin/localedef %s" % (path, i18npath, qemu, treedir, qemu_options, treedir, localedef_opts) | ||
| 208 | bb.note("generating locale %s (%s)" % (locale, encoding)) | ||
| 209 | if os.system(cmd): | ||
| 210 | raise bb.build.FuncFailed("localedef returned an error (command was %s)." % cmd) | ||
| 211 | |||
| 212 | def output_locale(name, locale, encoding): | ||
| 213 | use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1) | ||
| 214 | if use_bin == "compile": | ||
| 215 | output_locale_binary(name, locale, encoding) | ||
| 216 | else: | ||
| 217 | output_locale_source(name, locale, encoding) | ||
| 218 | |||
| 219 | use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1) | ||
| 220 | if use_bin == "compile": | ||
| 221 | bb.note("preparing tree for binary locale generation") | ||
| 222 | bb.build.exec_func("do_prep_locale_tree", d) | ||
| 223 | |||
| 224 | # Reshuffle names so that UTF-8 is preferred over other encodings | ||
| 225 | non_utf8 = [] | ||
| 226 | for l in encodings.keys(): | ||
| 227 | if len(encodings[l]) == 1: | ||
| 228 | output_locale(l, l, encodings[l][0]) | ||
| 229 | if encodings[l][0] != "UTF-8": | ||
| 230 | non_utf8.append(l) | ||
| 231 | else: | ||
| 232 | if "UTF-8" in encodings[l]: | ||
| 233 | output_locale(l, l, "UTF-8") | ||
| 234 | encodings[l].remove("UTF-8") | ||
| 235 | else: | ||
| 236 | non_utf8.append(l) | ||
| 237 | for e in encodings[l]: | ||
| 238 | output_locale('%s.%s' % (l, e), l, e) | ||
| 239 | |||
| 240 | if non_utf8 != []: | ||
| 241 | bb.note("the following locales are supported only in legacy encodings:") | ||
| 242 | bb.note(" " + " ".join(non_utf8)) | ||
| 243 | |||
| 244 | use_bin = bb.data.getVar("GLIBC_INTERNAL_USE_BINARY_LOCALE", d, 1) | ||
| 245 | if use_bin == "compile": | ||
| 246 | bb.note("collecting binary locales from locale tree") | ||
| 247 | bb.build.exec_func("do_collect_bins_from_locale_tree", d) | ||
| 248 | 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) | ||
| 249 | else: | ||
| 250 | bb.note("generation of binary locales disabled. this may break i18n!") | ||
| 251 | |||
| 252 | } | ||
| 253 | |||
| 254 | # We want to do this indirection so that we can safely 'return' | ||
| 255 | # from the called function even though we're prepending | ||
| 256 | python populate_packages_prepend () { | ||
| 257 | if bb.data.getVar('DEBIAN_NAMES', d, 1): | ||
| 258 | bb.data.setVar('PKG_glibc', 'libc6', d) | ||
| 259 | bb.data.setVar('PKG_glibc-dev', 'libc6-dev', d) | ||
| 260 | bb.build.exec_func('package_do_split_gconvs', d) | ||
| 261 | } | ||
