summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2009-09-12 22:05:48 +0200
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>2009-09-12 22:05:48 +0200
commit01ae9e3573c2b218b31323c9e26553324649c28e (patch)
tree88a0bf2d8c45a7255c79c60a1d54757bb9faf2eb
downloaddebianrt-kbuild-01ae9e3573c2b218b31323c9e26553324649c28e.tar.gz
debianrt-kbuild-01ae9e3573c2b218b31323c9e26553324649c28e.tar.xz
svn://svn.debian.org/kernel/dists/trunk/linux-kbuild-2.6@13259
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
-rw-r--r--Makefile12
-rw-r--r--Makefile.inc48
-rwxr-xr-xdebian/bin/gencontrol.py123
-rwxr-xr-xdebian/bin/genorig.py116
-rw-r--r--debian/changelog103
-rw-r--r--debian/compat1
-rw-r--r--debian/copyright32
-rw-r--r--debian/lib/python/debian_linux/__init__.py0
-rw-r--r--debian/lib/python/debian_linux/config.py209
-rw-r--r--debian/lib/python/debian_linux/debian.py344
-rw-r--r--debian/lib/python/debian_linux/gencontrol.py312
-rw-r--r--debian/lib/python/debian_linux/utils.py100
-rwxr-xr-xdebian/rules77
-rw-r--r--debian/rules.defs4
-rw-r--r--debian/rules.real38
-rw-r--r--debian/templates/control.main.in7
-rw-r--r--debian/templates/control.source.in7
-rw-r--r--scripts/Makefile46
-rw-r--r--scripts/basic/Makefile11
-rw-r--r--scripts/genksyms/Makefile24
-rw-r--r--scripts/kconfig/Makefile24
-rw-r--r--scripts/mod/Makefile26
-rw-r--r--scripts/mod/Makefile.real14
-rw-r--r--scripts/mod/elfconfig.h7
-rwxr-xr-xscripts/mod/gendef.py20
-rw-r--r--scripts/mod/modpost.c72
-rw-r--r--scripts/mod/real-lsb-32/elfconfig.h4
-rw-r--r--scripts/mod/real-lsb-64/elfconfig.h4
-rw-r--r--scripts/mod/real-msb-32/elfconfig.h4
-rw-r--r--scripts/mod/real-msb-64/elfconfig.h4
30 files changed, 1793 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..1ca911f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,12 @@
+DATA = \
+ Kbuild \
+ Makefile \
+
+SUBDIRS = \
+ scripts
+
+OUTDIR = .
+
+top_srcdir = .
+
+include $(top_srcdir)/Makefile.inc
diff --git a/Makefile.inc b/Makefile.inc
new file mode 100644
index 0000000..c3e5577
--- /dev/null
+++ b/Makefile.inc
@@ -0,0 +1,48 @@
+SHELL = /bin/sh -e
+
+CC = gcc
+CXX = g++
+CFLAGS ?= -O2 -Wall
+CXXFLAGS = $(CFLAGS)
+
+all: all-local all-recursive
+clean: clean-local clean-recursive
+install: install-local install-recursive
+
+%-recursive:
+ +@list='$(SUBDIRS)'; \
+ for subdir in $$list; do \
+ echo "Making $* in $$subdir"; \
+ $(MAKE) -C $$subdir $* \
+ || exit 1; \
+ done
+
+all-local: $(PROGS)
+
+clean-local::
+ rm -f $(PROGS) *.o
+
+install-local: install-local-progs install-local-scripts install-local-data
+
+install-local-progs: $(PROGS)
+ @for p in $^; do \
+ echo " install -m755 '$$p' '$(prefix)/$(OUTDIR)'"; \
+ install -D -m755 "$$p" "$(prefix)/$(OUTDIR)/$$(basename $$p)"; \
+ done
+
+SCRIPTS_REAL = $(addprefix $(top_srcdir)/kbuild/$(OUTDIR)/,$(SCRIPTS))
+
+install-local-scripts: $(SCRIPTS_REAL)
+ @for p in $^; do \
+ echo " install -m755 '$$p' '$(prefix)/$(OUTDIR)'"; \
+ install -D -m755 "$$p" "$(prefix)/$(OUTDIR)/$$(basename $$p)"; \
+ done
+
+DATA_REAL = $(addprefix $(top_srcdir)/kbuild/$(OUTDIR)/,$(DATA))
+
+install-local-data: $(DATA_REAL)
+ @for p in $^; do \
+ echo " install -m644 '$$p' '$(prefix)/$(OUTDIR)'"; \
+ install -D -m644 "$$p" "$(prefix)/$(OUTDIR)/$$(basename $$p)"; \
+ done
+
diff --git a/debian/bin/gencontrol.py b/debian/bin/gencontrol.py
new file mode 100755
index 0000000..2fdcdfd
--- /dev/null
+++ b/debian/bin/gencontrol.py
@@ -0,0 +1,123 @@
+#!/usr/bin/env python2.4
+
+import sys
+sys.path.append("debian/lib/python")
+
+from debian_linux.debian import *
+from debian_linux.gencontrol import PackagesList, Makefile, MakeFlags
+from debian_linux.utils import *
+
+class gencontrol(object):
+ makefile_targets = ('binary-arch', 'build')
+
+ def __init__(self, underlay = None):
+ self.templates = Templates(['debian/templates'])
+ self.process_changelog()
+
+ def __call__(self):
+ packages = PackagesList()
+ makefile = Makefile()
+
+ self.do_source(packages)
+ self.do_main(packages, makefile)
+
+ self.write_control(packages.itervalues())
+ self.write_makefile(makefile)
+
+ def do_source(self, packages):
+ source = self.templates["control.source"]
+ packages['source'] = self.process_package(source[0], self.vars)
+
+ def do_main(self, packages, makefile):
+ vars = self.vars.copy()
+ makeflags = MakeFlags()
+
+ self.do_main_setup(vars, makeflags)
+ self.do_main_packages(packages)
+ self.do_main_makefile(makefile, makeflags)
+
+ def do_main_setup(self, vars, makeflags):
+ makeflags.update({
+ 'MAJOR': self.version.linux_major,
+ 'VERSION': self.version.linux_version,
+ 'UPSTREAMVERSION': self.version.linux_upstream,
+ })
+
+ def do_main_makefile(self, makefile, makeflags):
+ for i in self.makefile_targets:
+ makefile.add(i, cmds = ["$(MAKE) -f debian/rules.real %s %s" % (i, makeflags)])
+
+ def do_main_packages(self, packages):
+ main = self.templates["control.main"]
+ packages.extend(self.process_packages(main, self.vars))
+
+ def process_changelog(self):
+ changelog = Changelog(version = VersionLinux)
+ self.version = version = changelog[0].version
+ self.vars = {
+ 'upstreamversion': version.linux_upstream,
+ 'version': version.linux_version,
+ 'source_upstream': version.upstream,
+ 'major': version.linux_major,
+ }
+
+ def process_relation(self, key, e, in_e, vars):
+ import copy
+ dep = copy.deepcopy(in_e[key])
+ for groups in dep:
+ for item in groups:
+ item.name = self.substitute(item.name, vars)
+ e[key] = dep
+
+ def process_description(self, e, in_e, vars):
+ in_desc = in_e['Description']
+ desc = in_desc.__class__()
+ desc.short = self.substitute(in_desc.short, vars)
+ for i in in_desc.long:
+ desc.append(self.substitute(i, vars))
+ e['Description'] = desc
+
+ def process_package(self, in_entry, vars):
+ e = Package()
+ for key, value in in_entry.iteritems():
+ if isinstance(value, PackageRelation):
+ self.process_relation(key, e, in_entry, vars)
+ elif key == 'Description':
+ self.process_description(e, in_entry, vars)
+ elif key[:2] == 'X-':
+ pass
+ else:
+ e[key] = self.substitute(value, vars)
+ return e
+
+ def process_packages(self, in_entries, vars):
+ entries = []
+ for i in in_entries:
+ entries.append(self.process_package(i, vars))
+ return entries
+
+ def substitute(self, s, vars):
+ if isinstance(s, (list, tuple)):
+ for i in xrange(len(s)):
+ s[i] = self.substitute(s[i], vars)
+ return s
+ def subst(match):
+ return vars[match.group(1)]
+ return re.sub(r'@([a-z_]+)@', subst, s)
+
+ def write_control(self, list):
+ self.write_rfc822(file("debian/control", 'w'), list)
+
+ def write_makefile(self, makefile):
+ f = file("debian/rules.gen", 'w')
+ makefile.write(f)
+ f.close()
+
+ def write_rfc822(self, f, list):
+ for entry in list:
+ for key, value in entry.iteritems():
+ f.write("%s: %s\n" % (key, value))
+ f.write('\n')
+
+if __name__ == '__main__':
+ gencontrol()()
diff --git a/debian/bin/genorig.py b/debian/bin/genorig.py
new file mode 100755
index 0000000..e01ca97
--- /dev/null
+++ b/debian/bin/genorig.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+
+import sys
+sys.path.append("debian/lib/python")
+
+import os, os.path, re, shutil
+from debian_linux.debian import Changelog, VersionLinux
+
+class Main(object):
+ def __init__(self, input_tar, input_patch, override_version):
+ self.log = sys.stdout.write
+
+ self.input_tar = input_tar
+ self.input_patch = input_patch
+
+ changelog = Changelog(version = VersionLinux)[0]
+ source = changelog.source
+ version = changelog.version
+
+ if override_version:
+ version = VersionLinux('%s-undef' % override_version)
+
+ self.log('Using source name %s, version %s\n' % (source, version.upstream))
+
+ self.orig = '%s-%s' % (source, version.upstream)
+ self.orig_tar = '%s_%s.orig.tar.gz' % (source, version.upstream)
+
+ def __call__(self):
+ import tempfile
+ self.dir = tempfile.mkdtemp(prefix = 'genorig', dir = 'debian')
+ try:
+ self.upstream_extract()
+ self.upstream_patch()
+ self.generate()
+ self.tar()
+ finally:
+ shutil.rmtree(self.dir)
+
+ def upstream_extract(self):
+ self.log("Extracting tarball %s\n" % self.input_tar)
+ match = re.match(r'(^|.*/)(?P<dir>linux-[\d.]+(-\S+)?)\.tar(\.(?P<extension>(bz2|gz)))?$', self.input_tar)
+ if not match:
+ raise RuntimeError("Can't identify name of tarball")
+ cmdline = ['tar -xf', self.input_tar, '-C', self.dir]
+ if match.group('extension') == 'bz2':
+ cmdline.append('-j')
+ elif match.group('extension') == 'gz':
+ cmdline.append('-z')
+ if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)]):
+ raise RuntimeError("Can't extract tarball")
+ os.rename(os.path.join(self.dir, match.group('dir')), os.path.join(self.dir, 'temp'))
+
+ def upstream_patch(self):
+ if self.input_patch is None:
+ return
+ self.log("Patching source with %s\n" % self.input_patch)
+ match = re.match(r'(^|.*/)patch-\d+\.\d+\.\d+(-\S+?)?(\.(?P<extension>(bz2|gz)))?$', self.input_patch)
+ if not match:
+ raise RuntimeError("Can't identify name of patch")
+ cmdline = []
+ if match.group('extension') == 'bz2':
+ cmdline.append('bzcat')
+ elif match.group('extension') == 'gz':
+ cmdline.append('zcat')
+ else:
+ cmdline.append('cat')
+ cmdline.append(self.input_patch)
+ cmdline.append('| (cd %s; patch -p1 -f -s -t --no-backup-if-mismatch)' % os.path.join(self.dir, 'temp'))
+ if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)]):
+ raise RuntimeError("Can't patch source")
+
+ def generate(self):
+ self.log("Generate orig\n")
+ orig = os.path.join(self.dir, self.orig, 'kbuild')
+ temp = os.path.join(self.dir, 'temp')
+ os.makedirs(os.path.join(orig, 'include', 'linux'))
+ for i in 'COPYING', 'Kbuild', 'Makefile':
+ shutil.copyfile(os.path.join(temp, i), os.path.join(orig, i))
+ for i in 'input.h', 'license.h', 'mod_devicetable.h':
+ shutil.copyfile(os.path.join(temp, 'include', 'linux', i), os.path.join(orig, 'include', 'linux', i))
+ shutil.copytree(os.path.join(temp, 'scripts'), os.path.join(orig, 'scripts'))
+
+ def tar(self):
+ out = os.path.join("../orig", self.orig_tar)
+ try:
+ os.mkdir("../orig")
+ except OSError: pass
+ try:
+ os.stat(out)
+ raise RuntimeError("Destination already exists")
+ except OSError: pass
+ self.log("Generate tarball %s\n" % out)
+ cmdline = ['tar -czf', out, '-C', self.dir, self.orig]
+ try:
+ if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)]):
+ raise RuntimeError("Can't patch source")
+ os.chmod(out, 0644)
+ except:
+ try:
+ os.unlink(out)
+ except OSError:
+ pass
+ raise
+
+if __name__ == '__main__':
+ from optparse import OptionParser
+ parser = OptionParser(usage = "%prog [OPTION]... TAR [PATCH]")
+ parser.add_option("-V", "--override-version", dest = "override_version", help = "Override version", metavar = "VERSION")
+ options, args = parser.parse_args()
+
+ input_tar = args[0]
+ input_patch = None
+ if len(args) > 1:
+ input_patch = args[1]
+
+ Main(input_tar, input_patch, options.override_version)()
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..7c5b48b
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,103 @@
+linux-kbuild-2.6 (2.6.29-1) unstable; urgency=low
+
+ * New upstream version.
+ * Autogenerate list of supported options in modpost. (closes: #518961)
+ - Build-depend against python.
+ * Use debhelper compat level 7.
+
+ -- Bastian Blank <waldi@debian.org> Thu, 26 Mar 2009 12:54:47 +0100
+
+linux-kbuild-2.6 (2.6.28-1) unstable; urgency=low
+
+ * New upstream version.
+
+ -- Bastian Blank <waldi@debian.org> Sun, 22 Feb 2009 13:45:39 +0100
+
+linux-kbuild-2.6 (2.6.26-3) unstable; urgency=low
+
+ * Fix recursive installation. (closes: #494435)
+
+ -- Bastian Blank <waldi@debian.org> Sun, 10 Aug 2008 13:01:41 +0200
+
+linux-kbuild-2.6 (2.6.26-2) unstable; urgency=low
+
+ * Include new scripts. (closes: #494435)
+
+ -- Bastian Blank <waldi@debian.org> Sat, 09 Aug 2008 20:45:12 +0200
+
+linux-kbuild-2.6 (2.6.26-1) unstable; urgency=low
+
+ * New upstream version.
+ * modpost: Support new parameters.
+
+ -- Bastian Blank <waldi@debian.org> Sat, 02 Aug 2008 13:09:54 +0200
+
+linux-kbuild-2.6 (2.6.25-2) unstable; urgency=low
+
+ * modpost: Support new parameters. (closes: #479271)
+
+ -- Bastian Blank <waldi@debian.org> Mon, 05 May 2008 19:58:40 +0200
+
+linux-kbuild-2.6 (2.6.25-1) unstable; urgency=low
+
+ * New upstream version.
+
+ -- Bastian Blank <waldi@debian.org> Fri, 02 May 2008 10:32:13 +0200
+
+linux-kbuild-2.6 (2.6.24-1) unstable; urgency=low
+
+ * New upstream version.
+
+ -- Bastian Blank <waldi@debian.org> Tue, 29 Jan 2008 14:03:06 +0100
+
+linux-kbuild-2.6 (2.6.23-1) unstable; urgency=low
+
+ * New upstream version.
+ * modpost: Support -s.
+
+ -- Bastian Blank <waldi@debian.org> Wed, 05 Dec 2007 08:23:28 +0100
+
+linux-kbuild-2.6 (2.6.22-1) unstable; urgency=low
+
+ * New upstream version.
+ * Don't fail if no module is specified.
+
+ -- Bastian Blank <waldi@debian.org> Tue, 17 Jul 2007 23:14:23 +0200
+
+linux-kbuild-2.6 (2.6.21-1) unstable; urgency=low
+
+ * New upstream version.
+
+ -- Bastian Blank <waldi@debian.org> Fri, 18 May 2007 23:45:14 +0200
+
+linux-kbuild-2.6 (2.6.20-1) unstable; urgency=low
+
+ * New upstream version.
+ * modpost: Support -w.
+
+ -- Bastian Blank <waldi@debian.org> Thu, 12 Apr 2007 06:53:00 +0200
+
+linux-kbuild-2.6 (2.6.18-1) unstable; urgency=low
+
+ * New upstream version.
+ * Use included headers. (closes: #382286, #384211)
+
+ -- Bastian Blank <waldi@debian.org> Mon, 25 Sep 2006 21:45:50 +0200
+
+linux-kbuild-2.6 (2.6.17-3) unstable; urgency=low
+
+ * Replace own modpost with original one.
+
+ -- Bastian Blank <waldi@debian.org> Tue, 1 Aug 2006 11:01:18 +0200
+
+linux-kbuild-2.6 (2.6.17-2) unstable; urgency=low
+
+ * Fix uninitialied variable. (closes: #377656)
+
+ -- Bastian Blank <waldi@debian.org> Tue, 11 Jul 2006 10:10:24 +0200
+
+linux-kbuild-2.6 (2.6.17-1) unstable; urgency=low
+
+ * Initial release. (closes: #368544)
+
+ -- Bastian Blank <waldi@debian.org> Sat, 1 Jul 2006 19:10:07 +0200
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..7f8f011
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+7
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..fc6c007
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,32 @@
+This is the Debian GNU/Linux prepackaged version of the Linux kernel.
+
+It was downloaded from http://ftp.kernel.org/pub/linux/kernel/.
+
+Copyright:
+
+ Copyright (C) 1996, 1997 Linux International
+ 2000, 2006 IBM Corporation
+ 2002, 2003 Kai Germaschewski
+ 2002-2004 Rusty Russell
+ 2002-2005 Roman Zippel
+ and others
+
+License:
+
+ This package is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation.
+
+ This package is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this package; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+On Debian systems, the complete text of the GNU General Public License version
+2 can be found in `/usr/share/common-licenses/GPL-2'.
+
+The Debian packaging is licensed under the GPL v2, see above.
diff --git a/debian/lib/python/debian_linux/__init__.py b/debian/lib/python/debian_linux/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/debian/lib/python/debian_linux/__init__.py
diff --git a/debian/lib/python/debian_linux/config.py b/debian/lib/python/debian_linux/config.py
new file mode 100644
index 0000000..7e3e12a
--- /dev/null
+++ b/debian/lib/python/debian_linux/config.py
@@ -0,0 +1,209 @@
+import os, os.path, re, sys, textwrap
+
+__all__ = [
+ 'ConfigParser',
+ 'ConfigReaderCore',
+]
+
+class SchemaItemBoolean(object):
+ def __call__(self, i):
+ i = i.strip().lower()
+ if i in ("true", "1"):
+ return True
+ if i in ("false", "0"):
+ return False
+ raise Error
+
+class SchemaItemList(object):
+ def __init__(self, type = "\s+"):
+ self.type = type
+
+ def __call__(self, i):
+ i = i.strip()
+ if not i:
+ return []
+ return [j.strip() for j in re.split(self.type, i)]
+
+class ConfigReaderCore(dict):
+ config_name = "defines"
+
+ schemas = {
+ 'base': {
+ 'arches': SchemaItemList(),
+ 'enabled': SchemaItemBoolean(),
+ 'featuresets': SchemaItemList(),
+ 'flavours': SchemaItemList(),
+ 'modules': SchemaItemBoolean(),
+ },
+ 'image': {
+ 'configs': SchemaItemList(),
+ 'initramfs': SchemaItemBoolean(),
+ 'initramfs-generators': SchemaItemList(),
+ },
+ 'relations': {
+ },
+ 'xen': {
+ 'dom0-support': SchemaItemBoolean(),
+ 'versions': SchemaItemList(),
+ }
+ }
+
+ def __init__(self, dirs = []):
+ self._dirs = dirs
+ self._read_base()
+
+ def _read_arch(self, arch):
+ config = ConfigParser(self.schemas)
+ config.read(self.get_files("%s/%s" % (arch, self.config_name)))
+
+ featuresets = config['base',].get('featuresets', [])
+ flavours = config['base',].get('flavours', [])
+
+ for section in iter(config):
+ if section[0] in featuresets:
+ real = (section[-1], arch, section[0])
+ elif len(section) > 1:
+ real = (section[-1], arch, None) + section[:-1]
+ else:
+ real = (section[-1], arch) + section[:-1]
+ s = self.get(real, {})
+ s.update(config[section])
+ self[tuple(real)] = s
+
+ for featureset in featuresets:
+ self._read_arch_featureset(arch, featureset)
+
+ if flavours:
+ base = self['base', arch]
+ featuresets.insert(0, 'none')
+ base['featuresets'] = featuresets
+ del base['flavours']
+ self['base', arch] = base
+ self['base', arch, 'none'] = {'flavours': flavours, 'implicit-flavour': True}
+
+ def _read_arch_featureset(self, arch, featureset):
+ config = ConfigParser(self.schemas)
+ config.read(self.get_files("%s/%s/%s" % (arch, featureset, self.config_name)))
+
+ flavours = config['base',].get('flavours', [])
+
+ for section in iter(config):
+ real = (section[-1], arch, featureset) + section[:-1]
+ s = self.get(real, {})
+ s.update(config[section])
+ self[tuple(real)] = s
+
+ def _read_base(self):
+ config = ConfigParser(self.schemas)
+ config.read(self.get_files(self.config_name))
+
+ arches = config['base',]['arches']
+ featuresets = config['base',]['featuresets']
+
+ for section in iter(config):
+ if section[0].startswith('featureset-'):
+ real = (section[-1], None, section[0].lstrip('featureset-'))
+ else:
+ real = (section[-1],) + section[1:]
+ self[real] = config[section]
+
+ for arch in arches:
+ self._read_arch(arch)
+ for featureset in featuresets:
+ self._read_featureset(featureset)
+
+ def _read_featureset(self, featureset):
+ config = ConfigParser(self.schemas)
+ config.read(self.get_files("featureset-%s/%s" % (featureset, self.config_name)))
+
+ for section in iter(config):
+ real = (section[-1], None, featureset)
+ s = self.get(real, {})
+ s.update(config[section])
+ self[real] = s
+
+ def get_files(self, name):
+ return [os.path.join(i, name) for i in self._dirs if i]
+
+ def merge(self, section, arch = None, featureset = None, flavour = None):
+ ret = {}
+ ret.update(self.get((section,), {}))
+ if featureset:
+ ret.update(self.get((section, None, featureset), {}))
+ if arch:
+ ret.update(self.get((section, arch), {}))
+ if arch and featureset:
+ ret.update(self.get((section, arch, featureset), {}))
+ if arch and featureset and flavour:
+ ret.update(self.get((section, arch, None, flavour), {}))
+ ret.update(self.get((section, arch, featureset, flavour), {}))
+ return ret
+
+class ConfigParser(object):
+ __slots__ = '_config', 'schemas'
+
+ def __init__(self, schemas):
+ self.schemas = schemas
+
+ from ConfigParser import RawConfigParser
+ self._config = config = RawConfigParser()
+
+ def __getitem__(self, key):
+ return self._convert()[key]
+
+ def __iter__(self):
+ return iter(self._convert())
+
+ def __str__(self):
+ return '<%s(%s)>' % (self.__class__.__name__, self._convert())
+
+ def _convert(self):
+ ret = {}
+ for section in self._config.sections():
+ data = {}
+ for key, value in self._config.items(section):
+ data[key] = value
+ s1 = section.split('_')
+ if s1[-1] in self.schemas:
+ ret[tuple(s1)] = self.SectionSchema(data, self.schemas[s1[-1]])
+ else:
+ ret[(section,)] = self.Section(data)
+ return ret
+
+ def keys(self):
+ return self._convert().keys()
+
+ def read(self, data):
+ return self._config.read(data)
+
+ class Section(dict):
+ def __init__(self, data):
+ super(ConfigParser.Section, self).__init__(data)
+
+ def __str__(self):
+ return '<%s(%s)>' % (self.__class__.__name__, self._data)
+
+ class SectionSchema(Section):
+ __slots__ = ()
+
+ def __init__(self, data, schema):
+ for key in data.keys():
+ try:
+ data[key] = schema[key](data[key])
+ except KeyError: pass
+ super(ConfigParser.SectionSchema, self).__init__(data)
+
+if __name__ == '__main__':
+ import sys
+ config = ConfigReaderCore(['debian/config'])
+ sections = config.keys()
+ sections.sort()
+ for section in sections:
+ print "[%s]" % (section,)
+ items = config[section]
+ items_keys = items.keys()
+ items_keys.sort()
+ for item in items:
+ print "%s: %s" % (item, items[item])
+ print
+
diff --git a/debian/lib/python/debian_linux/debian.py b/debian/lib/python/debian_linux/debian.py
new file mode 100644
index 0000000..3b5d98c
--- /dev/null
+++ b/debian/lib/python/debian_linux/debian.py
@@ -0,0 +1,344 @@
+import itertools, os.path, re, utils
+
+class Changelog(list):
+ _rules = r"""
+^
+(?P<source>
+ \w[-+0-9a-z.]+
+)
+\
+\(
+(?P<version>
+ [^\(\)\ \t]+
+)
+\)
+\s+
+(?P<distribution>
+ [-+0-9a-zA-Z.]+
+)
+\;
+"""
+ _re = re.compile(_rules, re.X)
+
+ class Entry(object):
+ __slot__ = 'distribution', 'source', 'version'
+
+ def __init__(self, distribution, source, version):
+ self.distribution, self.source, self.version = distribution, source, version
+
+ def __init__(self, dir = '', version = None):
+ if version is None:
+ version = Version
+ f = file(os.path.join(dir, "debian/changelog"))
+ while True:
+ line = f.readline()
+ if not line:
+ break
+ match = self._re.match(line)
+ if not match:
+ continue
+ try:
+ v = version(match.group('version'))
+ except Exception:
+ if not len(self):
+ raise
+ v = Version(match.group('version'))
+ self.append(self.Entry(match.group('distribution'), match.group('source'), v))
+
+class Version(object):
+ _version_rules = ur"""
+^
+(?:
+ (?P<epoch>
+ \d+
+ )
+ :
+)?
+(?P<upstream>
+ .+?
+)
+(?:
+ -
+ (?P<debian>[^-]+)
+)?
+$
+"""
+ _version_re = re.compile(_version_rules, re.X)
+
+ def __init__(self, version):
+ match = self._version_re.match(version)
+ if match is None:
+ raise RuntimeError, "Invalid debian version"
+ self.epoch = None
+ if match.group("epoch") is not None:
+ self.epoch = int(match.group("epoch"))
+ self.upstream = match.group("upstream")
+ self.debian = match.group("debian")
+
+ def __str__(self):
+ return self.complete
+
+ @property
+ def complete(self):
+ if self.epoch is not None:
+ return "%d:%s" % (self.epoch, self.complete_noepoch)
+ return self.complete_noepoch
+
+ @property
+ def complete_noepoch(self):
+ if self.debian is not None:
+ return "%s-%s" % (self.upstream, self.debian)
+ return self.upstream
+
+class VersionLinux(Version):
+ _version_linux_rules = ur"""
+^
+(?P<version>
+ (?P<major>\d+\.\d+)
+ \.
+ \d+
+)
+(?:
+ (\.\d+)
+ |
+ ~
+ (?P<modifier>
+ .+?
+ )
+)?
+(?:
+ \.dfsg\.
+ (?P<dfsg>
+ \d+
+ )
+)?
+-
+(?:[^-]+)
+$
+"""
+ _version_linux_re = re.compile(_version_linux_rules, re.X)
+
+ def __init__(self, version):
+ super(VersionLinux, self).__init__(version)
+ match = self._version_linux_re.match(version)
+ if match is None:
+ raise RuntimeError, "Invalid debian linux version"
+ d = match.groupdict()
+ self.linux_major = d['major']
+ self.linux_modifier = d['modifier']
+ self.linux_version = d['version']
+ if d['modifier'] is not None:
+ self.linux_upstream = '-'.join((d['version'], d['modifier']))
+ else:
+ self.linux_upstream = d['version']
+ self.linux_dfsg = d['dfsg']
+
+class PackageFieldList(list):
+ def __init__(self, value = None):
+ self.extend(value)
+
+ def __str__(self):
+ return ' '.join(self)
+
+ def _extend(self, value):
+ if value is not None:
+ self.extend([j.strip() for j in re.split('\s', value.strip())])
+
+ def extend(self, value):
+ if isinstance(value, str):
+ self._extend(value)
+ else:
+ super(PackageFieldList, self).extend(value)
+
+class PackageDescription(object):
+ __slots__ = "short", "long"
+
+ def __init__(self, value = None):
+ self.long = []
+ if value is not None:
+ self.short, long = value.split("\n", 1)
+ self.append(long)
+ else:
+ self.short = None
+
+ def __str__(self):
+ ret = self.short + '\n'
+ w = utils.TextWrapper(width = 74, fix_sentence_endings = True)
+ pars = []
+ for i in self.long:
+ pars.append('\n '.join(w.wrap(i)))
+ return self.short + '\n ' + '\n .\n '.join(pars)
+
+ def append(self, str):
+ str = str.strip()
+ if str:
+ self.long.extend(str.split("\n.\n"))
+
+class PackageRelation(list):
+ def __init__(self, value = None):
+ if value is not None:
+ self.extend(value)
+
+ def __str__(self):
+ return ', '.join([str(i) for i in self])
+
+ def _match(self, value):
+ for i in self:
+ if i._match(value):
+ return i
+ return None
+
+ def append(self, value):
+ if isinstance(value, basestring):
+ value = PackageRelationGroup(value)
+ elif not isinstance(value, PackageRelationGroup):
+ raise ValueError, "got %s" % type(value)
+ j = self._match(value)
+ if j:
+ j._updateArches(value)
+ else:
+ super(PackageRelation, self).append(value)
+
+ def extend(self, value):
+ if isinstance(value, basestring):
+ value = [j.strip() for j in re.split(',', value.strip())]
+ elif not isinstance(value, (list, tuple)):
+ raise ValueError, "got %s" % type(value)
+ for i in value:
+ self.append(i)
+
+class PackageRelationGroup(list):
+ def __init__(self, value = None):
+ if value is not None:
+ self.extend(value)
+
+ def __str__(self):
+ return ' | '.join([str(i) for i in self])
+
+ def _match(self, value):
+ for i, j in itertools.izip(self, value):
+ if i.name != j.name or i.version != j.version:
+ return None
+ return self
+
+ def _updateArches(self, value):
+ for i, j in itertools.izip(self, value):
+ if i.arches:
+ for arch in j.arches:
+ if arch not in i.arches:
+ i.arches.append(arch)
+
+ def append(self, value):
+ if isinstance(value, basestring):
+ value = PackageRelationEntry(value)
+ elif not isinstance(value, PackageRelationEntry):
+ raise ValueError
+ super(PackageRelationGroup, self).append(value)
+
+ def extend(self, value):
+ if isinstance(value, basestring):
+ value = [j.strip() for j in re.split('\|', value.strip())]
+ elif not isinstance(value, (list, tuple)):
+ raise ValueError
+ for i in value:
+ self.append(i)
+
+class PackageRelationEntry(object):
+ __slots__ = "name", "operator", "version", "arches"
+
+ _re = re.compile(r'^(\S+)(?: \((<<|<=|=|!=|>=|>>)\s*([^)]+)\))?(?: \[([^]]+)\])?$')
+
+ class _operator(object):
+ OP_LT = 1; OP_LE = 2; OP_EQ = 3; OP_NE = 4; OP_GE = 5; OP_GT = 6
+ operators = { '<<': OP_LT, '<=': OP_LE, '=': OP_EQ, '!=': OP_NE, '>=': OP_GE, '>>': OP_GT }
+ operators_neg = { OP_LT: OP_GE, OP_LE: OP_GT, OP_EQ: OP_NE, OP_NE: OP_EQ, OP_GE: OP_LT, OP_GT: OP_LE }
+ operators_text = dict([(b, a) for a, b in operators.iteritems()])
+
+ __slots__ = '_op',
+
+ def __init__(self, value):
+ self._op = self.operators[value]
+
+ def __neg__(self):
+ return self.__class__(self.operators_text[self.operators_neg[self._op]])
+
+ def __str__(self):
+ return self.operators_text[self._op]
+
+ def __init__(self, value = None):
+ if isinstance(value, basestring):
+ self.parse(value)
+ else:
+ raise ValueError
+
+ def __str__(self):
+ ret = [self.name]
+ if self.operator is not None and self.version is not None:
+ ret.extend([' (', str(self.operator), ' ', self.version, ')'])
+ if self.arches:
+ ret.extend([' [', ' '.join(self.arches), ']'])
+ return ''.join(ret)
+
+ def parse(self, value):
+ match = self._re.match(value)
+ if match is None:
+ raise RuntimeError, "Can't parse dependency %s" % value
+ match = match.groups()
+ self.name = match[0]
+ if match[1] is not None:
+ self.operator = self._operator(match[1])
+ else:
+ self.operator = None
+ self.version = match[2]
+ if match[3] is not None:
+ self.arches = re.split('\s+', match[3])
+ else:
+ self.arches = []
+
+class Package(dict):
+ _fields = utils.SortedDict((
+ ('Package', str),
+ ('Source', str),
+ ('Architecture', PackageFieldList),
+ ('Section', str),
+ ('Priority', str),
+ ('Maintainer', str),
+ ('Uploaders', str),
+ ('Standards-Version', str),
+ ('Build-Depends', PackageRelation),
+ ('Build-Depends-Indep', PackageRelation),
+ ('Provides', PackageRelation),
+ ('Pre-Depends', PackageRelation),
+ ('Depends', PackageRelation),
+ ('Recommends', PackageRelation),
+ ('Suggests', PackageRelation),
+ ('Replaces', PackageRelation),
+ ('Conflicts', PackageRelation),
+ ('Description', PackageDescription),
+ ))
+
+ def __setitem__(self, key, value):
+ try:
+ cls = self._fields[key]
+ if not isinstance(value, cls):
+ value = cls(value)
+ except KeyError: pass
+ super(Package, self).__setitem__(key, value)
+
+ def iterkeys(self):
+ keys = set(self.keys())
+ for i in self._fields.iterkeys():
+ if self.has_key(i):
+ keys.remove(i)
+ yield i
+ for i in keys:
+ yield i
+
+ def iteritems(self):
+ for i in self.iterkeys():
+ yield (i, self[i])
+
+ def itervalues(self):
+ for i in self.iterkeys():
+ yield self[i]
+
diff --git a/debian/lib/python/debian_linux/gencontrol.py b/debian/lib/python/debian_linux/gencontrol.py
new file mode 100644
index 0000000..90b009f
--- /dev/null
+++ b/debian/lib/python/debian_linux/gencontrol.py
@@ -0,0 +1,312 @@
+from config import *
+from debian import *
+from utils import *
+
+class PackagesList(SortedDict):
+ def append(self, package):
+ self[package['Package']] = package
+
+ def extend(self, packages):
+ for package in packages:
+ self[package['Package']] = package
+
+class Makefile(object):
+ def __init__(self):
+ self.rules = {}
+ self.add('.NOTPARALLEL')
+
+ def add(self, name, deps = None, cmds = None):
+ if name in self.rules:
+ self.rules[name].add(deps, cmds)
+ else:
+ self.rules[name] = self.Rule(name, deps, cmds)
+
+ def write(self, out):
+ r = self.rules.keys()
+ r.sort()
+ for i in r:
+ self.rules[i].write(out)
+
+ class Rule(object):
+ def __init__(self, name, deps = None, cmds = None):
+ self.name = name
+ self.deps, self.cmds = set(), []
+ self.add(deps, cmds)
+
+ def add(self, deps = None, cmds = None):
+ if deps is not None:
+ self.deps.update(deps)
+ if cmds is not None:
+ self.cmds.append(cmds)
+
+ def write(self, out):
+ deps_string = ''
+ if self.deps:
+ deps = list(self.deps)
+ deps.sort()
+ deps_string = ' ' + ' '.join(deps)
+
+ if self.cmds:
+ if deps_string:
+ out.write('%s::%s\n' % (self.name, deps_string))
+ for c in self.cmds:
+ out.write('%s::\n' % self.name)
+ for i in c:
+ out.write('\t%s\n' % i)
+ else:
+ out.write('%s:%s\n' % (self.name, deps_string))
+
+class MakeFlags(dict):
+ def __repr__(self):
+ repr = super(flags, self).__repr__()
+ return "%s(%s)" % (self.__class__.__name__, repr)
+
+ def __str__(self):
+ return ' '.join(["%s='%s'" % i for i in self.iteritems()])
+
+ def copy(self):
+ return self.__class__(super(MakeFlags, self).copy())
+
+class Gencontrol(object):
+ makefile_targets = ('binary-arch', 'build', 'setup', 'source')
+
+ def __init__(self, config, templates):
+ self.config, self.templates = config, templates
+
+ def __call__(self):
+ packages = PackagesList()
+ makefile = Makefile()
+
+ self.do_source(packages)
+ self.do_main(packages, makefile)
+ self.do_extra(packages, makefile)
+
+ self.write_control(packages.itervalues())
+ self.write_makefile(makefile)
+
+ def do_source(self, packages):
+ source = self.templates["control.source"]
+ packages['source'] = self.process_package(source[0], self.vars)
+
+ def do_main(self, packages, makefile):
+ config_entry = self.config['base',]
+ vars = self.vars.copy()
+ vars.update(config_entry)
+
+ makeflags = MakeFlags()
+ extra = {}
+
+ self.do_main_setup(vars, makeflags, extra)
+ self.do_main_packages(packages, extra)
+ self.do_main_makefile(makefile, makeflags, extra)
+
+ for arch in iter(self.config['base',]['arches']):
+ self.do_arch(packages, makefile, arch, vars.copy(), makeflags.copy(), extra)
+
+ def do_main_setup(self, vars, makeflags, extra):
+ makeflags.update({
+ 'MAJOR': self.version.linux_major,
+ 'VERSION': self.version.linux_version,
+ 'UPSTREAMVERSION': self.version.linux_upstream,
+ 'ABINAME': self.abiname,
+ })
+
+ def do_main_makefile(self, makefile, makeflags, extra):
+ makefile.add('binary-indep', cmds = ["$(MAKE) -f debian/rules.real binary-indep %s" % makeflags])
+
+ def do_main_packages(self, packages, extra):
+ pass
+
+ def do_extra(self, packages, makefile):
+ try:
+ templates_extra = self.templates["control.extra"]
+ except IOError:
+ return
+
+ packages.extend(self.process_packages(templates_extra, {}))
+ extra_arches = {}
+ for package in templates_extra:
+ arches = package['Architecture']
+ for arch in arches:
+ i = extra_arches.get(arch, [])
+ i.append(package)
+ extra_arches[arch] = i
+ archs = extra_arches.keys()
+ archs.sort()
+ for arch in archs:
+ cmds = []
+ for i in extra_arches[arch]:
+ tmp = []
+ if i.has_key('X-Version-Overwrite-Epoch'):
+ tmp.append("-v1:%s" % self.version['source'])
+ cmds.append("$(MAKE) -f debian/rules.real install-dummy DH_OPTIONS='-p%s' GENCONTROL_ARGS='%s'" % (i['Package'], ' '.join(tmp)))
+ makefile.add('binary-arch_%s' % arch ['binary-arch_%s_extra' % arch])
+ makefile.add("binary-arch_%s_extra" % arch, cmds = cmds)
+
+ def do_arch(self, packages, makefile, arch, vars, makeflags, extra):
+ config_base = self.config['base', arch]
+ vars.update(config_base)
+ vars['arch'] = arch
+
+ makeflags['ARCH'] = arch
+
+ self.do_arch_setup(vars, makeflags, arch, extra)
+ self.do_arch_makefile(makefile, arch, makeflags, extra)
+ self.do_arch_packages(packages, makefile, arch, vars, makeflags, extra)
+ self.do_arch_recurse(packages, makefile, arch, vars, makeflags, extra)
+
+ def do_arch_setup(self, vars, makeflags, arch, extra):
+ pass
+
+ def do_arch_makefile(self, makefile, arch, makeflags, extra):
+ for i in self.makefile_targets:
+ target1 = i
+ target2 = "%s_%s" % (i, arch)
+ makefile.add(target1, [target2])
+ makefile.add(target2, ['%s_real' % target2])
+ makefile.add('%s_real' % target2)
+
+ def do_arch_packages(self, packages, makefile, arch, vars, makeflags, extra):
+ pass
+
+ def do_arch_recurse(self, packages, makefile, arch, vars, makeflags, extra):
+ for featureset in self.config['base', arch]['featuresets']:
+ self.do_featureset(packages, makefile, arch, featureset, vars.copy(), makeflags.copy(), extra)
+
+ def do_featureset(self, packages, makefile, arch, featureset, vars, makeflags, extra):
+ config_base = self.config.merge('base', arch, featureset)
+ vars.update(config_base)
+
+ if not config_base.get('enabled', True):
+ return
+
+ makeflags['FEATURESET'] = featureset
+
+ vars['localversion'] = ''
+ if featureset != 'none':
+ vars['localversion'] = '-' + featureset
+
+ self.do_featureset_setup(vars, makeflags, arch, featureset, extra)
+ self.do_featureset_makefile(makefile, arch, featureset, makeflags, extra)
+ self.do_featureset_packages(packages, makefile, arch, featureset, vars, makeflags, extra)
+ self.do_featureset_recurse(packages, makefile, arch, featureset, vars, makeflags, extra)
+
+ def do_featureset_setup(self, vars, makeflags, arch, featureset, extra):
+ pass
+
+ def do_featureset_makefile(self, makefile, arch, featureset, makeflags, extra):
+ for i in self.makefile_targets:
+ target1 = "%s_%s" % (i, arch)
+ target2 = "%s_%s_%s" % (i, arch, featureset)
+ makefile.add(target1, [target2])
+ makefile.add(target2, ['%s_real' % target2])
+ makefile.add('%s_real' % target2)
+
+ def do_featureset_packages(self, packages, makefile, arch, featureset, vars, makeflags, extra):
+ pass
+
+ def do_featureset_recurse(self, packages, makefile, arch, featureset, vars, makeflags, extra):
+ for flavour in self.config['base', arch, featureset]['flavours']:
+ self.do_flavour(packages, makefile, arch, featureset, flavour, vars.copy(), makeflags.copy(), extra)
+
+ def do_flavour(self, packages, makefile, arch, featureset, flavour, vars, makeflags, extra):
+ config_base = self.config.merge('base', arch, featureset, flavour)
+ vars.update(config_base)
+
+ if not vars.has_key('longclass'):
+ vars['longclass'] = vars['class']
+
+ makeflags['FLAVOUR'] = flavour
+ vars['localversion'] += '-' + flavour
+
+ self.do_flavour_setup(vars, makeflags, arch, featureset, flavour, extra)
+ self.do_flavour_makefile(makefile, arch, featureset, flavour, makeflags, extra)
+ self.do_flavour_packages(packages, makefile, arch, featureset, flavour, vars, makeflags, extra)
+
+ def do_flavour_setup(self, vars, makeflags, arch, featureset, flavour, extra):
+ for i in (
+ ('kernel-arch', 'KERNEL_ARCH'),
+ ('localversion', 'LOCALVERSION'),
+ ):
+ if vars.has_key(i[0]):
+ makeflags[i[1]] = vars[i[0]]
+
+ def do_flavour_makefile(self, makefile, arch, featureset, flavour, makeflags, extra):
+ for i in self.makefile_targets:
+ target1 = "%s_%s_%s" % (i, arch, featureset)
+ target2 = "%s_%s_%s_%s" % (i, arch, featureset, flavour)
+ makefile.add(target1, [target2])
+ makefile.add(target2, ['%s_real' % target2])
+ makefile.add('%s_real' % target2)
+
+ def do_flavour_packages(self, packages, makefile, arch, featureset, flavour, vars, makeflags, extra):
+ pass
+
+ def process_relation(self, key, e, in_e, vars):
+ import copy
+ dep = copy.deepcopy(in_e[key])
+ for groups in dep:
+ for item in groups:
+ item.name = self.substitute(item.name, vars)
+ e[key] = dep
+
+ def process_description(self, e, in_e, vars):
+ in_desc = in_e['Description']
+ desc = in_desc.__class__()
+ desc.short = self.substitute(in_desc.short, vars)
+ for i in in_desc.long:
+ desc.append(self.substitute(i, vars))
+ e['Description'] = desc
+
+ def process_package(self, in_entry, vars):
+ e = Package()
+ for key, value in in_entry.iteritems():
+ if isinstance(value, PackageRelation):
+ self.process_relation(key, e, in_entry, vars)
+ elif key == 'Description':
+ self.process_description(e, in_entry, vars)
+ elif key[:2] == 'X-':
+ pass
+ else:
+ e[key] = self.substitute(value, vars)
+ return e
+
+ def process_packages(self, in_entries, vars):
+ entries = []
+ for i in in_entries:
+ entries.append(self.process_package(i, vars))
+ return entries
+
+ def process_version_linux(self, version, abiname):
+ return {
+ 'upstreamversion': version.linux_upstream,
+ 'version': version.linux_version,
+ 'source_upstream': version.upstream,
+ 'major': version.linux_major,
+ 'abiname': abiname,
+ }
+
+ def substitute(self, s, vars):
+ if isinstance(s, (list, tuple)):
+ for i in xrange(len(s)):
+ s[i] = self.substitute(s[i], vars)
+ return s
+ def subst(match):
+ return vars[match.group(1)]
+ return re.sub(r'@([-_a-z]+)@', subst, s)
+
+ def write_control(self, list):
+ self.write_rfc822(file("debian/control", 'w'), list)
+
+ def write_makefile(self, makefile):
+ f = file("debian/rules.gen", 'w')
+ makefile.write(f)
+ f.close()
+
+ def write_rfc822(self, f, list):
+ for entry in list:
+ for key, value in entry.iteritems():
+ f.write("%s: %s\n" % (key, value))
+ f.write('\n')
+
+
diff --git a/debian/lib/python/debian_linux/utils.py b/debian/lib/python/debian_linux/utils.py
new file mode 100644
index 0000000..abe46b7
--- /dev/null
+++ b/debian/lib/python/debian_linux/utils.py
@@ -0,0 +1,100 @@
+import debian, re, os, textwrap
+
+class SortedDict(dict):
+ __slots__ = '_list',
+
+ def __init__(self, entries = None):
+ super(SortedDict, self).__init__()
+ self._list = []
+ if entries is not None:
+ for key, value in entries:
+ self[key] = value
+
+ def __delitem__(self, key):
+ super(SortedDict, self).__delitem__(key)
+ self._list.remove(key)
+
+ def __setitem__(self, key, value):
+ super(SortedDict, self).__setitem__(key, value)
+ if key not in self._list:
+ self._list.append(key)
+
+ def iterkeys(self):
+ for i in iter(self._list):
+ yield i
+
+ def iteritems(self):
+ for i in iter(self._list):
+ yield (i, self[i])
+
+ def itervalues(self):
+ for i in iter(self._list):
+ yield self[i]
+
+class Templates(dict):
+ def __init__(self, dirs = ["debian/templates"]):
+ self.dirs = dirs
+
+ def __getitem__(self, key):
+ try:
+ return super(Templates, self).__getitem__(key)
+ except KeyError: pass
+ value = self._read(key)
+ super(Templates, self).__setitem__(key, value)
+ return value
+
+ def __setitem__(self, key, value):
+ raise NotImplemented()
+
+ def _read(self, name):
+ prefix, id = name.split('.', 1)
+
+ for dir in self.dirs:
+ filename = "%s/%s.in" % (dir, name)
+ if os.path.exists(filename):
+ f = file(filename)
+ if prefix == 'control':
+ return self._read_control(f)
+ return f.read()
+ raise KeyError(name)
+
+ def _read_control(self, f):
+ entries = []
+
+ while True:
+ e = debian.Package()
+ last = None
+ lines = []
+ while True:
+ line = f.readline()
+ if not line:
+ break
+ line = line.strip('\n')
+ if not line:
+ break
+ if line[0] in ' \t':
+ if not last:
+ raise ValueError('Continuation line seen before first header')
+ lines.append(line.lstrip())
+ continue
+ if last:
+ e[last] = '\n'.join(lines)
+ i = line.find(':')
+ if i < 0:
+ raise ValueError("Not a header, not a continuation: ``%s''" % line)
+ last = line[:i]
+ lines = [line[i+1:].lstrip()]
+ if last:
+ e[last] = '\n'.join(lines)
+ if not e:
+ break
+
+ entries.append(e)
+
+ return entries
+
+class TextWrapper(textwrap.TextWrapper):
+ wordsep_re = re.compile(
+ r'(\s+|' # any whitespace
+ r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))') # em-dash
+
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..25d147c
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,77 @@
+#!/usr/bin/make -f
+
+SHELL := sh -e
+DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
+DEB_BUILD_ARCH := $(shell dpkg-architecture -qDEB_BUILD_ARCH)
+SOURCE := $(shell dpkg-parsechangelog | sed -ne 's,^Source: *\(.*\)$$,\1,p')
+VERSION_DEBIAN := $(shell dpkg-parsechangelog | sed -ne 's,^Version: *\(.*\)$$,\1,p')
+VERSION := $(shell echo "$(VERSION_DEBIAN)" | sed -e 's,-[^-]*$$,,')
+VERSION_DEBIAN_BINNMU := $(shell echo "$(VERSION_DEBIAN)" | sed -ne 's,.*\+b\(.*\)$$,\1,p')
+
+include debian/rules.defs
+
+build: debian/control $(STAMPS_DIR)/build-base
+$(STAMPS_DIR)/build-base: $(BUILD_DIR) $(STAMPS_DIR)
+ dh_testdir
+ $(MAKE) -f debian/rules.gen build
+ touch $@
+
+$(BUILD_DIR) $(STAMPS_DIR):
+ @[ -d $@ ] || mkdir $@
+
+DIR_ORIG = ../orig/$(SOURCE)-$(VERSION)
+TAR_ORIG_NAME = $(SOURCE)_$(VERSION).orig.tar.gz
+TAR_ORIG = $(firstword $(wildcard ../$(TAR_ORIG_NAME)) $(wildcard ../orig/$(TAR_ORIG_NAME)))
+
+orig: $(DIR_ORIG)
+ rsync --delete --link-dest=$(CURDIR)/$(DIR_ORIG)/kbuild/ -a $(DIR_ORIG)/kbuild/ kbuild
+
+$(DIR_ORIG):
+ifeq ($(TAR_ORIG),)
+ $(error Cannot find orig tarball $(TAR_ORIG_NAME))
+else
+ mkdir -p ../orig
+ tar -C ../orig -xzf $(TAR_ORIG)
+endif
+
+maintainerclean:
+ -rm debian/control debian/control.md5sum debian/rules.gen
+ -rm -rf kbuild
+
+clean: debian/control
+ dh_testdir
+ rm -rf $(BUILD_DIR) $(STAMPS_DIR) debian/lib/python/debian_linux/*.pyc
+ dh_clean
+
+binary-indep:
+ dh_testdir
+
+binary-arch:
+ dh_testdir
+ $(MAKE) -f debian/rules.gen binary-arch
+
+binary: binary-indep binary-arch
+
+CONTROL_FILES = debian/changelog $(wildcard debian/templates/control.*)
+debian/control debian/rules.gen: debian/bin/gencontrol.py $(CONTROL_FILES)
+ +if [ -f debian/control.md5sum ]; then \
+ if md5sum $^ | diff - debian/control.md5sum > /dev/null; then true; else \
+ $(MAKE) -f debian/rules debian/control-real; \
+ fi \
+ else \
+ $(MAKE) -f debian/rules debian/control-real; \
+ fi
+
+debian/control-real: debian/bin/gencontrol.py $(CONTROL_FILES)
+ chmod +x $<
+ $<
+ md5sum $^ > debian/control.md5sum
+ @echo
+ @echo This target is made to fail intentionally, to make sure
+ @echo that it is NEVER run during the automated build. Please
+ @echo ignore the following error, the debian/control file has
+ @echo been generated SUCCESSFULLY.
+ @echo
+ exit 1
+
+.PHONY: clean build setup binary-indep binary-arch binary
diff --git a/debian/rules.defs b/debian/rules.defs
new file mode 100644
index 0000000..06b3f3e
--- /dev/null
+++ b/debian/rules.defs
@@ -0,0 +1,4 @@
+BUILD_DIR = debian/build
+STAMPS_DIR = debian/stamps
+TEMPLATES_DIR = debian/templates
+
diff --git a/debian/rules.real b/debian/rules.real
new file mode 100644
index 0000000..9fdcc23
--- /dev/null
+++ b/debian/rules.real
@@ -0,0 +1,38 @@
+export DH_OPTIONS
+
+include debian/rules.defs
+
+binary-arch: install-kbuild
+
+build: $(STAMPS_DIR)/build
+
+$(STAMPS_DIR)/build: SOURCE_FILES = $(filter-out debian, $(wildcard * .[^.]*))
+$(STAMPS_DIR)/build: DIR=$(BUILD_DIR)/build
+$(STAMPS_DIR)/build:
+ rm -rf '$(DIR)'
+ mkdir -p '$(DIR)'
+ cp -al $(SOURCE_FILES) '$(DIR)'
+ $(MAKE) -C $(DIR) top_srcdir=$(CURDIR)
+ touch '$@'
+
+install-kbuild: PACKAGE_NAME = linux-kbuild-$(VERSION)
+install-kbuild: DH_OPTIONS = -p$(PACKAGE_NAME)
+install-kbuild: BASE_DIR = /usr/src/$(PACKAGE_NAME)
+install-kbuild: SOURCE_DIR = $(BUILD_DIR)/build
+install-kbuild: DIR = $(CURDIR)/debian/$(PACKAGE_NAME)/$(BASE_DIR)
+install-kbuild: $(STAMPS_DIR)/build
+ dh_testdir
+ dh_testroot
+ dh_clean -k -d
+ $(MAKE) -C $(SOURCE_DIR) install prefix=$(DIR) top_srcdir=$(CURDIR)
+ dh_installchangelogs
+ dh_installdocs
+ dh_strip
+ dh_compress
+ dh_fixperms
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
diff --git a/debian/templates/control.main.in b/debian/templates/control.main.in
new file mode 100644
index 0000000..b172cbc
--- /dev/null
+++ b/debian/templates/control.main.in
@@ -0,0 +1,7 @@
+Package: linux-kbuild-@version@
+Architecture: any
+Section: devel
+Priority: optional
+Depends: ${shlibs:Depends}
+Description: Kbuild infrastructure for Linux @version@
+ This package provides the kbuild infrastructure for the headers packages for Linux kernel version @version@.
diff --git a/debian/templates/control.source.in b/debian/templates/control.source.in
new file mode 100644
index 0000000..b6b63c6
--- /dev/null
+++ b/debian/templates/control.source.in
@@ -0,0 +1,7 @@
+Source: linux-kbuild-@major@
+Section: devel
+Priority: optional
+Maintainer: Debian Kernel Team <debian-kernel@lists.debian.org>
+Uploaders: Bastian Blank <waldi@debian.org>
+Standards-Version: 3.7.3
+Build-Depends: debhelper (>> 7), python
diff --git a/scripts/Makefile b/scripts/Makefile
new file mode 100644
index 0000000..7359e5e
--- /dev/null
+++ b/scripts/Makefile
@@ -0,0 +1,46 @@
+PROGS = \
+ bin2c \
+ conmakehash \
+ kallsyms \
+ pnmtologo
+
+DATA = \
+ Kbuild.include \
+ Makefile.build \
+ Makefile.clean \
+ Makefile.host \
+ Makefile.lib \
+ Makefile.modinst \
+ Makefile.modpost \
+ mkversion
+
+SCRIPTS = \
+ checkincludes.pl \
+ checkstack.pl \
+ checkversion.pl \
+ gcc-version.sh \
+ gcc-x86_64-has-stack-protector.sh \
+ gen_initramfs_list.sh \
+ kernel-doc \
+ Lindent \
+ makelst \
+ mksysmap \
+ mkuboot.sh \
+ namespace.pl \
+ patch-kernel \
+ setlocalversion \
+ ver_linux
+
+SUBDIRS = \
+ basic \
+ genksyms \
+ kconfig \
+ mod
+
+OUTDIR = scripts
+
+top_srcdir = ..
+
+VPATH = $(top_srcdir)/kbuild/scripts
+
+include $(top_srcdir)/Makefile.inc
diff --git a/scripts/basic/Makefile b/scripts/basic/Makefile
new file mode 100644
index 0000000..a654314
--- /dev/null
+++ b/scripts/basic/Makefile
@@ -0,0 +1,11 @@
+PROGS = \
+ docproc \
+ fixdep
+
+OUTDIR = scripts/basic
+
+top_srcdir = ../..
+
+VPATH = $(top_srcdir)/kbuild/$(OUTDIR)
+
+include $(top_srcdir)/Makefile.inc
diff --git a/scripts/genksyms/Makefile b/scripts/genksyms/Makefile
new file mode 100644
index 0000000..b6af7f2
--- /dev/null
+++ b/scripts/genksyms/Makefile
@@ -0,0 +1,24 @@
+PROGS = genksyms
+
+OUTDIR = scripts/genksyms
+
+top_srcdir = ../..
+
+VPATH = $(top_srcdir)/kbuild/$(OUTDIR)
+
+include $(top_srcdir)/Makefile.inc
+
+CFLAGS += -I$(VPATH)
+
+genksyms: genksyms.o parse.o lex.o
+
+lex.o: keywords.c parse.h
+
+%.c: %.c_shipped
+ ln -s $< $@
+
+%.h: %.h_shipped
+ ln -s $< $@
+
+clean:
+ rm -f keywords.c parse.h
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
new file mode 100644
index 0000000..9100f3e
--- /dev/null
+++ b/scripts/kconfig/Makefile
@@ -0,0 +1,24 @@
+PROGS = conf
+
+OUTDIR = scripts/kconfig
+
+top_srcdir = ../..
+
+VPATH = $(top_srcdir)/kbuild/$(OUTDIR)
+
+include $(top_srcdir)/Makefile.inc
+
+CFLAGS += -I$(VPATH)
+
+conf: conf.o zconf.tab.o
+
+zconf.tab.c: zconf.hash.c lex.zconf.c
+
+%.c: %.c_shipped
+ ln -sf $< $@
+
+%.h: %.h_shipped
+ ln -sf $< $@
+
+clean:
+ rm -f zconf.tab.c zconf.hash.c lex.zconf.c
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
new file mode 100644
index 0000000..0e01d9f
--- /dev/null
+++ b/scripts/mod/Makefile
@@ -0,0 +1,26 @@
+PROGS = \
+ modpost \
+ modpost.real-lsb-32 \
+ modpost.real-lsb-64 \
+ modpost.real-msb-32 \
+ modpost.real-msb-64
+
+OUTDIR = scripts/mod
+
+top_srcdir = ../..
+
+include $(top_srcdir)/Makefile.inc
+
+modpost.real-%:
+ $(MAKE) -f Makefile.real TYPE=$* SOURCEDIR=$(top_srcdir)/kbuild/scripts/mod
+
+%: %.o
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
+modpost.h: $(top_srcdir)/kbuild/scripts/mod/modpost.c
+ python ./gendef.py $< > $@
+
+modpost.o: modpost.c modpost.h
+
+clean:
+ rm -f modpost.h
diff --git a/scripts/mod/Makefile.real b/scripts/mod/Makefile.real
new file mode 100644
index 0000000..be0d63c
--- /dev/null
+++ b/scripts/mod/Makefile.real
@@ -0,0 +1,14 @@
+PROGS = modpost.real-$(TYPE)
+
+top_srcdir = ../..
+
+CFLAGS += -I$(top_srcdir)/kbuild/include
+
+include $(top_srcdir)/Makefile.inc
+
+modpost.real-$(TYPE): file2alias.real-$(TYPE).o modpost.real-$(TYPE).o sumversion.real-$(TYPE).o
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
+%.real-$(TYPE).o: $(SOURCEDIR)/%.c
+ $(CC) -I real-$(TYPE) $(CFLAGS) -c -o $@ $^
+
diff --git a/scripts/mod/elfconfig.h b/scripts/mod/elfconfig.h
new file mode 100644
index 0000000..8c90ea6
--- /dev/null
+++ b/scripts/mod/elfconfig.h
@@ -0,0 +1,7 @@
+#include <endian.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define HOST_ELFDATA ELFDATA2LSB
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define HOST_ELFDATA ELFDATA2MSB
+#endif
diff --git a/scripts/mod/gendef.py b/scripts/mod/gendef.py
new file mode 100755
index 0000000..22dbd7d
--- /dev/null
+++ b/scripts/mod/gendef.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+import re
+import sys
+
+for line in open(sys.argv[1]):
+ match = re.search('getopt\(argc, argv, "([\w:]*?)"\)', line)
+ if match:
+ options = match.group(1)
+ break
+else:
+ raise RuntimeError
+
+print '#define GETOPT_OPTIONS "%s"' % options
+
+print '#define GETOPT_CASE',
+for c in options:
+ if c == ':':
+ continue
+ print "case '%c':" % c,
+print
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
new file mode 100644
index 0000000..cd94433
--- /dev/null
+++ b/scripts/mod/modpost.c
@@ -0,0 +1,72 @@
+#include <elf.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "modpost.h"
+
+int main (int argc, char *argv[])
+{
+ char const *data, *class;
+ char prog[1024];
+ unsigned char ei[EI_NIDENT];
+ int opt;
+ FILE *file;
+
+ while ((opt = getopt (argc, argv, GETOPT_OPTIONS)) != -1)
+ {
+ switch(opt)
+ {
+ GETOPT_CASE
+ break;
+ default:
+ return EXIT_FAILURE;
+ }
+ }
+
+ if (optind == argc)
+ return EXIT_SUCCESS;
+
+ if (!(file = fopen (argv[optind], "r")))
+ {
+ fprintf (stderr, "Can't open file\n");
+ return EXIT_FAILURE;
+ }
+
+ if (fread (ei, 1, EI_NIDENT, file) != EI_NIDENT)
+ {
+ fprintf (stderr, "Error: input truncated\n");
+ return EXIT_FAILURE;
+ }
+
+ if (memcmp (ei, ELFMAG, SELFMAG) != 0)
+ {
+ fprintf (stderr, "Error: not ELF\n");
+ return EXIT_FAILURE;
+ }
+ switch (ei[EI_DATA]) {
+ case ELFDATA2LSB:
+ data = "lsb";
+ break;
+ case ELFDATA2MSB:
+ data = "msb";
+ break;
+ default:
+ return EXIT_FAILURE;
+ }
+ switch (ei[EI_CLASS]) {
+ case ELFCLASS32:
+ class = "32";
+ break;
+ case ELFCLASS64:
+ class = "64";
+ break;
+ default:
+ return EXIT_FAILURE;
+ }
+ snprintf (prog, sizeof prog, "%s.real-%s-%s", argv[0], data, class);
+
+ return execv (prog, argv);
+}
diff --git a/scripts/mod/real-lsb-32/elfconfig.h b/scripts/mod/real-lsb-32/elfconfig.h
new file mode 100644
index 0000000..1f7a732
--- /dev/null
+++ b/scripts/mod/real-lsb-32/elfconfig.h
@@ -0,0 +1,4 @@
+#define KERNEL_ELFCLASS ELFCLASS32
+#define KERNEL_ELFDATA ELFDATA2LSB
+#define MODULE_SYMBOL_PREFIX ""
+#include "../elfconfig.h"
diff --git a/scripts/mod/real-lsb-64/elfconfig.h b/scripts/mod/real-lsb-64/elfconfig.h
new file mode 100644
index 0000000..e6f519f
--- /dev/null
+++ b/scripts/mod/real-lsb-64/elfconfig.h
@@ -0,0 +1,4 @@
+#define KERNEL_ELFCLASS ELFCLASS64
+#define KERNEL_ELFDATA ELFDATA2LSB
+#define MODULE_SYMBOL_PREFIX ""
+#include "../elfconfig.h"
diff --git a/scripts/mod/real-msb-32/elfconfig.h b/scripts/mod/real-msb-32/elfconfig.h
new file mode 100644
index 0000000..a9ae561
--- /dev/null
+++ b/scripts/mod/real-msb-32/elfconfig.h
@@ -0,0 +1,4 @@
+#define KERNEL_ELFCLASS ELFCLASS32
+#define KERNEL_ELFDATA ELFDATA2MSB
+#define MODULE_SYMBOL_PREFIX ""
+#include "../elfconfig.h"
diff --git a/scripts/mod/real-msb-64/elfconfig.h b/scripts/mod/real-msb-64/elfconfig.h
new file mode 100644
index 0000000..844d22f
--- /dev/null
+++ b/scripts/mod/real-msb-64/elfconfig.h
@@ -0,0 +1,4 @@
+#define KERNEL_ELFCLASS ELFCLASS64
+#define KERNEL_ELFDATA ELFDATA2MSB
+#define MODULE_SYMBOL_PREFIX ""
+#include "../elfconfig.h"