blob: 90c9a8ac7adb81d9dc10d0cb00eda86ee3a35a8f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/bin/sh
2#
Frans Pop49644512009-04-23 01:09:25 +02003# builddeb 1.3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
5#
6# Simple script to generate a deb package for a Linux kernel. All the
Frans Pop4f661992009-04-23 01:08:31 +02007# complexity of what to do with a kernel after it is installed or removed
Linus Torvalds1da177e2005-04-16 15:20:36 -07008# is left to other scripts and packages: they can install scripts in the
Frans Popfe233cb2009-04-23 01:10:10 +02009# /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
10# specified in KDEB_HOOKDIR) that will be called on package install and
11# removal.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13set -e
14
Frans Pop3e2ab252009-04-23 01:08:44 +020015create_package() {
16 local pname="$1" pdir="$2"
17
Riku Voipiobf7b0052015-05-28 12:11:14 +030018 mkdir -m 755 -p "$pdir/DEBIAN"
19 mkdir -p "$pdir/usr/share/doc/$pname"
Frans Pop9461f662009-04-24 19:08:24 +020020 cp debian/copyright "$pdir/usr/share/doc/$pname/"
maximilian attems1ab18482009-06-26 20:04:36 +020021 cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
22 gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
FEJES Jozsefb59a1222010-03-05 18:19:36 +010023 sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
24 | xargs -r0 md5sum > DEBIAN/md5sums"
Frans Pop9461f662009-04-24 19:08:24 +020025
Frans Pop3e2ab252009-04-23 01:08:44 +020026 # Fix ownership and permissions
27 chown -R root:root "$pdir"
28 chmod -R go-w "$pdir"
Henning Schildca617dc2016-07-22 14:46:52 +020029 # in case we are in a restrictive umask environment like 0077
30 chmod -R a+rX "$pdir"
Frans Pop3e2ab252009-04-23 01:08:44 +020031
Riku Voipiodca0c022015-04-16 16:42:46 +030032 # Create the package
Riku Voipiob41d9202018-04-05 14:22:29 +030033 dpkg-gencontrol -p$pname -P"$pdir"
Riku Voipiodca0c022015-04-16 16:42:46 +030034 dpkg --build "$pdir" ..
35}
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037version=$KERNELRELEASE
38tmpdir="$objtree/debian/tmp"
maximilian attemsee81b782011-01-07 16:13:06 +010039kernel_headers_dir="$objtree/debian/hdrtmp"
40libc_headers_dir="$objtree/debian/headertmp"
Anisse Astier810e8432013-07-03 16:02:04 +020041dbg_dir="$objtree/debian/dbgtmp"
maximilian attemsf7a2c312009-04-23 01:12:01 +020042packagename=linux-image-$version
maximilian attemsee81b782011-01-07 16:13:06 +010043kernel_headers_packagename=linux-headers-$version
44libc_headers_packagename=linux-libc-dev
Anisse Astier810e8432013-07-03 16:02:04 +020045dbg_packagename=$packagename-dbg
Sam Ravnborg687c3da2005-07-14 20:24:00 +000046
Frans Pop4f661992009-04-23 01:08:31 +020047if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000048 packagename=user-mode-linux-$version
49fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Anisse Astier9de70172013-07-03 16:02:05 +020051# Not all arches have the same installed path in debian
52# XXX: have each arch Makefile export a variable of the canonical image install
53# path instead
54case $ARCH in
55um)
56 installed_image_path="usr/bin/linux-$version"
57 ;;
58parisc|mips|powerpc)
59 installed_image_path="boot/vmlinux-$version"
60 ;;
61*)
62 installed_image_path="boot/vmlinuz-$version"
63esac
64
Anisse Astier810e8432013-07-03 16:02:04 +020065BUILD_DEBUG="$(grep -s '^CONFIG_DEBUG_INFO=y' $KCONFIG_CONFIG || true)"
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067# Setup the directory structure
Masahiro Yamadacc18abb2017-09-18 18:22:19 +090068rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files
maximilian attemse86c2412010-10-29 15:55:50 +020069mkdir -m 755 -p "$tmpdir/DEBIAN"
Riku Voipiobf7b0052015-05-28 12:11:14 +030070mkdir -p "$tmpdir/lib" "$tmpdir/boot"
Joerg Roedela47b6c62012-02-15 17:38:26 +010071mkdir -p "$kernel_headers_dir/lib/modules/$version/"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73# Build and install the kernel
Frans Pop4f661992009-04-23 01:08:31 +020074if [ "$ARCH" = "um" ] ; then
Riku Voipiobf7b0052015-05-28 12:11:14 +030075 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000076 $MAKE linux
77 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
Anisse Astierd2091762013-07-03 16:02:03 +020078 cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
Sam Ravnborg687c3da2005-07-14 20:24:00 +000079 gzip "$tmpdir/usr/share/doc/$packagename/config"
Masahiro Yamada38385f82014-04-28 16:26:18 +090080else
Sam Ravnborg687c3da2005-07-14 20:24:00 +000081 cp System.map "$tmpdir/boot/System.map-$version"
Anisse Astierd2091762013-07-03 16:02:03 +020082 cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version"
Anisse Astier9de70172013-07-03 16:02:05 +020083fi
Michal Marek09549aa2016-11-22 22:34:34 +010084cp "$($MAKE -s image_name)" "$tmpdir/$installed_image_path"
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Arnaud Patard (Rtp)ca2a9d22015-02-03 13:16:33 +010086if grep -q "^CONFIG_OF=y" $KCONFIG_CONFIG ; then
87 # Only some architectures with OF support have this target
88 if grep -q dtbs_install "${srctree}/arch/$SRCARCH/Makefile"; then
89 $MAKE KBUILD_SRC= INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
90 fi
91fi
92
Anisse Astierd2091762013-07-03 16:02:03 +020093if grep -q '^CONFIG_MODULES=y' $KCONFIG_CONFIG ; then
Joerg Roedeldddcbb72012-02-16 19:56:37 +010094 INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_install
Joerg Roedela47b6c62012-02-15 17:38:26 +010095 rm -f "$tmpdir/lib/modules/$version/build"
96 rm -f "$tmpdir/lib/modules/$version/source"
Frans Pop4f661992009-04-23 01:08:31 +020097 if [ "$ARCH" = "um" ] ; then
Sam Ravnborg687c3da2005-07-14 20:24:00 +000098 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
99 rmdir "$tmpdir/lib/modules/$version"
100 fi
Anisse Astier810e8432013-07-03 16:02:04 +0200101 if [ -n "$BUILD_DEBUG" ] ; then
Michal Marek2d087132014-08-22 15:51:03 +0200102 for module in $(find $tmpdir/lib/modules/ -name *.ko -printf '%P\n'); do
103 module=lib/modules/$module
104 mkdir -p $(dirname $dbg_dir/usr/lib/debug/$module)
105 # only keep debug symbols in the debug file
106 $OBJCOPY --only-keep-debug $tmpdir/$module $dbg_dir/usr/lib/debug/$module
107 # strip original module from debug symbols
108 $OBJCOPY --strip-debug $tmpdir/$module
109 # then add a link to those
110 $OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $tmpdir/$module
111 done
Andrey Skvortsov64178cb2015-03-16 11:20:54 +0300112
113 # resign stripped modules
114 MODULE_SIG_ALL="$(grep -s '^CONFIG_MODULE_SIG_ALL=y' $KCONFIG_CONFIG || true)"
115 if [ -n "$MODULE_SIG_ALL" ]; then
116 INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_sign
117 fi
Anisse Astier810e8432013-07-03 16:02:04 +0200118 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119fi
120
Joerg Roedeld7d357b2012-02-15 17:38:27 +0100121if [ "$ARCH" != "um" ]; then
Joerg Roedeldddcbb72012-02-16 19:56:37 +0100122 $MAKE headers_check KBUILD_SRC=
123 $MAKE headers_install KBUILD_SRC= INSTALL_HDR_PATH="$libc_headers_dir/usr"
Joerg Roedeld7d357b2012-02-15 17:38:27 +0100124fi
maximilian attemse6807782011-01-01 16:44:13 +0100125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126# Install the maintainer scripts
Frans Popfe233cb2009-04-23 01:10:10 +0200127# Note: hook scripts under /etc/kernel are also executed by official Debian
Ben Hutchings1c8ddae2013-11-15 03:03:25 +0000128# kernel packages, as well as kernel packages built using make-kpkg.
129# make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
130# so do we; recent versions of dracut and initramfs-tools will obey this.
Frans Popfe233cb2009-04-23 01:10:10 +0200131debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
Ben Hutchings1c8ddae2013-11-15 03:03:25 +0000132if grep -q '^CONFIG_BLK_DEV_INITRD=y' $KCONFIG_CONFIG; then
133 want_initrd=Yes
134else
135 want_initrd=No
136fi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137for script in postinst postrm preinst prerm ; do
Frans Popfe233cb2009-04-23 01:10:10 +0200138 mkdir -p "$tmpdir$debhookdir/$script.d"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 cat <<EOF > "$tmpdir/DEBIAN/$script"
140#!/bin/sh
141
142set -e
143
Frans Pop49644512009-04-23 01:09:25 +0200144# Pass maintainer script parameters to hook scripts
maximilian attems241ad112009-07-05 20:17:34 +0200145export DEB_MAINT_PARAMS="\$*"
Frans Pop49644512009-04-23 01:09:25 +0200146
Ben Hutchings1c8ddae2013-11-15 03:03:25 +0000147# Tell initramfs builder whether it's wanted
148export INITRD=$want_initrd
149
Anisse Astierc95182b2013-07-03 16:02:06 +0200150test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151exit 0
152EOF
153 chmod 755 "$tmpdir/DEBIAN/$script"
154done
155
Fathi Boudra8bf13562014-04-15 14:51:48 +0300156# Build kernel header package
Michal Mareka765a7c2014-06-16 16:11:29 +0200157(cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles"
Jan Kiszkaf8437522018-03-21 13:15:28 +0800158(cd $srctree; find arch/*/include include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles"
Fathi Boudra8bf13562014-04-15 14:51:48 +0300159(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
160(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
Wilfried Klaebe15f6d3372016-06-28 12:21:33 +0000161if grep -q '^CONFIG_STACK_VALIDATION=y' $KCONFIG_CONFIG ; then
162 (cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles"
163fi
Michal Mareka765a7c2014-06-16 16:11:29 +0200164(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
Kees Cookd3e27732016-08-15 10:36:22 -0700165if grep -q '^CONFIG_GCC_PLUGINS=y' $KCONFIG_CONFIG ; then
166 (cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles"
167fi
maximilian attemsee81b782011-01-07 16:13:06 +0100168destdir=$kernel_headers_dir/usr/src/linux-headers-$version
169mkdir -p "$destdir"
Michal Mareka765a7c2014-06-16 16:11:29 +0200170(cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
171(cd $objtree; tar -c -f - -T -) < "$objtree/debian/hdrobjfiles" | (cd $destdir; tar -xf -)
Anisse Astierd2091762013-07-03 16:02:03 +0200172(cd $objtree; cp $KCONFIG_CONFIG $destdir/.config) # copy .config manually to be where it's expected to be
Joerg Roedela47b6c62012-02-15 17:38:26 +0100173ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build"
Ben Hutchings6c635222012-02-15 14:17:29 +0000174rm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles"
Theodore Ts'ocd8d60a2010-12-24 09:42:10 -0500175
Joerg Roedeld7d357b2012-02-15 17:38:27 +0100176if [ "$ARCH" != "um" ]; then
177 create_package "$kernel_headers_packagename" "$kernel_headers_dir"
178 create_package "$libc_headers_packagename" "$libc_headers_dir"
179fi
180
Frans Pop3e2ab252009-04-23 01:08:44 +0200181create_package "$packagename" "$tmpdir"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Anisse Astier810e8432013-07-03 16:02:04 +0200183if [ -n "$BUILD_DEBUG" ] ; then
184 # Build debug package
185 # Different tools want the image in different locations
186 # perf
187 mkdir -p $dbg_dir/usr/lib/debug/lib/modules/$version/
188 cp vmlinux $dbg_dir/usr/lib/debug/lib/modules/$version/
189 # systemtap
190 mkdir -p $dbg_dir/usr/lib/debug/boot/
191 ln -s ../lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/boot/vmlinux-$version
192 # kdump-tools
193 ln -s lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/vmlinux-$version
Anisse Astier810e8432013-07-03 16:02:04 +0200194 create_package "$dbg_packagename" "$dbg_dir"
195fi
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197exit 0