xref: /openbmc/linux/scripts/package/builddeb (revision 10f26fa6)
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
2810f26fa6SAsbjoern Sloth Toennesen	# Attempt to find the correct Debian architecture
2910f26fa6SAsbjoern Sloth Toennesen	local forcearch="" debarch=""
3010f26fa6SAsbjoern Sloth Toennesen	case "$UTS_MACHINE" in
3110f26fa6SAsbjoern Sloth Toennesen	i386|ia64|alpha)
3210f26fa6SAsbjoern Sloth Toennesen		debarch="$UTS_MACHINE" ;;
3310f26fa6SAsbjoern Sloth Toennesen	x86_64)
3410f26fa6SAsbjoern Sloth Toennesen		debarch=amd64 ;;
3510f26fa6SAsbjoern Sloth Toennesen	sparc*)
3610f26fa6SAsbjoern Sloth Toennesen		debarch=sparc ;;
3710f26fa6SAsbjoern Sloth Toennesen	s390*)
3810f26fa6SAsbjoern Sloth Toennesen		debarch=s390 ;;
3910f26fa6SAsbjoern Sloth Toennesen	ppc*)
4010f26fa6SAsbjoern Sloth Toennesen		debarch=powerpc ;;
4110f26fa6SAsbjoern Sloth Toennesen	parisc*)
4210f26fa6SAsbjoern Sloth Toennesen		debarch=hppa ;;
4310f26fa6SAsbjoern Sloth Toennesen	mips*)
4410f26fa6SAsbjoern Sloth Toennesen		debarch=mips$(grep -q CPU_LITTLE_ENDIAN=y .config && echo el) ;;
4510f26fa6SAsbjoern Sloth Toennesen	arm*)
4610f26fa6SAsbjoern Sloth Toennesen		debarch=arm$(grep -q CONFIG_AEABI=y .config && echo el) ;;
4710f26fa6SAsbjoern Sloth Toennesen	*)
4810f26fa6SAsbjoern Sloth Toennesen		echo "" >&2
4910f26fa6SAsbjoern Sloth Toennesen		echo "** ** **  WARNING  ** ** **" >&2
5010f26fa6SAsbjoern Sloth Toennesen		echo "" >&2
5110f26fa6SAsbjoern Sloth Toennesen		echo "Your architecture doesn't have it's equivalent" >&2
5210f26fa6SAsbjoern Sloth Toennesen		echo "Debian userspace architecture defined!" >&2
5310f26fa6SAsbjoern Sloth Toennesen		echo "Falling back to using your current userspace instead!" >&2
5410f26fa6SAsbjoern Sloth Toennesen		echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
5510f26fa6SAsbjoern Sloth Toennesen		echo "" >&2
5610f26fa6SAsbjoern Sloth Toennesen	esac
5710f26fa6SAsbjoern Sloth Toennesen	if [ -n "$debarch" ] ; then
5810f26fa6SAsbjoern Sloth Toennesen		forcearch="-DArchitecture=$debarch"
5910f26fa6SAsbjoern Sloth Toennesen	fi
6010f26fa6SAsbjoern Sloth Toennesen
613e2ab256SFrans Pop	# Create the package
6210f26fa6SAsbjoern Sloth Toennesen	dpkg-gencontrol -isp $forcearch -p$pname -P"$pdir"
633e2ab256SFrans Pop	dpkg --build "$pdir" ..
643e2ab256SFrans Pop}
653e2ab256SFrans Pop
661da177e4SLinus Torvalds# Some variables and settings used throughout the script
671da177e4SLinus Torvaldsversion=$KERNELRELEASE
684f66199bSFrans Poprevision=$(cat .version)
69c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then
70c72c75dbSFrans Pop	packageversion=$KDEB_PKGVERSION
71c72c75dbSFrans Popelse
72c72c75dbSFrans Pop	packageversion=$version-$revision
73c72c75dbSFrans Popfi
741da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp"
75bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp"
76f7a2c31fSmaximilian attemspackagename=linux-image-$version
77bf1b3644SJonathan McDowellfwpackagename=linux-firmware-image
78687c3dacSSam Ravnborg
794f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
80687c3dacSSam Ravnborg	packagename=user-mode-linux-$version
81687c3dacSSam Ravnborgfi
821da177e4SLinus Torvalds
831da177e4SLinus Torvalds# Setup the directory structure
84bf1b3644SJonathan McDowellrm -rf "$tmpdir" "$fwdir"
85e86c2412Smaximilian attemsmkdir -m 755 -p "$tmpdir/DEBIAN"
86e86c2412Smaximilian attemsmkdir -p  "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
87e86c2412Smaximilian attemsmkdir -m 755 -p "$fwdir/DEBIAN"
88e86c2412Smaximilian attemsmkdir -p "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
894f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
909461f666SFrans Pop	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
91687c3dacSSam Ravnborgfi
921da177e4SLinus Torvalds
931da177e4SLinus Torvalds# Build and install the kernel
944f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
95687c3dacSSam Ravnborg	$MAKE linux
96687c3dacSSam Ravnborg	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
97687c3dacSSam Ravnborg	cp .config "$tmpdir/usr/share/doc/$packagename/config"
98687c3dacSSam Ravnborg	gzip "$tmpdir/usr/share/doc/$packagename/config"
99687c3dacSSam Ravnborg	cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
100687c3dacSSam Ravnborgelse
1011da177e4SLinus Torvalds	cp System.map "$tmpdir/boot/System.map-$version"
1021da177e4SLinus Torvalds	cp .config "$tmpdir/boot/config-$version"
103a89b433bSFrans Pop	# Not all arches include the boot path in KBUILD_IMAGE
104242c5ab0SGuillem Jover	if [ -e $KBUILD_IMAGE ]; then
105242c5ab0SGuillem Jover		cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
106242c5ab0SGuillem Jover	else
107a89b433bSFrans Pop		cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
108a89b433bSFrans Pop	fi
109687c3dacSSam Ravnborgfi
1101da177e4SLinus Torvalds
1111da177e4SLinus Torvaldsif grep -q '^CONFIG_MODULES=y' .config ; then
112a91f98a2SSam Ravnborg	INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
1134f66199bSFrans Pop	if [ "$ARCH" = "um" ] ; then
114687c3dacSSam Ravnborg		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
115687c3dacSSam Ravnborg		rmdir "$tmpdir/lib/modules/$version"
116687c3dacSSam Ravnborg	fi
1171da177e4SLinus Torvaldsfi
1181da177e4SLinus Torvalds
1191da177e4SLinus Torvalds# Install the maintainer scripts
120fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian
121fe233cb6SFrans Pop# kernel packages, as well as kernel packages built using make-kpkg
122fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel}
1231da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do
124fe233cb6SFrans Pop	mkdir -p "$tmpdir$debhookdir/$script.d"
1251da177e4SLinus Torvalds	cat <<EOF > "$tmpdir/DEBIAN/$script"
1261da177e4SLinus Torvalds#!/bin/sh
1271da177e4SLinus Torvalds
1281da177e4SLinus Torvaldsset -e
1291da177e4SLinus Torvalds
1304964451aSFrans Pop# Pass maintainer script parameters to hook scripts
131241ad11fSmaximilian attemsexport DEB_MAINT_PARAMS="\$*"
1324964451aSFrans Pop
133fe233cb6SFrans Poptest -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
1341da177e4SLinus Torvaldsexit 0
1351da177e4SLinus TorvaldsEOF
1361da177e4SLinus Torvalds	chmod 755 "$tmpdir/DEBIAN/$script"
1371da177e4SLinus Torvaldsdone
1381da177e4SLinus Torvalds
139edec611dSmaximilian attems# Try to determine maintainer and email values
140edec611dSmaximilian attemsif [ -n "$DEBEMAIL" ]; then
141edec611dSmaximilian attems       email=$DEBEMAIL
142edec611dSmaximilian attemselif [ -n "$EMAIL" ]; then
143edec611dSmaximilian attems       email=$EMAIL
144edec611dSmaximilian attemselse
145edec611dSmaximilian attems       email=$(id -nu)@$(hostname -f)
146edec611dSmaximilian attemsfi
147edec611dSmaximilian attemsif [ -n "$DEBFULLNAME" ]; then
148edec611dSmaximilian attems       name=$DEBFULLNAME
149edec611dSmaximilian attemselif [ -n "$NAME" ]; then
150edec611dSmaximilian attems       name=$NAME
151edec611dSmaximilian attemselse
152edec611dSmaximilian attems       name="Anonymous"
153edec611dSmaximilian attemsfi
154edec611dSmaximilian attemsmaintainer="$name <$email>"
155edec611dSmaximilian attems
1561da177e4SLinus Torvalds# Generate a simple changelog template
1571da177e4SLinus Torvaldscat <<EOF > debian/changelog
1584bf4cd49SFrans Poplinux-upstream ($packageversion) unstable; urgency=low
1591da177e4SLinus Torvalds
160a83ca277SFrans Pop  * Custom built Linux kernel.
1611da177e4SLinus Torvalds
162edec611dSmaximilian attems -- $maintainer  $(date -R)
1631da177e4SLinus TorvaldsEOF
1641da177e4SLinus Torvalds
1659461f666SFrans Pop# Generate copyright file
1669461f666SFrans Popcat <<EOF > debian/copyright
1679461f666SFrans PopThis is a packacked upstream version of the Linux kernel.
1689461f666SFrans Pop
1699461f666SFrans PopThe sources may be found at most Linux ftp sites, including:
1709461f666SFrans Popftp://ftp.kernel.org/pub/linux/kernel
1719461f666SFrans Pop
1729461f666SFrans PopCopyright: 1991 - 2009 Linus Torvalds and others.
1739461f666SFrans Pop
1749461f666SFrans PopThe git repository for mainline kernel development is at:
1759461f666SFrans Popgit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
1769461f666SFrans Pop
1779461f666SFrans Pop    This program is free software; you can redistribute it and/or modify
1789461f666SFrans Pop    it under the terms of the GNU General Public License as published by
1799461f666SFrans Pop    the Free Software Foundation; version 2 dated June, 1991.
1809461f666SFrans Pop
1819461f666SFrans PopOn Debian GNU/Linux systems, the complete text of the GNU General Public
1829461f666SFrans PopLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
1839461f666SFrans PopEOF
1849461f666SFrans Pop
1851da177e4SLinus Torvalds# Generate a control file
1861da177e4SLinus Torvaldscat <<EOF > debian/control
1874bf4cd49SFrans PopSource: linux-upstream
188aa42abedSRogério BritoSection: kernel
1891da177e4SLinus TorvaldsPriority: optional
190edec611dSmaximilian attemsMaintainer: $maintainer
1912d7204acSRogério BritoStandards-Version: 3.8.4
192ee6eed80SRogério BritoHomepage: http://www.kernel.org/
1933e2ab256SFrans PopEOF
1943e2ab256SFrans Pop
1953e2ab256SFrans Popif [ "$ARCH" = "um" ]; then
1963e2ab256SFrans Pop	cat <<EOF >> debian/control
1971da177e4SLinus Torvalds
198687c3dacSSam RavnborgPackage: $packagename
1998ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
2001da177e4SLinus TorvaldsArchitecture: any
201dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version
202dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call
203dc5962fdSSam Ravnborg interface.  It provides a kind of virtual machine, which runs Linux
204dc5962fdSSam Ravnborg as a user process under another Linux kernel.  This is useful for
205dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and
206dc5962fdSSam Ravnborg many other things.
207dc5962fdSSam Ravnborg .
2081da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other
209a83ca277SFrans Pop files, version: $version.
2101da177e4SLinus TorvaldsEOF
2111da177e4SLinus Torvalds
212dc5962fdSSam Ravnborgelse
2133e2ab256SFrans Pop	cat <<EOF >> debian/control
214dc5962fdSSam Ravnborg
215dc5962fdSSam RavnborgPackage: $packagename
2168ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
217bf1b3644SJonathan McDowellSuggests: $fwpackagename
218dc5962fdSSam RavnborgArchitecture: any
219dc5962fdSSam RavnborgDescription: Linux kernel, version $version
220dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other
221a83ca277SFrans Pop files, version: $version.
222dc5962fdSSam RavnborgEOF
2234f66199bSFrans Pop
224dc5962fdSSam Ravnborgfi
225dc5962fdSSam Ravnborg
226bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package.
227bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then
228bf1b3644SJonathan McDowell	mv "$tmpdir/lib/firmware" "$fwdir/lib/"
229bf1b3644SJonathan McDowell
230bf1b3644SJonathan McDowell	cat <<EOF >> debian/control
231bf1b3644SJonathan McDowell
232bf1b3644SJonathan McDowellPackage: $fwpackagename
233bf1b3644SJonathan McDowellArchitecture: all
234bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version
235a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version.
236bf1b3644SJonathan McDowellEOF
237bf1b3644SJonathan McDowell
2383e2ab256SFrans Pop	create_package "$fwpackagename" "$fwdir"
239bf1b3644SJonathan McDowellfi
240bf1b3644SJonathan McDowell
2413e2ab256SFrans Popcreate_package "$packagename" "$tmpdir"
2421da177e4SLinus Torvalds
2431da177e4SLinus Torvaldsexit 0
244