Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
Frans Pop | 4964451 | 2009-04-23 01:09:25 +0200 | [diff] [blame] | 3 | # builddeb 1.3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | # Copyright 2003 Wichert Akkerman <wichert@wiggy.net> |
| 5 | # |
| 6 | # Simple script to generate a deb package for a Linux kernel. All the |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 7 | # complexity of what to do with a kernel after it is installed or removed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | # is left to other scripts and packages: they can install scripts in the |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame] | 9 | # /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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | set -e |
| 14 | |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 15 | create_package() { |
| 16 | local pname="$1" pdir="$2" |
| 17 | |
Riku Voipio | bf7b005 | 2015-05-28 12:11:14 +0300 | [diff] [blame] | 18 | mkdir -m 755 -p "$pdir/DEBIAN" |
| 19 | mkdir -p "$pdir/usr/share/doc/$pname" |
Frans Pop | 9461f66 | 2009-04-24 19:08:24 +0200 | [diff] [blame] | 20 | cp debian/copyright "$pdir/usr/share/doc/$pname/" |
maximilian attems | 1ab1848 | 2009-06-26 20:04:36 +0200 | [diff] [blame] | 21 | cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian" |
| 22 | gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian" |
FEJES Jozsef | b59a122 | 2010-03-05 18:19:36 +0100 | [diff] [blame] | 23 | sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \ |
| 24 | | xargs -r0 md5sum > DEBIAN/md5sums" |
Frans Pop | 9461f66 | 2009-04-24 19:08:24 +0200 | [diff] [blame] | 25 | |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 26 | # Fix ownership and permissions |
| 27 | chown -R root:root "$pdir" |
| 28 | chmod -R go-w "$pdir" |
Henning Schild | ca617dc | 2016-07-22 14:46:52 +0200 | [diff] [blame] | 29 | # in case we are in a restrictive umask environment like 0077 |
| 30 | chmod -R a+rX "$pdir" |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 31 | |
Riku Voipio | dca0c02 | 2015-04-16 16:42:46 +0300 | [diff] [blame] | 32 | # Create the package |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 33 | dpkg-gencontrol -p$pname -P"$pdir" |
Riku Voipio | dca0c02 | 2015-04-16 16:42:46 +0300 | [diff] [blame] | 34 | dpkg --build "$pdir" .. |
| 35 | } |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | version=$KERNELRELEASE |
| 38 | tmpdir="$objtree/debian/tmp" |
maximilian attems | ee81b78 | 2011-01-07 16:13:06 +0100 | [diff] [blame] | 39 | kernel_headers_dir="$objtree/debian/hdrtmp" |
| 40 | libc_headers_dir="$objtree/debian/headertmp" |
Anisse Astier | 810e843 | 2013-07-03 16:02:04 +0200 | [diff] [blame] | 41 | dbg_dir="$objtree/debian/dbgtmp" |
maximilian attems | f7a2c31 | 2009-04-23 01:12:01 +0200 | [diff] [blame] | 42 | packagename=linux-image-$version |
maximilian attems | ee81b78 | 2011-01-07 16:13:06 +0100 | [diff] [blame] | 43 | kernel_headers_packagename=linux-headers-$version |
| 44 | libc_headers_packagename=linux-libc-dev |
Anisse Astier | 810e843 | 2013-07-03 16:02:04 +0200 | [diff] [blame] | 45 | dbg_packagename=$packagename-dbg |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 46 | |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 47 | if [ "$ARCH" = "um" ] ; then |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 48 | packagename=user-mode-linux-$version |
| 49 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Anisse Astier | 9de7017 | 2013-07-03 16:02:05 +0200 | [diff] [blame] | 51 | # 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 |
| 54 | case $ARCH in |
| 55 | um) |
| 56 | installed_image_path="usr/bin/linux-$version" |
| 57 | ;; |
| 58 | parisc|mips|powerpc) |
| 59 | installed_image_path="boot/vmlinux-$version" |
| 60 | ;; |
| 61 | *) |
| 62 | installed_image_path="boot/vmlinuz-$version" |
| 63 | esac |
| 64 | |
Anisse Astier | 810e843 | 2013-07-03 16:02:04 +0200 | [diff] [blame] | 65 | BUILD_DEBUG="$(grep -s '^CONFIG_DEBUG_INFO=y' $KCONFIG_CONFIG || true)" |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | # Setup the directory structure |
Masahiro Yamada | cc18abb | 2017-09-18 18:22:19 +0900 | [diff] [blame] | 68 | rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files |
maximilian attems | e86c241 | 2010-10-29 15:55:50 +0200 | [diff] [blame] | 69 | mkdir -m 755 -p "$tmpdir/DEBIAN" |
Riku Voipio | bf7b005 | 2015-05-28 12:11:14 +0300 | [diff] [blame] | 70 | mkdir -p "$tmpdir/lib" "$tmpdir/boot" |
Joerg Roedel | a47b6c6 | 2012-02-15 17:38:26 +0100 | [diff] [blame] | 71 | mkdir -p "$kernel_headers_dir/lib/modules/$version/" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | # Build and install the kernel |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 74 | if [ "$ARCH" = "um" ] ; then |
Riku Voipio | bf7b005 | 2015-05-28 12:11:14 +0300 | [diff] [blame] | 75 | mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename" |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 76 | $MAKE linux |
| 77 | cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" |
Anisse Astier | d209176 | 2013-07-03 16:02:03 +0200 | [diff] [blame] | 78 | cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config" |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 79 | gzip "$tmpdir/usr/share/doc/$packagename/config" |
Masahiro Yamada | 38385f8 | 2014-04-28 16:26:18 +0900 | [diff] [blame] | 80 | else |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 81 | cp System.map "$tmpdir/boot/System.map-$version" |
Anisse Astier | d209176 | 2013-07-03 16:02:03 +0200 | [diff] [blame] | 82 | cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version" |
Anisse Astier | 9de7017 | 2013-07-03 16:02:05 +0200 | [diff] [blame] | 83 | fi |
Michal Marek | 09549aa | 2016-11-22 22:34:34 +0100 | [diff] [blame] | 84 | cp "$($MAKE -s image_name)" "$tmpdir/$installed_image_path" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Arnaud Patard (Rtp) | ca2a9d2 | 2015-02-03 13:16:33 +0100 | [diff] [blame] | 86 | if 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 |
| 91 | fi |
| 92 | |
Anisse Astier | d209176 | 2013-07-03 16:02:03 +0200 | [diff] [blame] | 93 | if grep -q '^CONFIG_MODULES=y' $KCONFIG_CONFIG ; then |
Joerg Roedel | dddcbb7 | 2012-02-16 19:56:37 +0100 | [diff] [blame] | 94 | INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_install |
Joerg Roedel | a47b6c6 | 2012-02-15 17:38:26 +0100 | [diff] [blame] | 95 | rm -f "$tmpdir/lib/modules/$version/build" |
| 96 | rm -f "$tmpdir/lib/modules/$version/source" |
Frans Pop | 4f66199 | 2009-04-23 01:08:31 +0200 | [diff] [blame] | 97 | if [ "$ARCH" = "um" ] ; then |
Sam Ravnborg | 687c3da | 2005-07-14 20:24:00 +0000 | [diff] [blame] | 98 | mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" |
| 99 | rmdir "$tmpdir/lib/modules/$version" |
| 100 | fi |
Anisse Astier | 810e843 | 2013-07-03 16:02:04 +0200 | [diff] [blame] | 101 | if [ -n "$BUILD_DEBUG" ] ; then |
Michal Marek | 2d08713 | 2014-08-22 15:51:03 +0200 | [diff] [blame] | 102 | 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 Skvortsov | 64178cb | 2015-03-16 11:20:54 +0300 | [diff] [blame] | 112 | |
| 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 Astier | 810e843 | 2013-07-03 16:02:04 +0200 | [diff] [blame] | 118 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | fi |
| 120 | |
Joerg Roedel | d7d357b | 2012-02-15 17:38:27 +0100 | [diff] [blame] | 121 | if [ "$ARCH" != "um" ]; then |
Joerg Roedel | dddcbb7 | 2012-02-16 19:56:37 +0100 | [diff] [blame] | 122 | $MAKE headers_check KBUILD_SRC= |
| 123 | $MAKE headers_install KBUILD_SRC= INSTALL_HDR_PATH="$libc_headers_dir/usr" |
Joerg Roedel | d7d357b | 2012-02-15 17:38:27 +0100 | [diff] [blame] | 124 | fi |
maximilian attems | e680778 | 2011-01-01 16:44:13 +0100 | [diff] [blame] | 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | # Install the maintainer scripts |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame] | 127 | # Note: hook scripts under /etc/kernel are also executed by official Debian |
Ben Hutchings | 1c8ddae | 2013-11-15 03:03:25 +0000 | [diff] [blame] | 128 | # 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 Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame] | 131 | debhookdir=${KDEB_HOOKDIR:-/etc/kernel} |
Ben Hutchings | 1c8ddae | 2013-11-15 03:03:25 +0000 | [diff] [blame] | 132 | if grep -q '^CONFIG_BLK_DEV_INITRD=y' $KCONFIG_CONFIG; then |
| 133 | want_initrd=Yes |
| 134 | else |
| 135 | want_initrd=No |
| 136 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | for script in postinst postrm preinst prerm ; do |
Frans Pop | fe233cb | 2009-04-23 01:10:10 +0200 | [diff] [blame] | 138 | mkdir -p "$tmpdir$debhookdir/$script.d" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | cat <<EOF > "$tmpdir/DEBIAN/$script" |
| 140 | #!/bin/sh |
| 141 | |
| 142 | set -e |
| 143 | |
Frans Pop | 4964451 | 2009-04-23 01:09:25 +0200 | [diff] [blame] | 144 | # Pass maintainer script parameters to hook scripts |
maximilian attems | 241ad11 | 2009-07-05 20:17:34 +0200 | [diff] [blame] | 145 | export DEB_MAINT_PARAMS="\$*" |
Frans Pop | 4964451 | 2009-04-23 01:09:25 +0200 | [diff] [blame] | 146 | |
Ben Hutchings | 1c8ddae | 2013-11-15 03:03:25 +0000 | [diff] [blame] | 147 | # Tell initramfs builder whether it's wanted |
| 148 | export INITRD=$want_initrd |
| 149 | |
Anisse Astier | c95182b | 2013-07-03 16:02:06 +0200 | [diff] [blame] | 150 | test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | exit 0 |
| 152 | EOF |
| 153 | chmod 755 "$tmpdir/DEBIAN/$script" |
| 154 | done |
| 155 | |
Fathi Boudra | 8bf1356 | 2014-04-15 14:51:48 +0300 | [diff] [blame] | 156 | # Build kernel header package |
Michal Marek | a765a7c | 2014-06-16 16:11:29 +0200 | [diff] [blame] | 157 | (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles" |
Jan Kiszka | f843752 | 2018-03-21 13:15:28 +0800 | [diff] [blame] | 158 | (cd $srctree; find arch/*/include include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles" |
Fathi Boudra | 8bf1356 | 2014-04-15 14:51:48 +0300 | [diff] [blame] | 159 | (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 Klaebe | 15f6d337 | 2016-06-28 12:21:33 +0000 | [diff] [blame] | 161 | if grep -q '^CONFIG_STACK_VALIDATION=y' $KCONFIG_CONFIG ; then |
| 162 | (cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles" |
| 163 | fi |
Michal Marek | a765a7c | 2014-06-16 16:11:29 +0200 | [diff] [blame] | 164 | (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles" |
Kees Cook | d3e2773 | 2016-08-15 10:36:22 -0700 | [diff] [blame] | 165 | if 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" |
| 167 | fi |
maximilian attems | ee81b78 | 2011-01-07 16:13:06 +0100 | [diff] [blame] | 168 | destdir=$kernel_headers_dir/usr/src/linux-headers-$version |
| 169 | mkdir -p "$destdir" |
Michal Marek | a765a7c | 2014-06-16 16:11:29 +0200 | [diff] [blame] | 170 | (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 Astier | d209176 | 2013-07-03 16:02:03 +0200 | [diff] [blame] | 172 | (cd $objtree; cp $KCONFIG_CONFIG $destdir/.config) # copy .config manually to be where it's expected to be |
Joerg Roedel | a47b6c6 | 2012-02-15 17:38:26 +0100 | [diff] [blame] | 173 | ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build" |
Ben Hutchings | 6c63522 | 2012-02-15 14:17:29 +0000 | [diff] [blame] | 174 | rm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles" |
Theodore Ts'o | cd8d60a | 2010-12-24 09:42:10 -0500 | [diff] [blame] | 175 | |
Joerg Roedel | d7d357b | 2012-02-15 17:38:27 +0100 | [diff] [blame] | 176 | if [ "$ARCH" != "um" ]; then |
| 177 | create_package "$kernel_headers_packagename" "$kernel_headers_dir" |
| 178 | create_package "$libc_headers_packagename" "$libc_headers_dir" |
| 179 | fi |
| 180 | |
Frans Pop | 3e2ab25 | 2009-04-23 01:08:44 +0200 | [diff] [blame] | 181 | create_package "$packagename" "$tmpdir" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Anisse Astier | 810e843 | 2013-07-03 16:02:04 +0200 | [diff] [blame] | 183 | if [ -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 Astier | 810e843 | 2013-07-03 16:02:04 +0200 | [diff] [blame] | 194 | create_package "$dbg_packagename" "$dbg_dir" |
| 195 | fi |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | exit 0 |