blob: 5868c0f2e613326fabae956ce6dbb4e84564d144 [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)
Frans Popc72c75d2009-04-23 01:09:44 +020029if [ -n "$KDEB_PKGVERSION" ]; then
30 packageversion=$KDEB_PKGVERSION
31else
32 packageversion=$version-$revision
33fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070034tmpdir="$objtree/debian/tmp"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010035fwdir="$objtree/debian/fwtmp"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000036packagename=linux-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010037fwpackagename=linux-firmware-image
Sam Ravnborg687c3da2005-07-14 20:24:00 +000038
Frans Pop4f661992009-04-23 01:08:31 +020039if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000040 packagename=user-mode-linux-$version
41fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43# Setup the directory structure
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010044rm -rf "$tmpdir" "$fwdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010046mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
Frans Pop4f661992009-04-23 01:08:31 +020047if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000048 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
49fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51# Build and install the kernel
Frans Pop4f661992009-04-23 01:08:31 +020052if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000053 $MAKE linux
54 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
55 cp .config "$tmpdir/usr/share/doc/$packagename/config"
56 gzip "$tmpdir/usr/share/doc/$packagename/config"
57 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
58else
59 cp System.map "$tmpdir/boot/System.map-$version"
60 cp .config "$tmpdir/boot/config-$version"
Frans Popa89b433bd2009-04-23 01:09:04 +020061 # Not all arches include the boot path in KBUILD_IMAGE
62 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
63 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
64 fi
Sam Ravnborg687c3da2005-07-14 20:24:00 +000065fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67if grep -q '^CONFIG_MODULES=y' .config ; then
Sam Ravnborga91f98a2005-07-14 20:26:09 +000068 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
Frans Pop4f661992009-04-23 01:08:31 +020069 if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000070 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
71 rmdir "$tmpdir/lib/modules/$version"
72 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070073fi
74
75# Install the maintainer scripts
76for script in postinst postrm preinst prerm ; do
77 mkdir -p "$tmpdir/etc/kernel/$script.d"
78 cat <<EOF > "$tmpdir/DEBIAN/$script"
79#!/bin/sh
80
81set -e
82
Frans Pop49644512009-04-23 01:09:25 +020083# Pass maintainer script parameters to hook scripts
84export DEB_MAINT_PARAMS="\$@"
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
87exit 0
88EOF
89 chmod 755 "$tmpdir/DEBIAN/$script"
90done
91
92name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
93# Generate a simple changelog template
94cat <<EOF > debian/changelog
Frans Popc72c75d2009-04-23 01:09:44 +020095linux ($packageversion) unstable; urgency=low
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 * A standard release
98
99 -- $name $(date -R)
100EOF
101
102# Generate a control file
Frans Pop3e2ab252009-04-23 01:08:44 +0200103cat <<EOF > debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104Source: linux
105Section: base
106Priority: optional
107Maintainer: $name
108Standards-Version: 3.6.1
Frans Pop3e2ab252009-04-23 01:08:44 +0200109EOF
110
111if [ "$ARCH" = "um" ]; then
112 cat <<EOF >> debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Sam Ravnborg687c3da2005-07-14 20:24:00 +0000114Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700115Provides: kernel-image-$version, linux-image-$version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116Architecture: any
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000117Description: User Mode Linux kernel, version $version
118 User-mode Linux is a port of the Linux kernel to its own system call
119 interface. It provides a kind of virtual machine, which runs Linux
120 as a user process under another Linux kernel. This is useful for
121 kernel development, sandboxes, jails, experimentation, and
122 many other things.
123 .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 This package contains the Linux kernel, modules and corresponding other
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000125 files version $version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126EOF
127
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000128else
Frans Pop3e2ab252009-04-23 01:08:44 +0200129 cat <<EOF >> debian/control
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000130
131Package: $packagename
bugme-daemon@bugzilla.kernel.org6f67a002007-08-29 07:57:41 -0700132Provides: kernel-image-$version, linux-image-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100133Suggests: $fwpackagename
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000134Architecture: any
135Description: Linux kernel, version $version
136 This package contains the Linux kernel, modules and corresponding other
137 files version $version
138EOF
Frans Pop4f661992009-04-23 01:08:31 +0200139
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000140fi
141
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100142# Do we have firmware? Move it out of the way and build it into a package.
143if [ -e "$tmpdir/lib/firmware" ]; then
144 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
145
146 cat <<EOF >> debian/control
147
148Package: $fwpackagename
149Architecture: all
150Description: Linux kernel firmware, version $version
151 This package contains firmware from the Linux kernel, version $version
152EOF
153
Frans Pop3e2ab252009-04-23 01:08:44 +0200154 create_package "$fwpackagename" "$fwdir"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100155fi
156
Frans Pop3e2ab252009-04-23 01:08:44 +0200157create_package "$packagename" "$tmpdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159exit 0