blob: 07f2fbde2abf85a5f92040a10608a38e23db3905 [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/"
maximilian attems1ab18482009-06-26 20:04:36 +020019 cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
20 gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
FEJES Jozsefb59a1222010-03-05 18:19:36 +010021 sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
22 | xargs -r0 md5sum > DEBIAN/md5sums"
Frans Pop9461f662009-04-24 19:08:24 +020023
Frans Pop3e2ab252009-04-23 01:08:44 +020024 # Fix ownership and permissions
25 chown -R root:root "$pdir"
26 chmod -R go-w "$pdir"
27
28 # Create the package
29 dpkg-gencontrol -isp -p$pname -P"$pdir"
30 dpkg --build "$pdir" ..
31}
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033# Some variables and settings used throughout the script
34version=$KERNELRELEASE
Frans Pop4f661992009-04-23 01:08:31 +020035revision=$(cat .version)
Frans Popc72c75d2009-04-23 01:09:44 +020036if [ -n "$KDEB_PKGVERSION" ]; then
37 packageversion=$KDEB_PKGVERSION
38else
39 packageversion=$version-$revision
40fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070041tmpdir="$objtree/debian/tmp"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010042fwdir="$objtree/debian/fwtmp"
maximilian attemsf7a2c312009-04-23 01:12:01 +020043packagename=linux-image-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010044fwpackagename=linux-firmware-image
Sam Ravnborg687c3da2005-07-14 20:24:00 +000045
Frans Pop4f661992009-04-23 01:08:31 +020046if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000047 packagename=user-mode-linux-$version
48fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50# Setup the directory structure
Jonathan McDowellbf1b3642008-09-13 17:08:31 +010051rm -rf "$tmpdir" "$fwdir"
Frans Pop9461f662009-04-24 19:08:24 +020052mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
53mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
Frans Pop4f661992009-04-23 01:08:31 +020054if [ "$ARCH" = "um" ] ; then
Frans Pop9461f662009-04-24 19:08:24 +020055 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000056fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58# Build and install the kernel
Frans Pop4f661992009-04-23 01:08:31 +020059if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000060 $MAKE linux
61 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
62 cp .config "$tmpdir/usr/share/doc/$packagename/config"
63 gzip "$tmpdir/usr/share/doc/$packagename/config"
64 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
65else
66 cp System.map "$tmpdir/boot/System.map-$version"
67 cp .config "$tmpdir/boot/config-$version"
Frans Popa89b433bd2009-04-23 01:09:04 +020068 # Not all arches include the boot path in KBUILD_IMAGE
69 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
70 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
71 fi
Sam Ravnborg687c3da2005-07-14 20:24:00 +000072fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74if grep -q '^CONFIG_MODULES=y' .config ; then
Sam Ravnborga91f98a2005-07-14 20:26:09 +000075 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
Frans Pop4f661992009-04-23 01:08:31 +020076 if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000077 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
78 rmdir "$tmpdir/lib/modules/$version"
79 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070080fi
81
82# Install the maintainer scripts
Frans Popfe233cb2009-04-23 01:10:10 +020083# Note: hook scripts under /etc/kernel are also executed by official Debian
84# kernel packages, as well as kernel packages built using make-kpkg
85debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
Linus Torvalds1da177e2005-04-16 15:20:36 -070086for script in postinst postrm preinst prerm ; do
Frans Popfe233cb2009-04-23 01:10:10 +020087 mkdir -p "$tmpdir$debhookdir/$script.d"
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 cat <<EOF > "$tmpdir/DEBIAN/$script"
89#!/bin/sh
90
91set -e
92
Frans Pop49644512009-04-23 01:09:25 +020093# Pass maintainer script parameters to hook scripts
maximilian attems241ad112009-07-05 20:17:34 +020094export DEB_MAINT_PARAMS="\$*"
Frans Pop49644512009-04-23 01:09:25 +020095
Frans Popfe233cb2009-04-23 01:10:10 +020096test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
Linus Torvalds1da177e2005-04-16 15:20:36 -070097exit 0
98EOF
99 chmod 755 "$tmpdir/DEBIAN/$script"
100done
101
maximilian attemsedec6112009-04-23 01:11:20 +0200102# Try to determine maintainer and email values
103if [ -n "$DEBEMAIL" ]; then
104 email=$DEBEMAIL
105elif [ -n "$EMAIL" ]; then
106 email=$EMAIL
107else
108 email=$(id -nu)@$(hostname -f)
109fi
110if [ -n "$DEBFULLNAME" ]; then
111 name=$DEBFULLNAME
112elif [ -n "$NAME" ]; then
113 name=$NAME
114else
115 name="Anonymous"
116fi
117maintainer="$name <$email>"
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119# Generate a simple changelog template
120cat <<EOF > debian/changelog
Frans Pop4bf4cd42009-04-23 01:11:43 +0200121linux-upstream ($packageversion) unstable; urgency=low
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Frans Popa83ca2772009-04-23 01:10:25 +0200123 * Custom built Linux kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
maximilian attemsedec6112009-04-23 01:11:20 +0200125 -- $maintainer $(date -R)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126EOF
127
Frans Pop9461f662009-04-24 19:08:24 +0200128# Generate copyright file
129cat <<EOF > debian/copyright
130This is a packacked upstream version of the Linux kernel.
131
132The sources may be found at most Linux ftp sites, including:
133ftp://ftp.kernel.org/pub/linux/kernel
134
135Copyright: 1991 - 2009 Linus Torvalds and others.
136
137The git repository for mainline kernel development is at:
138git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
139
140 This program is free software; you can redistribute it and/or modify
141 it under the terms of the GNU General Public License as published by
142 the Free Software Foundation; version 2 dated June, 1991.
143
144On Debian GNU/Linux systems, the complete text of the GNU General Public
145License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
146EOF
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148# Generate a control file
Frans Pop3e2ab252009-04-23 01:08:44 +0200149cat <<EOF > debian/control
Frans Pop4bf4cd42009-04-23 01:11:43 +0200150Source: linux-upstream
maximilian attems54c33552009-04-23 01:12:41 +0200151Section: admin
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152Priority: optional
maximilian attemsedec6112009-04-23 01:11:20 +0200153Maintainer: $maintainer
maximilian attems6d992322009-04-23 01:12:58 +0200154Standards-Version: 3.8.1
Frans Pop3e2ab252009-04-23 01:08:44 +0200155EOF
156
157if [ "$ARCH" = "um" ]; then
158 cat <<EOF >> debian/control
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Sam Ravnborg687c3da2005-07-14 20:24:00 +0000160Package: $packagename
maximilian attems8ebc2fe2009-04-23 01:12:21 +0200161Provides: linux-image, linux-image-2.6, linux-modules-$version
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162Architecture: any
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000163Description: User Mode Linux kernel, version $version
164 User-mode Linux is a port of the Linux kernel to its own system call
165 interface. It provides a kind of virtual machine, which runs Linux
166 as a user process under another Linux kernel. This is useful for
167 kernel development, sandboxes, jails, experimentation, and
168 many other things.
169 .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 This package contains the Linux kernel, modules and corresponding other
Frans Popa83ca2772009-04-23 01:10:25 +0200171 files, version: $version.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172EOF
173
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000174else
Frans Pop3e2ab252009-04-23 01:08:44 +0200175 cat <<EOF >> debian/control
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000176
177Package: $packagename
maximilian attems8ebc2fe2009-04-23 01:12:21 +0200178Provides: linux-image, linux-image-2.6, linux-modules-$version
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100179Suggests: $fwpackagename
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000180Architecture: any
181Description: Linux kernel, version $version
182 This package contains the Linux kernel, modules and corresponding other
Frans Popa83ca2772009-04-23 01:10:25 +0200183 files, version: $version.
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000184EOF
Frans Pop4f661992009-04-23 01:08:31 +0200185
Sam Ravnborgdc5962f2005-07-14 20:24:56 +0000186fi
187
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100188# Do we have firmware? Move it out of the way and build it into a package.
189if [ -e "$tmpdir/lib/firmware" ]; then
190 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
191
192 cat <<EOF >> debian/control
193
194Package: $fwpackagename
195Architecture: all
196Description: Linux kernel firmware, version $version
Frans Popa83ca2772009-04-23 01:10:25 +0200197 This package contains firmware from the Linux kernel, version $version.
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100198EOF
199
Frans Pop3e2ab252009-04-23 01:08:44 +0200200 create_package "$fwpackagename" "$fwdir"
Jonathan McDowellbf1b3642008-09-13 17:08:31 +0100201fi
202
Frans Pop3e2ab252009-04-23 01:08:44 +0200203create_package "$packagename" "$tmpdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205exit 0