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 189461f666SFrans Pop cp debian/copyright "$pdir/usr/share/doc/$pname/" 191ab18486Smaximilian attems cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian" 201ab18486Smaximilian attems gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian" 21b59a1225SFEJES Jozsef sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \ 22b59a1225SFEJES Jozsef | xargs -r0 md5sum > DEBIAN/md5sums" 239461f666SFrans Pop 243e2ab256SFrans Pop # Fix ownership and permissions 253e2ab256SFrans Pop chown -R root:root "$pdir" 263e2ab256SFrans Pop chmod -R go-w "$pdir" 273e2ab256SFrans Pop 2810f26fa6SAsbjoern Sloth Toennesen # Attempt to find the correct Debian architecture 2910f26fa6SAsbjoern Sloth Toennesen local forcearch="" debarch="" 3010f26fa6SAsbjoern Sloth Toennesen case "$UTS_MACHINE" in 3110f26fa6SAsbjoern Sloth Toennesen i386|ia64|alpha) 3210f26fa6SAsbjoern Sloth Toennesen debarch="$UTS_MACHINE" ;; 3310f26fa6SAsbjoern Sloth Toennesen x86_64) 3410f26fa6SAsbjoern Sloth Toennesen debarch=amd64 ;; 3510f26fa6SAsbjoern Sloth Toennesen sparc*) 3610f26fa6SAsbjoern Sloth Toennesen debarch=sparc ;; 3710f26fa6SAsbjoern Sloth Toennesen s390*) 3810f26fa6SAsbjoern Sloth Toennesen debarch=s390 ;; 3910f26fa6SAsbjoern Sloth Toennesen ppc*) 4010f26fa6SAsbjoern Sloth Toennesen debarch=powerpc ;; 4110f26fa6SAsbjoern Sloth Toennesen parisc*) 4210f26fa6SAsbjoern Sloth Toennesen debarch=hppa ;; 4310f26fa6SAsbjoern Sloth Toennesen mips*) 4410f26fa6SAsbjoern Sloth Toennesen debarch=mips$(grep -q CPU_LITTLE_ENDIAN=y .config && echo el) ;; 4510f26fa6SAsbjoern Sloth Toennesen arm*) 4610f26fa6SAsbjoern Sloth Toennesen debarch=arm$(grep -q CONFIG_AEABI=y .config && echo el) ;; 4710f26fa6SAsbjoern Sloth Toennesen *) 4810f26fa6SAsbjoern Sloth Toennesen echo "" >&2 4910f26fa6SAsbjoern Sloth Toennesen echo "** ** ** WARNING ** ** **" >&2 5010f26fa6SAsbjoern Sloth Toennesen echo "" >&2 5110f26fa6SAsbjoern Sloth Toennesen echo "Your architecture doesn't have it's equivalent" >&2 5210f26fa6SAsbjoern Sloth Toennesen echo "Debian userspace architecture defined!" >&2 5310f26fa6SAsbjoern Sloth Toennesen echo "Falling back to using your current userspace instead!" >&2 5410f26fa6SAsbjoern Sloth Toennesen echo "Please add support for $UTS_MACHINE to ${0} ..." >&2 5510f26fa6SAsbjoern Sloth Toennesen echo "" >&2 5610f26fa6SAsbjoern Sloth Toennesen esac 5755f88eccSAsbjoern Sloth Toennesen if [ -n "$KBUILD_DEBARCH" ] ; then 5855f88eccSAsbjoern Sloth Toennesen debarch="$KBUILD_DEBARCH" 5955f88eccSAsbjoern Sloth Toennesen fi 6010f26fa6SAsbjoern Sloth Toennesen if [ -n "$debarch" ] ; then 6110f26fa6SAsbjoern Sloth Toennesen forcearch="-DArchitecture=$debarch" 6210f26fa6SAsbjoern Sloth Toennesen fi 6310f26fa6SAsbjoern Sloth Toennesen 643e2ab256SFrans Pop # Create the package 6510f26fa6SAsbjoern Sloth Toennesen dpkg-gencontrol -isp $forcearch -p$pname -P"$pdir" 663e2ab256SFrans Pop dpkg --build "$pdir" .. 673e2ab256SFrans Pop} 683e2ab256SFrans Pop 691da177e4SLinus Torvalds# Some variables and settings used throughout the script 701da177e4SLinus Torvaldsversion=$KERNELRELEASE 714f66199bSFrans Poprevision=$(cat .version) 72c72c75dbSFrans Popif [ -n "$KDEB_PKGVERSION" ]; then 73c72c75dbSFrans Pop packageversion=$KDEB_PKGVERSION 74c72c75dbSFrans Popelse 75c72c75dbSFrans Pop packageversion=$version-$revision 76c72c75dbSFrans Popfi 771da177e4SLinus Torvaldstmpdir="$objtree/debian/tmp" 78bf1b3644SJonathan McDowellfwdir="$objtree/debian/fwtmp" 79ee81b786Smaximilian attemskernel_headers_dir="$objtree/debian/hdrtmp" 80ee81b786Smaximilian attemslibc_headers_dir="$objtree/debian/headertmp" 81f7a2c31fSmaximilian attemspackagename=linux-image-$version 82bf1b3644SJonathan McDowellfwpackagename=linux-firmware-image 83ee81b786Smaximilian attemskernel_headers_packagename=linux-headers-$version 84ee81b786Smaximilian attemslibc_headers_packagename=linux-libc-dev 85687c3dacSSam Ravnborg 864f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 87687c3dacSSam Ravnborg packagename=user-mode-linux-$version 88687c3dacSSam Ravnborgfi 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds# Setup the directory structure 91ee81b786Smaximilian attemsrm -rf "$tmpdir" "$fwdir" "$kernel_headers_dir" "$libc_headers_dir" 92e86c2412Smaximilian attemsmkdir -m 755 -p "$tmpdir/DEBIAN" 93e86c2412Smaximilian attemsmkdir -p "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename" 94e86c2412Smaximilian attemsmkdir -m 755 -p "$fwdir/DEBIAN" 95e86c2412Smaximilian attemsmkdir -p "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename" 96ee81b786Smaximilian attemsmkdir -m 755 -p "$libc_headers_dir/DEBIAN" 97ee81b786Smaximilian attemsmkdir -p "$libc_headers_dir/usr/share/doc/$libc_headers_packagename" 98ee81b786Smaximilian attemsmkdir -m 755 -p "$kernel_headers_dir/DEBIAN" 99ee81b786Smaximilian attemsmkdir -p "$kernel_headers_dir/usr/share/doc/$kernel_headers_packagename" 100a47b6c61SJoerg Roedelmkdir -p "$kernel_headers_dir/lib/modules/$version/" 1014f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 1029461f666SFrans Pop mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" 103687c3dacSSam Ravnborgfi 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds# Build and install the kernel 1064f66199bSFrans Popif [ "$ARCH" = "um" ] ; then 107687c3dacSSam Ravnborg $MAKE linux 108687c3dacSSam Ravnborg cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" 109687c3dacSSam Ravnborg cp .config "$tmpdir/usr/share/doc/$packagename/config" 110687c3dacSSam Ravnborg gzip "$tmpdir/usr/share/doc/$packagename/config" 111687c3dacSSam Ravnborg cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version" 112687c3dacSSam Ravnborgelse 1131da177e4SLinus Torvalds cp System.map "$tmpdir/boot/System.map-$version" 1141da177e4SLinus Torvalds cp .config "$tmpdir/boot/config-$version" 115a89b433bSFrans Pop # Not all arches include the boot path in KBUILD_IMAGE 116242c5ab0SGuillem Jover if [ -e $KBUILD_IMAGE ]; then 117242c5ab0SGuillem Jover cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" 118242c5ab0SGuillem Jover else 119a89b433bSFrans Pop cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" 120a89b433bSFrans Pop fi 121687c3dacSSam Ravnborgfi 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvaldsif grep -q '^CONFIG_MODULES=y' .config ; then 124dddcbb7cSJoerg Roedel INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_install 125a47b6c61SJoerg Roedel rm -f "$tmpdir/lib/modules/$version/build" 126a47b6c61SJoerg Roedel rm -f "$tmpdir/lib/modules/$version/source" 1274f66199bSFrans Pop if [ "$ARCH" = "um" ] ; then 128687c3dacSSam Ravnborg mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" 129687c3dacSSam Ravnborg rmdir "$tmpdir/lib/modules/$version" 130687c3dacSSam Ravnborg fi 1311da177e4SLinus Torvaldsfi 1321da177e4SLinus Torvalds 133d7d357bcSJoerg Roedelif [ "$ARCH" != "um" ]; then 134dddcbb7cSJoerg Roedel $MAKE headers_check KBUILD_SRC= 135dddcbb7cSJoerg Roedel $MAKE headers_install KBUILD_SRC= INSTALL_HDR_PATH="$libc_headers_dir/usr" 136d7d357bcSJoerg Roedelfi 137e6807785Smaximilian attems 1381da177e4SLinus Torvalds# Install the maintainer scripts 139fe233cb6SFrans Pop# Note: hook scripts under /etc/kernel are also executed by official Debian 140fe233cb6SFrans Pop# kernel packages, as well as kernel packages built using make-kpkg 141fe233cb6SFrans Popdebhookdir=${KDEB_HOOKDIR:-/etc/kernel} 1421da177e4SLinus Torvaldsfor script in postinst postrm preinst prerm ; do 143fe233cb6SFrans Pop mkdir -p "$tmpdir$debhookdir/$script.d" 1441da177e4SLinus Torvalds cat <<EOF > "$tmpdir/DEBIAN/$script" 1451da177e4SLinus Torvalds#!/bin/sh 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvaldsset -e 1481da177e4SLinus Torvalds 1494964451aSFrans Pop# Pass maintainer script parameters to hook scripts 150241ad11fSmaximilian attemsexport DEB_MAINT_PARAMS="\$*" 1514964451aSFrans Pop 152fe233cb6SFrans Poptest -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d 1531da177e4SLinus Torvaldsexit 0 1541da177e4SLinus TorvaldsEOF 1551da177e4SLinus Torvalds chmod 755 "$tmpdir/DEBIAN/$script" 1561da177e4SLinus Torvaldsdone 1571da177e4SLinus Torvalds 158edec611dSmaximilian attems# Try to determine maintainer and email values 159edec611dSmaximilian attemsif [ -n "$DEBEMAIL" ]; then 160edec611dSmaximilian attems email=$DEBEMAIL 161edec611dSmaximilian attemselif [ -n "$EMAIL" ]; then 162edec611dSmaximilian attems email=$EMAIL 163edec611dSmaximilian attemselse 164edec611dSmaximilian attems email=$(id -nu)@$(hostname -f) 165edec611dSmaximilian attemsfi 166edec611dSmaximilian attemsif [ -n "$DEBFULLNAME" ]; then 167edec611dSmaximilian attems name=$DEBFULLNAME 168edec611dSmaximilian attemselif [ -n "$NAME" ]; then 169edec611dSmaximilian attems name=$NAME 170edec611dSmaximilian attemselse 171edec611dSmaximilian attems name="Anonymous" 172edec611dSmaximilian attemsfi 173edec611dSmaximilian attemsmaintainer="$name <$email>" 174edec611dSmaximilian attems 1751da177e4SLinus Torvalds# Generate a simple changelog template 1761da177e4SLinus Torvaldscat <<EOF > debian/changelog 1774bf4cd49SFrans Poplinux-upstream ($packageversion) unstable; urgency=low 1781da177e4SLinus Torvalds 179a83ca277SFrans Pop * Custom built Linux kernel. 1801da177e4SLinus Torvalds 181edec611dSmaximilian attems -- $maintainer $(date -R) 1821da177e4SLinus TorvaldsEOF 1831da177e4SLinus Torvalds 1849461f666SFrans Pop# Generate copyright file 1859461f666SFrans Popcat <<EOF > debian/copyright 1869461f666SFrans PopThis is a packacked upstream version of the Linux kernel. 1879461f666SFrans Pop 1889461f666SFrans PopThe sources may be found at most Linux ftp sites, including: 1899461f666SFrans Popftp://ftp.kernel.org/pub/linux/kernel 1909461f666SFrans Pop 1919461f666SFrans PopCopyright: 1991 - 2009 Linus Torvalds and others. 1929461f666SFrans Pop 1939461f666SFrans PopThe git repository for mainline kernel development is at: 1949461f666SFrans Popgit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git 1959461f666SFrans Pop 1969461f666SFrans Pop This program is free software; you can redistribute it and/or modify 1979461f666SFrans Pop it under the terms of the GNU General Public License as published by 1989461f666SFrans Pop the Free Software Foundation; version 2 dated June, 1991. 1999461f666SFrans Pop 2009461f666SFrans PopOn Debian GNU/Linux systems, the complete text of the GNU General Public 2019461f666SFrans PopLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'. 2029461f666SFrans PopEOF 2039461f666SFrans Pop 2041da177e4SLinus Torvalds# Generate a control file 2051da177e4SLinus Torvaldscat <<EOF > debian/control 2064bf4cd49SFrans PopSource: linux-upstream 207aa42abedSRogério BritoSection: kernel 2081da177e4SLinus TorvaldsPriority: optional 209edec611dSmaximilian attemsMaintainer: $maintainer 2102d7204acSRogério BritoStandards-Version: 3.8.4 211ee6eed80SRogério BritoHomepage: http://www.kernel.org/ 2123e2ab256SFrans PopEOF 2133e2ab256SFrans Pop 2143e2ab256SFrans Popif [ "$ARCH" = "um" ]; then 2153e2ab256SFrans Pop cat <<EOF >> debian/control 2161da177e4SLinus Torvalds 217687c3dacSSam RavnborgPackage: $packagename 2188ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version 2191da177e4SLinus TorvaldsArchitecture: any 220dc5962fdSSam RavnborgDescription: User Mode Linux kernel, version $version 221dc5962fdSSam Ravnborg User-mode Linux is a port of the Linux kernel to its own system call 222dc5962fdSSam Ravnborg interface. It provides a kind of virtual machine, which runs Linux 223dc5962fdSSam Ravnborg as a user process under another Linux kernel. This is useful for 224dc5962fdSSam Ravnborg kernel development, sandboxes, jails, experimentation, and 225dc5962fdSSam Ravnborg many other things. 226dc5962fdSSam Ravnborg . 2271da177e4SLinus Torvalds This package contains the Linux kernel, modules and corresponding other 228a83ca277SFrans Pop files, version: $version. 2291da177e4SLinus TorvaldsEOF 2301da177e4SLinus Torvalds 231dc5962fdSSam Ravnborgelse 2323e2ab256SFrans Pop cat <<EOF >> debian/control 233dc5962fdSSam Ravnborg 234dc5962fdSSam RavnborgPackage: $packagename 2358ebc2fe9Smaximilian attemsProvides: linux-image, linux-image-2.6, linux-modules-$version 236bf1b3644SJonathan McDowellSuggests: $fwpackagename 237dc5962fdSSam RavnborgArchitecture: any 238dc5962fdSSam RavnborgDescription: Linux kernel, version $version 239dc5962fdSSam Ravnborg This package contains the Linux kernel, modules and corresponding other 240a83ca277SFrans Pop files, version: $version. 241dc5962fdSSam RavnborgEOF 2424f66199bSFrans Pop 243dc5962fdSSam Ravnborgfi 244dc5962fdSSam Ravnborg 245cd8d60a2STheodore Ts'o# Build header package 2466c635224SBen Hutchings(cd $srctree; find . -name Makefile -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles") 2476c635224SBen Hutchings(cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles") 2486c635224SBen Hutchings(cd $objtree; find .config Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles") 249ee81b786Smaximilian attemsdestdir=$kernel_headers_dir/usr/src/linux-headers-$version 250ee81b786Smaximilian attemsmkdir -p "$destdir" 2516c635224SBen Hutchings(cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -) 2526c635224SBen Hutchings(cd $objtree; tar -c -f - -T "$objtree/debian/hdrobjfiles") | (cd $destdir; tar -xf -) 253a47b6c61SJoerg Roedelln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build" 2546c635224SBen Hutchingsrm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles" 255cd8d60a2STheodore Ts'oarch=$(dpkg --print-architecture) 256cd8d60a2STheodore Ts'o 257cd8d60a2STheodore Ts'ocat <<EOF >> debian/control 258cd8d60a2STheodore Ts'o 259ee81b786Smaximilian attemsPackage: $kernel_headers_packagename 260cd8d60a2STheodore Ts'oProvides: linux-headers, linux-headers-2.6 261cd8d60a2STheodore Ts'oArchitecture: $arch 262cd8d60a2STheodore Ts'oDescription: Linux kernel headers for $KERNELRELEASE on $arch 263cd8d60a2STheodore Ts'o This package provides kernel header files for $KERNELRELEASE on $arch 264cd8d60a2STheodore Ts'o . 265cd8d60a2STheodore Ts'o This is useful for people who need to build external modules 266cd8d60a2STheodore Ts'oEOF 267cd8d60a2STheodore Ts'o 268bf1b3644SJonathan McDowell# Do we have firmware? Move it out of the way and build it into a package. 269bf1b3644SJonathan McDowellif [ -e "$tmpdir/lib/firmware" ]; then 270bf1b3644SJonathan McDowell mv "$tmpdir/lib/firmware" "$fwdir/lib/" 271bf1b3644SJonathan McDowell 272bf1b3644SJonathan McDowell cat <<EOF >> debian/control 273bf1b3644SJonathan McDowell 274bf1b3644SJonathan McDowellPackage: $fwpackagename 275bf1b3644SJonathan McDowellArchitecture: all 276bf1b3644SJonathan McDowellDescription: Linux kernel firmware, version $version 277a83ca277SFrans Pop This package contains firmware from the Linux kernel, version $version. 278bf1b3644SJonathan McDowellEOF 279bf1b3644SJonathan McDowell 2803e2ab256SFrans Pop create_package "$fwpackagename" "$fwdir" 281bf1b3644SJonathan McDowellfi 282bf1b3644SJonathan McDowell 283e6807785Smaximilian attemscat <<EOF >> debian/control 284e6807785Smaximilian attems 285ee81b786Smaximilian attemsPackage: $libc_headers_packagename 286e6807785Smaximilian attemsSection: devel 287e6807785Smaximilian attemsProvides: linux-kernel-headers 288e6807785Smaximilian attemsArchitecture: any 289e6807785Smaximilian attemsDescription: Linux support headers for userspace development 290e6807785Smaximilian attems This package provides userspaces headers from the Linux kernel. These headers 291e6807785Smaximilian attems are used by the installed headers for GNU glibc and other system libraries. 292e6807785Smaximilian attemsEOF 293e6807785Smaximilian attems 294d7d357bcSJoerg Roedelif [ "$ARCH" != "um" ]; then 295d7d357bcSJoerg Roedel create_package "$kernel_headers_packagename" "$kernel_headers_dir" 296ee81b786Smaximilian attems create_package "$libc_headers_packagename" "$libc_headers_dir" 297d7d357bcSJoerg Roedelfi 298d7d357bcSJoerg Roedel 2993e2ab256SFrans Popcreate_package "$packagename" "$tmpdir" 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvaldsexit 0 302