merge of 'a713e30a7c1eae8ab3bf00e2e3eb7f9a6ffb1e3b'
[openembedded.git] / classes / debian.bbclass
1 STAGING_PKGMAPS_DIR = "${STAGING_DIR}/pkgmaps/debian"
2
3 # Debian package renaming only occurs when a package is built
4 # We therefore have to make sure we build all runtime packages
5 # before building the current package to make the packages runtime
6 # depends are correct
7 #
8 # Better expressed as ensure all RDEPENDS package before we package
9 # This means we can't have circular RDEPENDS/RRECOMMENDS
10 do_package_write[rdeptask] = "do_package"
11
12 python debian_package_name_hook () {
13         import glob, copy, stat, errno, re
14
15         workdir = bb.data.getVar('WORKDIR', d, 1)
16         packages = bb.data.getVar('PACKAGES', d, 1)
17
18         def socrunch(s):
19                 s = s.lower().replace('_', '-')
20                 m = re.match("^(.*)(.)\.so\.(.*)$", s)
21                 if m is None:
22                         return None
23                 if m.group(2) in '0123456789':
24                         bin = '%s%s-%s' % (m.group(1), m.group(2), m.group(3))
25                 else:
26                         bin = m.group(1) + m.group(2) + m.group(3)
27                 dev = m.group(1) + m.group(2)
28                 return (bin, dev)
29
30         def isexec(path):
31                 try:
32                         s = os.stat(path)
33                 except (os.error, AttributeError):
34                         return 0
35                 return (s[stat.ST_MODE] & stat.S_IEXEC)
36
37         def auto_libname(packages, orig_pkg):
38                 bin_re = re.compile(".*/s?bin$")
39                 lib_re = re.compile(".*/lib$")
40                 so_re = re.compile("lib.*\.so")
41                 sonames = []
42                 has_bins = 0
43                 has_libs = 0
44                 pkg_dir = os.path.join(workdir, "install", orig_pkg)
45                 for root, dirs, files in os.walk(pkg_dir):
46                         if bin_re.match(root) and files:
47                                 has_bins = 1
48                         if lib_re.match(root) and files:
49                                 has_libs = 1
50                                 for f in files:
51                                         if so_re.match(f):
52                                                 fp = os.path.join(root, f)
53                                                 cmd = (bb.data.getVar('BUILD_PREFIX', d, 1) or "") + "objdump -p " + fp + " 2>/dev/null"
54                                                 fd = os.popen(cmd)
55                                                 lines = fd.readlines()
56                                                 fd.close()
57                                                 for l in lines:
58                                                         m = re.match("\s+SONAME\s+([^\s]*)", l)
59                                                         if m and not m.group(1) in sonames:
60                                                                 sonames.append(m.group(1))
61
62                 bb.debug(1, 'LIBNAMES: pkg %s libs %d bins %d sonames %s' % (orig_pkg, has_libs, has_bins, sonames))
63                 soname = None
64                 if len(sonames) == 1:
65                         soname = sonames[0]
66                 elif len(sonames) > 1:
67                         lead = bb.data.getVar('LEAD_SONAME', d, 1)
68                         if lead:
69                                 r = re.compile(lead)
70                                 filtered = []
71                                 for s in sonames:
72                                         if r.match(s):
73                                                 filtered.append(s)
74                                 if len(filtered) == 1:
75                                         soname = filtered[0]
76                                 elif len(filtered) > 1:
77                                         bb.note("Multiple matches (%s) for LEAD_SONAME '%s'" % (", ".join(filtered), lead))
78                                 else:
79                                         bb.note("Multiple libraries (%s) found, but LEAD_SONAME '%s' doesn't match any of them" % (", ".join(sonames), lead))
80                         else:
81                                 bb.note("Multiple libraries (%s) found and LEAD_SONAME not defined" % ", ".join(sonames))
82
83                 if has_libs and not has_bins and soname:
84                         soname_result = socrunch(soname)
85                         if soname_result:
86                                 (pkgname, devname) = soname_result
87                                 for pkg in packages.split():
88                                         if (bb.data.getVar('PKG_' + pkg, d) or bb.data.getVar('DEBIAN_NOAUTONAME_' + pkg, d)):
89                                                 continue
90                                         if pkg == orig_pkg:
91                                                 newpkg = pkgname
92                                         else:
93                                                 newpkg = pkg.replace(orig_pkg, devname, 1)
94                                         if newpkg != pkg:
95                                                 bb.data.setVar('PKG_' + pkg, newpkg, d)
96
97         for pkg in (bb.data.getVar('AUTO_LIBNAME_PKGS', d, 1) or "").split():
98                 auto_libname(packages, pkg)
99 }
100
101 EXPORT_FUNCTIONS package_name_hook
102
103 DEBIAN_NAMES = "1"
104