merge of '603b2d0c7e4ad80e5779bd3bbdb822331cc0ea2b'
[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_ipk[rdeptask] = "do_package"
11 do_package_write_deb[rdeptask] = "do_package"
12 do_package_write_tar[rdeptask] = "do_package"
13 do_package_write_rpm[rdeptask] = "do_package"
14
15 python debian_package_name_hook () {
16         import glob, copy, stat, errno, re
17
18         workdir = bb.data.getVar('WORKDIR', d, 1)
19         packages = bb.data.getVar('PACKAGES', d, 1)
20
21         def socrunch(s):
22                 s = s.lower().replace('_', '-')
23                 m = re.match("^(.*)(.)\.so\.(.*)$", s)
24                 if m is None:
25                         return None
26                 if m.group(2) in '0123456789':
27                         bin = '%s%s-%s' % (m.group(1), m.group(2), m.group(3))
28                 else:
29                         bin = m.group(1) + m.group(2) + m.group(3)
30                 dev = m.group(1) + m.group(2)
31                 return (bin, dev)
32
33         def isexec(path):
34                 try:
35                         s = os.stat(path)
36                 except (os.error, AttributeError):
37                         return 0
38                 return (s[stat.ST_MODE] & stat.S_IEXEC)
39
40         def auto_libname(packages, orig_pkg):
41                 bin_re = re.compile(".*/s?bin$")
42                 lib_re = re.compile(".*/lib$")
43                 so_re = re.compile("lib.*\.so")
44                 sonames = []
45                 has_bins = 0
46                 has_libs = 0
47                 pkg_dir = os.path.join(workdir, "install", orig_pkg)
48                 for root, dirs, files in os.walk(pkg_dir):
49                         if bin_re.match(root) and files:
50                                 has_bins = 1
51                         if lib_re.match(root) and files:
52                                 has_libs = 1
53                                 for f in files:
54                                         if so_re.match(f):
55                                                 fp = os.path.join(root, f)
56                                                 cmd = (bb.data.getVar('BUILD_PREFIX', d, 1) or "") + "objdump -p " + fp + " 2>/dev/null"
57                                                 fd = os.popen(cmd)
58                                                 lines = fd.readlines()
59                                                 fd.close()
60                                                 for l in lines:
61                                                         m = re.match("\s+SONAME\s+([^\s]*)", l)
62                                                         if m and not m.group(1) in sonames:
63                                                                 sonames.append(m.group(1))
64
65                 bb.debug(1, 'LIBNAMES: pkg %s libs %d bins %d sonames %s' % (orig_pkg, has_libs, has_bins, sonames))
66                 soname = None
67                 if len(sonames) == 1:
68                         soname = sonames[0]
69                 elif len(sonames) > 1:
70                         lead = bb.data.getVar('LEAD_SONAME', d, 1)
71                         if lead:
72                                 r = re.compile(lead)
73                                 filtered = []
74                                 for s in sonames:
75                                         if r.match(s):
76                                                 filtered.append(s)
77                                 if len(filtered) == 1:
78                                         soname = filtered[0]
79                                 elif len(filtered) > 1:
80                                         bb.note("Multiple matches (%s) for LEAD_SONAME '%s'" % (", ".join(filtered), lead))
81                                 else:
82                                         bb.note("Multiple libraries (%s) found, but LEAD_SONAME '%s' doesn't match any of them" % (", ".join(sonames), lead))
83                         else:
84                                 bb.note("Multiple libraries (%s) found and LEAD_SONAME not defined" % ", ".join(sonames))
85
86                 if has_libs and not has_bins and soname:
87                         soname_result = socrunch(soname)
88                         if soname_result:
89                                 (pkgname, devname) = soname_result
90                                 for pkg in packages.split():
91                                         if (bb.data.getVar('PKG_' + pkg, d) or bb.data.getVar('DEBIAN_NOAUTONAME_' + pkg, d)):
92                                                 continue
93                                         if pkg == orig_pkg:
94                                                 newpkg = pkgname
95                                         else:
96                                                 newpkg = pkg.replace(orig_pkg, devname, 1)
97                                         if newpkg != pkg:
98                                                 bb.data.setVar('PKG_' + pkg, newpkg, d)
99
100         for pkg in (bb.data.getVar('AUTO_LIBNAME_PKGS', d, 1) or "").split():
101                 auto_libname(packages, pkg)
102 }
103
104 EXPORT_FUNCTIONS package_name_hook
105
106 DEBIAN_NAMES = "1"
107