Allow the kernel ABI version and the configuration directory (default:
current directory) to be specified as command-line arguments where
relevant, and pass them between sub-commands where necessary.

check: Allow package names to be specified as arguments.  If no
arguments are given, call $(dh_listpackages -s) as before,

copy-modules: If modules.dep is missing, use depmod to generate it in
the temporary directory.

gen-control: If build-dependencies are specified as '-', do not
generate a source section.

install-files: If installedname is specified as '-', generate the
name automatically from the kernel ABI version and flavour.
If $SOURCEDIR is not set and build-dependencies are specified as '-',
use the package build directory under debian/ as source.
---
Tested in conjunction with appropriate changes to the linux-2.6 source
package.  Also tested that linux-kernel-di-i386-2.6 can still be built.

Ben.

 commands/check         |    7 ++++++-
 commands/copy-modules  |   29 ++++++++++++++++-------------
 commands/gen-control   |   47 ++++++++++++++++++++++++++++++-----------------
 commands/gen-deps      |   11 ++++++-----
 commands/install-files |   48 +++++++++++++++++++++++++++++++++++++-----------
 debian/changelog       |    3 +++
 6 files changed, 98 insertions(+), 47 deletions(-)

diff --git a/commands/check b/commands/check
index 8c07359..9fe7470 100755
--- a/commands/check
+++ b/commands/check
@@ -1,6 +1,11 @@
 #!/bin/sh -e
 empty=
