xref: /openbmc/linux/scripts/package/builddeb (revision 152b695d)
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"
29ca617dc6SHenning Schild	# in case we are in a restrictive umask environment like 0077
30ca617dc6SHenning Schild	chmod -R a+rX "$pdir"
313e2ab256SFrans Pop
32dca0c024SRiku Voipio	# Create the package
33dca0c024SRiku Voipio	dpkg-gencontrol $forcearch -Vkernel:debarch="${debarch}" -p$pname -P"$pdir"
34dca0c024SRiku Voipio	dpkg --build "$pdir" ..
35dca0c024SRiku Voipio}
36dca0c024SRiku Voipio
37dca0c024SRiku Voipioset_debarch() {
3810f26fa6SAsbjoern Sloth Toennesen	# Attempt to find the correct Debian architecture
3910f26fa6SAsbjoern Sloth Toennesen	case "$UTS_MACHINE" in
4010f26fa6SAsbjoern Sloth Toennesen	i386|ia64|alpha)
4110f26fa6SAsbjoern Sloth Toennesen		debarch="$UTS_MACHINE" ;;
4210f26fa6SAsbjoern Sloth Toennesen	x86_64)
4310f26fa6SAsbjoern Sloth Toennesen		debarch=amd64 ;;
4410f26fa6SAsbjoern Sloth Toennesen	sparc*)
4510f26fa6SAsbjoern Sloth Toennesen		debarch=sparc ;;
4610f26fa6SAsbjoern Sloth Toennesen	s390*)
47a1323fd1SBen Hutchings		debarch=s390$(grep -q CONFIG_64BIT=y $KCONFIG_CONFIG && echo x || true) ;;
4810f26fa6SAsbjoern Sloth Toennesen	ppc*)
4922739edfSMichael Neuling		debarch=$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo ppc64el || echo powerpc) ;;
5010f26fa6SAsbjoern Sloth Toennesen	parisc*)
5110f26fa6SAsbjoern Sloth Toennesen		debarch=hppa ;;
5210f26fa6SAsbjoern Sloth Toennesen	mips*)
53c5e318f6SBen Hutchings		debarch=mips$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo el || true) ;;
54152b695dSAdam Borowski	aarch64|arm64)
55a8d9c9f1SFathi Boudra		debarch=arm64 ;;
5610f26fa6SAsbjoern Sloth Toennesen	arm*)
5763a478fbSBen Hutchings		if grep -q CONFIG_AEABI=y $KCONFIG_CONFIG; then
5863a478fbSBen Hutchings		    if grep -q CONFIG_VFP=y $KCONFIG_CONFIG; then
5963a478fbSBen Hutchings			debarch=armhf
6063a478fbSBen Hutchings		    else
6163a478fbSBen Hutchings			debarch=armel
6263a478fbSBen Hutchings		    fi
6363a478fbSBen Hutchings		else
6463a478fbSBen Hutchings		    debarch=arm
6563a478fbSBen Hutchings		fi
6663a478fbSBen Hutchings		;;
6710f26fa6SAsbjoern Sloth Toennesen	*)
68dca0c024SRiku Voipio		debarch=$(dpkg --print-architecture)
6910f26fa6SAsbjoern Sloth Toennesen		echo "" >&2
7010f26fa6SAsbjoern Sloth Toennesen		echo "** ** **  WARNING  ** ** **" >&2
7110f26fa6SAsbjoern Sloth Toennesen		echo "" >&2
7210f26fa6SAsbjoern Sloth Toennesen		echo "Your architecture doesn't have it's equivalent" >&2
7310f26fa6SAsbjoern Sloth Toennesen		echo "Debian userspace architecture defined!" >&2
7410f26fa6SAsbjoern Sloth Toennesen		echo "Falling back to using your current userspace instead!" >&2
7510f26fa6SAsbjoern Sloth Toennesen		echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
7610f26fa6SAsbjoern Sloth Toennesen		echo "" >&2
7710f26fa6SAsbjoern Sloth Toennesen	esac
7855f88eccSAsbjoern Sloth Toennesen	if [ -n "$KBUILD_DEBARCH" ] ; then
7955f88eccSAsbjoern Sloth Toennesen		debarch="$KBUILD_DEBARCH"
8055f88eccSAsbjoern Sloth Toennesen	fi
8110f26fa6SAsbjoern Sloth Toennesen	forcearch="-DArchitecture=$debarch"
8210f26fa6SAsbjoern Sloth Toennesen
833e2ab256SFrans Pop}
843e2ab256SFrans Pop
851da177e4SLinus Torvalds# Some variables and settings used throughout the script
861da177e4SLinus Torvaldsversion=$KERNELRELEASE
874f66199bSFrans Poprevision=$(cat .version)
88c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then
89c72c75dbSFrans Pop	packageversion=$KDEB_PKGVERSION
90c72c75dbSFrans Popelse
91c72c75dbSFrans Pop	packageversion=$version-$revision
92c72c75dbSFrans Popfi
933716001bSRiku Voipiosourcename=$KDEB_SOURCENAME
941da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp"
95bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp"
96ee81b786Smaximilian attemskernel_headers_dir="$objtree/debian/hdrtmp"
97ee81b786Smaximilian attemslibc_headers_dir="$objtree/debian/headertmp"
98810e8437SAnisse Astierdbg_dir="$objtree/debian/dbgtmp"
99f7a2c31fSmaximilian attemspackagename=linux-image-$version
10095e2a7d8SHeinrich Schuchardtfwpackagename=linux-firmware-image-$version
101ee81b786Smaximilian attemskernel_headers_packagename=linux-headers-$version
102ee81b786Smaximilian attemslibc_headers_packagename=linux-libc-dev
103810e8437SAnisse Astierdbg_packagename=$packagename-dbg
104dca0c024SRiku Voipiodebarch=
105dca0c024SRiku Voipioforcearch=
106dca0c024SRiku Voipioset_debarch
107687c3dacSSam Ravnborg
1084f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
109687c3dacSSam Ravnborg	packagename=user-mode-linux-$version
110687c3dacSSam Ravnborgfi
1111da177e4SLinus Torvalds
1129de70176SAnisse Astier# Not all arches have the same installed path in debian
1139de70176SAnisse Astier# XXX: have each arch Makefile export a variable of the canonical image install
1149de70176SAnisse Astier# path instead
1159de70176SAnisse Astiercase $ARCH in
1169de70176SAnisse Astierum)
1179de70176SAnisse Astier	installed_image_path="usr/bin/linux-$version"
1189de70176SAnisse Astier	;;
1199de70176SAnisse Astierparisc|mips|powerpc)
1209de70176SAnisse Astier	installed_image_path="boot/vmlinux-$version"
1219de70176SAnisse Astier	;;
1229de70176SAnisse Astier*)
1239de70176SAnisse Astier	installed_image_path="boot/vmlinuz-$version"
1249de70176SAnisse Astieresac
1259de70176SAnisse Astier
126810e8437SAnisse AstierBUILD_DEBUG="$(grep -s '^CONFIG_DEBUG_INFO=y' $KCONFIG_CONFIG || true)"
127810e8437SAnisse Astier
1281da177e4SLinus Torvalds# Setup the directory structure
1298d740a37SRiku Voipiorm -rf "$tmpdir" "$fwdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files
130e86c2412Smaximilian attemsmkdir -m 755 -p "$tmpdir/DEBIAN"
131bf7b0055SRiku Voipiomkdir -p "$tmpdir/lib" "$tmpdir/boot"
132bf7b0055SRiku Voipiomkdir -p "$fwdir/lib/firmware/$version/"
133a47b6c61SJoerg Roedelmkdir -p "$kernel_headers_dir/lib/modules/$version/"
1341da177e4SLinus Torvalds
1351da177e4SLinus Torvalds# Build and install the kernel
1364f66199bSFrans Popif [ "$ARCH" = "um" ] ; then
137bf7b0055SRiku Voipio	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename"
138687c3dacSSam Ravnborg	$MAKE linux
139687c3dacSSam Ravnborg	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
140d2091767SAnisse Astier	cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
141687c3dacSSam Ravnborg	gzip "$tmpdir/usr/share/doc/$packagename/config"
142687c3dacSSam Ravnborgelse
1431da177e4SLinus Torvalds	cp System.map "$tmpdir/boot/System.map-$version"
144d2091767SAnisse Astier	cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version"
1459de70176SAnisse Astierfi
146a89b433bSFrans Pop# Not all arches include the boot path in KBUILD_IMAGE
147242c5ab0SGuillem Joverif [ -e $KBUILD_IMAGE ]; then
1489de70176SAnisse Astier	cp $KBUILD_IMAGE "$tmpdir/$installed_image_path"
149242c5ab0SGuillem Joverelse
1509de70176SAnisse Astier	cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/$installed_image_path"
151687c3dacSSam Ravnborgfi
1521da177e4SLinus Torvalds
153ca2a9d2cSArnaud Patard (Rtp)if grep -q "^CONFIG_OF=y" $KCONFIG_CONFIG ; then
154ca2a9d2cSArnaud Patard (Rtp)	# Only some architectures with OF support have this target
155ca2a9d2cSArnaud Patard (Rtp)	if grep -q dtbs_install "${srctree}/arch/$SRCARCH/Makefile"; then
156ca2a9d2cSArnaud Patard (Rtp)		$MAKE KBUILD_SRC= INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
157ca2a9d2cSArnaud Patard (Rtp)	fi
158ca2a9d2cSArnaud Patard (Rtp)fi
159ca2a9d2cSArnaud Patard (Rtp)
160d2091767SAnisse Astierif grep -q '^CONFIG_MODULES=y' $KCONFIG_CONFIG ; then
161dddcbb7cSJoerg Roedel	INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_install
162a47b6c61SJoerg Roedel	rm -f "$tmpdir/lib/modules/$version/build"
163a47b6c61SJoerg Roedel	rm -f "$tmpdir/lib/modules/$version/source"
1644f66199bSFrans Pop	if [ "$ARCH" = "um" ] ; then
165687c3dacSSam Ravnborg		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
166687c3dacSSam Ravnborg		rmdir "$tmpdir/lib/modules/$version"
167687c3dacSSam Ravnborg	fi
168810e8437SAnisse Astier	if [ -n "$BUILD_DEBUG" ] ; then
1692d087139SMichal Marek		for module in $(find $tmpdir/lib/modules/ -name *.ko -printf '%P\n'); do
1702d087139SMichal Marek			module=lib/modules/$module
171810e8437SAnisse Astier			mkdir -p $(dirname $dbg_dir/usr/lib/debug/$module)
172810e8437SAnisse Astier			# only keep debug symbols in the debug file
1732d087139SMichal Marek			$OBJCOPY --only-keep-debug $tmpdir/$module $dbg_dir/usr/lib/debug/$module
174810e8437SAnisse Astier			# strip original module from debug symbols
1752d087139SMichal Marek			$OBJCOPY --strip-debug $tmpdir/$module
176810e8437SAnisse Astier			# then add a link to those
1772d087139SMichal Marek			$OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $tmpdir/$module
178810e8437SAnisse Astier		done
17964178cb6SAndrey Skvortsov
18064178cb6SAndrey Skvortsov		# resign stripped modules
18164178cb6SAndrey Skvortsov		MODULE_SIG_ALL="$(grep -s '^CONFIG_MODULE_SIG_ALL=y' $KCONFIG_CONFIG || true)"
18264178cb6SAndrey Skvortsov		if [ -n "$MODULE_SIG_ALL" ]; then
18364178cb6SAndrey Skvortsov			INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_sign
18464178cb6SAndrey Skvortsov		fi
185810e8437SAnisse Astier	fi
1861da177e4SLinus Torvaldsfi
1871da177e4SLinus Torvalds
188d7d357bcSJoerg Roedelif [ "$ARCH" != "um" ]; then
189dddcbb7cSJoerg Roedel	$MAKE headers_check KBUILD_SRC=
190dddcbb7cSJoerg Roedel	$MAKE headers_install KBUILD_SRC= INSTALL_HDR_PATH="$libc_headers_dir/usr"
191d7d357bcSJoerg Roedelfi
192e6807785Smaximilian attems
1931da177e4SLinus Torvalds# Install the maintainer scripts
194fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian
1951c8ddae0SBen Hutchings# kernel packages, as well as kernel packages built using make-kpkg.
1961c8ddae0SBen Hutchings# make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
1971c8ddae0SBen Hutchings# so do we; recent versions of dracut and initramfs-tools will obey this.
198fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel}
1991c8ddae0SBen Hutchingsif grep -q '^CONFIG_BLK_DEV_INITRD=y' $KCONFIG_CONFIG; then
2001c8ddae0SBen Hutchings	want_initrd=Yes
2011c8ddae0SBen Hutchingselse
2021c8ddae0SBen Hutchings	want_initrd=No
2031c8ddae0SBen Hutchingsfi
2041da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do
205fe233cb6SFrans Pop	mkdir -p "$tmpdir$debhookdir/$script.d"
2061da177e4SLinus Torvalds	cat <<EOF > "$tmpdir/DEBIAN/$script"
2071da177e4SLinus Torvalds#!/bin/sh
2081da177e4SLinus Torvalds
2091da177e4SLinus Torvaldsset -e
2101da177e4SLinus Torvalds
2114964451aSFrans Pop# Pass maintainer script parameters to hook scripts
212241ad11fSmaximilian attemsexport DEB_MAINT_PARAMS="\$*"
2134964451aSFrans Pop
2141c8ddae0SBen Hutchings# Tell initramfs builder whether it's wanted
2151c8ddae0SBen Hutchingsexport INITRD=$want_initrd
2161c8ddae0SBen Hutchings
217c95182bfSAnisse Astiertest -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d
2181da177e4SLinus Torvaldsexit 0
2191da177e4SLinus TorvaldsEOF
2201da177e4SLinus Torvalds	chmod 755 "$tmpdir/DEBIAN/$script"
2211da177e4SLinus Torvaldsdone
2221da177e4SLinus Torvalds
223edec611dSmaximilian attems# Try to determine maintainer and email values
224edec611dSmaximilian attemsif [ -n "$DEBEMAIL" ]; then
225edec611dSmaximilian attems       email=$DEBEMAIL
226edec611dSmaximilian attemselif [ -n "$EMAIL" ]; then
227edec611dSmaximilian attems       email=$EMAIL
228edec611dSmaximilian attemselse
229bea107b1SChristian Kujau       email=$(id -nu)@$(hostname -f 2>/dev/null || hostname)
230edec611dSmaximilian attemsfi
231edec611dSmaximilian attemsif [ -n "$DEBFULLNAME" ]; then
232edec611dSmaximilian attems       name=$DEBFULLNAME
233edec611dSmaximilian attemselif [ -n "$NAME" ]; then
234edec611dSmaximilian attems       name=$NAME
235edec611dSmaximilian attemselse
236edec611dSmaximilian attems       name="Anonymous"
237edec611dSmaximilian attemsfi
238edec611dSmaximilian attemsmaintainer="$name <$email>"
239edec611dSmaximilian attems
240d9f711dbSSedat Dilek# Try to determine distribution
241d9f711dbSSedat Dilekif [ -n "$KDEB_CHANGELOG_DIST" ]; then
242d9f711dbSSedat Dilek        distribution=$KDEB_CHANGELOG_DIST
2434c586062SMarcin Mielniczuk# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
2444c586062SMarcin Mielniczukelif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
245d9f711dbSSedat Dilek        : # nothing to do in this case
246d9f711dbSSedat Dilekelse
247d9f711dbSSedat Dilek        distribution="unstable"
248d9f711dbSSedat Dilek        echo >&2 "Using default distribution of 'unstable' in the changelog"
249d9f711dbSSedat Dilek        echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
250d9f711dbSSedat Dilekfi
251d9f711dbSSedat Dilek
2521da177e4SLinus Torvalds# Generate a simple changelog template
2531da177e4SLinus Torvaldscat <<EOF > debian/changelog
2543716001bSRiku Voipio$sourcename ($packageversion) $distribution; urgency=low
2551da177e4SLinus Torvalds
256a83ca277SFrans Pop  * Custom built Linux kernel.
2571da177e4SLinus Torvalds
258edec611dSmaximilian attems -- $maintainer  $(date -R)
2591da177e4SLinus TorvaldsEOF
2601da177e4SLinus Torvalds
2619461f666SFrans Pop# Generate copyright file
2629461f666SFrans Popcat <<EOF > debian/copyright
2639461f666SFrans PopThis is a packacked upstream version of the Linux kernel.
2649461f666SFrans Pop
2659461f666SFrans PopThe sources may be found at most Linux ftp sites, including:
2669461f666SFrans Popftp://ftp.kernel.org/pub/linux/kernel
2679461f666SFrans Pop
268701ca30cSSedat DilekCopyright: 1991 - 2015 Linus Torvalds and others.
2699461f666SFrans Pop
2709461f666SFrans PopThe git repository for mainline kernel development is at:
271701ca30cSSedat Dilekgit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
2729461f666SFrans Pop
2739461f666SFrans Pop    This program is free software; you can redistribute it and/or modify
2749461f666SFrans Pop    it under the terms of the GNU General Public License as published by
2759461f666SFrans Pop    the Free Software Foundation; version 2 dated June, 1991.
2769461f666SFrans Pop
2779461f666SFrans PopOn Debian GNU/Linux systems, the complete text of the GNU General Public
2789461f666SFrans PopLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
2799461f666SFrans PopEOF
2809461f666SFrans Pop
2813716001bSRiku Voipio
2823716001bSRiku Voipiobuild_depends="bc, kmod, cpio "
2833716001bSRiku Voipio
2841da177e4SLinus Torvalds# Generate a control file
2851da177e4SLinus Torvaldscat <<EOF > debian/control
2863716001bSRiku VoipioSource: $sourcename
287aa42abedSRogério BritoSection: kernel
2881da177e4SLinus TorvaldsPriority: optional
289edec611dSmaximilian attemsMaintainer: $maintainer
2903716001bSRiku VoipioBuild-Depends: $build_depends
2912d7204acSRogério BritoStandards-Version: 3.8.4
292ee6eed80SRogério BritoHomepage: http://www.kernel.org/
2933e2ab256SFrans PopEOF
2943e2ab256SFrans Pop
2953e2ab256SFrans Popif [ "$ARCH" = "um" ]; then
2963e2ab256SFrans Pop	cat <<EOF >> debian/control
2971da177e4SLinus Torvalds
298687c3dacSSam RavnborgPackage: $packagename
2998ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
3001da177e4SLinus TorvaldsArchitecture: any
301dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version
302dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call
303dc5962fdSSam Ravnborg interface.  It provides a kind of virtual machine, which runs Linux
304dc5962fdSSam Ravnborg as a user process under another Linux kernel.  This is useful for
305dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and
306dc5962fdSSam Ravnborg many other things.
307dc5962fdSSam Ravnborg .
3081da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other
309a83ca277SFrans Pop files, version: $version.
3101da177e4SLinus TorvaldsEOF
3111da177e4SLinus Torvalds
312dc5962fdSSam Ravnborgelse
3133e2ab256SFrans Pop	cat <<EOF >> debian/control
314dc5962fdSSam Ravnborg
315dc5962fdSSam RavnborgPackage: $packagename
3168ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version
317bf1b3644SJonathan McDowellSuggests: $fwpackagename
318dc5962fdSSam RavnborgArchitecture: any
319dc5962fdSSam RavnborgDescription: Linux kernel, version $version
320dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other
321a83ca277SFrans Pop files, version: $version.
322dc5962fdSSam RavnborgEOF
3234f66199bSFrans Pop
324dc5962fdSSam Ravnborgfi
325dc5962fdSSam Ravnborg
3268bf13561SFathi Boudra# Build kernel header package
327a765a7ceSMichal Marek(cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles"
328962475acSAzriel Samson(cd $srctree; find arch/*/include include scripts -type f) >> "$objtree/debian/hdrsrcfiles"
3298bf13561SFathi Boudra(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
3308bf13561SFathi Boudra(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
33115f6d337SWilfried Klaebeif grep -q '^CONFIG_STACK_VALIDATION=y' $KCONFIG_CONFIG ; then
33215f6d337SWilfried Klaebe	(cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles"
33315f6d337SWilfried Klaebefi
334a765a7ceSMichal Marek(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
335d3e2773cSKees Cookif grep -q '^CONFIG_GCC_PLUGINS=y' $KCONFIG_CONFIG ; then
3366b90bd4bSEmese Revfy	(cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles"
337d3e2773cSKees Cookfi
338ee81b786Smaximilian attemsdestdir=$kernel_headers_dir/usr/src/linux-headers-$version
339ee81b786Smaximilian attemsmkdir -p "$destdir"
340a765a7ceSMichal Marek(cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
341a765a7ceSMichal Marek(cd $objtree; tar -c -f - -T -) < "$objtree/debian/hdrobjfiles" | (cd $destdir; tar -xf -)
342d2091767SAnisse Astier(cd $objtree; cp $KCONFIG_CONFIG $destdir/.config) # copy .config manually to be where it's expected to be
343a47b6c61SJoerg Roedelln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build"
3446c635224SBen Hutchingsrm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles"
345cd8d60a2STheodore Ts'o
346cd8d60a2STheodore Ts'ocat <<EOF >> debian/control
347cd8d60a2STheodore Ts'o
348ee81b786Smaximilian attemsPackage: $kernel_headers_packagename
349cd8d60a2STheodore Ts'oProvides: linux-headers, linux-headers-2.6
350f8ce239dSBen HutchingsArchitecture: any
351f8ce239dSBen HutchingsDescription: Linux kernel headers for $KERNELRELEASE on \${kernel:debarch}
352f8ce239dSBen Hutchings This package provides kernel header files for $KERNELRELEASE on \${kernel:debarch}
353cd8d60a2STheodore Ts'o .
354cd8d60a2STheodore Ts'o This is useful for people who need to build external modules
355cd8d60a2STheodore Ts'oEOF
356cd8d60a2STheodore Ts'o
357bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package.
358bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then
3596607ddadSmaximilian attems	mv "$tmpdir/lib/firmware"/* "$fwdir/lib/firmware/$version/"
3606607ddadSmaximilian attems	rmdir "$tmpdir/lib/firmware"
361bf1b3644SJonathan McDowell
362bf1b3644SJonathan McDowell	cat <<EOF >> debian/control
363bf1b3644SJonathan McDowell
364bf1b3644SJonathan McDowellPackage: $fwpackagename
365bf1b3644SJonathan McDowellArchitecture: all
366bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version
367a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version.
368bf1b3644SJonathan McDowellEOF
369bf1b3644SJonathan McDowell
3703e2ab256SFrans Pop	create_package "$fwpackagename" "$fwdir"
371bf1b3644SJonathan McDowellfi
372bf1b3644SJonathan McDowell
373e6807785Smaximilian attemscat <<EOF >> debian/control
374e6807785Smaximilian attems
375ee81b786Smaximilian attemsPackage: $libc_headers_packagename
376e6807785Smaximilian attemsSection: devel
377e6807785Smaximilian attemsProvides: linux-kernel-headers
378e6807785Smaximilian attemsArchitecture: any
379e6807785Smaximilian attemsDescription: Linux support headers for userspace development
380e6807785Smaximilian attems This package provides userspaces headers from the Linux kernel.  These headers
381e6807785Smaximilian attems are used by the installed headers for GNU glibc and other system libraries.
382e6807785Smaximilian attemsEOF
383e6807785Smaximilian attems
384d7d357bcSJoerg Roedelif [ "$ARCH" != "um" ]; then
385d7d357bcSJoerg Roedel	create_package "$kernel_headers_packagename" "$kernel_headers_dir"
386ee81b786Smaximilian attems	create_package "$libc_headers_packagename" "$libc_headers_dir"
387d7d357bcSJoerg Roedelfi
388d7d357bcSJoerg Roedel
3893e2ab256SFrans Popcreate_package "$packagename" "$tmpdir"
3901da177e4SLinus Torvalds
391810e8437SAnisse Astierif [ -n "$BUILD_DEBUG" ] ; then
392810e8437SAnisse Astier	# Build debug package
393810e8437SAnisse Astier	# Different tools want the image in different locations
394810e8437SAnisse Astier	# perf
395810e8437SAnisse Astier	mkdir -p $dbg_dir/usr/lib/debug/lib/modules/$version/
396810e8437SAnisse Astier	cp vmlinux $dbg_dir/usr/lib/debug/lib/modules/$version/
397810e8437SAnisse Astier	# systemtap
398810e8437SAnisse Astier	mkdir -p $dbg_dir/usr/lib/debug/boot/
399810e8437SAnisse Astier	ln -s ../lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/boot/vmlinux-$version
400810e8437SAnisse Astier	# kdump-tools
401810e8437SAnisse Astier	ln -s lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/vmlinux-$version
402810e8437SAnisse Astier
403810e8437SAnisse Astier	cat <<EOF >> debian/control
404810e8437SAnisse Astier
405810e8437SAnisse AstierPackage: $dbg_packagename
406810e8437SAnisse AstierSection: debug
407810e8437SAnisse AstierProvides: linux-debug, linux-debug-$version
408810e8437SAnisse AstierArchitecture: any
409810e8437SAnisse AstierDescription: Linux kernel debugging symbols for $version
410810e8437SAnisse Astier This package will come in handy if you need to debug the kernel. It provides
411810e8437SAnisse Astier all the necessary debug symbols for the kernel and its modules.
412810e8437SAnisse AstierEOF
413810e8437SAnisse Astier
414810e8437SAnisse Astier	create_package "$dbg_packagename" "$dbg_dir"
415810e8437SAnisse Astierfi
416810e8437SAnisse Astier
4173716001bSRiku Voipioif [ "x$1" = "xdeb-pkg" ]
4183716001bSRiku Voipiothen
4193716001bSRiku Voipio    cat <<EOF > debian/rules
4203716001bSRiku Voipio#!/usr/bin/make -f
4213716001bSRiku Voipio
4223716001bSRiku Voipiobuild:
4233716001bSRiku Voipio	\$(MAKE)
4243716001bSRiku Voipio
4253716001bSRiku Voipiobinary-arch:
4263716001bSRiku Voipio	\$(MAKE) KDEB_SOURCENAME=${sourcename} KDEB_PKGVERSION=${packageversion} bindeb-pkg
4273716001bSRiku Voipio
4283716001bSRiku Voipioclean:
4298d740a37SRiku Voipio	rm -rf debian/*tmp debian/files
4303716001bSRiku Voipio	mv debian/ debian.backup # debian/ might be cleaned away
4313716001bSRiku Voipio	\$(MAKE) clean
4323716001bSRiku Voipio	mv debian.backup debian
4333716001bSRiku Voipio
4343716001bSRiku Voipiobinary: binary-arch
4353716001bSRiku VoipioEOF
4363716001bSRiku Voipio	mv ${sourcename}.tar.gz ../${sourcename}_${version}.orig.tar.gz
4373716001bSRiku Voipio	tar caf ../${sourcename}_${packageversion}.debian.tar.gz debian/{copyright,rules,changelog,control}
4383716001bSRiku Voipio	dpkg-source -cdebian/control -ldebian/changelog --format="3.0 (custom)" --target-format="3.0 (quilt)" \
4393716001bSRiku Voipio		-b / ../${sourcename}_${version}.orig.tar.gz  ../${sourcename}_${packageversion}.debian.tar.gz
4403716001bSRiku Voipio	mv ${sourcename}_${packageversion}*dsc ..
4413716001bSRiku Voipio	dpkg-genchanges > ../${sourcename}_${packageversion}_${debarch}.changes
4423716001bSRiku Voipioelse
4433716001bSRiku Voipio	dpkg-genchanges -b > ../${sourcename}_${packageversion}_${debarch}.changes
4443716001bSRiku Voipiofi
4453716001bSRiku Voipio
4461da177e4SLinus Torvaldsexit 0
447