xref: /openbmc/linux/scripts/package/builddeb (revision aa42abed)
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
69a89b433bSFrans Pop	if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
70a89b433bSFrans Pop		cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
71a89b433bSFrans Pop	fi
72687c3dacSSam Ravnborgfi
731da177e4SLinus Torvalds
741da177e4SLinus Torvaldsif grep -q '^CONFIG_MODULES=y' .config ; then
75a91f98a2SSam Ravnborg	INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
764f66199bSFrans Pop	if [ "$ARCH" = "um" ] ; then
77687c3dacSSam Ravnborg		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
78687c3dacSSam Ravnborg		rmdir "$tmpdir/lib/modules/$version"
79687c3dacSSam Ravnborg	fi
801da177e4SLinus Torvaldsfi
811da177e4SLinus Torvalds
821da177e4SLinus Torvalds# Install the maintainer scripts
83fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian
84fe233cb6SFrans Pop# kernel packages, as well as kernel packages built using make-kpkg
85fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel}
861da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do
87fe233cb6SFrans Pop	mkdir -p "$tmpdir$debhookdir/$script.d"
881da177e4SLinus Torvalds	cat <<EOF > "$tmpdir/DEBIAN/$script"
891da177e4SLinus Torvalds#!/bin/sh
901da177e4SLinus Torvalds
911da177e4SLinus Torvaldsset -e
921da177e4SLinus Torvalds
934964451aSFrans Pop# Pass maintainer script parameters to hook scripts
94241ad11fSmaximilian attemsexport DEB_MAINT_PARAMS="\$*"
954964451aSFrans Pop
96fe233cb6SFrans Poptest -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
971da177e4SLinus Torvaldsexit 0
981da177e4SLinus TorvaldsEOF
991da177e4SLinus Torvalds	chmod 755 "$tmpdir/DEBIAN/$script"
1001da177e4SLinus Torvaldsdone
1011da177e4SLinus Torvalds
102edec611dSmaximilian attems# Try to determine maintainer and email values
103edec611dSmaximilian attemsif [ -n "$DEBEMAIL" ]; then
104edec611dSmaximilian attems       email=$DEBEMAIL
105edec611dSmaximilian attemselif [ -n "$EMAIL" ]; then
106edec611dSmaximilian attems       email=$EMAIL
107edec611dSmaximilian attemselse
108edec611dSmaximilian attems       email=$(id -nu)@$(hostname -f)
109edec611dSmaximilian attemsfi
110edec611dSmaximilian attemsif [ -n "$DEBFULLNAME" ]; then
111edec611dSmaximilian attems       name=$DEBFULLNAME
112edec611dSmaximilian attemselif [ -n "$NAME" ]; then
113edec611dSmaximilian attems       name=$NAME
114edec611dSmaximilian attemselse
115edec611dSmaximilian attems       name="Anonymous"
116edec611dSmaximilian attemsfi
117edec611dSmaximilian attemsmaintainer="$name <$email>"
118edec611dSmaximilian attems
1191da177e4SLinus Torvalds# Generate a simple changelog template
1201da177e4SLinus Torvaldscat <<EOF > debian/changelog
1214bf4cd49SFrans Poplinux-upstream ($packageversion) unstable; urgency=low
1221da177e4SLinus Torvalds
123a83ca277SFrans Pop  * Custom built Linux kernel.
1241da177e4SLinus Torvalds
125edec611dSmaximilian attems -- $maintainer  $(date -R)
1261da177e4SLinus TorvaldsEOF
1271da177e4SLinus Torvalds
1289461f666SFrans Pop# Generate copyright file
1299461f666SFrans Popcat <<EOF > debian/copyright
1309461f666SFrans PopThis is a packacked upstream version of the Linux kernel.
1319461f666SFrans Pop
1329461f666SFrans PopThe sources may be found at most Linux ftp sites, including:
1339461f666SFrans Popftp://ftp.kernel.org/pub/linux/kernel
1349461f666SFrans Pop
1359461f666SFrans PopCopyright: 1991 - 2009 Linus Torvalds and others.
1369461f666SFrans Pop
1379461f666SFrans PopThe git repository for mainline kernel development is at:
1389461f666SFrans Popgit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
1399461f666SFrans Pop
1409461f666SFrans Pop    This program is free software; you can redistribute it and/or modify
1419461f666SFrans Pop    it under the terms of the GNU General Public License as published by
1429461f666SFrans Pop    the Free Software Foundation; version 2 dated June, 1991.
1439461f666SFrans Pop
1449461f666SFrans PopOn Debian GNU/Linux systems, the complete text of the GNU General Public
1459461f666SFrans PopLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
1469461f666SFrans PopEOF
1479461f666SFrans Pop
1481da177e4SLinus Torvalds# Generate a control file
1491da177e4SLinus Torvaldscat <<EOF > debian/control
1504bf4cd49SFrans PopSource: linux-upstream
151aa42abedSRogério BritoSection: kernel
1521da177e4SLinus TorvaldsPriority: optional
153edec611dSmaximilian attemsMaintainer: $maintainer
1542d7204acSRogério BritoStandards-Version: 3.8.4
155ee6eed80SRogério BritoHomepage: http://www.kernel.org/
1563e2ab256SFrans PopEOF
1573e2ab256SFrans Pop
1583e2ab256SFrans Popif [ "$ARCH" = "um" ]; then
1593e2ab256SFrans Pop	cat <<EOF >> debian/control
1601da177e4SLinus Torvalds
161687c3dacSSam RavnborgPackage: $packagename
1628ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
1631da177e4SLinus TorvaldsArchitecture: any
164dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version
165dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call
166dc5962fdSSam Ravnborg interface.  It provides a kind of virtual machine, which runs Linux
167dc5962fdSSam Ravnborg as a user process under another Linux kernel.  This is useful for
168dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and
169dc5962fdSSam Ravnborg many other things.
170dc5962fdSSam Ravnborg .
1711da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other
172a83ca277SFrans Pop files, version: $version.
1731da177e4SLinus TorvaldsEOF
1741da177e4SLinus Torvalds
175dc5962fdSSam Ravnborgelse
1763e2ab256SFrans Pop	cat <<EOF >> debian/control
177dc5962fdSSam Ravnborg
178dc5962fdSSam RavnborgPackage: $packagename
1798ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
180bf1b3644SJonathan McDowellSuggests: $fwpackagename
181dc5962fdSSam RavnborgArchitecture: any
182dc5962fdSSam RavnborgDescription: Linux kernel, version $version
183dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other
184a83ca277SFrans Pop files, version: $version.
185dc5962fdSSam RavnborgEOF
1864f66199bSFrans Pop
187dc5962fdSSam Ravnborgfi
188dc5962fdSSam Ravnborg
189bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package.
190bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then
191bf1b3644SJonathan McDowell	mv "$tmpdir/lib/firmware" "$fwdir/lib/"
192bf1b3644SJonathan McDowell
193bf1b3644SJonathan McDowell	cat <<EOF >> debian/control
194bf1b3644SJonathan McDowell
195bf1b3644SJonathan McDowellPackage: $fwpackagename
196bf1b3644SJonathan McDowellArchitecture: all
197bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version
198a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version.
199bf1b3644SJonathan McDowellEOF
200bf1b3644SJonathan McDowell
2013e2ab256SFrans Pop	create_package "$fwpackagename" "$fwdir"
202bf1b3644SJonathan McDowellfi
203bf1b3644SJonathan McDowell
2043e2ab256SFrans Popcreate_package "$packagename" "$tmpdir"
2051da177e4SLinus Torvalds
2061da177e4SLinus Torvaldsexit 0
207