xref: /openbmc/linux/scripts/package/builddeb (revision bea107b1)
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
18bf7b0055SRiku Voipio	mkdir -m 755 -p "$pdir/DEBIAN"
19bf7b0055SRiku Voipio	mkdir -p "$pdir/usr/share/doc/$pname"
209461f666SFrans Pop	cp debian/copyright "$pdir/usr/share/doc/$pname/"
211ab18486Smaximilian attems	cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
221ab18486Smaximilian attems	gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
23b59a1225SFEJES Jozsef	sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
24b59a1225SFEJES Jozsef		| xargs -r0 md5sum > DEBIAN/md5sums"
259461f666SFrans Pop
263e2ab256SFrans Pop	# Fix ownership and permissions
273e2ab256SFrans Pop	chown -R root:root "$pdir"
283e2ab256SFrans Pop	chmod -R go-w "$pdir"
293e2ab256SFrans Pop
30dca0c024SRiku Voipio	# Create the package
31dca0c024SRiku Voipio	dpkg-gencontrol $forcearch -Vkernel:debarch="${debarch}" -p$pname -P"$pdir"
32dca0c024SRiku Voipio	dpkg --build "$pdir" ..
33dca0c024SRiku Voipio}
34dca0c024SRiku Voipio
35dca0c024SRiku Voipioset_debarch() {
3610f26fa6SAsbjoern Sloth Toennesen	# Attempt to find the correct Debian architecture
3710f26fa6SAsbjoern Sloth Toennesen	case "$UTS_MACHINE" in
3810f26fa6SAsbjoern Sloth Toennesen	i386|ia64|alpha)
3910f26fa6SAsbjoern Sloth Toennesen		debarch="$UTS_MACHINE" ;;
4010f26fa6SAsbjoern Sloth Toennesen	x86_64)
4110f26fa6SAsbjoern Sloth Toennesen		debarch=amd64 ;;
4210f26fa6SAsbjoern Sloth Toennesen	sparc*)
4310f26fa6SAsbjoern Sloth Toennesen		debarch=sparc ;;
4410f26fa6SAsbjoern Sloth Toennesen	s390*)
45a1323fd1SBen Hutchings		debarch=s390$(grep -q CONFIG_64BIT=y $KCONFIG_CONFIG && echo x || true) ;;
4610f26fa6SAsbjoern Sloth Toennesen	ppc*)
4722739edfSMichael Neuling		debarch=$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo ppc64el || echo powerpc) ;;
4810f26fa6SAsbjoern Sloth Toennesen	parisc*)
4910f26fa6SAsbjoern Sloth Toennesen		debarch=hppa ;;
5010f26fa6SAsbjoern Sloth Toennesen	mips*)
51c5e318f6SBen Hutchings		debarch=mips$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo el || true) ;;
52a8d9c9f1SFathi Boudra	arm64)
53a8d9c9f1SFathi Boudra		debarch=arm64 ;;
5410f26fa6SAsbjoern Sloth Toennesen	arm*)
55c5e318f6SBen Hutchings		debarch=arm$(grep -q CONFIG_AEABI=y $KCONFIG_CONFIG && echo el || true) ;;
5610f26fa6SAsbjoern Sloth Toennesen	*)
57dca0c024SRiku Voipio		debarch=$(dpkg --print-architecture)
5810f26fa6SAsbjoern Sloth Toennesen		echo "" >&2
5910f26fa6SAsbjoern Sloth Toennesen		echo "** ** **  WARNING  ** ** **" >&2
6010f26fa6SAsbjoern Sloth Toennesen		echo "" >&2
6110f26fa6SAsbjoern Sloth Toennesen		echo "Your architecture doesn't have it's equivalent" >&2
6210f26fa6SAsbjoern Sloth Toennesen		echo "Debian userspace architecture defined!" >&2
6310f26fa6SAsbjoern Sloth Toennesen		echo "Falling back to using your current userspace instead!" >&2
6410f26fa6SAsbjoern Sloth Toennesen		echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
6510f26fa6SAsbjoern Sloth Toennesen		echo "" >&2
6610f26fa6SAsbjoern Sloth Toennesen	esac
6755f88eccSAsbjoern Sloth Toennesen	if [ -n "$KBUILD_DEBARCH" ] ; then
6855f88eccSAsbjoern Sloth Toennesen		debarch="$KBUILD_DEBARCH"
6955f88eccSAsbjoern Sloth Toennesen	fi
7010f26fa6SAsbjoern Sloth Toennesen	forcearch="-DArchitecture=$debarch"
7110f26fa6SAsbjoern Sloth Toennesen
723e2ab256SFrans Pop}
733e2ab256SFrans Pop
741da177e4SLinus Torvalds# Some variables and settings used throughout the script
751da177e4SLinus Torvaldsversion=$KERNELRELEASE
764f66199bSFrans Poprevision=$(cat .version)
77c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then
78c72c75dbSFrans Pop	packageversion=$KDEB_PKGVERSION
79c72c75dbSFrans Popelse
80c72c75dbSFrans Pop	packageversion=$version-$revision
81c72c75dbSFrans Popfi
821da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp"
83bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp"
84ee81b786Smaximilian attemskernel_headers_dir="$objtree/debian/hdrtmp"
85ee81b786Smaximilian attemslibc_headers_dir="$objtree/debian/headertmp"
86810e8437SAnisse Astierdbg_dir="$objtree/debian/dbgtmp"
87f7a2c31fSmaximilian attemspackagename=linux-image-$version
8895e2a7d8SHeinrich Schuchardtfwpackagename=linux-firmware-image-$version
89ee81b786Smaximilian attemskernel_headers_packagename=linux-headers-$version
90ee81b786Smaximilian attemslibc_headers_packagename=linux-libc-dev
91810e8437SAnisse Astierdbg_packagename=$packagename-dbg
92dca0c024SRiku Voipiodebarch=
93dca0c024SRiku Voipioforcearch=
94dca0c024SRiku Voipioset_debarch
95687c3dacSSam Ravnborg
964f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
97687c3dacSSam Ravnborg	packagename=user-mode-linux-$version
98687c3dacSSam Ravnborgfi
991da177e4SLinus Torvalds
1009de70176SAnisse Astier# Not all arches have the same installed path in debian
1019de70176SAnisse Astier# XXX: have each arch Makefile export a variable of the canonical image install
1029de70176SAnisse Astier# path instead
1039de70176SAnisse Astiercase $ARCH in
1049de70176SAnisse Astierum)
1059de70176SAnisse Astier	installed_image_path="usr/bin/linux-$version"
1069de70176SAnisse Astier	;;
1079de70176SAnisse Astierparisc|mips|powerpc)
1089de70176SAnisse Astier	installed_image_path="boot/vmlinux-$version"
1099de70176SAnisse Astier	;;
1109de70176SAnisse Astier*)
1119de70176SAnisse Astier	installed_image_path="boot/vmlinuz-$version"
1129de70176SAnisse Astieresac
1139de70176SAnisse Astier
114810e8437SAnisse AstierBUILD_DEBUG="$(grep -s '^CONFIG_DEBUG_INFO=y' $KCONFIG_CONFIG || true)"
115810e8437SAnisse Astier
1161da177e4SLinus Torvalds# Setup the directory structure
117810e8437SAnisse Astierrm -rf "$tmpdir" "$fwdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir"
118e86c2412Smaximilian attemsmkdir -m 755 -p "$tmpdir/DEBIAN"
119bf7b0055SRiku Voipiomkdir -p "$tmpdir/lib" "$tmpdir/boot"
120bf7b0055SRiku Voipiomkdir -p "$fwdir/lib/firmware/$version/"
121a47b6c61SJoerg Roedelmkdir -p "$kernel_headers_dir/lib/modules/$version/"
1221da177e4SLinus Torvalds
1231da177e4SLinus Torvalds# Build and install the kernel
1244f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
125bf7b0055SRiku Voipio	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename"
126687c3dacSSam Ravnborg	$MAKE linux
127687c3dacSSam Ravnborg	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
128d2091767SAnisse Astier	cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
129687c3dacSSam Ravnborg	gzip "$tmpdir/usr/share/doc/$packagename/config"
130687c3dacSSam Ravnborgelse
1311da177e4SLinus Torvalds	cp System.map "$tmpdir/boot/System.map-$version"
132d2091767SAnisse Astier	cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version"
1339de70176SAnisse Astierfi
134a89b433bSFrans Pop# Not all arches include the boot path in KBUILD_IMAGE
135242c5ab0SGuillem Joverif [ -e $KBUILD_IMAGE ]; then
1369de70176SAnisse Astier	cp $KBUILD_IMAGE "$tmpdir/$installed_image_path"
137242c5ab0SGuillem Joverelse
1389de70176SAnisse Astier	cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/$installed_image_path"
139687c3dacSSam Ravnborgfi
1401da177e4SLinus Torvalds
141ca2a9d2cSArnaud Patard (Rtp)if grep -q "^CONFIG_OF=y" $KCONFIG_CONFIG ; then
142ca2a9d2cSArnaud Patard (Rtp)	# Only some architectures with OF support have this target
143ca2a9d2cSArnaud Patard (Rtp)	if grep -q dtbs_install "${srctree}/arch/$SRCARCH/Makefile"; then
144ca2a9d2cSArnaud Patard (Rtp)		$MAKE KBUILD_SRC= INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
145ca2a9d2cSArnaud Patard (Rtp)	fi
146ca2a9d2cSArnaud Patard (Rtp)fi
147ca2a9d2cSArnaud Patard (Rtp)
148d2091767SAnisse Astierif grep -q '^CONFIG_MODULES=y' $KCONFIG_CONFIG ; then
149dddcbb7cSJoerg Roedel	INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_install
150a47b6c61SJoerg Roedel	rm -f "$tmpdir/lib/modules/$version/build"
151a47b6c61SJoerg Roedel	rm -f "$tmpdir/lib/modules/$version/source"
1524f66199bSFrans Pop	if [ "$ARCH" = "um" ] ; then
153687c3dacSSam Ravnborg		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
154687c3dacSSam Ravnborg		rmdir "$tmpdir/lib/modules/$version"
155687c3dacSSam Ravnborg	fi
156810e8437SAnisse Astier	if [ -n "$BUILD_DEBUG" ] ; then
1572d087139SMichal Marek		for module in $(find $tmpdir/lib/modules/ -name *.ko -printf '%P\n'); do
1582d087139SMichal Marek			module=lib/modules/$module
159810e8437SAnisse Astier			mkdir -p $(dirname $dbg_dir/usr/lib/debug/$module)
160810e8437SAnisse Astier			# only keep debug symbols in the debug file
1612d087139SMichal Marek			$OBJCOPY --only-keep-debug $tmpdir/$module $dbg_dir/usr/lib/debug/$module
162810e8437SAnisse Astier			# strip original module from debug symbols
1632d087139SMichal Marek			$OBJCOPY --strip-debug $tmpdir/$module
164810e8437SAnisse Astier			# then add a link to those
1652d087139SMichal Marek			$OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $tmpdir/$module
166810e8437SAnisse Astier		done
16764178cb6SAndrey Skvortsov
16864178cb6SAndrey Skvortsov		# resign stripped modules
16964178cb6SAndrey Skvortsov		MODULE_SIG_ALL="$(grep -s '^CONFIG_MODULE_SIG_ALL=y' $KCONFIG_CONFIG || true)"
17064178cb6SAndrey Skvortsov		if [ -n "$MODULE_SIG_ALL" ]; then
17164178cb6SAndrey Skvortsov			INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_sign
17264178cb6SAndrey Skvortsov		fi
173810e8437SAnisse Astier	fi
1741da177e4SLinus Torvaldsfi
1751da177e4SLinus Torvalds
176d7d357bcSJoerg Roedelif [ "$ARCH" != "um" ]; then
177dddcbb7cSJoerg Roedel	$MAKE headers_check KBUILD_SRC=
178dddcbb7cSJoerg Roedel	$MAKE headers_install KBUILD_SRC= INSTALL_HDR_PATH="$libc_headers_dir/usr"
179d7d357bcSJoerg Roedelfi
180e6807785Smaximilian attems
1811da177e4SLinus Torvalds# Install the maintainer scripts
182fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian
1831c8ddae0SBen Hutchings# kernel packages, as well as kernel packages built using make-kpkg.
1841c8ddae0SBen Hutchings# make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
1851c8ddae0SBen Hutchings# so do we; recent versions of dracut and initramfs-tools will obey this.
186fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel}
1871c8ddae0SBen Hutchingsif grep -q '^CONFIG_BLK_DEV_INITRD=y' $KCONFIG_CONFIG; then
1881c8ddae0SBen Hutchings	want_initrd=Yes
1891c8ddae0SBen Hutchingselse
1901c8ddae0SBen Hutchings	want_initrd=No
1911c8ddae0SBen Hutchingsfi
1921da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do
193fe233cb6SFrans Pop	mkdir -p "$tmpdir$debhookdir/$script.d"
1941da177e4SLinus Torvalds	cat <<EOF > "$tmpdir/DEBIAN/$script"
1951da177e4SLinus Torvalds#!/bin/sh
1961da177e4SLinus Torvalds
1971da177e4SLinus Torvaldsset -e
1981da177e4SLinus Torvalds
1994964451aSFrans Pop# Pass maintainer script parameters to hook scripts
200241ad11fSmaximilian attemsexport DEB_MAINT_PARAMS="\$*"
2014964451aSFrans Pop
2021c8ddae0SBen Hutchings# Tell initramfs builder whether it's wanted
2031c8ddae0SBen Hutchingsexport INITRD=$want_initrd
2041c8ddae0SBen Hutchings
205c95182bfSAnisse Astiertest -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d
2061da177e4SLinus Torvaldsexit 0
2071da177e4SLinus TorvaldsEOF
2081da177e4SLinus Torvalds	chmod 755 "$tmpdir/DEBIAN/$script"
2091da177e4SLinus Torvaldsdone
2101da177e4SLinus Torvalds
211edec611dSmaximilian attems# Try to determine maintainer and email values
212edec611dSmaximilian attemsif [ -n "$DEBEMAIL" ]; then
213edec611dSmaximilian attems       email=$DEBEMAIL
214edec611dSmaximilian attemselif [ -n "$EMAIL" ]; then
215edec611dSmaximilian attems       email=$EMAIL
216edec611dSmaximilian attemselse
217bea107b1SChristian Kujau       email=$(id -nu)@$(hostname -f 2>/dev/null || hostname)
218edec611dSmaximilian attemsfi
219edec611dSmaximilian attemsif [ -n "$DEBFULLNAME" ]; then
220edec611dSmaximilian attems       name=$DEBFULLNAME
221edec611dSmaximilian attemselif [ -n "$NAME" ]; then
222edec611dSmaximilian attems       name=$NAME
223edec611dSmaximilian attemselse
224edec611dSmaximilian attems       name="Anonymous"
225edec611dSmaximilian attemsfi
226edec611dSmaximilian attemsmaintainer="$name <$email>"
227edec611dSmaximilian attems
228d9f711dbSSedat Dilek# Try to determine distribution
229d9f711dbSSedat Dilekif [ -n "$KDEB_CHANGELOG_DIST" ]; then
230d9f711dbSSedat Dilek        distribution=$KDEB_CHANGELOG_DIST
231d9f711dbSSedat Dilekelif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ]; then
232d9f711dbSSedat Dilek        : # nothing to do in this case
233d9f711dbSSedat Dilekelse
234d9f711dbSSedat Dilek        distribution="unstable"
235d9f711dbSSedat Dilek        echo >&2 "Using default distribution of 'unstable' in the changelog"
236d9f711dbSSedat Dilek        echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
237d9f711dbSSedat Dilekfi
238d9f711dbSSedat Dilek
2391da177e4SLinus Torvalds# Generate a simple changelog template
2401da177e4SLinus Torvaldscat <<EOF > debian/changelog
241d9f711dbSSedat Dileklinux-upstream ($packageversion) $distribution; urgency=low
2421da177e4SLinus Torvalds
243a83ca277SFrans Pop  * Custom built Linux kernel.
2441da177e4SLinus Torvalds
245edec611dSmaximilian attems -- $maintainer  $(date -R)
2461da177e4SLinus TorvaldsEOF
2471da177e4SLinus Torvalds
2489461f666SFrans Pop# Generate copyright file
2499461f666SFrans Popcat <<EOF > debian/copyright
2509461f666SFrans PopThis is a packacked upstream version of the Linux kernel.
2519461f666SFrans Pop
2529461f666SFrans PopThe sources may be found at most Linux ftp sites, including:
2539461f666SFrans Popftp://ftp.kernel.org/pub/linux/kernel
2549461f666SFrans Pop
255701ca30cSSedat DilekCopyright: 1991 - 2015 Linus Torvalds and others.
2569461f666SFrans Pop
2579461f666SFrans PopThe git repository for mainline kernel development is at:
258701ca30cSSedat Dilekgit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
2599461f666SFrans Pop
2609461f666SFrans Pop    This program is free software; you can redistribute it and/or modify
2619461f666SFrans Pop    it under the terms of the GNU General Public License as published by
2629461f666SFrans Pop    the Free Software Foundation; version 2 dated June, 1991.
2639461f666SFrans Pop
2649461f666SFrans PopOn Debian GNU/Linux systems, the complete text of the GNU General Public
2659461f666SFrans PopLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
2669461f666SFrans PopEOF
2679461f666SFrans Pop
2681da177e4SLinus Torvalds# Generate a control file
2691da177e4SLinus Torvaldscat <<EOF > debian/control
2704bf4cd49SFrans PopSource: linux-upstream
271aa42abedSRogério BritoSection: kernel
2721da177e4SLinus TorvaldsPriority: optional
273edec611dSmaximilian attemsMaintainer: $maintainer
2742d7204acSRogério BritoStandards-Version: 3.8.4
275ee6eed80SRogério BritoHomepage: http://www.kernel.org/
2763e2ab256SFrans PopEOF
2773e2ab256SFrans Pop
2783e2ab256SFrans Popif [ "$ARCH" = "um" ]; then
2793e2ab256SFrans Pop	cat <<EOF >> debian/control
2801da177e4SLinus Torvalds
281687c3dacSSam RavnborgPackage: $packagename
2828ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
2831da177e4SLinus TorvaldsArchitecture: any
284dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version
285dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call
286dc5962fdSSam Ravnborg interface.  It provides a kind of virtual machine, which runs Linux
287dc5962fdSSam Ravnborg as a user process under another Linux kernel.  This is useful for
288dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and
289dc5962fdSSam Ravnborg many other things.
290dc5962fdSSam Ravnborg .
2911da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other
292a83ca277SFrans Pop files, version: $version.
2931da177e4SLinus TorvaldsEOF
2941da177e4SLinus Torvalds
295dc5962fdSSam Ravnborgelse
2963e2ab256SFrans Pop	cat <<EOF >> debian/control
297dc5962fdSSam Ravnborg
298dc5962fdSSam RavnborgPackage: $packagename
2998ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
300bf1b3644SJonathan McDowellSuggests: $fwpackagename
301dc5962fdSSam RavnborgArchitecture: any
302dc5962fdSSam RavnborgDescription: Linux kernel, version $version
303dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other
304a83ca277SFrans Pop files, version: $version.
305dc5962fdSSam RavnborgEOF
3064f66199bSFrans Pop
307dc5962fdSSam Ravnborgfi
308dc5962fdSSam Ravnborg
3098bf13561SFathi Boudra# Build kernel header package
310a765a7ceSMichal Marek(cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles"
311a765a7ceSMichal Marek(cd $srctree; find arch/$SRCARCH/include include scripts -type f) >> "$objtree/debian/hdrsrcfiles"
3128bf13561SFathi Boudra(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
3138bf13561SFathi Boudra(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
314a765a7ceSMichal Marek(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
315ee81b786Smaximilian attemsdestdir=$kernel_headers_dir/usr/src/linux-headers-$version
316ee81b786Smaximilian attemsmkdir -p "$destdir"
317a765a7ceSMichal Marek(cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
318a765a7ceSMichal Marek(cd $objtree; tar -c -f - -T -) < "$objtree/debian/hdrobjfiles" | (cd $destdir; tar -xf -)
319d2091767SAnisse Astier(cd $objtree; cp $KCONFIG_CONFIG $destdir/.config) # copy .config manually to be where it's expected to be
320a47b6c61SJoerg Roedelln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build"
3216c635224SBen Hutchingsrm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles"
322cd8d60a2STheodore Ts'o
323cd8d60a2STheodore Ts'ocat <<EOF >> debian/control
324cd8d60a2STheodore Ts'o
325ee81b786Smaximilian attemsPackage: $kernel_headers_packagename
326cd8d60a2STheodore Ts'oProvides: linux-headers, linux-headers-2.6
327f8ce239dSBen HutchingsArchitecture: any
328f8ce239dSBen HutchingsDescription: Linux kernel headers for $KERNELRELEASE on \${kernel:debarch}
329f8ce239dSBen Hutchings This package provides kernel header files for $KERNELRELEASE on \${kernel:debarch}
330cd8d60a2STheodore Ts'o .
331cd8d60a2STheodore Ts'o This is useful for people who need to build external modules
332cd8d60a2STheodore Ts'oEOF
333cd8d60a2STheodore Ts'o
334bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package.
335bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then
3366607ddadSmaximilian attems	mv "$tmpdir/lib/firmware"/* "$fwdir/lib/firmware/$version/"
3376607ddadSmaximilian attems	rmdir "$tmpdir/lib/firmware"
338bf1b3644SJonathan McDowell
339bf1b3644SJonathan McDowell	cat <<EOF >> debian/control
340bf1b3644SJonathan McDowell
341bf1b3644SJonathan McDowellPackage: $fwpackagename
342bf1b3644SJonathan McDowellArchitecture: all
343bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version
344a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version.
345bf1b3644SJonathan McDowellEOF
346bf1b3644SJonathan McDowell
3473e2ab256SFrans Pop	create_package "$fwpackagename" "$fwdir"
348bf1b3644SJonathan McDowellfi
349bf1b3644SJonathan McDowell
350e6807785Smaximilian attemscat <<EOF >> debian/control
351e6807785Smaximilian attems
352ee81b786Smaximilian attemsPackage: $libc_headers_packagename
353e6807785Smaximilian attemsSection: devel
354e6807785Smaximilian attemsProvides: linux-kernel-headers
355e6807785Smaximilian attemsArchitecture: any
356e6807785Smaximilian attemsDescription: Linux support headers for userspace development
357e6807785Smaximilian attems This package provides userspaces headers from the Linux kernel.  These headers
358e6807785Smaximilian attems are used by the installed headers for GNU glibc and other system libraries.
359e6807785Smaximilian attemsEOF
360e6807785Smaximilian attems
361d7d357bcSJoerg Roedelif [ "$ARCH" != "um" ]; then
362d7d357bcSJoerg Roedel	create_package "$kernel_headers_packagename" "$kernel_headers_dir"
363ee81b786Smaximilian attems	create_package "$libc_headers_packagename" "$libc_headers_dir"
364d7d357bcSJoerg Roedelfi
365d7d357bcSJoerg Roedel
3663e2ab256SFrans Popcreate_package "$packagename" "$tmpdir"
3671da177e4SLinus Torvalds
368810e8437SAnisse Astierif [ -n "$BUILD_DEBUG" ] ; then
369810e8437SAnisse Astier	# Build debug package
370810e8437SAnisse Astier	# Different tools want the image in different locations
371810e8437SAnisse Astier	# perf
372810e8437SAnisse Astier	mkdir -p $dbg_dir/usr/lib/debug/lib/modules/$version/
373810e8437SAnisse Astier	cp vmlinux $dbg_dir/usr/lib/debug/lib/modules/$version/
374810e8437SAnisse Astier	# systemtap
375810e8437SAnisse Astier	mkdir -p $dbg_dir/usr/lib/debug/boot/
376810e8437SAnisse Astier	ln -s ../lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/boot/vmlinux-$version
377810e8437SAnisse Astier	# kdump-tools
378810e8437SAnisse Astier	ln -s lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/vmlinux-$version
379810e8437SAnisse Astier
380810e8437SAnisse Astier	cat <<EOF >> debian/control
381810e8437SAnisse Astier
382810e8437SAnisse AstierPackage: $dbg_packagename
383810e8437SAnisse AstierSection: debug
384810e8437SAnisse AstierProvides: linux-debug, linux-debug-$version
385810e8437SAnisse AstierArchitecture: any
386810e8437SAnisse AstierDescription: Linux kernel debugging symbols for $version
387810e8437SAnisse Astier This package will come in handy if you need to debug the kernel. It provides
388810e8437SAnisse Astier all the necessary debug symbols for the kernel and its modules.
389810e8437SAnisse AstierEOF
390810e8437SAnisse Astier
391810e8437SAnisse Astier	create_package "$dbg_packagename" "$dbg_dir"
392810e8437SAnisse Astierfi
393810e8437SAnisse Astier
3941da177e4SLinus Torvaldsexit 0
395