blob: c01f81287ce6d342aae0c0e7bcaac2681c6eb17d [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
Frans Popfe233cb2009-04-23 01:10:10 +02009# /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
11# removal.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13set -e
14
Frans Pop3e2ab252009-04-23 01:08:44 +020015create_package() {
16 local pname="$1" pdir="$2"
17
18 # Fix ownership and permissions
19 chown -R root:root "$pdir"
20 chmod -R go-w "$pdir"
21
22 # Create the package
23 dpkg-gencontrol -isp -p$pname -P"$pdir"
24 dpkg --build "$pdir" ..
25}
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027# Some variables and settings used throughout the script
28version=$KERNELRELEASE
Frans Pop4f661992009-04-23 01:08:31 +020029revision=$(cat .version)
Frans Popc72c75d2009-04-23 01:09:44 +020030if [ -n "$KDEB_PKGVERSION" ]; then
31 packageversion=$KDEB_PKGVERSION
32else
33 packageversion=$version-$revision
34fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070035tmpdir="$objtree/debian/tmp"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010036fwdir="$objtree/debian/fwtmp"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000037packagename=linux-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010038fwpackagename=linux-firmware-image
Sam Ravnborg687c3da2005-07-14 20:24:00 +000039
Frans Pop4f661992009-04-23 01:08:31 +020040if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000041 packagename=user-mode-linux-$version
42fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44# Setup the directory structure
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010045rm -rf "$tmpdir" "$fwdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010047mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
Frans Pop4f661992009-04-23 01:08:31 +020048if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000049 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
50fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52# Build and install the kernel
Frans Pop4f661992009-04-23 01:08:31 +020053if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000054 $MAKE linux
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"
59else
60 cp System.map "$tmpdir/boot/System.map-$version"
61 cp .config "$tmpdir/boot/config-$version"
Frans Popa89b433bd2009-04-23 01:09:04 +020062 # 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"
65 fi
Sam Ravnborg687c3da2005-07-14 20:24:00 +000066fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68if grep -q '^CONFIG_MODULES=y' .config ; then
Sam Ravnborga91f98a2005-07-14 20:26:09 +000069 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
Frans Pop4f661992009-04-23 01:08:31 +020070 if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000071 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
72 rmdir "$tmpdir/lib/modules/$version"
73 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070074fi
75
76# Install the maintainer scripts
Frans Popfe233cb2009-04-23 01:10:10 +020077# Note: hook scripts under /etc/kernel are also executed by official Debian
78# kernel packages, as well as kernel packages built using make-kpkg
79debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
Linus Torvalds1da177e2005-04-16 15:20:36 -070080for script in postinst postrm preinst prerm ; do
Frans Popfe233cb2009-04-23 01:10:10 +020081 mkdir -p "$tmpdir$debhookdir/$script.d"
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 cat <<EOF > "$tmpdir/DEBIAN/$script"
83#!/bin/sh
84
85set -e
86
Frans Pop49644512009-04-23 01:09:25 +020087# Pass maintainer script parameters to hook scripts
88export DEB_MAINT_PARAMS="\$@"
89
Frans Popfe233cb2009-04-23 01:10:10 +020090test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
Linus Torvalds1da177e2005-04-16 15:20:36 -070091exit 0
92EOF
93 chmod 755 "$tmpdir/DEBIAN/$script"
94done
95
96name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
97# Generate a simple changelog template
98cat <<EOF > debian/changelog
Frans Popc72c75d2009-04-23 01:09:44 +020099linux ($packageversion) unstable; urgency=low
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 * A standard release
102
103 -- $name $(date -R)
104EOF
105
106# Generate a control file
Frans Pop3e2ab252009-04-23 01:08:44 +0200107cat <<EOF > debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108Source: linux
109Section: base
110Priority: optional
111Maintainer: $name
112Standards-Version: 3.6.1
Frans Pop3e2ab252009-04-23 01:08:44 +0200113EOF
114
115if [ "$ARCH" = "um" ]; then
116 cat <<EOF >> debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Sam Ravnborg687c3da2005-07-14 20:24:00 +0000118Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700119Provides: kernel-image-$version, linux-image-$version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120Architecture: any
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000121Description: 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
126 many other things.
127 .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 This package contains the Linux kernel, modules and corresponding other
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000129 files version $version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130EOF
131
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000132else
Frans Pop3e2ab252009-04-23 01:08:44 +0200133 cat <<EOF >> debian/control
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000134
135Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700136Provides: kernel-image-$version, linux-image-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100137Suggests: $fwpackagename
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000138Architecture: any
139Description: Linux kernel, version $version
140 This package contains the Linux kernel, modules and corresponding other
141 files version $version
142EOF
Frans Pop4f661992009-04-23 01:08:31 +0200143
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000144fi
145
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100146# Do we have firmware? Move it out of the way and build it into a package.
147if [ -e "$tmpdir/lib/firmware" ]; then
148 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
149
150 cat <<EOF >> debian/control
151
152Package: $fwpackagename
153Architecture: all
154Description: Linux kernel firmware, version $version
155 This package contains firmware from the Linux kernel, version $version
156EOF
157
Frans Pop3e2ab252009-04-23 01:08:44 +0200158 create_package "$fwpackagename" "$fwdir"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100159fi
160
Frans Pop3e2ab252009-04-23 01:08:44 +0200161create_package "$packagename" "$tmpdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163exit 0