1 #!/bin/sh 1 #!/bin/sh 2 # 2 # 3 # builddeb 1.3 3 # builddeb 1.3 4 # Copyright 2003 Wichert Akkerman <wichert@wigg 4 # Copyright 2003 Wichert Akkerman <wichert@wiggy.net> 5 # 5 # 6 # Simple script to generate a deb package for 6 # Simple script to generate a deb package for a Linux kernel. All the 7 # complexity of what to do with a kernel after 7 # complexity of what to do with a kernel after it is installed or removed 8 # is left to other scripts and packages: they 8 # is left to other scripts and packages: they can install scripts in the 9 # /etc/kernel/{pre,post}{inst,rm}.d/ directori 9 # /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location 10 # specified in KDEB_HOOKDIR) that will be call 10 # specified in KDEB_HOOKDIR) that will be called on package install and 11 # removal. 11 # removal. 12 12 13 set -eu !! 13 set -e 14 14 15 is_enabled() { !! 15 create_package() { 16 grep -q "^$1=y" include/config/auto.co !! 16 local pname="$1" pdir="$2" 17 } << 18 << 19 if_enabled_echo() { << 20 if is_enabled "$1"; then << 21 echo -n "$2" << 22 elif [ $# -ge 3 ]; then << 23 echo -n "$3" << 24 fi << 25 } << 26 17 27 install_linux_image () { !! 18 cp debian/copyright "$pdir/usr/share/doc/$pname/" 28 pname=$1 !! 19 cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian" 29 pdir=debian/$1 !! 20 gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian" 30 !! 21 31 # Only some architectures with OF supp !! 22 # Fix ownership and permissions 32 if is_enabled CONFIG_OF_EARLY_FLATTREE !! 23 chown -R root:root "$pdir" 33 ${MAKE} -f ${srctree}/Makefile !! 24 chmod -R go-w "$pdir" >> 25 >> 26 # Create the package >> 27 dpkg-gencontrol -isp -p$pname -P"$pdir" >> 28 dpkg --build "$pdir" .. >> 29 } >> 30 >> 31 # Some variables and settings used throughout the script >> 32 version=$KERNELRELEASE >> 33 revision=$(cat .version) >> 34 if [ -n "$KDEB_PKGVERSION" ]; then >> 35 packageversion=$KDEB_PKGVERSION >> 36 else >> 37 packageversion=$version-$revision >> 38 fi >> 39 tmpdir="$objtree/debian/tmp" >> 40 fwdir="$objtree/debian/fwtmp" >> 41 packagename=linux-image-$version >> 42 fwpackagename=linux-firmware-image >> 43 >> 44 if [ "$ARCH" = "um" ] ; then >> 45 packagename=user-mode-linux-$version >> 46 fi >> 47 >> 48 # Setup the directory structure >> 49 rm -rf "$tmpdir" "$fwdir" >> 50 mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename" >> 51 mkdir -p "$fwdir/DEBIAN" "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename" >> 52 if [ "$ARCH" = "um" ] ; then >> 53 mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" >> 54 fi >> 55 >> 56 # Build and install the kernel >> 57 if [ "$ARCH" = "um" ] ; then >> 58 $MAKE linux >> 59 cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" >> 60 cp .config "$tmpdir/usr/share/doc/$packagename/config" >> 61 gzip "$tmpdir/usr/share/doc/$packagename/config" >> 62 cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version" >> 63 else >> 64 cp System.map "$tmpdir/boot/System.map-$version" >> 65 cp .config "$tmpdir/boot/config-$version" >> 66 # Not all arches include the boot path in KBUILD_IMAGE >> 67 if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then >> 68 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version" 34 fi 69 fi >> 70 fi 35 71 36 ${MAKE} -f ${srctree}/Makefile INSTALL !! 72 if grep -q '^CONFIG_MODULES=y' .config ; then 37 rm -f "${pdir}/lib/modules/${KERNELREL !! 73 INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install 38 !! 74 if [ "$ARCH" = "um" ] ; then 39 # Install the kernel !! 75 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" 40 if [ "${ARCH}" = um ] ; then !! 76 rmdir "$tmpdir/lib/modules/$version" 41 mkdir -p "${pdir}/usr/lib/uml/ << 42 mv "${pdir}/lib/modules/${KERN << 43 mkdir -p "${pdir}/usr/bin" "${ << 44 cp System.map "${pdir}/usr/lib << 45 cp ${KCONFIG_CONFIG} "${pdir}/ << 46 gzip "${pdir}/usr/share/doc/${ << 47 else << 48 mkdir -p "${pdir}/boot" << 49 cp System.map "${pdir}/boot/Sy << 50 cp ${KCONFIG_CONFIG} "${pdir}/ << 51 fi 77 fi >> 78 fi 52 79 53 # Not all arches have the same install !! 80 # Install the maintainer scripts 54 # XXX: have each arch Makefile export !! 81 # Note: hook scripts under /etc/kernel are also executed by official Debian 55 # path instead !! 82 # kernel packages, as well as kernel packages built using make-kpkg 56 case "${SRCARCH}" in !! 83 debhookdir=${KDEB_HOOKDIR:-/etc/kernel} 57 um) !! 84 for script in postinst postrm preinst prerm ; do 58 installed_image_path="usr/bin/ !! 85 mkdir -p "$tmpdir$debhookdir/$script.d" 59 parisc|mips|powerpc) !! 86 cat <<EOF > "$tmpdir/DEBIAN/$script" 60 installed_image_path="boot/vml !! 87 #!/bin/sh 61 *) !! 88 62 installed_image_path="boot/vml !! 89 set -e 63 esac !! 90 64 cp "$(${MAKE} -s -f ${srctree}/Makefil !! 91 # Pass maintainer script parameters to hook scripts 65 !! 92 export DEB_MAINT_PARAMS="\$*" 66 # Install the maintainer scripts !! 93 67 # Note: hook scripts under /etc/kernel !! 94 test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d 68 # kernel packages, as well as kernel p !! 95 exit 0 69 # make-kpkg sets $INITRD to indicate w !! 96 EOF 70 # so do we; recent versions of dracut !! 97 chmod 755 "$tmpdir/DEBIAN/$script" 71 debhookdir=${KDEB_HOOKDIR:-/etc/kernel !! 98 done 72 for script in postinst postrm preinst !! 99 73 mkdir -p "${pdir}${debhookdir} !! 100 # Try to determine maintainer and email values 74 !! 101 if [ -n "$DEBEMAIL" ]; then 75 mkdir -p "${pdir}/DEBIAN" !! 102 email=$DEBEMAIL 76 cat <<-EOF > "${pdir}/DEBIAN/$ !! 103 elif [ -n "$EMAIL" ]; then 77 #!/bin/sh !! 104 email=$EMAIL 78 !! 105 else 79 set -e !! 106 email=$(id -nu)@$(hostname -f) 80 !! 107 fi 81 # Pass maintainer script param !! 108 if [ -n "$DEBFULLNAME" ]; then 82 export DEB_MAINT_PARAMS="\$*" !! 109 name=$DEBFULLNAME 83 !! 110 elif [ -n "$NAME" ]; then 84 # Tell initramfs builder wheth !! 111 name=$NAME 85 export INITRD=$(if_enabled_ech !! 112 else 86 !! 113 name="Anonymous" 87 test -d ${debhookdir}/${script !! 114 fi 88 exit 0 !! 115 maintainer="$name <$email>" 89 EOF !! 116 90 chmod 755 "${pdir}/DEBIAN/${sc !! 117 # Generate a simple changelog template 91 done !! 118 cat <<EOF > debian/changelog 92 } !! 119 linux-upstream ($packageversion) unstable; urgency=low 93 !! 120 94 install_linux_image_dbg () { !! 121 * Custom built Linux kernel. 95 pdir=debian/$1 !! 122 96 !! 123 -- $maintainer $(date -R) 97 # Parse modules.order directly because !! 124 EOF 98 # compress modules, and then run unnee !! 125 99 while read -r mod; do !! 126 # Generate copyright file 100 mod="${mod%.o}.ko" !! 127 cat <<EOF > debian/copyright 101 dbg="${pdir}/usr/lib/debug/lib !! 128 This is a packacked upstream version of the Linux kernel. 102 buildid=$("${READELF}" -n "${m !! 129 103 link="${pdir}/usr/lib/debug/.b !! 130 The sources may be found at most Linux ftp sites, including: 104 !! 131 ftp://ftp.kernel.org/pub/linux/kernel 105 mkdir -p "${dbg%/*}" "${link%/ !! 132 106 "${OBJCOPY}" --only-keep-debug !! 133 Copyright: 1991 - 2009 Linus Torvalds and others. 107 ln -sf --relative "${dbg}" "${ !! 134 108 done < modules.order !! 135 The git repository for mainline kernel development is at: 109 !! 136 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git 110 # Build debug package !! 137 111 # Different tools want the image in di !! 138 This program is free software; you can redistribute it and/or modify 112 # perf !! 139 it under the terms of the GNU General Public License as published by 113 mkdir -p ${pdir}/usr/lib/debug/lib/mod !! 140 the Free Software Foundation; version 2 dated June, 1991. 114 cp vmlinux ${pdir}/usr/lib/debug/lib/m !! 141 115 # systemtap !! 142 On Debian GNU/Linux systems, the complete text of the GNU General Public 116 mkdir -p ${pdir}/usr/lib/debug/boot/ !! 143 License version 2 can be found in \`/usr/share/common-licenses/GPL-2'. 117 ln -s ../lib/modules/${KERNELRELEASE}/ !! 144 EOF 118 # kdump-tools !! 145 119 ln -s lib/modules/${KERNELRELEASE}/vml !! 146 # Generate a control file 120 } !! 147 cat <<EOF > debian/control 121 !! 148 Source: linux-upstream 122 install_kernel_headers () { !! 149 Section: admin 123 pdir=debian/$1 !! 150 Priority: optional 124 version=${1#linux-headers-} !! 151 Maintainer: $maintainer 125 !! 152 Standards-Version: 3.8.1 126 CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctr !! 153 EOF 127 !! 154 128 mkdir -p $pdir/lib/modules/$version/ !! 155 if [ "$ARCH" = "um" ]; then 129 ln -s /usr/src/linux-headers-$version !! 156 cat <<EOF >> debian/control 130 } !! 157 131 !! 158 Package: $packagename 132 install_libc_headers () { !! 159 Provides: linux-image, linux-image-2.6, linux-modules-$version 133 pdir=debian/$1 !! 160 Architecture: any >> 161 Description: User Mode Linux kernel, version $version >> 162 User-mode Linux is a port of the Linux kernel to its own system call >> 163 interface. It provides a kind of virtual machine, which runs Linux >> 164 as a user process under another Linux kernel. This is useful for >> 165 kernel development, sandboxes, jails, experimentation, and >> 166 many other things. >> 167 . >> 168 This package contains the Linux kernel, modules and corresponding other >> 169 files, version: $version. >> 170 EOF >> 171 >> 172 else >> 173 cat <<EOF >> debian/control >> 174 >> 175 Package: $packagename >> 176 Provides: linux-image, linux-image-2.6, linux-modules-$version >> 177 Suggests: $fwpackagename >> 178 Architecture: any >> 179 Description: Linux kernel, version $version >> 180 This package contains the Linux kernel, modules and corresponding other >> 181 files, version: $version. >> 182 EOF >> 183 >> 184 fi >> 185 >> 186 # Do we have firmware? Move it out of the way and build it into a package. >> 187 if [ -e "$tmpdir/lib/firmware" ]; then >> 188 mv "$tmpdir/lib/firmware" "$fwdir/lib/" >> 189 >> 190 cat <<EOF >> debian/control >> 191 >> 192 Package: $fwpackagename >> 193 Architecture: all >> 194 Description: Linux kernel firmware, version $version >> 195 This package contains firmware from the Linux kernel, version $version. >> 196 EOF 134 197 135 $MAKE -f $srctree/Makefile headers_ins !! 198 create_package "$fwpackagename" "$fwdir" 136 !! 199 fi 137 # move asm headers to /usr/include/<li << 138 # used by Debian-based distros (to sup << 139 mkdir "$pdir/usr/include/${DEB_HOST_MU << 140 mv "$pdir/usr/include/asm" "$pdir/usr/ << 141 } << 142 200 143 package=$1 !! 201 create_package "$packagename" "$tmpdir" 144 202 145 case "${package}" in !! 203 exit 0 146 *-dbg) << 147 install_linux_image_dbg "${package}";; << 148 linux-image-*|user-mode-linux-*) << 149 install_linux_image "${package}";; << 150 linux-libc-dev) << 151 install_libc_headers "${package}";; << 152 linux-headers-*) << 153 install_kernel_headers "${package}";; << 154 esac <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.