#!/bin/sh
# build-modules -- Build several flavors of module packages automatically.

set -e
SIGNCHANGES=1; export SIGNCHANGES

arch=`dpkg-architecture -qDEB_BUILD_ARCH`
headers=
if [ "$arch" = "i386" ] ; then
    for kver in 3.2.0-4-686-pae 3.12-0.bpo.1-686-pae ; do
        headers="$headers linux-headers-$kver linux-headers-$kver-bigmem"
    done
elif [ "$arch" = "amd64" ] ; then
    for kver in 3.2.0-4-amd64 3.12-0.bpo.1-amd64 ; do
        headers="$headers linux-headers-$kver"
    done
fi

cd /usr/src
for hd in $headers ; do
    echo ""
    echo "======================================================"
    if [ -e $hd ] ; then
        echo "Building for: $hd ..."
        for md in "$@" ; do
            fakeroot module-assistant -t -k /usr/src/$hd build $md
            fakeroot module-assistant -t -k /usr/src/$hd clean $md
        done
    else
        echo "Headers not found ($hd) ... skipping"
    fi
    echo "======================================================"
done

exit 0

DOCS=<<__END_OF_DOCS__

=for stopwords
Allbery Huaqing Zheng

=head1 NAME

build-modules - Build several flavors of module packages automatically

=head1 SYNOPSIS

B<build-modules> I<module> [I<module> ...]

=head1 DESCRIPTION

B<build-modules> is a wrapper around B<module-assistant> that builds the
specified kernel modules for multiple different versions of the Linux kernel.
The modules are built with the option set to generate a *.changes file so that
they can be signed easily for upload.

Currently, the list of kernel versions for which to build modules is
hard-coded in the script and will need to be updated for newer versions.

=head1 AUTHORS

Huaqing Zheng <morpheus@stanford.edu> and Russ Allbery <rra@stanford.edu>

=cut
__END_OF_DOCS__
