kbuild, deb-pkg: improve Source field
[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
FP
18 cp debian/copyright "$pdir/usr/share/doc/$pname/"
19
3e2ab256
FP
20 # 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
1da177e4
LT
29# Some variables and settings used throughout the script
30version=$KERNELRELEASE
4f66199b 31revision=$(cat .version)
c72c75db
FP
32if [ -n "$KDEB_PKGVERSION" ]; then
33 packageversion=$KDEB_PKGVERSION
34else
35 packageversion=$version-$revision
36fi
1da177e4 37tmpdir="$objtree/debian/tmp"
bf1b3644 38fwdir="$objtree/debian/fwtmp"
687c3dac 39packagename=linux-$version
bf1b3644 40fwpackagename=linux-firmware-image
687c3dac 41
4f66199b 42if [ "$ARCH" = "um" ] ; then
687c3dac
SR
43 packagename=user-mode-linux-$version
44fi
1da177e4
LT
45
46# Setup the directory structure
bf1b3644 47rm -rf "$tmpdir" "$fwdir"
9461f666
FP
48mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
49mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
4f66199b 50if [ "$ARCH" = "um" ] ; then
9461f666 51 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
687c3dac 52fi
1da177e4
LT
53
54# Build and install the kernel
4f66199b 55if [ "$ARCH" = "um" ] ; then
687c3dac
SR
56 $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"
a89b433b
FP
64 # 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
687c3dac 68fi
1da177e4
LT
69
70if grep -q '^CONFIG_MODULES=y' .config ; then
a91f98a2 71 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
4f66199b 72 if [ "$ARCH" = "um" ] ; then
687c3dac
SR
73 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
74 rmdir "$tmpdir/lib/modules/$version"
75 fi
1da177e4
LT
76fi
77
78# Install the maintainer scripts
fe233cb6
FP
79# 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}
1da177e4 82for script in postinst postrm preinst prerm ; do
fe233cb6 83 mkdir -p "$tmpdir$debhookdir/$script.d"
1da177e4
LT
84 cat <<EOF > "$tmpdir/DEBIAN/$script"
85#!/bin/sh
86
87set -e
88
4964451a
FP
89# Pass maintainer script parameters to hook scripts
90export DEB_MAINT_PARAMS="\$@"
91
fe233cb6 92test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
1da177e4
LT
93exit 0
94EOF
95 chmod 755 "$tmpdir/DEBIAN/$script"
96done
97
edec611d 98# 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
1da177e4
LT
115# Generate a simple changelog template
116cat <<EOF > debian/changelog
4bf4cd49 117linux-upstream ($packageversion) unstable; urgency=low
1da177e4 118
a83ca277 119 * Custom built Linux kernel.
1da177e4 120
edec611d 121 -- $maintainer $(date -R)
1da177e4
LT
122EOF
123
9461f666
FP
124# 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
1da177e4 144# Generate a control file
3e2ab256 145cat <<EOF > debian/control
4bf4cd49 146Source: linux-upstream
dc5962fd
SR
147Section: base
148Priority: optional
edec611d 149Maintainer: $maintainer
dc5962fd 150Standards-Version: 3.6.1
3e2ab256
FP
151EOF
152
153if [ "$ARCH" = "um" ]; then
154 cat <<EOF >> debian/control
dc5962fd
SR
155
156Package: $packagename
6f67a004 157Provides: kernel-image-$version, linux-image-$version
dc5962fd
SR
158Architecture: any
159Description: 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 .
166 This package contains the Linux kernel, modules and corresponding other
a83ca277 167 files, version: $version.
dc5962fd
SR
168EOF
169
170else
3e2ab256 171 cat <<EOF >> debian/control
1da177e4 172
687c3dac 173Package: $packagename
6f67a004 174Provides: kernel-image-$version, linux-image-$version
bf1b3644 175Suggests: $fwpackagename
1da177e4 176Architecture: any
dc5962fd 177Description: Linux kernel, version $version
1da177e4 178 This package contains the Linux kernel, modules and corresponding other
a83ca277 179 files, version: $version.
1da177e4 180EOF
4f66199b 181
dc5962fd 182fi
1da177e4 183
bf1b3644
JM
184# 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
a83ca277 193 This package contains firmware from the Linux kernel, version $version.
bf1b3644
JM
194EOF
195
3e2ab256 196 create_package "$fwpackagename" "$fwdir"
bf1b3644
JM
197fi
198
3e2ab256 199create_package "$packagename" "$tmpdir"
1da177e4
LT
200
201exit 0
This page took 0.353044 seconds and 5 git commands to generate.