blob: e1dd1892eb30c3f73dd8388e133a8ea7bbd505e7 [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"
maximilian attemsf7a2c312009-04-23 01:12:01 +020039packagename=linux-image-$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 Popa89b433bd2009-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
maximilian attemsedec6112009-04-23 01:11:20 +020098# Try to determine maintainer and email values
99if [ -n "$DEBEMAIL" ]; then
100 email=$DEBEMAIL
101elif [ -n "$EMAIL" ]; then
102 email=$EMAIL
103else
104 email=$(id -nu)@$(hostname -f)
105fi
106if [ -n "$DEBFULLNAME" ]; then
107 name=$DEBFULLNAME
108elif [ -n "$NAME" ]; then
109 name=$NAME
110else
111 name="Anonymous"
112fi
113maintainer="$name <$email>"
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115# Generate a simple changelog template
116cat <<EOF > debian/changelog
Frans Pop4bf4cd42009-04-23 01:11:43 +0200117linux-upstream ($packageversion) unstable; urgency=low
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Frans Popa83ca2772009-04-23 01:10:25 +0200119 * Custom built Linux kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
maximilian attemsedec6112009-04-23 01:11:20 +0200121 -- $maintainer $(date -R)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122EOF
123
Frans Pop9461f662009-04-24 19:08:24 +0200124# Generate copyright file
125cat <<EOF > debian/copyright
126This is a packacked upstream version of the Linux kernel.
127
128The sources may be found at most Linux ftp sites, including:
129ftp://ftp.kernel.org/pub/linux/kernel
130
131Copyright: 1991 - 2009 Linus Torvalds and others.
132
133The git repository for mainline kernel development is at:
134git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
135
136 This program is free software; you can redistribute it and/or modify
137 it under the terms of the GNU General Public License as published by
138 the Free Software Foundation; version 2 dated June, 1991.
139
140On Debian GNU/Linux systems, the complete text of the GNU General Public
141License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
142EOF
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144# Generate a control file
Frans Pop3e2ab252009-04-23 01:08:44 +0200145cat <<EOF > debian/control
Frans Pop4bf4cd42009-04-23 01:11:43 +0200146Source: linux-upstream
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147Section: base
148Priority: optional
maximilian attemsedec6112009-04-23 01:11:20 +0200149Maintainer: $maintainer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150Standards-Version: 3.6.1
Frans Pop3e2ab252009-04-23 01:08:44 +0200151EOF
152
153if [ "$ARCH" = "um" ]; then
154 cat <<EOF >> debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Sam Ravnborg687c3da2005-07-14 20:24:00 +0000156Package: $packagename
maximilian attems8ebc2fe2009-04-23 01:12:21 +0200157Provides: linux-image, linux-image-2.6, linux-modules-$version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158Architecture: any
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000159Description: User Mode Linux kernel, version $version
160 User-mode Linux is a port of the Linux kernel to its own system call
161 interface. It provides a kind of virtual machine, which runs Linux
162 as a user process under another Linux kernel. This is useful for
163 kernel development, sandboxes, jails, experimentation, and
164 many other things.
165 .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 This package contains the Linux kernel, modules and corresponding other
Frans Popa83ca2772009-04-23 01:10:25 +0200167 files, version: $version.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168EOF
169
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000170else
Frans Pop3e2ab252009-04-23 01:08:44 +0200171 cat <<EOF >> debian/control
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000172
173Package: $packagename
maximilian attems8ebc2fe2009-04-23 01:12:21 +0200174Provides: linux-image, linux-image-2.6, linux-modules-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100175Suggests: $fwpackagename
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000176Architecture: any
177Description: Linux kernel, version $version
178 This package contains the Linux kernel, modules and corresponding other
Frans Popa83ca2772009-04-23 01:10:25 +0200179 files, version: $version.
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000180EOF
Frans Pop4f661992009-04-23 01:08:31 +0200181
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000182fi
183
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100184# Do we have firmware? Move it out of the way and build it into a package.
185if [ -e "$tmpdir/lib/firmware" ]; then
186 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
187
188 cat <<EOF >> debian/control
189
190Package: $fwpackagename
191Architecture: all
192Description: Linux kernel firmware, version $version
Frans Popa83ca2772009-04-23 01:10:25 +0200193 This package contains firmware from the Linux kernel, version $version.
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100194EOF
195
Frans Pop3e2ab252009-04-23 01:08:44 +0200196 create_package "$fwpackagename" "$fwdir"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100197fi
198
Frans Pop3e2ab252009-04-23 01:08:44 +0200199create_package "$packagename" "$tmpdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201exit 0