xref: /openbmc/linux/scripts/package/builddeb (revision 241ad11f)
11da177e4SLinus Torvalds#!/bin/sh
21da177e4SLinus Torvalds#
34964451aSFrans Pop# builddeb 1.3
41da177e4SLinus Torvalds# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
51da177e4SLinus Torvalds#
61da177e4SLinus Torvalds# Simple script to generate a deb package for a Linux kernel. All the
74f66199bSFrans Pop# complexity of what to do with a kernel after it is installed or removed
81da177e4SLinus Torvalds# is left to other scripts and packages: they can install scripts in the
9fe233cb6SFrans Pop# /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
10fe233cb6SFrans Pop# specified in KDEB_HOOKDIR) that will be called on package install and
11fe233cb6SFrans Pop# removal.
121da177e4SLinus Torvalds
131da177e4SLinus Torvaldsset -e
141da177e4SLinus Torvalds
153e2ab256SFrans Popcreate_package() {
163e2ab256SFrans Pop	local pname="$1" pdir="$2"
173e2ab256SFrans Pop
189461f666SFrans Pop	cp debian/copyright "$pdir/usr/share/doc/$pname/"
191ab18486Smaximilian attems	cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
201ab18486Smaximilian attems	gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
219461f666SFrans Pop
223e2ab256SFrans Pop	# Fix ownership and permissions
233e2ab256SFrans Pop	chown -R root:root "$pdir"
243e2ab256SFrans Pop	chmod -R go-w "$pdir"
253e2ab256SFrans Pop
263e2ab256SFrans Pop	# Create the package
273e2ab256SFrans Pop	dpkg-gencontrol -isp -p$pname -P"$pdir"
283e2ab256SFrans Pop	dpkg --build "$pdir" ..
293e2ab256SFrans Pop}
303e2ab256SFrans Pop
311da177e4SLinus Torvalds# Some variables and settings used throughout the script
321da177e4SLinus Torvaldsversion=$KERNELRELEASE
334f66199bSFrans Poprevision=$(cat .version)
34c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then
35c72c75dbSFrans Pop	packageversion=$KDEB_PKGVERSION
36c72c75dbSFrans Popelse
37c72c75dbSFrans Pop	packageversion=$version-$revision
38c72c75dbSFrans Popfi
391da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp"
40bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp"
41f7a2c31fSmaximilian attemspackagename=linux-image-$version
42bf1b3644SJonathan McDowellfwpackagename=linux-firmware-image
43687c3dacSSam Ravnborg
444f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
45687c3dacSSam Ravnborg	packagename=user-mode-linux-$version
46687c3dacSSam Ravnborgfi
471da177e4SLinus Torvalds
481da177e4SLinus Torvalds# Setup the directory structure
49bf1b3644SJonathan McDowellrm -rf "$tmpdir" "$fwdir"
509461f666SFrans Popmkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
519461f666SFrans Popmkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
524f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
539461f666SFrans Pop	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
54687c3dacSSam Ravnborgfi
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds# Build and install the kernel
574f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
58687c3dacSSam Ravnborg	$MAKE linux
59687c3dacSSam Ravnborg	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
60687c3dacSSam Ravnborg	cp .config "$tmpdir/usr/share/doc/$packagename/config"
61687c3dacSSam Ravnborg	gzip "$tmpdir/usr/share/doc/$packagename/config"
62687c3dacSSam Ravnborg	cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
63687c3dacSSam Ravnborgelse
641da177e4SLinus Torvalds	cp System.map "$tmpdir/boot/System.map-$version"
651da177e4SLinus Torvalds	cp .config "$tmpdir/boot/config-$version"
66a89b433bSFrans Pop	# Not all arches include the boot path in KBUILD_IMAGE
67a89b433bSFrans Pop	if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
68a89b433bSFrans Pop		cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
69a89b433bSFrans Pop	fi
70687c3dacSSam Ravnborgfi
711da177e4SLinus Torvalds
721da177e4SLinus Torvaldsif grep -q '^CONFIG_MODULES=y' .config ; then
73a91f98a2SSam Ravnborg	INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
744f66199bSFrans Pop	if [ "$ARCH" = "um" ] ; then
75687c3dacSSam Ravnborg		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
76687c3dacSSam Ravnborg		rmdir "$tmpdir/lib/modules/$version"
77687c3dacSSam Ravnborg	fi
781da177e4SLinus Torvaldsfi
791da177e4SLinus Torvalds
801da177e4SLinus Torvalds# Install the maintainer scripts
81fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian
82fe233cb6SFrans Pop# kernel packages, as well as kernel packages built using make-kpkg
83fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel}
841da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do
85fe233cb6SFrans Pop	mkdir -p "$tmpdir$debhookdir/$script.d"
861da177e4SLinus Torvalds	cat <<EOF > "$tmpdir/DEBIAN/$script"
871da177e4SLinus Torvalds#!/bin/sh
881da177e4SLinus Torvalds
891da177e4SLinus Torvaldsset -e
901da177e4SLinus Torvalds
914964451aSFrans Pop# Pass maintainer script parameters to hook scripts
92241ad11fSmaximilian attemsexport DEB_MAINT_PARAMS="\$*"
934964451aSFrans Pop
94fe233cb6SFrans Poptest -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
951da177e4SLinus Torvaldsexit 0
961da177e4SLinus TorvaldsEOF
971da177e4SLinus Torvalds	chmod 755 "$tmpdir/DEBIAN/$script"
981da177e4SLinus Torvaldsdone
991da177e4SLinus Torvalds
100edec611dSmaximilian attems# Try to determine maintainer and email values
101edec611dSmaximilian attemsif [ -n "$DEBEMAIL" ]; then
102edec611dSmaximilian attems       email=$DEBEMAIL
103edec611dSmaximilian attemselif [ -n "$EMAIL" ]; then
104edec611dSmaximilian attems       email=$EMAIL
105edec611dSmaximilian attemselse
106edec611dSmaximilian attems       email=$(id -nu)@$(hostname -f)
107edec611dSmaximilian attemsfi
108edec611dSmaximilian attemsif [ -n "$DEBFULLNAME" ]; then
109edec611dSmaximilian attems       name=$DEBFULLNAME
110edec611dSmaximilian attemselif [ -n "$NAME" ]; then
111edec611dSmaximilian attems       name=$NAME
112edec611dSmaximilian attemselse
113edec611dSmaximilian attems       name="Anonymous"
114edec611dSmaximilian attemsfi
115edec611dSmaximilian attemsmaintainer="$name <$email>"
116edec611dSmaximilian attems
1171da177e4SLinus Torvalds# Generate a simple changelog template
1181da177e4SLinus Torvaldscat <<EOF > debian/changelog
1194bf4cd49SFrans Poplinux-upstream ($packageversion) unstable; urgency=low
1201da177e4SLinus Torvalds
121a83ca277SFrans Pop  * Custom built Linux kernel.
1221da177e4SLinus Torvalds
123edec611dSmaximilian attems -- $maintainer  $(date -R)
1241da177e4SLinus TorvaldsEOF
1251da177e4SLinus Torvalds
1269461f666SFrans Pop# Generate copyright file
1279461f666SFrans Popcat <<EOF > debian/copyright
1289461f666SFrans PopThis is a packacked upstream version of the Linux kernel.
1299461f666SFrans Pop
1309461f666SFrans PopThe sources may be found at most Linux ftp sites, including:
1319461f666SFrans Popftp://ftp.kernel.org/pub/linux/kernel
1329461f666SFrans Pop
1339461f666SFrans PopCopyright: 1991 - 2009 Linus Torvalds and others.
1349461f666SFrans Pop
1359461f666SFrans PopThe git repository for mainline kernel development is at:
1369461f666SFrans Popgit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
1379461f666SFrans Pop
1389461f666SFrans Pop    This program is free software; you can redistribute it and/or modify
1399461f666SFrans Pop    it under the terms of the GNU General Public License as published by
1409461f666SFrans Pop    the Free Software Foundation; version 2 dated June, 1991.
1419461f666SFrans Pop
1429461f666SFrans PopOn Debian GNU/Linux systems, the complete text of the GNU General Public
1439461f666SFrans PopLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
1449461f666SFrans PopEOF
1459461f666SFrans Pop
1461da177e4SLinus Torvalds# Generate a control file
1471da177e4SLinus Torvaldscat <<EOF > debian/control
1484bf4cd49SFrans PopSource: linux-upstream
14954c33556Smaximilian attemsSection: admin
1501da177e4SLinus TorvaldsPriority: optional
151edec611dSmaximilian attemsMaintainer: $maintainer
1526d992321Smaximilian attemsStandards-Version: 3.8.1
1533e2ab256SFrans PopEOF
1543e2ab256SFrans Pop
1553e2ab256SFrans Popif [ "$ARCH" = "um" ]; then
1563e2ab256SFrans Pop	cat <<EOF >> debian/control
1571da177e4SLinus Torvalds
158687c3dacSSam RavnborgPackage: $packagename
1598ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
1601da177e4SLinus TorvaldsArchitecture: any
161dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version
162dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call
163dc5962fdSSam Ravnborg interface.  It provides a kind of virtual machine, which runs Linux
164dc5962fdSSam Ravnborg as a user process under another Linux kernel.  This is useful for
165dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and
166dc5962fdSSam Ravnborg many other things.
167dc5962fdSSam Ravnborg .
1681da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other
169a83ca277SFrans Pop files, version: $version.
1701da177e4SLinus TorvaldsEOF
1711da177e4SLinus Torvalds
172dc5962fdSSam Ravnborgelse
1733e2ab256SFrans Pop	cat <<EOF >> debian/control
174dc5962fdSSam Ravnborg
175dc5962fdSSam RavnborgPackage: $packagename
1768ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
177bf1b3644SJonathan McDowellSuggests: $fwpackagename
178dc5962fdSSam RavnborgArchitecture: any
179dc5962fdSSam RavnborgDescription: Linux kernel, version $version
180dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other
181a83ca277SFrans Pop files, version: $version.
182dc5962fdSSam RavnborgEOF
1834f66199bSFrans Pop
184dc5962fdSSam Ravnborgfi
185dc5962fdSSam Ravnborg
186bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package.
187bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then
188bf1b3644SJonathan McDowell	mv "$tmpdir/lib/firmware" "$fwdir/lib/"
189bf1b3644SJonathan McDowell
190bf1b3644SJonathan McDowell	cat <<EOF >> debian/control
191bf1b3644SJonathan McDowell
192bf1b3644SJonathan McDowellPackage: $fwpackagename
193bf1b3644SJonathan McDowellArchitecture: all
194bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version
195a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version.
196bf1b3644SJonathan McDowellEOF
197bf1b3644SJonathan McDowell
1983e2ab256SFrans Pop	create_package "$fwpackagename" "$fwdir"
199bf1b3644SJonathan McDowellfi
200bf1b3644SJonathan McDowell
2013e2ab256SFrans Popcreate_package "$packagename" "$tmpdir"
2021da177e4SLinus Torvalds
2031da177e4SLinus Torvaldsexit 0
204