blob: 5eecbbe5811458ca28390953d6eb5e4cff13a785 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/bin/sh
2#
Frans Pop49644512009-04-23 01:09:25 +02003# builddeb 1.3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
5#
6# Simple script to generate a deb package for a Linux kernel. All the
Frans Pop4f661992009-04-23 01:08:31 +02007# complexity of what to do with a kernel after it is installed or removed
Linus Torvalds1da177e2005-04-16 15:20:36 -07008# is left to other scripts and packages: they can install scripts in the
9# /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on
10# package install and removal.
11
12set -e
13
Frans Pop3e2ab252009-04-23 01:08:44 +020014create_package() {
15 local pname="$1" pdir="$2"
16
17 # Fix ownership and permissions
18 chown -R root:root "$pdir"
19 chmod -R go-w "$pdir"
20
21 # Create the package
22 dpkg-gencontrol -isp -p$pname -P"$pdir"
23 dpkg --build "$pdir" ..
24}
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026# Some variables and settings used throughout the script
27version=$KERNELRELEASE
Frans Pop4f661992009-04-23 01:08:31 +020028revision=$(cat .version)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029tmpdir="$objtree/debian/tmp"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010030fwdir="$objtree/debian/fwtmp"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000031packagename=linux-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010032fwpackagename=linux-firmware-image
Sam Ravnborg687c3da2005-07-14 20:24:00 +000033
Frans Pop4f661992009-04-23 01:08:31 +020034if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000035 packagename=user-mode-linux-$version
36fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38# Setup the directory structure
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010039rm -rf "$tmpdir" "$fwdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010041mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
Frans Pop4f661992009-04-23 01:08:31 +020042if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000043 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
44fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46# Build and install the kernel
Frans Pop4f661992009-04-23 01:08:31 +020047if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000048 $MAKE linux
49 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
50 cp .config "$tmpdir/usr/share/doc/$packagename/config"
51 gzip "$tmpdir/usr/share/doc/$packagename/config"
52 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
53else
54 cp System.map "$tmpdir/boot/System.map-$version"
55 cp .config "$tmpdir/boot/config-$version"
Frans Popa89b433bd2009-04-23 01:09:04 +020056 # Not all arches include the boot path in KBUILD_IMAGE
57 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
58 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
59 fi
Sam Ravnborg687c3da2005-07-14 20:24:00 +000060fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62if grep -q '^CONFIG_MODULES=y' .config ; then
Sam Ravnborga91f98a2005-07-14 20:26:09 +000063 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
Frans Pop4f661992009-04-23 01:08:31 +020064 if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000065 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
66 rmdir "$tmpdir/lib/modules/$version"
67 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070068fi
69
70# Install the maintainer scripts
71for script in postinst postrm preinst prerm ; do
72 mkdir -p "$tmpdir/etc/kernel/$script.d"
73 cat <<EOF > "$tmpdir/DEBIAN/$script"
74#!/bin/sh
75
76set -e
77
Frans Pop49644512009-04-23 01:09:25 +020078# Pass maintainer script parameters to hook scripts
79export DEB_MAINT_PARAMS="\$@"
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
82exit 0
83EOF
84 chmod 755 "$tmpdir/DEBIAN/$script"
85done
86
87name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
88# Generate a simple changelog template
89cat <<EOF > debian/changelog
Michal Sojkaed2c9fa2008-02-07 17:18:51 +010090linux ($version-$revision) unstable; urgency=low
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 * A standard release
93
94 -- $name $(date -R)
95EOF
96
97# Generate a control file
Frans Pop3e2ab252009-04-23 01:08:44 +020098cat <<EOF > debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -070099Source: linux
100Section: base
101Priority: optional
102Maintainer: $name
103Standards-Version: 3.6.1
Frans Pop3e2ab252009-04-23 01:08:44 +0200104EOF
105
106if [ "$ARCH" = "um" ]; then
107 cat <<EOF >> debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Sam Ravnborg687c3da2005-07-14 20:24:00 +0000109Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700110Provides: kernel-image-$version, linux-image-$version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111Architecture: any
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000112Description: User Mode Linux kernel, version $version
113 User-mode Linux is a port of the Linux kernel to its own system call
114 interface. It provides a kind of virtual machine, which runs Linux
115 as a user process under another Linux kernel. This is useful for
116 kernel development, sandboxes, jails, experimentation, and
117 many other things.
118 .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 This package contains the Linux kernel, modules and corresponding other
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000120 files version $version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121EOF
122
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000123else
Frans Pop3e2ab252009-04-23 01:08:44 +0200124 cat <<EOF >> debian/control
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000125
126Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700127Provides: kernel-image-$version, linux-image-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100128Suggests: $fwpackagename
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000129Architecture: any
130Description: Linux kernel, version $version
131 This package contains the Linux kernel, modules and corresponding other
132 files version $version
133EOF
Frans Pop4f661992009-04-23 01:08:31 +0200134
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000135fi
136
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100137# Do we have firmware? Move it out of the way and build it into a package.
138if [ -e "$tmpdir/lib/firmware" ]; then
139 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
140
141 cat <<EOF >> debian/control
142
143Package: $fwpackagename
144Architecture: all
145Description: Linux kernel firmware, version $version
146 This package contains firmware from the Linux kernel, version $version
147EOF
148
Frans Pop3e2ab252009-04-23 01:08:44 +0200149 create_package "$fwpackagename" "$fwdir"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100150fi
151
Frans Pop3e2ab252009-04-23 01:08:44 +0200152create_package "$packagename" "$tmpdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154exit 0