Merge branch 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / scripts / package / builddeb
CommitLineData
1da177e4
LT
1#!/bin/sh
2#
4964451a 3# builddeb 1.3
1da177e4
LT
4# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
5#
6# Simple script to generate a deb package for a Linux kernel. All the
4f66199b 7# complexity of what to do with a kernel after it is installed or removed
1da177e4 8# is left to other scripts and packages: they can install scripts in the
fe233cb6
FP
9# /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.
1da177e4
LT
12
13set -e
14
3e2ab256
FP
15create_package() {
16 local pname="$1" pdir="$2"
17
9461f666 18 cp debian/copyright "$pdir/usr/share/doc/$pname/"
1ab18486 19 cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
20 gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
9461f666 21
3e2ab256
FP
22 # Fix ownership and permissions
23 chown -R root:root "$pdir"
24 chmod -R go-w "$pdir"
25
26 # Create the package
27 dpkg-gencontrol -isp -p$pname -P"$pdir"
28 dpkg --build "$pdir" ..
29}
30
1da177e4
LT
31# Some variables and settings used throughout the script
32version=$KERNELRELEASE
4f66199b 33revision=$(cat .version)
c72c75db
FP
34if [ -n "$KDEB_PKGVERSION" ]; then
35 packageversion=$KDEB_PKGVERSION
36else
37 packageversion=$version-$revision
38fi
1da177e4 39tmpdir="$objtree/debian/tmp"
bf1b3644 40fwdir="$objtree/debian/fwtmp"
f7a2c31f 41packagename=linux-image-$version
bf1b3644 42fwpackagename=linux-firmware-image
687c3dac 43
4f66199b 44if [ "$ARCH" = "um" ] ; then
687c3dac
SR
45 packagename=user-mode-linux-$version
46fi
1da177e4
LT
47
48# Setup the directory structure
bf1b3644 49rm -rf "$tmpdir" "$fwdir"
9461f666
FP
50mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
51mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
4f66199b 52if [ "$ARCH" = "um" ] ; then
9461f666 53 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
687c3dac 54fi
1da177e4
LT
55
56# Build and install the kernel
4f66199b 57if [ "$ARCH" = "um" ] ; then
687c3dac
SR
58 $MAKE linux
59 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
60 cp .config "$tmpdir/usr/share/doc/$packagename/config"
61 gzip "$tmpdir/usr/share/doc/$packagename/config"
62 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
63else
64 cp System.map "$tmpdir/boot/System.map-$version"
65 cp .config "$tmpdir/boot/config-$version"
a89b433b
FP
66 # Not all arches include the boot path in KBUILD_IMAGE
67 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
68 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
69 fi
687c3dac 70fi
1da177e4
LT
71
72if grep -q '^CONFIG_MODULES=y' .config ; then
a91f98a2 73 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
4f66199b 74 if [ "$ARCH" = "um" ] ; then
687c3dac
SR
75 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
76 rmdir "$tmpdir/lib/modules/$version"
77 fi
1da177e4
LT
78fi
79
80# Install the maintainer scripts
fe233cb6
FP
81# Note: hook scripts under /etc/kernel are also executed by official Debian
82# kernel packages, as well as kernel packages built using make-kpkg
83debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
1da177e4 84for script in postinst postrm preinst prerm ; do
fe233cb6 85 mkdir -p "$tmpdir$debhookdir/$script.d"
1da177e4
LT
86 cat <<EOF > "$tmpdir/DEBIAN/$script"
87#!/bin/sh
88
89set -e
90
4964451a 91# Pass maintainer script parameters to hook scripts
241ad11f 92export DEB_MAINT_PARAMS="\$*"
4964451a 93
fe233cb6 94test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
1da177e4
LT
95exit 0
96EOF
97 chmod 755 "$tmpdir/DEBIAN/$script"
98done
99
edec611d 100# Try to determine maintainer and email values
101if [ -n "$DEBEMAIL" ]; then
102 email=$DEBEMAIL
103elif [ -n "$EMAIL" ]; then
104 email=$EMAIL
105else
106 email=$(id -nu)@$(hostname -f)
107fi
108if [ -n "$DEBFULLNAME" ]; then
109 name=$DEBFULLNAME
110elif [ -n "$NAME" ]; then
111 name=$NAME
112else
113 name="Anonymous"
114fi
115maintainer="$name <$email>"
116
1da177e4
LT
117# Generate a simple changelog template
118cat <<EOF > debian/changelog
4bf4cd49 119linux-upstream ($packageversion) unstable; urgency=low
1da177e4 120
a83ca277 121 * Custom built Linux kernel.
1da177e4 122
edec611d 123 -- $maintainer $(date -R)
1da177e4
LT
124EOF
125
9461f666
FP
126# Generate copyright file
127cat <<EOF > debian/copyright
128This is a packacked upstream version of the Linux kernel.
129
130The sources may be found at most Linux ftp sites, including:
131ftp://ftp.kernel.org/pub/linux/kernel
132
133Copyright: 1991 - 2009 Linus Torvalds and others.
134
135The git repository for mainline kernel development is at:
136git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
137
138 This program is free software; you can redistribute it and/or modify
139 it under the terms of the GNU General Public License as published by
140 the Free Software Foundation; version 2 dated June, 1991.
141
142On Debian GNU/Linux systems, the complete text of the GNU General Public
143License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
144EOF
145
1da177e4 146# Generate a control file
3e2ab256 147cat <<EOF > debian/control
4bf4cd49 148Source: linux-upstream
54c33556 149Section: admin
dc5962fd 150Priority: optional
edec611d 151Maintainer: $maintainer
6d992321 152Standards-Version: 3.8.1
3e2ab256
FP
153EOF
154
155if [ "$ARCH" = "um" ]; then
156 cat <<EOF >> debian/control
dc5962fd
SR
157
158Package: $packagename
8ebc2fe9 159Provides: linux-image, linux-image-2.6, linux-modules-$version
dc5962fd
SR
160Architecture: any
161Description: User Mode Linux kernel, version $version
162 User-mode Linux is a port of the Linux kernel to its own system call
163 interface. It provides a kind of virtual machine, which runs Linux
164 as a user process under another Linux kernel. This is useful for
165 kernel development, sandboxes, jails, experimentation, and
166 many other things.
167 .
168 This package contains the Linux kernel, modules and corresponding other
a83ca277 169 files, version: $version.
dc5962fd
SR
170EOF
171
172else
3e2ab256 173 cat <<EOF >> debian/control
1da177e4 174
687c3dac 175Package: $packagename
8ebc2fe9 176Provides: linux-image, linux-image-2.6, linux-modules-$version
bf1b3644 177Suggests: $fwpackagename
1da177e4 178Architecture: any
dc5962fd 179Description: Linux kernel, version $version
1da177e4 180 This package contains the Linux kernel, modules and corresponding other
a83ca277 181 files, version: $version.
1da177e4 182EOF
4f66199b 183
dc5962fd 184fi
1da177e4 185
bf1b3644
JM
186# Do we have firmware? Move it out of the way and build it into a package.
187if [ -e "$tmpdir/lib/firmware" ]; then
188 mv "$tmpdir/lib/firmware" "$fwdir/lib/"
189
190 cat <<EOF >> debian/control
191
192Package: $fwpackagename
193Architecture: all
194Description: Linux kernel firmware, version $version
a83ca277 195 This package contains firmware from the Linux kernel, version $version.
bf1b3644
JM
196EOF
197
3e2ab256 198 create_package "$fwpackagename" "$fwdir"
bf1b3644
JM
199fi
200
3e2ab256 201create_package "$packagename" "$tmpdir"
1da177e4
LT
202
203exit 0
This page took 0.375973 seconds and 5 git commands to generate.