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