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 15515f4c63SMasahiro Yamadais_enabled() { 166fb7ef5aSMasahiro Yamada grep -q "^$1=y" include/config/auto.conf 17515f4c63SMasahiro Yamada} 18515f4c63SMasahiro Yamada 19515f4c63SMasahiro Yamadaif_enabled_echo() { 20515f4c63SMasahiro Yamada if is_enabled "$1"; then 21515f4c63SMasahiro Yamada echo -n "$2" 22515f4c63SMasahiro Yamada elif [ $# -ge 3 ]; then 23515f4c63SMasahiro Yamada echo -n "$3" 24515f4c63SMasahiro Yamada fi 25515f4c63SMasahiro Yamada} 26515f4c63SMasahiro Yamada 273e2ab256SFrans Popcreate_package() { 283e2ab256SFrans Pop local pname="$1" pdir="$2" 293e2ab256SFrans Pop 305e73758bSMasahiro Yamada export DH_OPTIONS="-p${pname} -P${pdir}" 319461f666SFrans Pop 325e73758bSMasahiro Yamada dh_installdocs 335e73758bSMasahiro Yamada dh_installchangelogs 345e73758bSMasahiro Yamada dh_compress 355e73758bSMasahiro Yamada dh_fixperms 365e73758bSMasahiro Yamada dh_gencontrol 375e73758bSMasahiro Yamada dh_md5sums 385e73758bSMasahiro Yamada dh_builddeb -- ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} 39dca0c024SRiku Voipio} 40dca0c024SRiku Voipio 41b611daaeSMasahiro Yamadainstall_linux_image () { 42b611daaeSMasahiro Yamada pdir=$1 43b611daaeSMasahiro Yamada pname=$2 44b611daaeSMasahiro Yamada 45b611daaeSMasahiro Yamada rm -rf ${pdir} 46b611daaeSMasahiro Yamada 47b611daaeSMasahiro Yamada # Only some architectures with OF support have this target 48b611daaeSMasahiro Yamada if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then 49b611daaeSMasahiro Yamada ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install 50b611daaeSMasahiro Yamada fi 51b611daaeSMasahiro Yamada 52*16c36f88SMasahiro Yamada ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" INSTALL_MOD_STRIP=1 modules_install 53b611daaeSMasahiro Yamada rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build" 54b611daaeSMasahiro Yamada 55b611daaeSMasahiro Yamada # Install the kernel 56b611daaeSMasahiro Yamada if [ "${ARCH}" = um ] ; then 571240dabeSMasahiro Yamada mkdir -p "${pdir}/usr/lib/uml/modules" 581240dabeSMasahiro Yamada mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}" 59b611daaeSMasahiro Yamada mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}" 60b611daaeSMasahiro Yamada cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map" 61b611daaeSMasahiro Yamada cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config" 62b611daaeSMasahiro Yamada gzip "${pdir}/usr/share/doc/${pname}/config" 63b611daaeSMasahiro Yamada else 64b611daaeSMasahiro Yamada mkdir -p "${pdir}/boot" 65b611daaeSMasahiro Yamada cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}" 66b611daaeSMasahiro Yamada cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}" 67b611daaeSMasahiro Yamada fi 68b611daaeSMasahiro Yamada 69b611daaeSMasahiro Yamada # Not all arches have the same installed path in debian 70b611daaeSMasahiro Yamada # XXX: have each arch Makefile export a variable of the canonical image install 71b611daaeSMasahiro Yamada # path instead 72b611daaeSMasahiro Yamada case "${SRCARCH}" in 73b611daaeSMasahiro Yamada um) 74b611daaeSMasahiro Yamada installed_image_path="usr/bin/linux-${KERNELRELEASE}";; 75b611daaeSMasahiro Yamada parisc|mips|powerpc) 76b611daaeSMasahiro Yamada installed_image_path="boot/vmlinux-${KERNELRELEASE}";; 77b611daaeSMasahiro Yamada *) 78b611daaeSMasahiro Yamada installed_image_path="boot/vmlinuz-${KERNELRELEASE}";; 79b611daaeSMasahiro Yamada esac 80b611daaeSMasahiro Yamada cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}" 81b611daaeSMasahiro Yamada 82b611daaeSMasahiro Yamada # Install the maintainer scripts 83b611daaeSMasahiro Yamada # Note: hook scripts under /etc/kernel are also executed by official Debian 84b611daaeSMasahiro Yamada # kernel packages, as well as kernel packages built using make-kpkg. 85b611daaeSMasahiro Yamada # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and 86b611daaeSMasahiro Yamada # so do we; recent versions of dracut and initramfs-tools will obey this. 87b611daaeSMasahiro Yamada debhookdir=${KDEB_HOOKDIR:-/etc/kernel} 88b611daaeSMasahiro Yamada for script in postinst postrm preinst prerm; do 89b611daaeSMasahiro Yamada mkdir -p "${pdir}${debhookdir}/${script}.d" 90b611daaeSMasahiro Yamada 91b611daaeSMasahiro Yamada mkdir -p "${pdir}/DEBIAN" 92b611daaeSMasahiro Yamada cat <<-EOF > "${pdir}/DEBIAN/${script}" 93b611daaeSMasahiro Yamada 94b611daaeSMasahiro Yamada #!/bin/sh 95b611daaeSMasahiro Yamada 96b611daaeSMasahiro Yamada set -e 97b611daaeSMasahiro Yamada 98b611daaeSMasahiro Yamada # Pass maintainer script parameters to hook scripts 99b611daaeSMasahiro Yamada export DEB_MAINT_PARAMS="\$*" 100b611daaeSMasahiro Yamada 101b611daaeSMasahiro Yamada # Tell initramfs builder whether it's wanted 102b611daaeSMasahiro Yamada export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No) 103b611daaeSMasahiro Yamada 104b611daaeSMasahiro Yamada test -d ${debhookdir}/${script}.d && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" ${debhookdir}/${script}.d 105b611daaeSMasahiro Yamada exit 0 106b611daaeSMasahiro Yamada EOF 107b611daaeSMasahiro Yamada chmod 755 "${pdir}/DEBIAN/${script}" 108b611daaeSMasahiro Yamada done 109b611daaeSMasahiro Yamada} 110b611daaeSMasahiro Yamada 111b611daaeSMasahiro Yamadainstall_linux_image_dbg () { 112b611daaeSMasahiro Yamada pdir=$1 113b611daaeSMasahiro Yamada 114b611daaeSMasahiro Yamada rm -rf ${pdir} 115b611daaeSMasahiro Yamada 116*16c36f88SMasahiro Yamada # Parse modules.order directly because 'make modules_install' may sign, 117*16c36f88SMasahiro Yamada # compress modules, and then run unneeded depmod. 118*16c36f88SMasahiro Yamada while read -r mod; do 119*16c36f88SMasahiro Yamada mod="${mod%.o}.ko" 120*16c36f88SMasahiro Yamada dbg="${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/kernel/${mod}" 121*16c36f88SMasahiro Yamada buildid=$("${READELF}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p') 122*16c36f88SMasahiro Yamada link="${pdir}/usr/lib/debug/.build-id/${buildid}.debug" 123b611daaeSMasahiro Yamada 124*16c36f88SMasahiro Yamada mkdir -p "${dbg%/*}" "${link%/*}" 125*16c36f88SMasahiro Yamada "${OBJCOPY}" --only-keep-debug "${mod}" "${dbg}" 126*16c36f88SMasahiro Yamada ln -sf --relative "${dbg}" "${link}" 127*16c36f88SMasahiro Yamada done < modules.order 128b611daaeSMasahiro Yamada 129b611daaeSMasahiro Yamada # Build debug package 130b611daaeSMasahiro Yamada # Different tools want the image in different locations 131b611daaeSMasahiro Yamada # perf 132b611daaeSMasahiro Yamada mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ 133b611daaeSMasahiro Yamada cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ 134b611daaeSMasahiro Yamada # systemtap 135b611daaeSMasahiro Yamada mkdir -p ${pdir}/usr/lib/debug/boot/ 136b611daaeSMasahiro Yamada ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE} 137b611daaeSMasahiro Yamada # kdump-tools 138b611daaeSMasahiro Yamada ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE} 139b611daaeSMasahiro Yamada} 140b611daaeSMasahiro Yamada 14136862e14SMasahiro Yamadainstall_kernel_headers () { 1423126c17dSMasahiro Yamada pdir=$1 1433ced71d2SKevin Locke version=$2 1443126c17dSMasahiro Yamada 1453126c17dSMasahiro Yamada rm -rf $pdir 1463126c17dSMasahiro Yamada 147fe66b5d2SMasahiro Yamada "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}" 1483126c17dSMasahiro Yamada 1493126c17dSMasahiro Yamada mkdir -p $pdir/lib/modules/$version/ 1503126c17dSMasahiro Yamada ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build 1513126c17dSMasahiro Yamada} 1523126c17dSMasahiro Yamada 15336862e14SMasahiro Yamadainstall_libc_headers () { 154451dff37SMasahiro Yamada pdir=$1 155451dff37SMasahiro Yamada 156451dff37SMasahiro Yamada rm -rf $pdir 157451dff37SMasahiro Yamada 158451dff37SMasahiro Yamada $MAKE -f $srctree/Makefile headers 159451dff37SMasahiro Yamada $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr 160451dff37SMasahiro Yamada 161451dff37SMasahiro Yamada # move asm headers to /usr/include/<libc-machine>/asm to match the structure 162451dff37SMasahiro Yamada # used by Debian-based distros (to support multi-arch) 163159956f3SMasahiro Yamada mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}" 164159956f3SMasahiro Yamada mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}" 165451dff37SMasahiro Yamada} 166451dff37SMasahiro Yamada 167b611daaeSMasahiro Yamadarm -f debian/files 1681da177e4SLinus Torvalds 16936862e14SMasahiro Yamadapackages_enabled=$(dh_listpackages) 1703126c17dSMasahiro Yamada 17136862e14SMasahiro Yamadafor package in ${packages_enabled} 17236862e14SMasahiro Yamadado 17336862e14SMasahiro Yamada case ${package} in 17436862e14SMasahiro Yamada *-dbg) 175*16c36f88SMasahiro Yamada install_linux_image_dbg debian/linux-image-dbg;; 17636862e14SMasahiro Yamada linux-image-*|user-mode-linux-*) 17736862e14SMasahiro Yamada install_linux_image debian/linux-image ${package};; 17836862e14SMasahiro Yamada linux-libc-dev) 17936862e14SMasahiro Yamada install_libc_headers debian/linux-libc-dev;; 18036862e14SMasahiro Yamada linux-headers-*) 1813ced71d2SKevin Locke install_kernel_headers debian/linux-headers ${package#linux-headers-};; 18236862e14SMasahiro Yamada esac 18336862e14SMasahiro Yamadadone 184d7d357bcSJoerg Roedel 18536862e14SMasahiro Yamadafor package in ${packages_enabled} 18636862e14SMasahiro Yamadado 18736862e14SMasahiro Yamada case ${package} in 18836862e14SMasahiro Yamada *-dbg) 18936862e14SMasahiro Yamada create_package ${package} debian/linux-image-dbg;; 19036862e14SMasahiro Yamada linux-image-*|user-mode-linux-*) 19136862e14SMasahiro Yamada create_package ${package} debian/linux-image;; 19236862e14SMasahiro Yamada linux-libc-dev) 19336862e14SMasahiro Yamada create_package ${package} debian/linux-libc-dev;; 19436862e14SMasahiro Yamada linux-headers-*) 19536862e14SMasahiro Yamada create_package ${package} debian/linux-headers;; 19636862e14SMasahiro Yamada esac 19736862e14SMasahiro Yamadadone 198b611daaeSMasahiro Yamada 1991da177e4SLinus Torvaldsexit 0 200