4 # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
6 # Simple script to generate a deb package for a Linux kernel. All the
7 # complexity of what to do with a kernel after it is installed or removed
8 # is left to other scripts and packages: they can install scripts in the
9 # /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
10 # specified in KDEB_HOOKDIR) that will be called on package install and
16 local pname="$1" pdir="$2"
18 # Fix ownership and permissions
19 chown -R root:root "$pdir"
23 dpkg-gencontrol -isp -p$pname -P"$pdir"
24 dpkg --build "$pdir" ..
27 # Some variables and settings used throughout the script
28 version=$KERNELRELEASE
29 revision=$(cat .version)
30 if [ -n "$KDEB_PKGVERSION" ]; then
31 packageversion=$KDEB_PKGVERSION
33 packageversion=$version-$revision
35 tmpdir="$objtree/debian/tmp"
36 fwdir="$objtree/debian/fwtmp"
37 packagename=linux-$version
38 fwpackagename=linux-firmware-image
40 if [ "$ARCH" = "um" ] ; then
41 packagename=user-mode-linux-$version
44 # Setup the directory structure
45 rm -rf "$tmpdir" "$fwdir"
46 mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
47 mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
48 if [ "$ARCH" = "um" ] ; then
49 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
52 # Build and install the kernel
53 if [ "$ARCH" = "um" ] ; then
55 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
56 cp .config "$tmpdir/usr/share/doc/$packagename/config"
57 gzip "$tmpdir/usr/share/doc/$packagename/config"
58 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
60 cp System.map "$tmpdir/boot/System.map-$version"
61 cp .config "$tmpdir/boot/config-$version"
62 # Not all arches include the boot path in KBUILD_IMAGE
63 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
64 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
68 if grep -q '^CONFIG_MODULES=y' .config ; then
69 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
70 if [ "$ARCH" = "um" ] ; then
71 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
72 rmdir "$tmpdir/lib/modules/$version"
76 # Install the maintainer scripts
77 # Note: hook scripts under /etc/kernel are also executed by official Debian
78 # kernel packages, as well as kernel packages built using make-kpkg
79 debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
80 for script in postinst postrm preinst prerm ; do
81 mkdir -p "$tmpdir$debhookdir/$script.d"
82 cat <<EOF > "$tmpdir/DEBIAN/$script"
87 # Pass maintainer script parameters to hook scripts
88 export DEB_MAINT_PARAMS="\$@"
90 test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
93 chmod 755 "$tmpdir/DEBIAN/$script"
96 name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
97 # Generate a simple changelog template
98 cat <<EOF > debian/changelog
99 linux ($packageversion) unstable; urgency=low
101 * Custom built Linux kernel.
106 # Generate a control file
107 cat <<EOF > debian/control
112 Standards-Version: 3.6.1
115 if [ "$ARCH" = "um" ]; then
116 cat <<EOF >> debian/control
118 Package: $packagename
119 Provides: kernel-image-$version, linux-image-$version
121 Description: User Mode Linux kernel, version $version
122 User-mode Linux is a port of the Linux kernel to its own system call
123 interface. It provides a kind of virtual machine, which runs Linux
124 as a user process under another Linux kernel. This is useful for
125 kernel development, sandboxes, jails, experimentation, and
128 This package contains the Linux kernel, modules and corresponding other
129 files, version: $version.
133 cat <<EOF >> debian/control
135 Package: $packagename
136 Provides: kernel-image-$version, linux-image-$version
137 Suggests: $fwpackagename
139 Description: Linux kernel, version $version
140 This package contains the Linux kernel, modules and corresponding other
141 files, version: $version.
146 # Do we have firmware? Move it out of the way and build it into a package.
147 if [ -e "$tmpdir/lib/firmware" ]; then
148 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
150 cat <<EOF >> debian/control
152 Package: $fwpackagename
154 Description: Linux kernel firmware, version $version
155 This package contains firmware from the Linux kernel, version $version.
158 create_package "$fwpackagename" "$fwdir"
161 create_package "$packagename" "$tmpdir"