builddeb 4.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2
#!/bin/sh
#
3
# builddeb 1.3
L
Linus Torvalds 已提交
4 5 6
# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
#
# Simple script to generate a deb package for a Linux kernel. All the
7
# complexity of what to do with a kernel after it is installed or removed
L
Linus Torvalds 已提交
8
# is left to other scripts and packages: they can install scripts in the
9 10 11
# /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
# specified in KDEB_HOOKDIR) that will be called on package install and
# removal.
L
Linus Torvalds 已提交
12 13 14

set -e

15 16 17 18 19 20 21 22 23 24 25 26
create_package() {
	local pname="$1" pdir="$2"

	# Fix ownership and permissions
	chown -R root:root "$pdir"
	chmod -R go-w "$pdir"

	# Create the package
	dpkg-gencontrol -isp -p$pname -P"$pdir"
	dpkg --build "$pdir" ..
}

L
Linus Torvalds 已提交
27 28
# Some variables and settings used throughout the script
version=$KERNELRELEASE
29
revision=$(cat .version)
30 31 32 33 34
if [ -n "$KDEB_PKGVERSION" ]; then
	packageversion=$KDEB_PKGVERSION
else
	packageversion=$version-$revision
fi
L
Linus Torvalds 已提交
35
tmpdir="$objtree/debian/tmp"
36
fwdir="$objtree/debian/fwtmp"
37
packagename=linux-$version
38
fwpackagename=linux-firmware-image
39

40
if [ "$ARCH" = "um" ] ; then
41 42
	packagename=user-mode-linux-$version
fi
L
Linus Torvalds 已提交
43 44

# Setup the directory structure
45
rm -rf "$tmpdir" "$fwdir"
L
Linus Torvalds 已提交
46
mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
47
mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
48
if [ "$ARCH" = "um" ] ; then
49 50
	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
fi
L
Linus Torvalds 已提交
51 52

# Build and install the kernel
53
if [ "$ARCH" = "um" ] ; then
54 55 56 57 58 59 60 61
	$MAKE linux
	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
	cp .config "$tmpdir/usr/share/doc/$packagename/config"
	gzip "$tmpdir/usr/share/doc/$packagename/config"
	cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
else 
	cp System.map "$tmpdir/boot/System.map-$version"
	cp .config "$tmpdir/boot/config-$version"
62 63 64 65
	# Not all arches include the boot path in KBUILD_IMAGE
	if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
		cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
	fi
66
fi
L
Linus Torvalds 已提交
67 68

if grep -q '^CONFIG_MODULES=y' .config ; then
69
	INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
70
	if [ "$ARCH" = "um" ] ; then
71 72 73
		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
		rmdir "$tmpdir/lib/modules/$version"
	fi
L
Linus Torvalds 已提交
74 75 76
fi

# Install the maintainer scripts
77 78 79
# Note: hook scripts under /etc/kernel are also executed by official Debian
# kernel packages, as well as kernel packages built using make-kpkg
debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
L
Linus Torvalds 已提交
80
for script in postinst postrm preinst prerm ; do
81
	mkdir -p "$tmpdir$debhookdir/$script.d"
L
Linus Torvalds 已提交
82 83 84 85 86
	cat <<EOF > "$tmpdir/DEBIAN/$script"
#!/bin/sh

set -e

87 88 89
# Pass maintainer script parameters to hook scripts
export DEB_MAINT_PARAMS="\$@"

90
test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
L
Linus Torvalds 已提交
91 92 93 94 95 96 97 98
exit 0
EOF
	chmod 755 "$tmpdir/DEBIAN/$script"
done

name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
# Generate a simple changelog template
cat <<EOF > debian/changelog
99
linux ($packageversion) unstable; urgency=low
L
Linus Torvalds 已提交
100

101
  * Custom built Linux kernel.
L
Linus Torvalds 已提交
102 103 104 105 106

 -- $name  $(date -R)
EOF

# Generate a control file
107
cat <<EOF > debian/control
108 109 110 111 112
Source: linux
Section: base
Priority: optional
Maintainer: $name
Standards-Version: 3.6.1
113 114 115 116
EOF

if [ "$ARCH" = "um" ]; then
	cat <<EOF >> debian/control
117 118

Package: $packagename
119
Provides: kernel-image-$version, linux-image-$version
120 121 122 123 124 125 126 127 128
Architecture: any
Description: User Mode Linux kernel, version $version
 User-mode Linux is a port of the Linux kernel to its own system call
 interface.  It provides a kind of virtual machine, which runs Linux
 as a user process under another Linux kernel.  This is useful for
 kernel development, sandboxes, jails, experimentation, and
 many other things.
 .
 This package contains the Linux kernel, modules and corresponding other
129
 files, version: $version.
130 131 132
EOF

else
133
	cat <<EOF >> debian/control
L
Linus Torvalds 已提交
134

135
Package: $packagename
136
Provides: kernel-image-$version, linux-image-$version
137
Suggests: $fwpackagename
L
Linus Torvalds 已提交
138
Architecture: any
139
Description: Linux kernel, version $version
L
Linus Torvalds 已提交
140
 This package contains the Linux kernel, modules and corresponding other
141
 files, version: $version.
L
Linus Torvalds 已提交
142
EOF
143

144
fi
L
Linus Torvalds 已提交
145

146 147 148 149 150 151 152 153 154
# Do we have firmware? Move it out of the way and build it into a package.
if [ -e "$tmpdir/lib/firmware" ]; then
	mv "$tmpdir/lib/firmware" "$fwdir/lib/"

	cat <<EOF >> debian/control

Package: $fwpackagename
Architecture: all
Description: Linux kernel firmware, version $version
155
 This package contains firmware from the Linux kernel, version $version.
156 157
EOF

158
	create_package "$fwpackagename" "$fwdir"
159 160
fi

161
create_package "$packagename" "$tmpdir"
L
Linus Torvalds 已提交
162 163

exit 0