builddeb 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/sh
  2. #
  3. # builddeb 1.3
  4. # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
  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. set -eu
  13. is_enabled() {
  14. grep -q "^$1=y" include/config/auto.conf
  15. }
  16. if_enabled_echo() {
  17. if is_enabled "$1"; then
  18. echo -n "$2"
  19. elif [ $# -ge 3 ]; then
  20. echo -n "$3"
  21. fi
  22. }
  23. install_linux_image () {
  24. pname=$1
  25. pdir=debian/$1
  26. # Only some architectures with OF support have this target
  27. if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
  28. ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install
  29. fi
  30. ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" INSTALL_MOD_STRIP=1 modules_install
  31. rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build"
  32. # Install the kernel
  33. if [ "${ARCH}" = um ] ; then
  34. mkdir -p "${pdir}/usr/lib/uml/modules"
  35. mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}"
  36. mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}"
  37. cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map"
  38. cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config"
  39. gzip "${pdir}/usr/share/doc/${pname}/config"
  40. else
  41. mkdir -p "${pdir}/boot"
  42. cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}"
  43. cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}"
  44. fi
  45. # Not all arches have the same installed path in debian
  46. # XXX: have each arch Makefile export a variable of the canonical image install
  47. # path instead
  48. case "${SRCARCH}" in
  49. um)
  50. installed_image_path="usr/bin/linux-${KERNELRELEASE}";;
  51. parisc|mips|powerpc)
  52. installed_image_path="boot/vmlinux-${KERNELRELEASE}";;
  53. *)
  54. installed_image_path="boot/vmlinuz-${KERNELRELEASE}";;
  55. esac
  56. cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}"
  57. # Install the maintainer scripts
  58. # Note: hook scripts under /etc/kernel are also executed by official Debian
  59. # kernel packages, as well as kernel packages built using make-kpkg.
  60. # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
  61. # so do we; recent versions of dracut and initramfs-tools will obey this.
  62. debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
  63. for script in postinst postrm preinst prerm; do
  64. mkdir -p "${pdir}${debhookdir}/${script}.d"
  65. mkdir -p "${pdir}/DEBIAN"
  66. cat <<-EOF > "${pdir}/DEBIAN/${script}"
  67. #!/bin/sh
  68. set -e
  69. # Pass maintainer script parameters to hook scripts
  70. export DEB_MAINT_PARAMS="\$*"
  71. # Tell initramfs builder whether it's wanted
  72. export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
  73. test -d ${debhookdir}/${script}.d && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" ${debhookdir}/${script}.d
  74. exit 0
  75. EOF
  76. chmod 755 "${pdir}/DEBIAN/${script}"
  77. done
  78. }
  79. install_linux_image_dbg () {
  80. pdir=debian/$1
  81. # Parse modules.order directly because 'make modules_install' may sign,
  82. # compress modules, and then run unneeded depmod.
  83. if is_enabled CONFIG_MODULES; then
  84. while read -r mod; do
  85. mod="${mod%.o}.ko"
  86. dbg="${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/kernel/${mod}"
  87. buildid=$("${READELF}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p')
  88. link="${pdir}/usr/lib/debug/.build-id/${buildid}.debug"
  89. mkdir -p "${dbg%/*}" "${link%/*}"
  90. "${OBJCOPY}" --only-keep-debug "${mod}" "${dbg}"
  91. ln -sf --relative "${dbg}" "${link}"
  92. done < modules.order
  93. fi
  94. # Build debug package
  95. # Different tools want the image in different locations
  96. # perf
  97. mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
  98. cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
  99. # systemtap
  100. mkdir -p ${pdir}/usr/lib/debug/boot/
  101. ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE}
  102. # kdump-tools
  103. ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE}
  104. }
  105. install_kernel_headers () {
  106. pdir=debian/$1
  107. version=${1#linux-headers-}
  108. CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
  109. mkdir -p $pdir/lib/modules/$version/
  110. ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
  111. }
  112. install_libc_headers () {
  113. pdir=debian/$1
  114. $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr
  115. # move asm headers to /usr/include/<libc-machine>/asm to match the structure
  116. # used by Debian-based distros (to support multi-arch)
  117. mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
  118. mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
  119. }
  120. package=$1
  121. case "${package}" in
  122. *-dbg)
  123. install_linux_image_dbg "${package}";;
  124. linux-image-*|user-mode-linux-*)
  125. install_linux_image "${package}";;
  126. linux-libc-dev)
  127. install_libc_headers "${package}";;
  128. linux-headers-*)
  129. install_kernel_headers "${package}";;
  130. esac