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 cp debian/copyright "$pdir/usr/share/doc/$pname/"
20 # Fix ownership and permissions
21 chown -R root:root "$pdir"
25 dpkg-gencontrol -isp -p$pname -P"$pdir"
26 dpkg --build "$pdir" ..
29 # Some variables and settings used throughout the script
30 version=$KERNELRELEASE
31 revision=$(cat .version)
32 if [ -n "$KDEB_PKGVERSION" ]; then
33 packageversion=$KDEB_PKGVERSION
35 packageversion=$version-$revision
37 tmpdir="$objtree/debian/tmp"
38 fwdir="$objtree/debian/fwtmp"
39 packagename=linux-$version
40 fwpackagename=linux-firmware-image
42 if [ "$ARCH" = "um" ] ; then
43 packagename=user-mode-linux-$version
46 # Setup the directory structure
47 rm -rf "$tmpdir" "$fwdir"
48 mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
49 mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
50 if [ "$ARCH" = "um" ] ; then
51 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
54 # Build and install the kernel
55 if [ "$ARCH" = "um" ] ; then
57 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
58 cp .config "$tmpdir/usr/share/doc/$packagename/config"
59 gzip "$tmpdir/usr/share/doc/$packagename/config"
60 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
62 cp System.map "$tmpdir/boot/System.map-$version"
63 cp .config "$tmpdir/boot/config-$version"
64 # Not all arches include the boot path in KBUILD_IMAGE
65 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
66 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
70 if grep -q '^CONFIG_MODULES=y' .config ; then
71 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
72 if [ "$ARCH" = "um" ] ; then
73 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
74 rmdir "$tmpdir/lib/modules/$version"
78 # Install the maintainer scripts
79 # Note: hook scripts under /etc/kernel are also executed by official Debian
80 # kernel packages, as well as kernel packages built using make-kpkg
81 debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
82 for script in postinst postrm preinst prerm ; do
83 mkdir -p "$tmpdir$debhookdir/$script.d"
84 cat <<EOF > "$tmpdir/DEBIAN/$script"
89 # Pass maintainer script parameters to hook scripts
90 export DEB_MAINT_PARAMS="\$@"
92 test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
95 chmod 755 "$tmpdir/DEBIAN/$script"
98 name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
99 # Generate a simple changelog template
100 cat <<EOF > debian/changelog
101 linux ($packageversion) unstable; urgency=low
103 * Custom built Linux kernel.
108 # Generate copyright file
109 cat <<EOF > debian/copyright
110 This is a packacked upstream version of the Linux kernel.
112 The sources may be found at most Linux ftp sites, including:
113 ftp://ftp.kernel.org/pub/linux/kernel
115 Copyright: 1991 - 2009 Linus Torvalds and others.
117 The git repository for mainline kernel development is at:
118 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
120 This program is free software; you can redistribute it and/or modify
121 it under the terms of the GNU General Public License as published by
122 the Free Software Foundation; version 2 dated June, 1991.
124 On Debian GNU/Linux systems, the complete text of the GNU General Public
125 License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
128 # Generate a control file
129 cat <<EOF > debian/control
134 Standards-Version: 3.6.1
137 if [ "$ARCH" = "um" ]; then
138 cat <<EOF >> debian/control
140 Package: $packagename
141 Provides: kernel-image-$version, linux-image-$version
143 Description: User Mode Linux kernel, version $version
144 User-mode Linux is a port of the Linux kernel to its own system call
145 interface. It provides a kind of virtual machine, which runs Linux
146 as a user process under another Linux kernel. This is useful for
147 kernel development, sandboxes, jails, experimentation, and
150 This package contains the Linux kernel, modules and corresponding other
151 files, version: $version.
155 cat <<EOF >> debian/control
157 Package: $packagename
158 Provides: kernel-image-$version, linux-image-$version
159 Suggests: $fwpackagename
161 Description: Linux kernel, version $version
162 This package contains the Linux kernel, modules and corresponding other
163 files, version: $version.
168 # Do we have firmware? Move it out of the way and build it into a package.
169 if [ -e "$tmpdir/lib/firmware" ]; then
170 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
172 cat <<EOF >> debian/control
174 Package: $fwpackagename
176 Description: Linux kernel firmware, version $version
177 This package contains firmware from the Linux kernel, version $version.
180 create_package "$fwpackagename" "$fwdir"
183 create_package "$packagename" "$tmpdir"