meta-*: use SUMMARY instead of DESCRIPTION where appropriate (max. 80 chars)
[opendreambox.git] / meta-opendreambox / recipes-multimedia / v4l-dvb / v4l-dvb-modules.inc
1 SUMMARY = "v4l-dvb drivers"
2 HOMEPAGE = "http://linuxtv.org/"
3 SECTION = "kernel/modules"
4 LICENSE = "GPLv2"
5 LIC_FILES_CHKSUM = "file://COPYING;md5=a907e355dcd2c89b14aa4dbcb7764d4f"
6 INC_PR = "r3"
7
8 inherit module
9
10 PACKAGES_DYNAMIC += "v4l-dvb-module-*"
11 PACKAGES_DYNAMIC += "v4l-dvb-firmware-*"
12
13 do_configure() {
14         install -m 0644 ${WORKDIR}/defconfig ${S}/v4l/.config
15 }
16
17 do_compile() {
18         unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
19         oe_runmake DIR="${STAGING_KERNEL_DIR}" ${MAKE_TARGETS}
20 }
21
22 do_install() {
23         unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
24         oe_runmake DIR="${STAGING_KERNEL_DIR}" DEPMOD=echo DESTDIR="${D}" install
25 }
26
27 PACKAGES = "v4l-dvb-modules"
28 FILES_${PN} = ""
29 ALLOW_EMPTY_${PN} = "1"
30
31 pkg_postinst_modules() {
32 if [ -z "$D" ]; then
33         depmod -a
34         update-modules || true
35 fi
36 }
37
38 pkg_postrm_modules() {
39 update-modules || true
40 }
41
42 autoload_postinst_fragment() {
43 if [ x"$D" = "x" ]; then
44         modprobe %s || true
45 fi
46 }
47
48 python populate_packages_prepend() {
49         import os
50         def extract_modinfo(file):
51                 import tempfile, re
52                 tempfile.tempdir = bb.data.getVar("WORKDIR", d, 1)
53                 tf = tempfile.mkstemp()
54                 tmpfile = tf[1]
55                 cmd = "PATH=\"%s\" %sobjcopy -j .modinfo -O binary %s %s" % (bb.data.getVar("PATH", d, 1), bb.data.getVar("HOST_PREFIX", d, 1) or "", file, tmpfile)
56                 os.system(cmd)
57                 f = open(tmpfile)
58                 l = f.read().split("\000")
59                 f.close()
60                 os.close(tf[0])
61                 os.unlink(tmpfile)
62                 exp = re.compile("([^=]+)=(.*)")
63                 vals = {}
64                 for i in l:
65                         m = exp.match(i)
66                         if not m:
67                                 continue
68                         vals[m.group(1)] = m.group(2)
69                 return vals
70
71         def parse_depmod():
72                 import re
73
74                 dvar = bb.data.getVar('PKGD', d, 1)
75                 if not dvar:
76                         bb.error("D not defined")
77                         return
78
79                 kernelver = bb.data.getVar('KERNEL_VERSION', d, 1)
80                 kernelver_stripped = kernelver
81                 m = re.match('^(.*-hh.*)[\.\+].*$', kernelver)
82                 if m:
83                         kernelver_stripped = m.group(1)
84                 path = bb.data.getVar("PATH", d, 1)
85                 host_prefix = bb.data.getVar("HOST_PREFIX", d, 1) or ""
86                 major_version = bb.data.getVar('KERNEL_MAJOR_VERSION', d, 1)
87
88                 cmd = "PATH=\"%s\" %sdepmod-%s -n -a -r -b %s -F %s/boot/System.map-%s %s" % (path, host_prefix, major_version, dvar, dvar, kernelver, kernelver_stripped)
89                 f = os.popen(cmd, 'r')
90
91                 deps = {}
92                 pattern0 = "^(.*\.k?o):..*$"
93                 pattern1 = "^(.*\.k?o):\s*(.*\.k?o)\s*$"
94                 pattern2 = "^(.*\.k?o):\s*(.*\.k?o)\s*\\\$"
95                 pattern3 = "^\t(.*\.k?o)\s*\\\$"
96                 pattern4 = "^\t(.*\.k?o)\s*$"
97
98                 line = f.readline()
99                 while line:
100                         if not re.match(pattern0, line):
101                                 line = f.readline()
102                                 continue
103                         m1 = re.match(pattern1, line)
104                         if m1:
105                                 deps[m1.group(1)] = m1.group(2).split()
106                         else:
107                                 m2 = re.match(pattern2, line)
108                                 if m2:
109                                         deps[m2.group(1)] = m2.group(2).split()
110                                         line = f.readline()
111                                         m3 = re.match(pattern3, line)
112                                         while m3:
113                                                 deps[m2.group(1)].extend(m3.group(1).split())
114                                                 line = f.readline()
115                                                 m3 = re.match(pattern3, line)
116                                         m4 = re.match(pattern4, line)
117                                         deps[m2.group(1)].extend(m4.group(1).split())
118                         line = f.readline()
119                 f.close()
120                 return deps
121
122         def get_dependencies(file, pattern, format):
123                 file = file.replace(bb.data.getVar('PKGD', d, 1) or '', '', 1)
124
125                 if module_deps.has_key(file):
126                         import re
127                         dependencies = []
128                         for i in module_deps[file]:
129                                 m = re.match(pattern, os.path.basename(i))
130                                 if not m:
131                                         continue
132                                 on = legitimize_package_name(m.group(1))
133                                 dependency_pkg = format % on
134                                 dependencies.append(dependency_pkg)
135                         return dependencies
136                 return []
137
138         def frob_metadata(file, pkg, pattern, format, basename):
139                 import re
140                 vals = extract_modinfo(file)
141
142                 dvar = bb.data.getVar('PKGD', d, 1)
143
144                 # If autoloading is requested, output /etc/modutils/<name> and append
145                 # appropriate modprobe commands to the postinst
146                 autoload = bb.data.getVar('module_autoload_%s' % basename, d, 1)
147                 if not autoload:
148                     # Also, try canonical name with dashes
149                     autoload = bb.data.getVar('module_autoload_%s' % basename.replace('_', '-'), d, 1)
150                 if autoload:
151                         name = '%s/etc/modutils/%s' % (dvar, basename)
152                         f = open(name, 'w')
153                         for m in autoload.split():
154                                 f.write('%s\n' % m)
155                         f.close()
156                         postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1)
157                         if not postinst:
158                                 bb.fatal("pkg_postinst_%s not defined" % pkg)
159                         postinst += bb.data.getVar('autoload_postinst_fragment', d, 1) % autoload
160                         bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
161
162                 # Write out any modconf fragment
163                 modconf = bb.data.getVar('module_conf_%s' % basename, d, 1)
164                 if modconf:
165                         if bb.data.getVar("KERNEL_MAJOR_VERSION", d, 1) == "2.6":
166                                 name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename)
167                         else:
168                                 name = '%s/etc/modutils/%s.conf' % (dvar, basename)
169                         f = open(name, 'w')
170                         f.write("%s\n" % modconf)
171                         f.close()
172
173                 files = bb.data.getVar('FILES_%s' % pkg, d, 1)
174                 files = "%s /etc/modutils/%s /etc/modutils/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename, basename)
175                 bb.data.setVar('FILES_%s' % pkg, files, d)
176
177                 if vals.has_key("description"):
178                         old_desc = bb.data.getVar('DESCRIPTION_' + pkg, d, 1) or ""
179                         bb.data.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"], d)
180
181                 rdepends_str = bb.data.getVar('RDEPENDS_' + pkg, d, 1)
182                 if rdepends_str:
183                         rdepends = rdepends_str.split()
184                 else:
185                         rdepends = []
186                 rdepends.extend(get_dependencies(file, pattern, format))
187                 bb.data.setVar('RDEPENDS_' + pkg, ' '.join(rdepends), d)
188
189         module_deps = parse_depmod()
190         module_regex = '^(.*)\.k?o$'
191         module_pattern = 'v4l-dvb-module-%s'
192
193         postinst = bb.data.getVar('pkg_postinst_modules', d, 1)
194         postrm = bb.data.getVar('pkg_postrm_modules', d, 1)
195
196         maybe_update_modules = "update-modules "
197         if bb.data.getVar("ONLINE_PACKAGE_MANAGEMENT", d) == "none":
198                 maybe_update_modules = ""
199
200         do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.bin$', output_pattern='v4l-dvb-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='')
201         do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.fw$', output_pattern='v4l-dvb-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='')
202         do_split_packages(d, root='/lib/modules', file_regex=module_regex, output_pattern=module_pattern, description='%s kernel module', postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata, extra_depends='%skernel-%s' % (maybe_update_modules, bb.data.getVar("KERNEL_VERSION", d, 1)))
203
204         import re
205         metapkg = bb.data.getVar('PN', d, 1)
206         bb.data.setVar('ALLOW_EMPTY_' + metapkg, "1", d)
207         bb.data.setVar('FILES_' + metapkg, "", d)
208         blacklist = []
209         for l in module_deps.values():
210                 for i in l:
211                         pkg = module_pattern % legitimize_package_name(re.match(module_regex, os.path.basename(i)).group(1))
212                         blacklist.append(pkg)
213         metapkg_rdepends = []
214         packages = bb.data.getVar('PACKAGES', d, 1).split()
215         for pkg in packages[1:]:
216                 if not pkg in blacklist and not pkg in metapkg_rdepends:
217                         metapkg_rdepends.append(pkg)
218                 p = pkg.find('v4l-dvb-module')
219                 if p != -1:
220                         name = pkg.split('-')[-1]
221                         bb.data.setVar('RREPLACES_' + pkg, 'kernel-module-' + name, d)
222                         bb.data.setVar('RCONFLICTS_' + pkg, 'kernel-module-' + name, d)
223         bb.data.setVar('RDEPENDS_' + metapkg, ' '.join(metapkg_rdepends), d)
224         bb.data.setVar('DESCRIPTION_' + metapkg, 'v4l-dvb modules meta package', d)
225 }