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