| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# builddeb 1.3 |
| 4 |
# Copyright 2003 Wichert Akkerman <[email protected]> |
| 5 |
# |
| 6 |
# Simple script to generate a deb package for a Linux kernel. All the |
| 7 |
# complexity of what to do with a kernel after it is installed or removed |
| 8 |
# is left to other scripts and packages: they can install scripts in the |
| 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. |
| 12 |
|
| 13 |
set -e |
| 14 |
|
| 15 |
create_package() { |
| 16 |
local pname="$1" pdir="$2" |
| 17 |
|
| 18 |
cp debian/copyright "$pdir/usr/share/doc/$pname/" |
| 19 |
cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian" |
| 20 |
gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian" |
| 21 |
sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \ |
| 22 |
| xargs -r0 md5sum > DEBIAN/md5sums" |
| 23 |
|
| 24 |
# Fix ownership and permissions |
| 25 |
chown -R root:root "$pdir" |
| 26 |
chmod -R go-w "$pdir" |
| 27 |
|
| 28 |
# Attempt to find the correct Debian architecture |
| 29 |
local forcearch="" debarch="" |
| 30 |
case "$UTS_MACHINE" in |
| 31 |
i386|ia64|alpha) |
| 32 |
debarch="$UTS_MACHINE" ;; |
| 33 |
x86_64) |
| 34 |
debarch=amd64 ;; |
| 35 |
sparc*) |
| 36 |
debarch=sparc ;; |
| 37 |
s390*) |
| 38 |
debarch=s390 ;; |
| 39 |
ppc*) |
| 40 |
debarch=powerpc ;; |
| 41 |
parisc*) |
| 42 |
debarch=hppa ;; |
| 43 |
mips*) |
| 44 |
debarch=mips$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo el || true) ;; |
| 45 |
arm*) |
| 46 |
debarch=arm$(grep -q CONFIG_AEABI=y $KCONFIG_CONFIG && echo el || true) ;; |
| 47 |
*) |
| 48 |
echo "" >&2 |
| 49 |
echo "** ** ** WARNING ** ** **" >&2 |
| 50 |
echo "" >&2 |
| 51 |
echo "Your architecture doesn't have it's equivalent" >&2 |
| 52 |
echo "Debian userspace architecture defined!" >&2 |
| 53 |
echo "Falling back to using your current userspace instead!" >&2 |
| 54 |
echo "Please add support for $UTS_MACHINE to ${0} ..." >&2 |
| 55 |
echo "" >&2 |
| 56 |
esac |
| 57 |
if [ -n "$KBUILD_DEBARCH" ] ; then |
| 58 |
debarch="$KBUILD_DEBARCH" |
| 59 |
fi |
| 60 |
if [ -n "$debarch" ] ; then |
| 61 |
forcearch="-DArchitecture=$debarch" |
| 62 |
fi |
| 63 |
|
| 64 |
# Create the package |
| 65 |
dpkg-gencontrol -isp -Vkernel:debarch="${debarch:-$(dpkg --print-architecture)}" -p$pname -P"$pdir" |
| 66 |
dpkg --build "$pdir" .. |
| 67 |
} |
| 68 |
|
| 69 |
# Some variables and settings used throughout the script |
| 70 |
version=$KERNELRELEASE |
| 71 |
if [ -n "$KDEB_PKGVERSION" ]; then |
| 72 |
packageversion=$KDEB_PKGVERSION |
| 73 |
else |
| 74 |
packageversion=$version-$(cat .version) |
| 75 |
fi |
| 76 |
tmpdir="$objtree/debian/tmp" |
| 77 |
fwdir="$objtree/debian/fwtmp" |
| 78 |
kernel_headers_dir="$objtree/debian/hdrtmp" |
| 79 |
libc_headers_dir="$objtree/debian/headertmp" |
| 80 |
dbg_dir="$objtree/debian/dbgtmp" |
| 81 |
packagename=linux-image-$version |
| 82 |
fwpackagename=linux-firmware-image-$version |
| 83 |
kernel_headers_packagename=linux-headers-$version |
| 84 |
libc_headers_packagename=linux-libc-dev-$KBUILD_DEBARCH-cross |
| 85 |
dbg_packagename=$packagename-dbg |
| 86 |
|
| 87 |
if [ "$ARCH" = "um" ] ; then |
| 88 |
packagename=user-mode-linux-$version |
| 89 |
fi |
| 90 |
|
| 91 |
# Not all arches have the same installed path in debian |
| 92 |
# XXX: have each arch Makefile export a variable of the canonical image install |
| 93 |
# path instead |
| 94 |
case $ARCH in |
| 95 |
um) |
| 96 |
installed_image_path="usr/bin/linux-$version" |
| 97 |
;; |
| 98 |
parisc|mips|powerpc) |
| 99 |
installed_image_path="boot/vmlinux-$version" |
| 100 |
;; |
| 101 |
*) |
| 102 |
installed_image_path="boot/vmlinuz-$version" |
| 103 |
esac |
| 104 |
|
| 105 |
BUILD_DEBUG="$(grep -s '^CONFIG_DEBUG_INFO=y' $KCONFIG_CONFIG || true)" |
| 106 |
|
| 107 |
# Setup the directory structure |
| 108 |
rm -rf "$tmpdir" "$fwdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" |
| 109 |
mkdir -m 755 -p "$tmpdir/DEBIAN" |
| 110 |
mkdir -p "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename" |
| 111 |
mkdir -m 755 -p "$fwdir/DEBIAN" |
| 112 |
mkdir -p "$fwdir/lib/firmware/$version/" "$fwdir/usr/share/doc/$fwpackagename" |
| 113 |
mkdir -m 755 -p "$libc_headers_dir/DEBIAN" |
| 114 |
mkdir -p "$libc_headers_dir/usr/share/doc/$libc_headers_packagename" |
| 115 |
mkdir -m 755 -p "$kernel_headers_dir/DEBIAN" |
| 116 |
mkdir -p "$kernel_headers_dir/usr/share/doc/$kernel_headers_packagename" |
| 117 |
mkdir -p "$kernel_headers_dir/lib/modules/$version/" |
| 118 |
if [ "$ARCH" = "um" ] ; then |
| 119 |
mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" |
| 120 |
fi |
| 121 |
if [ -n "$BUILD_DEBUG" ] ; then |
| 122 |
mkdir -p "$dbg_dir/usr/share/doc/$dbg_packagename" |
| 123 |
mkdir -m 755 -p "$dbg_dir/DEBIAN" |
| 124 |
fi |
| 125 |
|
| 126 |
# # Build and install the kernel |
| 127 |
# if [ "$ARCH" = "um" ] ; then |
| 128 |
# $MAKE linux |
| 129 |
# cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" |
| 130 |
# cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config" |
| 131 |
# gzip "$tmpdir/usr/share/doc/$packagename/config" |
| 132 |
# else |
| 133 |
# cp System.map "$tmpdir/boot/System.map-$version" |
| 134 |
# cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version" |
| 135 |
# fi |
| 136 |
# # Not all arches include the boot path in KBUILD_IMAGE |
| 137 |
# if [ -e $KBUILD_IMAGE ]; then |
| 138 |
# cp $KBUILD_IMAGE "$tmpdir/$installed_image_path" |
| 139 |
# else |
| 140 |
# cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/$installed_image_path" |
| 141 |
# fi |
| 142 |
|
| 143 |
# if grep -q '^CONFIG_MODULES=y' $KCONFIG_CONFIG ; then |
| 144 |
# INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_install |
| 145 |
# rm -f "$tmpdir/lib/modules/$version/build" |
| 146 |
# rm -f "$tmpdir/lib/modules/$version/source" |
| 147 |
# if [ "$ARCH" = "um" ] ; then |
| 148 |
# mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" |
| 149 |
# rmdir "$tmpdir/lib/modules/$version" |
| 150 |
# fi |
| 151 |
# if [ -n "$BUILD_DEBUG" ] ; then |
| 152 |
# ( |
| 153 |
# cd $tmpdir |
| 154 |
# for module in $(find lib/modules/ -name *.ko); do |
| 155 |
# mkdir -p $(dirname $dbg_dir/usr/lib/debug/$module) |
| 156 |
# # only keep debug symbols in the debug file |
| 157 |
# $OBJCOPY --only-keep-debug $module $dbg_dir/usr/lib/debug/$module |
| 158 |
# # strip original module from debug symbols |
| 159 |
# $OBJCOPY --strip-debug $module |
| 160 |
# # then add a link to those |
| 161 |
# $OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $module |
| 162 |
# done |
| 163 |
# ) |
| 164 |
# fi |
| 165 |
# fi |
| 166 |
|
| 167 |
# if [ "$ARCH" != "um" ]; then |
| 168 |
# $MAKE headers_check KBUILD_SRC= |
| 169 |
$MAKE headers_install KBUILD_SRC= INSTALL_HDR_PATH="$libc_headers_dir/usr" |
| 170 |
# fi |
| 171 |
|
| 172 |
# Install the maintainer scripts |
| 173 |
# Note: hook scripts under /etc/kernel are also executed by official Debian |
| 174 |
# kernel packages, as well as kernel packages built using make-kpkg |
| 175 |
# debhookdir=${KDEB_HOOKDIR:-/etc/kernel} |
| 176 |
# for script in postinst postrm preinst prerm ; do |
| 177 |
# mkdir -p "$tmpdir$debhookdir/$script.d" |
| 178 |
# cat <<EOF > "$tmpdir/DEBIAN/$script" |
| 179 |
# #!/bin/sh |
| 180 |
|
| 181 |
# set -e |
| 182 |
|
| 183 |
# # Pass maintainer script parameters to hook scripts |
| 184 |
# export DEB_MAINT_PARAMS="\$*" |
| 185 |
|
| 186 |
# test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d |
| 187 |
# exit 0 |
| 188 |
# EOF |
| 189 |
# chmod 755 "$tmpdir/DEBIAN/$script" |
| 190 |
# done |
| 191 |
|
| 192 |
# Try to determine maintainer and email values |
| 193 |
if [ -n "$DEBEMAIL" ]; then |
| 194 |
email=$DEBEMAIL |
| 195 |
elif [ -n "$EMAIL" ]; then |
| 196 |
email=$EMAIL |
| 197 |
else |
| 198 |
email=$(id -nu)@$(hostname -f) |
| 199 |
fi |
| 200 |
if [ -n "$DEBFULLNAME" ]; then |
| 201 |
name=$DEBFULLNAME |
| 202 |
elif [ -n "$NAME" ]; then |
| 203 |
name=$NAME |
| 204 |
else |
| 205 |
name="Anonymous" |
| 206 |
fi |
| 207 |
maintainer="$name <$email>" |
| 208 |
|
| 209 |
# Generate a simple changelog template |
| 210 |
cat <<EOF > debian/changelog |
| 211 |
cross-toolchain-base ($packageversion) unstable; urgency=low |
| 212 |
|
| 213 |
* Custom built Linux kernel. |
| 214 |
|
| 215 |
-- $maintainer $(date -R) |
| 216 |
EOF |
| 217 |
|
| 218 |
# Generate copyright file |
| 219 |
cat <<EOF > debian/copyright |
| 220 |
This is a packacked upstream version of the Linux kernel. |
| 221 |
|
| 222 |
The sources may be found at most Linux ftp sites, including: |
| 223 |
ftp://ftp.kernel.org/pub/linux/kernel |
| 224 |
|
| 225 |
Copyright: 1991 - 2009 Linus Torvalds and others. |
| 226 |
|
| 227 |
The git repository for mainline kernel development is at: |
| 228 |
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git |
| 229 |
|
| 230 |
This program is free software; you can redistribute it and/or modify |
| 231 |
it under the terms of the GNU General Public License as published by |
| 232 |
the Free Software Foundation; version 2 dated June, 1991. |
| 233 |
|
| 234 |
On Debian GNU/Linux systems, the complete text of the GNU General Public |
| 235 |
License version 2 can be found in \`/usr/share/common-licenses/GPL-2'. |
| 236 |
EOF |
| 237 |
|
| 238 |
# Generate a control file |
| 239 |
cat <<EOF > debian/control |
| 240 |
Source: cross-toolchain-base |
| 241 |
Section: kernel |
| 242 |
Priority: optional |
| 243 |
Maintainer: $maintainer |
| 244 |
Standards-Version: 3.8.4 |
| 245 |
Homepage: http://www.kernel.org/ |
| 246 |
EOF |
| 247 |
|
| 248 |
# if [ "$ARCH" = "um" ]; then |
| 249 |
# cat <<EOF >> debian/control |
| 250 |
|
| 251 |
# Package: $packagename |
| 252 |
# Provides: linux-image, linux-image-2.6, linux-modules-$version |
| 253 |
# Architecture: any |
| 254 |
# Description: User Mode Linux kernel, version $version |
| 255 |
# User-mode Linux is a port of the Linux kernel to its own system call |
| 256 |
# interface. It provides a kind of virtual machine, which runs Linux |
| 257 |
# as a user process under another Linux kernel. This is useful for |
| 258 |
# kernel development, sandboxes, jails, experimentation, and |
| 259 |
# many other things. |
| 260 |
# . |
| 261 |
# This package contains the Linux kernel, modules and corresponding other |
| 262 |
# files, version: $version. |
| 263 |
# EOF |
| 264 |
|
| 265 |
# else |
| 266 |
# cat <<EOF >> debian/control |
| 267 |
|
| 268 |
# Package: $packagename |
| 269 |
# Provides: linux-image, linux-image-2.6, linux-modules-$version |
| 270 |
# Suggests: $fwpackagename |
| 271 |
# Architecture: any |
| 272 |
# Description: Linux kernel, version $version |
| 273 |
# This package contains the Linux kernel, modules and corresponding other |
| 274 |
# files, version: $version. |
| 275 |
# EOF |
| 276 |
|
| 277 |
# fi |
| 278 |
|
| 279 |
# Build header package |
| 280 |
# (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles") |
| 281 |
# (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles") |
| 282 |
# (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles") |
| 283 |
# destdir=$kernel_headers_dir/usr/src/linux-headers-$version |
| 284 |
# mkdir -p "$destdir" |
| 285 |
# (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -) |
| 286 |
# (cd $objtree; tar -c -f - -T "$objtree/debian/hdrobjfiles") | (cd $destdir; tar -xf -) |
| 287 |
# (cd $objtree; cp $KCONFIG_CONFIG $destdir/.config) # copy .config manually to be where it's expected to be |
| 288 |
# ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build" |
| 289 |
# rm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles" |
| 290 |
|
| 291 |
# cat <<EOF >> debian/control |
| 292 |
|
| 293 |
# Package: $kernel_headers_packagename |
| 294 |
# Provides: linux-headers, linux-headers-2.6 |
| 295 |
# Architecture: any |
| 296 |
# Description: Linux kernel headers for $KERNELRELEASE on \${kernel:debarch} |
| 297 |
# This package provides kernel header files for $KERNELRELEASE on \${kernel:debarch} |
| 298 |
# . |
| 299 |
# This is useful for people who need to build external modules |
| 300 |
# EOF |
| 301 |
|
| 302 |
# # Do we have firmware? Move it out of the way and build it into a package. |
| 303 |
# if [ -e "$tmpdir/lib/firmware" ]; then |
| 304 |
# mv "$tmpdir/lib/firmware"/* "$fwdir/lib/firmware/$version/" |
| 305 |
# rmdir "$tmpdir/lib/firmware" |
| 306 |
|
| 307 |
# cat <<EOF >> debian/control |
| 308 |
|
| 309 |
# Package: $fwpackagename |
| 310 |
# Architecture: all |
| 311 |
# Description: Linux kernel firmware, version $version |
| 312 |
# This package contains firmware from the Linux kernel, version $version. |
| 313 |
# EOF |
| 314 |
|
| 315 |
# create_package "$fwpackagename" "$fwdir" |
| 316 |
# fi |
| 317 |
|
| 318 |
cat <<EOF >> debian/control |
| 319 |
|
| 320 |
Package: $libc_headers_packagename |
| 321 |
Section: devel |
| 322 |
Architecture: all |
| 323 |
Provides: linux-kernel-headers-${KBUILD_DEBARCH}-cross, linux-libc-dev-${KBUILD_DEBARCH}-dcv1 |
| 324 |
Description: Linux Kernel Headers for development (for cross-compiling) |
| 325 |
This package was generated by dpkg-cross for cross compiling. |
| 326 |
. |
| 327 |
This package provides headers from the Linux kernel. These headers |
| 328 |
are used by the installed headers for GNU glibc and other system |
| 329 |
libraries. They are NOT meant to be used to build third-party modules for |
| 330 |
your kernel. Use linux-headers-* packages for that. |
| 331 |
|
| 332 |
EOF |
| 333 |
|
| 334 |
# if [ "$ARCH" != "um" ]; then |
| 335 |
# create_package "$kernel_headers_packagename" "$kernel_headers_dir" |
| 336 |
create_package "$libc_headers_packagename" "$libc_headers_dir" |
| 337 |
# fi |
| 338 |
|
| 339 |
# create_package "$packagename" "$tmpdir" |
| 340 |
|
| 341 |
# if [ -n "$BUILD_DEBUG" ] ; then |
| 342 |
# # Build debug package |
| 343 |
# # Different tools want the image in different locations |
| 344 |
# # perf |
| 345 |
# mkdir -p $dbg_dir/usr/lib/debug/lib/modules/$version/ |
| 346 |
# cp vmlinux $dbg_dir/usr/lib/debug/lib/modules/$version/ |
| 347 |
# # systemtap |
| 348 |
# mkdir -p $dbg_dir/usr/lib/debug/boot/ |
| 349 |
# ln -s ../lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/boot/vmlinux-$version |
| 350 |
# # kdump-tools |
| 351 |
# ln -s lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/vmlinux-$version |
| 352 |
|
| 353 |
# cat <<EOF >> debian/control |
| 354 |
|
| 355 |
# Package: $dbg_packagename |
| 356 |
# Section: debug |
| 357 |
# Provides: linux-debug, linux-debug-$version |
| 358 |
# Architecture: any |
| 359 |
# Description: Linux kernel debugging symbols for $version |
| 360 |
# This package will come in handy if you need to debug the kernel. It provides |
| 361 |
# all the necessary debug symbols for the kernel and its modules. |
| 362 |
# EOF |
| 363 |
|
| 364 |
# create_package "$dbg_packagename" "$dbg_dir" |
| 365 |
# fi |
| 366 |
|
| 367 |
exit 0 |