-for pkg in $(dh_listpackages -s); do
+if [ $# -ge 1 ]; then
+    packages="$*"
+else
+    packages="$(dh_listpackages -s)"
+fi
+for pkg in $packages; do
        if [ -z  "$(find debian/$pkg -type f)" ]; then
                echo "$pkg will be empty" >&2
                empty=1
diff --git a/commands/copy-modules b/commands/copy-modules
index 75c4208..707bc5f 100755
--- a/commands/copy-modules
+++ b/commands/copy-modules
@@ -81,6 +81,7 @@ processmodules() {
 version=$1-$2
 flavour=$2
 installedname=$3
+configdir=$(readlink -f ${4:-.})
 arch=$(dpkg-architecture -qDEB_HOST_ARCH)
 os=$(dpkg-architecture -qDEB_HOST_ARCH_OS)
 home=$PWD
@@ -102,18 +103,20 @@ if [ ! -d $moddir ]; then
 fi
        
 # The directory of modules lists to use.
-if [ -d modules/$arch-$flavour ]; then
-       modlistdir=modules/$arch-$flavour
-elif [ -d modules/$flavour ]; then
-       modlistdir=modules/$flavour
+if [ -d $configdir/modules/$arch-$flavour ]; then
+       modlistdir=$configdir/modules/$arch-$flavour
+elif [ -d $configdir/modules/$flavour ]; then
+       modlistdir=$configdir/modules/$flavour
 else
-       modlistdir=modules/$arch
+       modlistdir=$configdir/modules/$arch
 fi
 
 if [ "$os" = "linux" ] ; then
-       if [ ! -e "$moddir/modules.dep" ]; then
-               echo "no $moddir/modules.dep. This file is required by 
kernel-wedge" >&2
-               exit 1
+       if [ -e "$moddir/modules.dep" ]; then
+               modulesdep=$moddir/modules.dep
+       else
+               modulesdep=$tmpdir/modules.dep
+               depmod ${SOURCEDIR:+-b $SOURCEDIR} -V $installedname -n 
>$modulesdep
        fi
 
        # get module dependencies from modules.dep
@@ -128,11 +131,11 @@ if [ "$os" = "linux" ] ; then
                foreach (@words) {
                        print "$module\t$_" unless $_ eq "\\";
                }
-       ' $moddir/modules.dep | sort -k 2,2 > $tmpdir/deps
+       ' $modulesdep | sort -k 2,2 > $tmpdir/deps
        
-       if [ ! -s $tmpdir/deps ] && [ ! -e $home/no-modules ]; then
+       if [ ! -s $tmpdir/deps ] && [ ! -e $configdir/no-modules ]; then
                echo "No module interdependencies found. This probably means 
your modules.dep is broken." >&2
-               echo "If this is intentional, touch $home/no-modules" >&2
+               echo "If this is intentional, touch $configdir/no-modules" >&2
                exit 1
        fi
 else
@@ -142,7 +145,7 @@ fi
 mkdir $tmpdir/module-deps $tmpdir/module-list
 
 # generate module interrelationships from package-list file
-kernel-wedge gen-deps $flavour > $tmpdir/module-deps.packages
+kernel-wedge gen-deps $flavour $configdir > $tmpdir/module-deps.packages
 
 code=0
 # loop over all udebs, sort that all dependent modules are processed first
@@ -164,7 +167,7 @@ for i in $(
        
        # preprocess file, handle includes and excludes and sort so that
        # the joins work, no matter what the order of the input.
-       kernel-wedge preprocess $home/$modlistdir/$i | sort > 
$tmpdir/module-list/$i
+       kernel-wedge preprocess $modlistdir/$i | sort > $tmpdir/module-list/$i
 
        # exclude modules in exclude from dependency list
        join -2 2 -v 2 $tmpdir/exclude $tmpdir/deps |
diff --git a/commands/gen-control b/commands/gen-control
index ed3f612..3f75211 100755
--- a/commands/gen-control
+++ b/commands/gen-control
@@ -11,7 +11,10 @@ my %packages;
 my @builddeps;
 my %excluded;
 
-if (open(EXCLUDED, "exclude-packages")) {
+my $fixkernelversion = $ARGV[0];
+my $configdir = ($ARGV[1] || '.');
+
+if (open(EXCLUDED, "$configdir/exclude-packages")) {
        while (<EXCLUDED>) {
                chomp;
                $excluded{$_}=1;
@@ -19,7 +22,7 @@ if (open(EXCLUDED, "exclude-packages")) {
        close EXCLUDED;
 }
 
-open(KVERS, "kernel-versions") || die "kernel-versions: $!";
+open(KVERS, "$configdir/kernel-versions") || die "kernel-versions: $!";
 while (<KVERS>) {
        chomp;
        next if /^#/ || ! length;
@@ -28,22 +31,32 @@ while (<KVERS>) {
        if (! length $arch || ! length $kernelversion || ! length $flavour) {
                die "parse error";
        }
+       if (defined($fixkernelversion)) {
+               $kernelversion = $fixkernelversion;
+       } elsif ($kernelversion eq "-") {
+               die "kernel version not set in file or on command line";
+       }
        push @versions, [ $arch, $kernelversion, $flavour ];
-       foreach my $pkg (split(", ", $builddep)) {
-               push @builddeps, "$pkg [$arch]";
+       if ($builddep ne "-") {
+               foreach my $pkg (split(", ", $builddep)) {
+                       push @builddeps, "$pkg [$arch]";
+               }
        }
 }
 close KVERS;
 
-open(STUB, "debian/control.stub") || die "debian/control.stub: $!";
-while (<STUB>) {
-       chomp;
-       if (/^Build-Depends:/) {
-               $_=join(", ", $_, @builddeps);
+# Building with installed kernel package, or as part of a package?
+if (@builddeps) {
+       open(STUB, "debian/control.stub") || die "debian/control.stub: $!";
+       while (<STUB>) {
+               chomp;
+               if (/^Build-Depends:/) {
+                       $_=join(", ", $_, @builddeps);
+               }
+               print $_."\n";
        }
-       print $_."\n";
+       close STUB;
 }
-close STUB;
 
 sub read_package_list
 {
@@ -96,7 +109,7 @@ sub read_package_list
        close LIST;
 }
 read_package_list("/usr/share/kernel-wedge/package-list");
-read_package_list("package-list");
+read_package_list("$configdir/package-list");
 
 foreach my $ver (@versions) {
        my ($arch, $kernelversion, $flavour) = @$ver;
@@ -121,14 +134,14 @@ foreach my $ver (@versions) {
                # Check for a modules list file for this architecture and
                # package.
                my $modlistdir="";
-               if (-d "modules/$arch-$flavour") {
-                       $modlistdir="modules/$arch-$flavour";
+               if (-d "$configdir/modules/$arch-$flavour") {
+                       $modlistdir = "$configdir/modules/$arch-$flavour";
                }
-               elsif (-d "modules/$flavour") {
-                       $modlistdir="modules/$flavour";
+               elsif (-d "$configdir/modules/$flavour") {
+                       $modlistdir = "$configdir/modules/$flavour";
                }
                else {
-                       $modlistdir="modules/$arch";
+                       $modlistdir = "$configdir/modules/$arch";
                }
                
                next unless -e "$modlistdir/".$package->("Package");
diff --git a/commands/gen-deps b/commands/gen-deps
index 94e77be..9dfd610 100755
--- a/commands/gen-deps
+++ b/commands/gen-deps
@@ -7,6 +7,7 @@ my $arch=`dpkg-architecture -qDEB_HOST_ARCH`;
 chomp $arch;
 
 my $flavour=$ARGV[0];
+my $configdir = ($ARGV[1] || '.');
 
 my @out;
 
@@ -26,14 +27,14 @@ sub read_package_list
                        my @depends=split(", ", $1);
                        # Skip packages that are not built for this 
architecture.
                        my $modlistdir="";
-                       if (-d "modules/$arch-$flavour") {
-                               $modlistdir="modules/$arch-$flavour";
+                       if (-d "$configdir/modules/$arch-$flavour") {
+                               $modlistdir = 
"$configdir/modules/$arch-$flavour";
                        }
                        elsif (-d "modules/$flavour") {
-                               $modlistdir="modules/$flavour";
+                               $modlistdir = "$configdir/modules/$flavour";
                        }
                        else {
-                               $modlistdir="modules/$arch";
+                               $modlistdir = "$configdir/modules/$arch";
                        }
                        next unless -e "$modlistdir/$package";
                        foreach my $dep (@depends) {
@@ -48,5 +49,5 @@ sub read_package_list
 }
 
 read_package_list("/usr/share/kernel-wedge/package-list");
-read_package_list("package-list");
+read_package_list("$configdir/package-list");
 print sort @out;
diff --git a/commands/install-files b/commands/install-files
index 9b88b71..46d9e25 100755
--- a/commands/install-files
+++ b/commands/install-files
@@ -12,12 +12,12 @@ sub doit {
 my $hostarch=`dpkg-architecture -qDEB_HOST_ARCH`;
 chomp $hostarch;
 
-my $sourcedir=$ENV{SOURCEDIR};
-if (! defined $sourcedir) {
-       $sourcedir="";
-}
+my $fixsourcedir = $ENV{SOURCEDIR};
+
+my $fixkernelversion = $ARGV[0];
+my $configdir = ($ARGV[1] || '.');
 
-open(KVERS, "kernel-versions") || die "kernel-versions: $!";
+open(KVERS, "$configdir/kernel-versions") || die "kernel-versions: $!";
 my $version = 0;
 while (<KVERS>) {
        chomp;
@@ -31,6 +31,32 @@ while (<KVERS>) {
        }
        next unless $arch eq $hostarch;
 
+       if (defined($fixkernelversion)) {
+               $kernelversion = $fixkernelversion;
+       } elsif ($kernelversion eq "-") {
+               die "kernel version not set in file or on command line";
+       }
+
+       if ($installedname eq "-") {
+               $installedname = "$kernelversion-$flavour";
+       }
+
+       if (defined $fixsourcedir) {
+               $sourcedir = $fixsourcedir;
+       } else {
+               # Building with installed kernel package, or as part
+               # of a package?
+               if ($builddep ne "-") {
+                       $sourcedir = "";
+               } elsif ($arch =~ /^kfreebsd-/) {
+                       $sourcedir = "debian/kfreebsd-image-$installedname";
+               } else {
+                       $sourcedir = "debian/linux-image-$installedname";
+               }
+               # Set SOURCEDIR for copy-modules
+               $ENV{SOURCEDIR} = $sourcedir;
+       }
+
        my $extraname="";
        if ($suffix =~ /^[yY]/) {
                $extraname="-$kernelversion-$flavour";
@@ -40,14 +66,14 @@ while (<KVERS>) {
        }
        
        my $modlistdir;
-       if (-d "modules/$arch-$flavour") {
-               $modlistdir="modules/$arch-$flavour";
+       if (-d "$configdir/modules/$arch-$flavour") {
+               $modlistdir = "$configdir/modules/$arch-$flavour";
        }
-       elsif (-d "modules/$flavour") {
-               $modlistdir="modules/$flavour";
+       elsif (-d "$configdir/modules/$flavour") {
+               $modlistdir = "$configdir/modules/$flavour";
        }
        else {
-               $modlistdir="modules/$arch";
+               $modlistdir = "$configdir/modules/$arch";
        }
 
        if (! -e "$modlistdir/kernel-image") {
@@ -100,7 +126,7 @@ while (<KVERS>) {
                        
"debian/kernel-image-$kernelversion-$flavour-di/usr/lib/$libdir-$installedname");
        }
 
-       doit("kernel-wedge", "copy-modules", $kernelversion, $flavour, 
$installedname);
+       doit("kernel-wedge", "copy-modules", $kernelversion, $flavour, 
$installedname, $configdir);
        doit("kernel-wedge", "find-dups", "$kernelversion-$flavour");
        doit("kernel-wedge", "strip-modules", "$kernelversion-$flavour");
 }
diff --git a/debian/changelog b/debian/changelog
index 2dcbad0..699a22a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,9 @@ kernel-wedge (2.79) UNRELEASED; urgency=low
   [ Samuel Thibault ]
   * sound-modules: Update to 3.0.
 
+  [ Ben Hutchings ]
+  * Add support for building within a kernel package
+
  -- Samuel Thibault <sthiba...@debian.org>  Mon, 08 Aug 2011 18:34:12 +0200
 
 kernel-wedge (2.78) unstable; urgency=low
-- 
1.7.5.4


Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to