blob: 1b6979a285d0b5511d517d95f3ad8849a27755ca [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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
12AUTO_LIBNAME_PKGS = "${PACKAGES}"
13
14inherit package
15
16DEBIANRDEP = "do_packagedata"
17do_package_write_ipk[rdeptask] = "${DEBIANRDEP}"
18do_package_write_deb[rdeptask] = "${DEBIANRDEP}"
19do_package_write_tar[rdeptask] = "${DEBIANRDEP}"
20do_package_write_rpm[rdeptask] = "${DEBIANRDEP}"
21
22python () {
23 if not d.getVar("PACKAGES", True):
24 d.setVar("DEBIANRDEP", "")
25}
26
27python debian_package_name_hook () {
28 import glob, copy, stat, errno, re
29
30 pkgdest = d.getVar('PKGDEST', True)
31 packages = d.getVar('PACKAGES', True)
32 bin_re = re.compile(".*/s?" + os.path.basename(d.getVar("bindir", True)) + "$")
33 lib_re = re.compile(".*/" + os.path.basename(d.getVar("libdir", True)) + "$")
34 so_re = re.compile("lib.*\.so")
35
36 def socrunch(s):
37 s = s.lower().replace('_', '-')
38 m = re.match("^(.*)(.)\.so\.(.*)$", s)
39 if m is None:
40 return None
41 if m.group(2) in '0123456789':
42 bin = '%s%s-%s' % (m.group(1), m.group(2), m.group(3))
43 else:
44 bin = m.group(1) + m.group(2) + m.group(3)
45 dev = m.group(1) + m.group(2)
46 return (bin, dev)
47
48 def isexec(path):
49 try:
50 s = os.stat(path)
51 except (os.error, AttributeError):
52 return 0
53 return (s[stat.ST_MODE] & stat.S_IEXEC)
54
55 def add_rprovides(pkg, d):
56 newpkg = d.getVar('PKG_' + pkg, False)
57 if newpkg and newpkg != pkg:
58 provs = (d.getVar('RPROVIDES_' + pkg, True) or "").split()
59 if pkg not in provs:
60 d.appendVar('RPROVIDES_' + pkg, " " + pkg + " (=" + d.getVar("PKGV", True) + ")")
61
62 def auto_libname(packages, orig_pkg):
63 sonames = []
64 has_bins = 0
65 has_libs = 0
66 for file in pkgfiles[orig_pkg]:
67 root = os.path.dirname(file)
68 if bin_re.match(root):
69 has_bins = 1
70 if lib_re.match(root):
71 has_libs = 1
72 if so_re.match(os.path.basename(file)):
73 cmd = (d.getVar('TARGET_PREFIX', True) or "") + "objdump -p " + file + " 2>/dev/null"
74 fd = os.popen(cmd)
75 lines = fd.readlines()
76 fd.close()
77 for l in lines:
78 m = re.match("\s+SONAME\s+([^\s]*)", l)
79 if m and not m.group(1) in sonames:
80 sonames.append(m.group(1))
81
82 bb.debug(1, 'LIBNAMES: pkg %s libs %d bins %d sonames %s' % (orig_pkg, has_libs, has_bins, sonames))
83 soname = None
84 if len(sonames) == 1:
85 soname = sonames[0]
86 elif len(sonames) > 1:
87 lead = d.getVar('LEAD_SONAME', True)
88 if lead:
89 r = re.compile(lead)
90 filtered = []
91 for s in sonames:
92 if r.match(s):
93 filtered.append(s)
94 if len(filtered) == 1:
95 soname = filtered[0]
96 elif len(filtered) > 1:
97 bb.note("Multiple matches (%s) for LEAD_SONAME '%s'" % (", ".join(filtered), lead))
98 else:
99 bb.note("Multiple libraries (%s) found, but LEAD_SONAME '%s' doesn't match any of them" % (", ".join(sonames), lead))
100 else:
101 bb.note("Multiple libraries (%s) found and LEAD_SONAME not defined" % ", ".join(sonames))
102
103 if has_libs and not has_bins and soname:
104 soname_result = socrunch(soname)
105 if soname_result:
106 (pkgname, devname) = soname_result
107 for pkg in packages.split():
108 if (d.getVar('PKG_' + pkg, False) or d.getVar('DEBIAN_NOAUTONAME_' + pkg, False)):
109 add_rprovides(pkg, d)
110 continue
111 debian_pn = d.getVar('DEBIANNAME_' + pkg, False)
112 if debian_pn:
113 newpkg = debian_pn
114 elif pkg == orig_pkg:
115 newpkg = pkgname
116 else:
117 newpkg = pkg.replace(orig_pkg, devname, 1)
118 mlpre=d.getVar('MLPREFIX', True)
119 if mlpre:
120 if not newpkg.find(mlpre) == 0:
121 newpkg = mlpre + newpkg
122 if newpkg != pkg:
123 d.setVar('PKG_' + pkg, newpkg)
124 add_rprovides(pkg, d)
125 else:
126 add_rprovides(orig_pkg, d)
127
128 # reversed sort is needed when some package is substring of another
129 # ie in ncurses we get without reverse sort:
130 # DEBUG: LIBNAMES: pkgname libtic5 devname libtic pkg ncurses-libtic orig_pkg ncurses-libtic debian_pn None newpkg libtic5
131 # and later
132 # DEBUG: LIBNAMES: pkgname libtic5 devname libtic pkg ncurses-libticw orig_pkg ncurses-libtic debian_pn None newpkg libticw
133 # so we need to handle ncurses-libticw->libticw5 before ncurses-libtic->libtic5
134 for pkg in sorted((d.getVar('AUTO_LIBNAME_PKGS', True) or "").split(), reverse=True):
135 auto_libname(packages, pkg)
136}
137
138EXPORT_FUNCTIONS package_name_hook
139
140DEBIAN_NAMES = "1"
141