blob: 122becc9cef71020c603aba2893bc6b52f285cfe [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
Frans Pop9461f662009-04-24 19:08:24 +020018 cp debian/copyright "$pdir/usr/share/doc/$pname/"
19
Frans Pop3e2ab252009-04-23 01:08:44 +020020 # Fix ownership and permissions
21 chown -R root:root "$pdir"
22 chmod -R go-w "$pdir"
23
24 # Create the package
25 dpkg-gencontrol -isp -p$pname -P"$pdir"
26 dpkg --build "$pdir" ..
27}
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029# Some variables and settings used throughout the script
30version=$KERNELRELEASE
Frans Pop4f661992009-04-23 01:08:31 +020031revision=$(cat .version)
Frans Popc72c75d2009-04-23 01:09:44 +020032if [ -n "$KDEB_PKGVERSION" ]; then
33 packageversion=$KDEB_PKGVERSION
34else
35 packageversion=$version-$revision
36fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070037tmpdir="$objtree/debian/tmp"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010038fwdir="$objtree/debian/fwtmp"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000039packagename=linux-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010040fwpackagename=linux-firmware-image
Sam Ravnborg687c3da2005-07-14 20:24:00 +000041
Frans Pop4f661992009-04-23 01:08:31 +020042if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000043 packagename=user-mode-linux-$version
44fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46# Setup the directory structure
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010047rm -rf "$tmpdir" "$fwdir"
Frans Pop9461f662009-04-24 19:08:24 +020048mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
49mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
Frans Pop4f661992009-04-23 01:08:31 +020050if [ "$ARCH" = "um" ] ; then
Frans Pop9461f662009-04-24 19:08:24 +020051 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000052fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54# Build and install the kernel
Frans Pop4f661992009-04-23 01:08:31 +020055if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000056 $MAKE linux
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"
61else
62 cp System.map "$tmpdir/boot/System.map-$version"
63 cp .config "$tmpdir/boot/config-$version"
Frans Popa89b4332009-04-23 01:09:04 +020064 # 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"
67 fi
Sam Ravnborg687c3da2005-07-14 20:24:00 +000068fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70if grep -q '^CONFIG_MODULES=y' .config ; then
Sam Ravnborga91f98a2005-07-14 20:26:09 +000071 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
Frans Pop4f661992009-04-23 01:08:31 +020072 if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000073 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
74 rmdir "$tmpdir/lib/modules/$version"
75 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070076fi
77
78# Install the maintainer scripts
Frans Popfe233cb2009-04-23 01:10:10 +020079# Note: hook scripts under /etc/kernel are also executed by official Debian
80# kernel packages, as well as kernel packages built using make-kpkg
81debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
Linus Torvalds1da177e2005-04-16 15:20:36 -070082for script in postinst postrm preinst prerm ; do
Frans Popfe233cb2009-04-23 01:10:10 +020083 mkdir -p "$tmpdir$debhookdir/$script.d"
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 cat <<EOF > "$tmpdir/DEBIAN/$script"
85#!/bin/sh
86
87set -e
88
Frans Pop49644512009-04-23 01:09:25 +020089# Pass maintainer script parameters to hook scripts
90export DEB_MAINT_PARAMS="\$@"
91
Frans Popfe233cb2009-04-23 01:10:10 +020092test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
Linus Torvalds1da177e2005-04-16 15:20:36 -070093exit 0
94EOF
95 chmod 755 "$tmpdir/DEBIAN/$script"
96done
97
98name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
99# Generate a simple changelog template
100cat <<EOF > debian/changelog
Frans Popc72c75d2009-04-23 01:09:44 +0200101linux ($packageversion) unstable; urgency=low
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Frans Popa83ca272009-04-23 01:10:25 +0200103 * Custom built Linux kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 -- $name $(date -R)
106EOF
107
Frans Pop9461f662009-04-24 19:08:24 +0200108# Generate copyright file
109cat <<EOF > debian/copyright
110This is a packacked upstream version of the Linux kernel.
111
112The sources may be found at most Linux ftp sites, including:
113ftp://ftp.kernel.org/pub/linux/kernel
114
115Copyright: 1991 - 2009 Linus Torvalds and others.
116
117The git repository for mainline kernel development is at:
118git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
119
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.
123
124On Debian GNU/Linux systems, the complete text of the GNU General Public
125License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
126EOF
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128# Generate a control file
Frans Pop3e2ab252009-04-23 01:08:44 +0200129cat <<EOF > debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130Source: linux
131Section: base
132Priority: optional
133Maintainer: $name
134Standards-Version: 3.6.1
Frans Pop3e2ab252009-04-23 01:08:44 +0200135EOF
136
137if [ "$ARCH" = "um" ]; then
138 cat <<EOF >> debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Sam Ravnborg687c3da2005-07-14 20:24:00 +0000140Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700141Provides: kernel-image-$version, linux-image-$version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142Architecture: any
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000143Description: 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
148 many other things.
149 .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 This package contains the Linux kernel, modules and corresponding other
Frans Popa83ca272009-04-23 01:10:25 +0200151 files, version: $version.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152EOF
153
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000154else
Frans Pop3e2ab252009-04-23 01:08:44 +0200155 cat <<EOF >> debian/control
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000156
157Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700158Provides: kernel-image-$version, linux-image-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100159Suggests: $fwpackagename
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000160Architecture: any
161Description: Linux kernel, version $version
162 This package contains the Linux kernel, modules and corresponding other
Frans Popa83ca272009-04-23 01:10:25 +0200163 files, version: $version.
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000164EOF
Frans Pop4f661992009-04-23 01:08:31 +0200165
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000166fi
167
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100168# Do we have firmware? Move it out of the way and build it into a package.
169if [ -e "$tmpdir/lib/firmware" ]; then
170 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
171
172 cat <<EOF >> debian/control
173
174Package: $fwpackagename
175Architecture: all
176Description: Linux kernel firmware, version $version
Frans Popa83ca272009-04-23 01:10:25 +0200177 This package contains firmware from the Linux kernel, version $version.
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100178EOF
179
Frans Pop3e2ab252009-04-23 01:08:44 +0200180 create_package "$fwpackagename" "$fwdir"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100181fi
182
Frans Pop3e2ab252009-04-23 01:08:44 +0200183create_package "$packagename" "$tmpdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185exit 0