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