xref: /openbmc/linux/scripts/package/builddeb (revision 242c5ab0)
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"
21b59a1225SFEJES Jozsef	sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
22b59a1225SFEJES Jozsef		| xargs -r0 md5sum > DEBIAN/md5sums"
239461f666SFrans Pop
243e2ab256SFrans Pop	# Fix ownership and permissions
253e2ab256SFrans Pop	chown -R root:root "$pdir"
263e2ab256SFrans Pop	chmod -R go-w "$pdir"
273e2ab256SFrans Pop
283e2ab256SFrans Pop	# Create the package
293e2ab256SFrans Pop	dpkg-gencontrol -isp -p$pname -P"$pdir"
303e2ab256SFrans Pop	dpkg --build "$pdir" ..
313e2ab256SFrans Pop}
323e2ab256SFrans Pop
331da177e4SLinus Torvalds# Some variables and settings used throughout the script
341da177e4SLinus Torvaldsversion=$KERNELRELEASE
354f66199bSFrans Poprevision=$(cat .version)
36c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then
37c72c75dbSFrans Pop	packageversion=$KDEB_PKGVERSION
38c72c75dbSFrans Popelse
39c72c75dbSFrans Pop	packageversion=$version-$revision
40c72c75dbSFrans Popfi
411da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp"
42bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp"
43f7a2c31fSmaximilian attemspackagename=linux-image-$version
44bf1b3644SJonathan McDowellfwpackagename=linux-firmware-image
45687c3dacSSam Ravnborg
464f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
47687c3dacSSam Ravnborg	packagename=user-mode-linux-$version
48687c3dacSSam Ravnborgfi
491da177e4SLinus Torvalds
501da177e4SLinus Torvalds# Setup the directory structure
51bf1b3644SJonathan McDowellrm -rf "$tmpdir" "$fwdir"
529461f666SFrans Popmkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
539461f666SFrans Popmkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
544f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
559461f666SFrans Pop	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
56687c3dacSSam Ravnborgfi
571da177e4SLinus Torvalds
581da177e4SLinus Torvalds# Build and install the kernel
594f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
60687c3dacSSam Ravnborg	$MAKE linux
61687c3dacSSam Ravnborg	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
62687c3dacSSam Ravnborg	cp .config "$tmpdir/usr/share/doc/$packagename/config"
63687c3dacSSam Ravnborg	gzip "$tmpdir/usr/share/doc/$packagename/config"
64687c3dacSSam Ravnborg	cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
65687c3dacSSam Ravnborgelse
661da177e4SLinus Torvalds	cp System.map "$tmpdir/boot/System.map-$version"
671da177e4SLinus Torvalds	cp .config "$tmpdir/boot/config-$version"
68a89b433bSFrans Pop	# Not all arches include the boot path in KBUILD_IMAGE
69242c5ab0SGuillem Jover	if [ -e $KBUILD_IMAGE ]; then
70242c5ab0SGuillem Jover		cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
71242c5ab0SGuillem Jover	else
72a89b433bSFrans Pop		cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
73a89b433bSFrans Pop	fi
74687c3dacSSam Ravnborgfi
751da177e4SLinus Torvalds
761da177e4SLinus Torvaldsif grep -q '^CONFIG_MODULES=y' .config ; then
77a91f98a2SSam Ravnborg	INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
784f66199bSFrans Pop	if [ "$ARCH" = "um" ] ; then
79687c3dacSSam Ravnborg		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
80687c3dacSSam Ravnborg		rmdir "$tmpdir/lib/modules/$version"
81687c3dacSSam Ravnborg	fi
821da177e4SLinus Torvaldsfi
831da177e4SLinus Torvalds
841da177e4SLinus Torvalds# Install the maintainer scripts
85fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian
86fe233cb6SFrans Pop# kernel packages, as well as kernel packages built using make-kpkg
87fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel}
881da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do
89fe233cb6SFrans Pop	mkdir -p "$tmpdir$debhookdir/$script.d"
901da177e4SLinus Torvalds	cat <<EOF > "$tmpdir/DEBIAN/$script"
911da177e4SLinus Torvalds#!/bin/sh
921da177e4SLinus Torvalds
931da177e4SLinus Torvaldsset -e
941da177e4SLinus Torvalds
954964451aSFrans Pop# Pass maintainer script parameters to hook scripts
96241ad11fSmaximilian attemsexport DEB_MAINT_PARAMS="\$*"
974964451aSFrans Pop
98fe233cb6SFrans Poptest -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
991da177e4SLinus Torvaldsexit 0
1001da177e4SLinus TorvaldsEOF
1011da177e4SLinus Torvalds	chmod 755 "$tmpdir/DEBIAN/$script"
1021da177e4SLinus Torvaldsdone
1031da177e4SLinus Torvalds
104edec611dSmaximilian attems# Try to determine maintainer and email values
105edec611dSmaximilian attemsif [ -n "$DEBEMAIL" ]; then
106edec611dSmaximilian attems       email=$DEBEMAIL
107edec611dSmaximilian attemselif [ -n "$EMAIL" ]; then
108edec611dSmaximilian attems       email=$EMAIL
109edec611dSmaximilian attemselse
110edec611dSmaximilian attems       email=$(id -nu)@$(hostname -f)
111edec611dSmaximilian attemsfi
112edec611dSmaximilian attemsif [ -n "$DEBFULLNAME" ]; then
113edec611dSmaximilian attems       name=$DEBFULLNAME
114edec611dSmaximilian attemselif [ -n "$NAME" ]; then
115edec611dSmaximilian attems       name=$NAME
116edec611dSmaximilian attemselse
117edec611dSmaximilian attems       name="Anonymous"
118edec611dSmaximilian attemsfi
119edec611dSmaximilian attemsmaintainer="$name <$email>"
120edec611dSmaximilian attems
1211da177e4SLinus Torvalds# Generate a simple changelog template
1221da177e4SLinus Torvaldscat <<EOF > debian/changelog
1234bf4cd49SFrans Poplinux-upstream ($packageversion) unstable; urgency=low
1241da177e4SLinus Torvalds
125a83ca277SFrans Pop  * Custom built Linux kernel.
1261da177e4SLinus Torvalds
127edec611dSmaximilian attems -- $maintainer  $(date -R)
1281da177e4SLinus TorvaldsEOF
1291da177e4SLinus Torvalds
1309461f666SFrans Pop# Generate copyright file
1319461f666SFrans Popcat <<EOF > debian/copyright
1329461f666SFrans PopThis is a packacked upstream version of the Linux kernel.
1339461f666SFrans Pop
1349461f666SFrans PopThe sources may be found at most Linux ftp sites, including:
1359461f666SFrans Popftp://ftp.kernel.org/pub/linux/kernel
1369461f666SFrans Pop
1379461f666SFrans PopCopyright: 1991 - 2009 Linus Torvalds and others.
1389461f666SFrans Pop
1399461f666SFrans PopThe git repository for mainline kernel development is at:
1409461f666SFrans Popgit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
1419461f666SFrans Pop
1429461f666SFrans Pop    This program is free software; you can redistribute it and/or modify
1439461f666SFrans Pop    it under the terms of the GNU General Public License as published by
1449461f666SFrans Pop    the Free Software Foundation; version 2 dated June, 1991.
1459461f666SFrans Pop
1469461f666SFrans PopOn Debian GNU/Linux systems, the complete text of the GNU General Public
1479461f666SFrans PopLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
1489461f666SFrans PopEOF
1499461f666SFrans Pop
1501da177e4SLinus Torvalds# Generate a control file
1511da177e4SLinus Torvaldscat <<EOF > debian/control
1524bf4cd49SFrans PopSource: linux-upstream
153aa42abedSRogério BritoSection: kernel
1541da177e4SLinus TorvaldsPriority: optional
155edec611dSmaximilian attemsMaintainer: $maintainer
1562d7204acSRogério BritoStandards-Version: 3.8.4
157ee6eed80SRogério BritoHomepage: http://www.kernel.org/
1583e2ab256SFrans PopEOF
1593e2ab256SFrans Pop
1603e2ab256SFrans Popif [ "$ARCH" = "um" ]; then
1613e2ab256SFrans Pop	cat <<EOF >> debian/control
1621da177e4SLinus Torvalds
163687c3dacSSam RavnborgPackage: $packagename
1648ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
1651da177e4SLinus TorvaldsArchitecture: any
166dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version
167dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call
168dc5962fdSSam Ravnborg interface.  It provides a kind of virtual machine, which runs Linux
169dc5962fdSSam Ravnborg as a user process under another Linux kernel.  This is useful for
170dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and
171dc5962fdSSam Ravnborg many other things.
172dc5962fdSSam Ravnborg .
1731da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other
174a83ca277SFrans Pop files, version: $version.
1751da177e4SLinus TorvaldsEOF
1761da177e4SLinus Torvalds
177dc5962fdSSam Ravnborgelse
1783e2ab256SFrans Pop	cat <<EOF >> debian/control
179dc5962fdSSam Ravnborg
180dc5962fdSSam RavnborgPackage: $packagename
1818ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
182bf1b3644SJonathan McDowellSuggests: $fwpackagename
183dc5962fdSSam RavnborgArchitecture: any
184dc5962fdSSam RavnborgDescription: Linux kernel, version $version
185dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other
186a83ca277SFrans Pop files, version: $version.
187dc5962fdSSam RavnborgEOF
1884f66199bSFrans Pop
189dc5962fdSSam Ravnborgfi
190dc5962fdSSam Ravnborg
191bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package.
192bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then
193bf1b3644SJonathan McDowell	mv "$tmpdir/lib/firmware" "$fwdir/lib/"
194bf1b3644SJonathan McDowell
195bf1b3644SJonathan McDowell	cat <<EOF >> debian/control
196bf1b3644SJonathan McDowell
197bf1b3644SJonathan McDowellPackage: $fwpackagename
198bf1b3644SJonathan McDowellArchitecture: all
199bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version
200a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version.
201bf1b3644SJonathan McDowellEOF
202bf1b3644SJonathan McDowell
2033e2ab256SFrans Pop	create_package "$fwpackagename" "$fwdir"
204bf1b3644SJonathan McDowellfi
205bf1b3644SJonathan McDowell
2063e2ab256SFrans Popcreate_package "$packagename" "$tmpdir"
2071da177e4SLinus Torvalds
2081da177e4SLinus Torvaldsexit 0
209