11da177e4SLinus Torvalds#!/bin/sh 21da177e4SLinus Torvalds# 34964451aSFrans Pop# builddeb 1.3 41da177e4SLinus Torvalds# Copyright 2003 Wichert Akkerman <[email protected]> 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" 293e854180SGuillem Jover local dpkg_deb_opts 303e2ab256SFrans Pop 31bf7b0055SRiku Voipio mkdir -m 755 -p "$pdir/DEBIAN" 32bf7b0055SRiku Voipio mkdir -p "$pdir/usr/share/doc/$pname" 339461f666SFrans Pop cp debian/copyright "$pdir/usr/share/doc/$pname/" 341ab18486Smaximilian attems cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian" 3551ccdbfbSGuillem Jover gzip -n -9 "$pdir/usr/share/doc/$pname/changelog.Debian" 36b59a1225SFEJES Jozsef sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \ 37b59a1225SFEJES Jozsef | xargs -r0 md5sum > DEBIAN/md5sums" 389461f666SFrans Pop 39a5e40d86SSven Joachim # a+rX in case we are in a restrictive umask environment like 0077 40a5e40d86SSven Joachim # ug-s in case we build in a setuid/setgid directory 41a5e40d86SSven Joachim chmod -R go-w,a+rX,ug-s "$pdir" 423e2ab256SFrans Pop 43dca0c024SRiku Voipio # Create the package 44b41d920aSRiku Voipio dpkg-gencontrol -p$pname -P"$pdir" 4553243e09SMasahiro Yamada dpkg-deb --root-owner-group ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" .. 46dca0c024SRiku Voipio} 47dca0c024SRiku Voipio 48b611daaeSMasahiro Yamadainstall_linux_image () { 49b611daaeSMasahiro Yamada pdir=$1 50b611daaeSMasahiro Yamada pname=$2 51b611daaeSMasahiro Yamada 52b611daaeSMasahiro Yamada rm -rf ${pdir} 53b611daaeSMasahiro Yamada 54b611daaeSMasahiro Yamada # Only some architectures with OF support have this target 55b611daaeSMasahiro Yamada if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then 56b611daaeSMasahiro Yamada ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install 57b611daaeSMasahiro Yamada fi 58b611daaeSMasahiro Yamada 59b611daaeSMasahiro Yamada ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" modules_install 60b611daaeSMasahiro Yamada rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build" 61b611daaeSMasahiro Yamada 62b611daaeSMasahiro Yamada # Install the kernel 63b611daaeSMasahiro Yamada if [ "${ARCH}" = um ] ; then 641240dabeSMasahiro Yamada mkdir -p "${pdir}/usr/lib/uml/modules" 651240dabeSMasahiro Yamada mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}" 66b611daaeSMasahiro Yamada mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}" 67b611daaeSMasahiro Yamada cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map" 68b611daaeSMasahiro Yamada cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config" 69b611daaeSMasahiro Yamada gzip "${pdir}/usr/share/doc/${pname}/config" 70b611daaeSMasahiro Yamada else 71b611daaeSMasahiro Yamada mkdir -p "${pdir}/boot" 72b611daaeSMasahiro Yamada cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}" 73b611daaeSMasahiro Yamada cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}" 74b611daaeSMasahiro Yamada fi 75b611daaeSMasahiro Yamada 76b611daaeSMasahiro Yamada # Not all arches have the same installed path in debian 77b611daaeSMasahiro Yamada # XXX: have each arch Makefile export a variable of the canonical image install 78b611daaeSMasahiro Yamada # path instead 79b611daaeSMasahiro Yamada case "${SRCARCH}" in 80b611daaeSMasahiro Yamada um) 81b611daaeSMasahiro Yamada installed_image_path="usr/bin/linux-${KERNELRELEASE}";; 82b611daaeSMasahiro Yamada parisc|mips|powerpc) 83b611daaeSMasahiro Yamada installed_image_path="boot/vmlinux-${KERNELRELEASE}";; 84b611daaeSMasahiro Yamada *) 85b611daaeSMasahiro Yamada installed_image_path="boot/vmlinuz-${KERNELRELEASE}";; 86b611daaeSMasahiro Yamada esac 87b611daaeSMasahiro Yamada cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}" 88b611daaeSMasahiro Yamada 89b611daaeSMasahiro Yamada # Install the maintainer scripts 90b611daaeSMasahiro Yamada # Note: hook scripts under /etc/kernel are also executed by official Debian 91b611daaeSMasahiro Yamada # kernel packages, as well as kernel packages built using make-kpkg. 92b611daaeSMasahiro Yamada # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and 93b611daaeSMasahiro Yamada # so do we; recent versions of dracut and initramfs-tools will obey this. 94b611daaeSMasahiro Yamada debhookdir=${KDEB_HOOKDIR:-/etc/kernel} 95b611daaeSMasahiro Yamada for script in postinst postrm preinst prerm; do 96b611daaeSMasahiro Yamada mkdir -p "${pdir}${debhookdir}/${script}.d" 97b611daaeSMasahiro Yamada 98b611daaeSMasahiro Yamada mkdir -p "${pdir}/DEBIAN" 99b611daaeSMasahiro Yamada cat <<-EOF > "${pdir}/DEBIAN/${script}" 100b611daaeSMasahiro Yamada 101b611daaeSMasahiro Yamada #!/bin/sh 102b611daaeSMasahiro Yamada 103b611daaeSMasahiro Yamada set -e 104b611daaeSMasahiro Yamada 105b611daaeSMasahiro Yamada # Pass maintainer script parameters to hook scripts 106b611daaeSMasahiro Yamada export DEB_MAINT_PARAMS="\$*" 107b611daaeSMasahiro Yamada 108b611daaeSMasahiro Yamada # Tell initramfs builder whether it's wanted 109b611daaeSMasahiro Yamada export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No) 110b611daaeSMasahiro Yamada 111b611daaeSMasahiro Yamada test -d ${debhookdir}/${script}.d && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" ${debhookdir}/${script}.d 112b611daaeSMasahiro Yamada exit 0 113b611daaeSMasahiro Yamada EOF 114b611daaeSMasahiro Yamada chmod 755 "${pdir}/DEBIAN/${script}" 115b611daaeSMasahiro Yamada done 116b611daaeSMasahiro Yamada} 117b611daaeSMasahiro Yamada 118b611daaeSMasahiro Yamadainstall_linux_image_dbg () { 119b611daaeSMasahiro Yamada pdir=$1 120b611daaeSMasahiro Yamada image_pdir=$2 121b611daaeSMasahiro Yamada 122b611daaeSMasahiro Yamada rm -rf ${pdir} 123b611daaeSMasahiro Yamada 124b611daaeSMasahiro Yamada for module in $(find ${image_pdir}/lib/modules/ -name *.ko -printf '%P\n'); do 125b611daaeSMasahiro Yamada module=lib/modules/${module} 126b611daaeSMasahiro Yamada mkdir -p $(dirname ${pdir}/usr/lib/debug/${module}) 127b611daaeSMasahiro Yamada # only keep debug symbols in the debug file 128b611daaeSMasahiro Yamada ${OBJCOPY} --only-keep-debug ${image_pdir}/${module} ${pdir}/usr/lib/debug/${module} 129b611daaeSMasahiro Yamada # strip original module from debug symbols 130b611daaeSMasahiro Yamada ${OBJCOPY} --strip-debug ${image_pdir}/${module} 131b611daaeSMasahiro Yamada # then add a link to those 132b611daaeSMasahiro Yamada ${OBJCOPY} --add-gnu-debuglink=${pdir}/usr/lib/debug/${module} ${image_pdir}/${module} 133b611daaeSMasahiro Yamada done 134b611daaeSMasahiro Yamada 135b611daaeSMasahiro Yamada # re-sign stripped modules 136b611daaeSMasahiro Yamada if is_enabled CONFIG_MODULE_SIG_ALL; then 137b611daaeSMasahiro Yamada ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${image_pdir}" modules_sign 138b611daaeSMasahiro Yamada fi 139b611daaeSMasahiro Yamada 140b611daaeSMasahiro Yamada # Build debug package 141b611daaeSMasahiro Yamada # Different tools want the image in different locations 142b611daaeSMasahiro Yamada # perf 143b611daaeSMasahiro Yamada mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ 144b611daaeSMasahiro Yamada cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ 145b611daaeSMasahiro Yamada # systemtap 146b611daaeSMasahiro Yamada mkdir -p ${pdir}/usr/lib/debug/boot/ 147b611daaeSMasahiro Yamada ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE} 148b611daaeSMasahiro Yamada # kdump-tools 149b611daaeSMasahiro Yamada ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE} 150b611daaeSMasahiro Yamada} 151b611daaeSMasahiro Yamada 15236862e14SMasahiro Yamadainstall_kernel_headers () { 1533126c17dSMasahiro Yamada pdir=$1 1543ced71d2SKevin Locke version=$2 1553126c17dSMasahiro Yamada 1563126c17dSMasahiro Yamada rm -rf $pdir 1573126c17dSMasahiro Yamada 158fe66b5d2SMasahiro Yamada "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}" 1593126c17dSMasahiro Yamada 1603126c17dSMasahiro Yamada mkdir -p $pdir/lib/modules/$version/ 1613126c17dSMasahiro Yamada ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build 1623126c17dSMasahiro Yamada} 1633126c17dSMasahiro Yamada 16436862e14SMasahiro Yamadainstall_libc_headers () { 165451dff37SMasahiro Yamada pdir=$1 166451dff37SMasahiro Yamada 167451dff37SMasahiro Yamada rm -rf $pdir 168451dff37SMasahiro Yamada 169451dff37SMasahiro Yamada $MAKE -f $srctree/Makefile headers 170451dff37SMasahiro Yamada $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr 171451dff37SMasahiro Yamada 172451dff37SMasahiro Yamada # move asm headers to /usr/include/<libc-machine>/asm to match the structure 173451dff37SMasahiro Yamada # used by Debian-based distros (to support multi-arch) 174*159956f3SMasahiro Yamada mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}" 175*159956f3SMasahiro Yamada mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}" 176451dff37SMasahiro Yamada} 177451dff37SMasahiro Yamada 178b611daaeSMasahiro Yamadarm -f debian/files 1791da177e4SLinus Torvalds 18036862e14SMasahiro Yamadapackages_enabled=$(dh_listpackages) 1813126c17dSMasahiro Yamada 18236862e14SMasahiro Yamadafor package in ${packages_enabled} 18336862e14SMasahiro Yamadado 18436862e14SMasahiro Yamada case ${package} in 18536862e14SMasahiro Yamada *-dbg) 18636862e14SMasahiro Yamada # This must be done after linux-image, that is, we expect the 18736862e14SMasahiro Yamada # debug package appears after linux-image in debian/control. 18836862e14SMasahiro Yamada install_linux_image_dbg debian/linux-image-dbg debian/linux-image;; 18936862e14SMasahiro Yamada linux-image-*|user-mode-linux-*) 19036862e14SMasahiro Yamada install_linux_image debian/linux-image ${package};; 19136862e14SMasahiro Yamada linux-libc-dev) 19236862e14SMasahiro Yamada install_libc_headers debian/linux-libc-dev;; 19336862e14SMasahiro Yamada linux-headers-*) 1943ced71d2SKevin Locke install_kernel_headers debian/linux-headers ${package#linux-headers-};; 19536862e14SMasahiro Yamada esac 19636862e14SMasahiro Yamadadone 197d7d357bcSJoerg Roedel 19836862e14SMasahiro Yamadafor package in ${packages_enabled} 19936862e14SMasahiro Yamadado 20036862e14SMasahiro Yamada case ${package} in 20136862e14SMasahiro Yamada *-dbg) 20236862e14SMasahiro Yamada create_package ${package} debian/linux-image-dbg;; 20336862e14SMasahiro Yamada linux-image-*|user-mode-linux-*) 20436862e14SMasahiro Yamada create_package ${package} debian/linux-image;; 20536862e14SMasahiro Yamada linux-libc-dev) 20636862e14SMasahiro Yamada create_package ${package} debian/linux-libc-dev;; 20736862e14SMasahiro Yamada linux-headers-*) 20836862e14SMasahiro Yamada create_package ${package} debian/linux-headers;; 20936862e14SMasahiro Yamada esac 21036862e14SMasahiro Yamadadone 211b611daaeSMasahiro Yamada 2121da177e4SLinus Torvaldsexit 0 213