diff options
Diffstat (limited to 'meta/classes/debian.bbclass')
-rw-r--r-- | meta/classes/debian.bbclass | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/meta/classes/debian.bbclass b/meta/classes/debian.bbclass new file mode 100644 index 0000000000..d7ea151a5d --- /dev/null +++ b/meta/classes/debian.bbclass | |||
@@ -0,0 +1,125 @@ | |||
1 | # Debian package renaming only occurs when a package is built | ||
2 | # We therefore have to make sure we build all runtime packages | ||
3 | # before building the current package to make the packages runtime | ||
4 | # depends are correct | ||
5 | # | ||
6 | # Custom library package names can be defined setting | ||
7 | # DEBIANNAME_ + pkgname to the desired name. | ||
8 | # | ||
9 | # Better expressed as ensure all RDEPENDS package before we package | ||
10 | # This means we can't have circular RDEPENDS/RRECOMMENDS | ||
11 | DEBIANRDEP = "do_packagedata" | ||
12 | do_package_write_ipk[rdeptask] = "${DEBIANRDEP}" | ||
13 | do_package_write_deb[rdeptask] = "${DEBIANRDEP}" | ||
14 | do_package_write_tar[rdeptask] = "${DEBIANRDEP}" | ||
15 | do_package_write_rpm[rdeptask] = "${DEBIANRDEP}" | ||
16 | |||
17 | python () { | ||
18 | if not d.getVar("PACKAGES", True): | ||
19 | d.setVar("DEBIANRDEP", "") | ||
20 | } | ||
21 | |||
22 | python debian_package_name_hook () { | ||
23 | import glob, copy, stat, errno, re | ||
24 | |||
25 | pkgdest = d.getVar('PKGDEST', True) | ||
26 | packages = d.getVar('PACKAGES', True) | ||
27 | bin_re = re.compile(".*/s?" + os.path.basename(d.getVar("bindir", True)) + "$") | ||
28 | lib_re = re.compile(".*/" + os.path.basename(d.getVar("libdir", True)) + "$") | ||
29 | so_re = re.compile("lib.*\.so") | ||
30 | |||
31 | def socrunch(s): | ||
32 | s = s.lower().replace('_', '-') | ||
33 | m = re.match("^(.*)(.)\.so\.(.*)$", s) | ||
34 | if m is None: | ||
35 | return None | ||
36 | if m.group(2) in '0123456789': | ||
37 | bin = '%s%s-%s' % (m.group(1), m.group(2), m.group(3)) | ||
38 | else: | ||
39 | bin = m.group(1) + m.group(2) + m.group(3) | ||
40 | dev = m.group(1) + m.group(2) | ||
41 | return (bin, dev) | ||
42 | |||
43 | def isexec(path): | ||
44 | try: | ||
45 | s = os.stat(path) | ||
46 | except (os.error, AttributeError): | ||
47 | return 0 | ||
48 | return (s[stat.ST_MODE] & stat.S_IEXEC) | ||
49 | |||
50 | def auto_libname(packages, orig_pkg): | ||
51 | sonames = [] | ||
52 | has_bins = 0 | ||
53 | has_libs = 0 | ||
54 | for file in pkgfiles[orig_pkg]: | ||
55 | root = os.path.dirname(file) | ||
56 | if bin_re.match(root): | ||
57 | has_bins = 1 | ||
58 | if lib_re.match(root): | ||
59 | has_libs = 1 | ||
60 | if so_re.match(os.path.basename(file)): | ||
61 | cmd = (d.getVar('TARGET_PREFIX', True) or "") + "objdump -p " + file + " 2>/dev/null" | ||
62 | fd = os.popen(cmd) | ||
63 | lines = fd.readlines() | ||
64 | fd.close() | ||
65 | for l in lines: | ||
66 | m = re.match("\s+SONAME\s+([^\s]*)", l) | ||
67 | if m and not m.group(1) in sonames: | ||
68 | sonames.append(m.group(1)) | ||
69 | |||
70 | bb.debug(1, 'LIBNAMES: pkg %s libs %d bins %d sonames %s' % (orig_pkg, has_libs, has_bins, sonames)) | ||
71 | soname = None | ||
72 | if len(sonames) == 1: | ||
73 | soname = sonames[0] | ||
74 | elif len(sonames) > 1: | ||
75 | lead = d.getVar('LEAD_SONAME', True) | ||
76 | if lead: | ||
77 | r = re.compile(lead) | ||
78 | filtered = [] | ||
79 | for s in sonames: | ||
80 | if r.match(s): | ||
81 | filtered.append(s) | ||
82 | if len(filtered) == 1: | ||
83 | soname = filtered[0] | ||
84 | elif len(filtered) > 1: | ||
85 | bb.note("Multiple matches (%s) for LEAD_SONAME '%s'" % (", ".join(filtered), lead)) | ||
86 | else: | ||
87 | bb.note("Multiple libraries (%s) found, but LEAD_SONAME '%s' doesn't match any of them" % (", ".join(sonames), lead)) | ||
88 | else: | ||
89 | bb.note("Multiple libraries (%s) found and LEAD_SONAME not defined" % ", ".join(sonames)) | ||
90 | |||
91 | if has_libs and not has_bins and soname: | ||
92 | soname_result = socrunch(soname) | ||
93 | if soname_result: | ||
94 | (pkgname, devname) = soname_result | ||
95 | for pkg in packages.split(): | ||
96 | if (d.getVar('PKG_' + pkg) or d.getVar('DEBIAN_NOAUTONAME_' + pkg)): | ||
97 | continue | ||
98 | debian_pn = d.getVar('DEBIANNAME_' + pkg) | ||
99 | if debian_pn: | ||
100 | newpkg = debian_pn | ||
101 | elif pkg == orig_pkg: | ||
102 | newpkg = pkgname | ||
103 | else: | ||
104 | newpkg = pkg.replace(orig_pkg, devname, 1) | ||
105 | mlpre=d.getVar('MLPREFIX', True) | ||
106 | if mlpre: | ||
107 | if not newpkg.find(mlpre) == 0: | ||
108 | newpkg = mlpre + newpkg | ||
109 | if newpkg != pkg: | ||
110 | d.setVar('PKG_' + pkg, newpkg) | ||
111 | |||
112 | # reversed sort is needed when some package is substring of another | ||
113 | # ie in ncurses we get without reverse sort: | ||
114 | # DEBUG: LIBNAMES: pkgname libtic5 devname libtic pkg ncurses-libtic orig_pkg ncurses-libtic debian_pn None newpkg libtic5 | ||
115 | # and later | ||
116 | # DEBUG: LIBNAMES: pkgname libtic5 devname libtic pkg ncurses-libticw orig_pkg ncurses-libtic debian_pn None newpkg libticw | ||
117 | # so we need to handle ncurses-libticw->libticw5 before ncurses-libtic->libtic5 | ||
118 | for pkg in sorted((d.getVar('AUTO_LIBNAME_PKGS', True) or "").split(), reverse=True): | ||
119 | auto_libname(packages, pkg) | ||
120 | } | ||
121 | |||
122 | EXPORT_FUNCTIONS package_name_hook | ||
123 | |||
124 | DEBIAN_NAMES = "1" | ||
125 | |||