builddeb 5.6 KB

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