kernel-debs.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. #!/usr/bin/env bash
  2. #
  3. # SPDX-License-Identifier: GPL-2.0
  4. #
  5. # Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
  6. #
  7. # This file is a part of the Armbian Build Framework
  8. # https://github.com/armbian/build/
  9. # This is a re-imagining of mkdebian and builddeb from the kernel tree.
  10. # We wanna produce Debian/Ubuntu compatible packages so we're able to use their standard tools, like
  11. # `flash-kernel`, `u-boot-menu`, `grub2`, and others, so we gotta stick to their conventions.
  12. # The main difference is that this is NOT invoked from KBUILD's Makefile, but instead
  13. # directly by Armbian, with references to the dirs where KBUILD's
  14. # `make install dtbs_install modules_install headers_install` have already successfully been run.
  15. # This will create a SET of packages. It should always create these:
  16. # image package: vmlinuz and such, config, modules, and dtbs (if exist) in /usr/lib/xxx
  17. # linux-headers package: "just" the kernel headers, for building out-of-tree modules, dkms, etc.
  18. # linux-dtbs package: only dtbs, if they exist. in /boot/
  19. # So this will handle
  20. # - Creating .deb package skeleton dir (mktemp)
  21. # - Moving/copying around of KBUILD installed stuff for Debian/Ubuntu/Armbian standard locations, in the correct packages
  22. # - Fixing the symlinks to stuff so they fit a target system.
  23. # - building the .debs.
  24. is_enabled() {
  25. grep -q "^$1=y" include/config/auto.conf
  26. }
  27. if_enabled_echo() {
  28. if is_enabled "$1"; then
  29. echo -n "$2"
  30. elif [ $# -ge 3 ]; then
  31. echo -n "$3"
  32. fi
  33. }
  34. function prepare_kernel_packaging_debs() {
  35. : "${artifact_version:?artifact_version is not set}"
  36. : "${kernel_debs_temp_dir:?kernel_debs_temp_dir is not set}"
  37. declare kernel_work_dir="${1}"
  38. declare kernel_dest_install_dir="${2}"
  39. declare kernel_version="${3}"
  40. declare -n tmp_kernel_install_dirs="${4}" # nameref to declare -n kernel_install_dirs dictionary
  41. declare debs_target_dir="${kernel_work_dir}/.."
  42. # Some variables and settings used throughout the script
  43. declare kernel_version_family="${kernel_version}-${LINUXFAMILY}"
  44. # Package version. Affects users upgrading from repo!
  45. display_alert "Kernel .deb package version" "${artifact_version}" "info"
  46. # show incoming tree
  47. #display_alert "Kernel install dir" "incoming from KBUILD make" "debug"
  48. #run_host_command_logged tree -C --du -h "${kernel_dest_install_dir}" "| grep --line-buffered -v -e '\.ko' -e '\.h' "
  49. # display_alert "tmp_kernel_install_dirs INSTALL_PATH:" "${tmp_kernel_install_dirs[INSTALL_PATH]}" "debug"
  50. # display_alert "tmp_kernel_install_dirs INSTALL_MOD_PATH:" "${tmp_kernel_install_dirs[INSTALL_MOD_PATH]}" "debug"
  51. # display_alert "tmp_kernel_install_dirs INSTALL_HDR_PATH:" "${tmp_kernel_install_dirs[INSTALL_HDR_PATH]}" "debug"
  52. # display_alert "tmp_kernel_install_dirs INSTALL_DTBS_PATH:" "${tmp_kernel_install_dirs[INSTALL_DTBS_PATH]}" "debug"
  53. # For armhf, kernel's "make install" gives us the wrong "vmlinuz-xx" file. We want the arch/arm/boot/zImage.
  54. if [[ "${ARCH}" == "armhf" ]]; then # @TODO: if you know a better way? some kbuild var? send PR.
  55. display_alert "armhf: using arch/arm/boot/zImage as vmlinuz" "armhf zImage" "info"
  56. run_host_command_logged ls -la "${kernel_work_dir}/arch/arm/boot/zImage" || true
  57. run_host_command_logged file "${kernel_work_dir}/arch/arm/boot/zImage" || true
  58. run_host_command_logged ls -la "${tmp_kernel_install_dirs[INSTALL_PATH]}/vmlinuz-${kernel_version_family}" || true
  59. run_host_command_logged file "${tmp_kernel_install_dirs[INSTALL_PATH]}/vmlinuz-${kernel_version_family}" || true
  60. # Just overwrite it...
  61. run_host_command_logged cp -v "${kernel_work_dir}/arch/arm/boot/zImage" "${tmp_kernel_install_dirs[INSTALL_PATH]}/vmlinuz-${kernel_version_family}"
  62. run_host_command_logged file "${tmp_kernel_install_dirs[INSTALL_PATH]}/vmlinuz-${kernel_version_family}"
  63. display_alert "armhf: using arch/arm/boot/zImage as vmlinuz" "done with armhf zImage" "debug"
  64. fi
  65. # package the linux-image (image, modules, dtbs (if present))
  66. display_alert "Packaging linux-image" "${LINUXFAMILY} ${LINUXCONFIG}" "info"
  67. create_kernel_deb "linux-image-${BRANCH}-${LINUXFAMILY}" "${debs_target_dir}" kernel_package_callback_linux_image
  68. # if dtbs present, package those too separately, for u-boot usage.
  69. if [[ -d "${tmp_kernel_install_dirs[INSTALL_DTBS_PATH]}" ]]; then
  70. display_alert "Packaging linux-dtb" "${LINUXFAMILY} ${LINUXCONFIG}" "info"
  71. create_kernel_deb "linux-dtb-${BRANCH}-${LINUXFAMILY}" "${debs_target_dir}" kernel_package_callback_linux_dtb
  72. fi
  73. if [[ "${KERNEL_HAS_WORKING_HEADERS}" == "yes" ]]; then
  74. display_alert "Packaging linux-headers" "${LINUXFAMILY} ${LINUXCONFIG}" "info"
  75. create_kernel_deb "linux-headers-${BRANCH}-${LINUXFAMILY}" "${debs_target_dir}" kernel_package_callback_linux_headers
  76. else
  77. display_alert "Skipping linux-headers package" "for ${KERNEL_MAJOR_MINOR} kernel version" "warn"
  78. fi
  79. }
  80. function create_kernel_deb() {
  81. : "${kernel_debs_temp_dir:?kernel_debs_temp_dir is not set}"
  82. declare package_name="${1}"
  83. declare deb_output_dir="${2}"
  84. declare callback_function="${3}"
  85. declare cleanup_id="" package_directory=""
  86. prepare_temp_dir_in_workdir_and_schedule_cleanup "deb-k-${package_name}" cleanup_id package_directory # namerefs
  87. declare package_DEBIAN_dir="${package_directory}/DEBIAN" # DEBIAN dir
  88. mkdir -p "${package_DEBIAN_dir}" # maintainer scripts et al
  89. # Generate copyright file
  90. mkdir -p "${package_directory}/usr/share/doc/${package_name}"
  91. cat <<- COPYRIGHT > "${package_directory}/usr/share/doc/${package_name}/copyright"
  92. This is a packaged Armbian patched version of the Linux kernel.
  93. The sources may be found at most Linux archive sites, including:
  94. https://www.kernel.org/pub/linux/kernel
  95. Copyright: 1991 - 2018 Linus Torvalds and others.
  96. The git repository for mainline kernel development is at:
  97. git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
  98. This program is free software; you can redistribute it and/or modify
  99. it under the terms of the GNU General Public License as published by
  100. the Free Software Foundation; version 2 dated June, 1991.
  101. On Debian GNU/Linux systems, the complete text of the GNU General Public
  102. License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
  103. COPYRIGHT
  104. # Run the callback.
  105. # display_alert "Running callback" "callback: ${callback_function}" "debug"
  106. "${callback_function}" "${@}"
  107. run_host_command_logged chown -R root:root "${package_directory}" # Fix ownership and permissions
  108. run_host_command_logged chmod -R go-w "${package_directory}" # Fix ownership and permissions
  109. run_host_command_logged chmod -R a+rX "${package_directory}" # in case we are in a restrictive umask environment like 0077
  110. run_host_command_logged chmod -R ug-s "${package_directory}" # in case we build in a setuid/setgid directory
  111. cd "${package_directory}" || exit_with_error "major failure 774 for ${package_name}"
  112. # create md5sums file
  113. # sh -c "cd '${package_directory}'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' | xargs -r0 md5sum > DEBIAN/md5sums"
  114. declare unpacked_size
  115. unpacked_size="$(du -h -s "${package_directory}" | awk '{print $1}')"
  116. display_alert "Unpacked ${package_name} tree" "${unpacked_size}" "debug"
  117. # Show it
  118. #display_alert "Package dir" "for package ${package_name}" "debug"
  119. #run_host_command_logged tree -C -h -d --du "${package_directory}"
  120. fakeroot_dpkg_deb_build "${package_directory}" "${kernel_debs_temp_dir}/"
  121. done_with_temp_dir "${cleanup_id}" # changes cwd to "${SRC}" and fires the cleanup function early
  122. }
  123. function kernel_package_hook_helper() {
  124. declare script="${1}"
  125. declare contents="${2}"
  126. cat >> "${package_DEBIAN_dir}/${script}" <<- EOT
  127. #!/bin/bash
  128. echo "Armbian '${package_name}' for '${kernel_version_family}': '${script}' starting."
  129. set -e # Error control
  130. set -x # Debugging
  131. $(cat "${contents}")
  132. set +x # Disable debugging
  133. echo "Armbian '${package_name}' for '${kernel_version_family}': '${script}' finishing."
  134. true
  135. EOT
  136. chmod 775 "${package_DEBIAN_dir}/${script}"
  137. # produce log asset for script
  138. LOG_ASSET="deb-${package_name}-${script}.sh" do_with_log_asset run_host_command_logged cat "${package_DEBIAN_dir}/${script}"
  139. }
  140. function kernel_package_callback_linux_image() {
  141. display_alert "linux-image deb packaging" "${package_directory}" "debug"
  142. declare installed_image_path="boot/vmlinuz-${kernel_version_family}" # using old mkdebian terminology here.
  143. declare image_name="Image" # "Image" for arm64. or, "zImage" for arm, or "vmlinuz" for others.
  144. # If NAME_KERNEL is set (usually in arch config file), warn and use that instead.
  145. if [[ -n "${NAME_KERNEL}" ]]; then
  146. display_alert "NAME_KERNEL is set" "using '${NAME_KERNEL}' instead of '${image_name}'" "debug"
  147. image_name="${NAME_KERNEL}"
  148. else
  149. display_alert "NAME_KERNEL is not set" "using default '${image_name}'" "debug"
  150. fi
  151. display_alert "Showing contents of Kbuild produced /boot" "linux-image" "debug"
  152. run_host_command_logged tree -C --du -h "${tmp_kernel_install_dirs[INSTALL_PATH]}"
  153. run_host_command_logged cp -rp "${tmp_kernel_install_dirs[INSTALL_PATH]}" "${package_directory}/" # /boot stuff
  154. run_host_command_logged cp -rp "${tmp_kernel_install_dirs[INSTALL_MOD_PATH]}/lib" "${package_directory}/" # so "lib" stuff sits at the root
  155. # Clean up symlinks in lib/modules/${kernel_version_family}/build and lib/modules/${kernel_version_family}/source; will be in the headers package
  156. run_host_command_logged rm -v -f "${package_directory}/lib/modules/${kernel_version_family}/build" "${package_directory}/lib/modules/${kernel_version_family}/source"
  157. display_alert "Showing contents of Kbuild produced modules" "linux-image" "debug"
  158. run_host_command_logged tree -C --du -h -d -L 1 "${package_directory}/lib/modules/${kernel_version_family}/kernel" "|| true" # do not fail
  159. if [[ -d "${tmp_kernel_install_dirs[INSTALL_DTBS_PATH]}" ]]; then
  160. # /usr/lib/linux-image-${kernel_version_family} is wanted by flash-kernel, u-boot-menu, and other standard Debian/Ubuntu utilities
  161. display_alert "DTBs present on kernel output" "DTBs ${package_name}: /usr/lib/linux-image-${kernel_version_family}" "debug"
  162. mkdir -p "${package_directory}/usr/lib"
  163. run_host_command_logged cp -rp "${tmp_kernel_install_dirs[INSTALL_DTBS_PATH]}" "${package_directory}/usr/lib/linux-image-${kernel_version_family}"
  164. fi
  165. # Generate a control file
  166. cat <<- CONTROL_FILE > "${package_DEBIAN_dir}/control"
  167. Package: ${package_name}
  168. Version: ${artifact_version}
  169. Source: linux-${kernel_version}
  170. Architecture: ${ARCH}
  171. Maintainer: ${MAINTAINER} <${MAINTAINERMAIL}>
  172. Section: kernel
  173. Provides: linux-image, linux-image-armbian, armbian-$BRANCH
  174. Description: Armbian Linux $BRANCH kernel image ${artifact_version_reason:-"${kernel_version_family}"}
  175. This package contains the Linux kernel, modules and corresponding other
  176. files, kernel_version_family: $kernel_version_family.
  177. CONTROL_FILE
  178. # Install the maintainer scripts
  179. # Note: hook scripts under /etc/kernel are also executed by official Debian
  180. # kernel packages, as well as kernel packages built using make-kpkg.
  181. # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
  182. # so do we; recent versions of dracut and initramfs-tools will obey this.
  183. declare debian_kernel_hook_dir="/etc/kernel"
  184. for script in "postinst" "postrm" "preinst" "prerm"; do
  185. mkdir -p "${package_directory}${debian_kernel_hook_dir}/${script}.d" # create kernel hook dir, make sure.
  186. kernel_package_hook_helper "${script}" <(
  187. cat <<- KERNEL_HOOK_DELEGATION
  188. export DEB_MAINT_PARAMS="\$*" # Pass maintainer script parameters to hook scripts
  189. export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No) # Tell initramfs builder whether it's wanted
  190. # Run the same hooks Debian/Ubuntu would for their kernel packages.
  191. test -d ${debian_kernel_hook_dir}/${script}.d && run-parts --arg="${kernel_version_family}" --arg="/${installed_image_path}" ${debian_kernel_hook_dir}/${script}.d
  192. KERNEL_HOOK_DELEGATION
  193. if [[ "${script}" == "preinst" ]]; then
  194. cat <<- HOOK_FOR_REMOVE_VFAT_BOOT_FILES
  195. check_boot_dev (){
  196. boot_partition=\$(findmnt -n -o SOURCE /boot)
  197. bootfstype=\$(blkid -s TYPE -o value \$boot_partition)
  198. if [ "\$bootfstype" = "vfat" ]; then
  199. rm -f /boot/System.map* /boot/config* /boot/vmlinuz* /boot/$image_name /boot/uImage
  200. fi
  201. }
  202. mountpoint -q /boot && check_boot_dev
  203. HOOK_FOR_REMOVE_VFAT_BOOT_FILES
  204. fi
  205. # @TODO: only if u-boot, only for postinst. Gotta find a hook scheme for these...
  206. if [[ "${script}" == "postinst" ]]; then
  207. cat <<- HOOK_FOR_LINK_TO_LAST_INSTALLED_KERNEL
  208. echo "Armbian: update last-installed kernel symlink to '$image_name'..."
  209. ln -sfv $(basename "${installed_image_path}") /boot/$image_name || mv -v /${installed_image_path} /boot/${image_name}
  210. touch /boot/.next
  211. HOOK_FOR_LINK_TO_LAST_INSTALLED_KERNEL
  212. fi
  213. )
  214. done
  215. }
  216. function kernel_package_callback_linux_dtb() {
  217. display_alert "linux-dtb packaging" "${package_directory}" "debug"
  218. display_alert "Showing tree of Kbuild produced DTBs" "linux-dtb" "debug"
  219. run_host_command_logged tree -C --du -h -L 2 "${tmp_kernel_install_dirs[INSTALL_DTBS_PATH]}"
  220. mkdir -p "${package_directory}/boot/"
  221. run_host_command_logged cp -rp "${tmp_kernel_install_dirs[INSTALL_DTBS_PATH]}" "${package_directory}/boot/dtb-${kernel_version_family}"
  222. # Generate a control file
  223. cat <<- CONTROL_FILE > "${package_DEBIAN_dir}/control"
  224. Version: ${artifact_version}
  225. Maintainer: ${MAINTAINER} <${MAINTAINERMAIL}>
  226. Section: kernel
  227. Package: ${package_name}
  228. Architecture: ${ARCH}
  229. Provides: linux-dtb, linux-dtb-armbian, armbian-$BRANCH
  230. Description: Armbian Linux $BRANCH DTBs ${artifact_version_reason:-"${kernel_version_family}"}
  231. This package contains device blobs from the Linux kernel, version ${kernel_version_family}
  232. CONTROL_FILE
  233. kernel_package_hook_helper "preinst" <(
  234. cat <<- EOT
  235. rm -rf /boot/dtb
  236. rm -rf /boot/dtb-${kernel_version_family}
  237. EOT
  238. )
  239. kernel_package_hook_helper "postinst" <(
  240. cat <<- EOT
  241. cd /boot
  242. ln -sfT dtb-${kernel_version_family} dtb || mv dtb-${kernel_version_family} dtb
  243. EOT
  244. )
  245. }
  246. function kernel_package_callback_linux_headers() {
  247. display_alert "linux-headers packaging" "${package_directory}" "debug"
  248. # targets.
  249. local headers_target_dir="${package_directory}/usr/src/linux-headers-${kernel_version_family}" # headers/tools etc
  250. local modules_target_dir="${package_directory}/lib/modules/${kernel_version_family}" # symlink to above later
  251. mkdir -p "${headers_target_dir}" "${modules_target_dir}" # create both dirs
  252. run_host_command_logged ln -v -s "/usr/src/linux-headers-${kernel_version_family}" "${modules_target_dir}/build" # Symlink in modules so builds find the headers
  253. run_host_command_logged cp -vp "${kernel_work_dir}"/.config "${headers_target_dir}"/.config # copy .config manually to be where it's expected to be
  254. # gather stuff from the linux source tree: ${kernel_work_dir} (NOT the make install destination)
  255. # those can be source files or object (binary/compiled) stuff
  256. # how to get SRCARCH? only from the makefile itself. ARCH=amd64 then SRCARCH=x86. How to we know? @TODO
  257. local SRC_ARCH="${ARCH}"
  258. [[ "${SRC_ARCH}" == "amd64" ]] && SRC_ARCH="x86"
  259. [[ "${SRC_ARCH}" == "armhf" ]] && SRC_ARCH="arm"
  260. [[ "${SRC_ARCH}" == "riscv64" ]] && SRC_ARCH="riscv"
  261. # @TODO: added KERNEL_SRC_ARCH to each arch'es .config file; let's make sure they're sane. Just use KERNEL_SRC_ARCH after confirmed.
  262. # Lets check and warn if it isn't. If warns don't popup over time we remove and just use ARCHITECTURE later.
  263. if [[ "${SRC_ARCH}" != "${KERNEL_SRC_ARCH}" ]]; then
  264. display_alert "WARNING: KERNEL_SRC_ARCH and SRC_ARCH don't match during kernel build." "KERNEL_SRC_ARCH=${ARCHITECTURE} SRC_ARCH=${SRC_ARCH}" "wrn"
  265. fi
  266. # Create a list of files to include, path-relative to the kernel tree
  267. local temp_file_list="${WORKDIR}/tmp_file_list_${kernel_version_family}.kernel.headers"
  268. # Find the files we want to include in the package. Those will be later cleaned, etc.
  269. (
  270. cd "${kernel_work_dir}" || exit 2
  271. find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl
  272. find arch/*/include include scripts -type f -o -type l
  273. find security/*/include -type f
  274. [[ -d "arch/${SRC_ARCH}" ]] && {
  275. find "arch/${SRC_ARCH}" -name module.lds -o -name Kbuild.platforms -o -name Platform
  276. # shellcheck disable=SC2046 # I need to expand. Thanks.
  277. find $(find "arch/${SRC_ARCH}" -name include -o -name scripts -type d) -type f
  278. find arch/${SRC_ARCH}/include -type f
  279. }
  280. find Module.symvers include scripts -type f
  281. find . -name "bitsperlong.h" -type f
  282. # tools/include/tools has the byteshift utilities shared between kernel proper and the build scripts/tools.
  283. # This replaces 'headers-debian-byteshift.patch' which was used for years in Armbian.
  284. find tools -type f # all tools; will trim a bit later
  285. find arch/x86/lib/insn.c # required by objtool stuff...
  286. if is_enabled CONFIG_GCC_PLUGINS; then
  287. find scripts/gcc-plugins -name gcc-common.h # @TODO something else here too?
  288. fi
  289. ) > "${temp_file_list}"
  290. # Now include/copy those, using tar as intermediary. Just like builddeb does it.
  291. tar -c -f - -C "${kernel_work_dir}" -T "${temp_file_list}" | tar -xf - -C "${headers_target_dir}"
  292. # ${temp_file_list} is left at WORKDIR for later debugging, will be removed by WORKDIR cleanup trap
  293. # Now, make the script dirs clean.
  294. # This is run in our _target_ dir, NOT the source tree, so we're free to make clean as we wish without invalidating the next build's cache.
  295. # Understand: I'm sending the logs of this to the bitbucket ON PURPOSE: "clean" tries to use clang, ALSA, etc, which are not available.
  296. # The logs produced during this step throw off developers casually looking at the logs.
  297. # Important: if the steps _fail_ here, you'll have to enable DEBUG=yes to see what's going on.
  298. declare make_bitbucket="&> /dev/null"
  299. [[ "${DEBUG}" == "yes" ]] && make_bitbucket=""
  300. run_host_command_logged cd "${headers_target_dir}" "&&" make -s "ARCH=${SRC_ARCH}" "M=scripts" clean "${make_bitbucket}"
  301. run_host_command_logged cd "${headers_target_dir}/tools" "&&" make -s "ARCH=${SRC_ARCH}" clean "${make_bitbucket}"
  302. # Trim down on the tools dir a bit after cleaning.
  303. rm -rf "${headers_target_dir}/tools/perf" "${headers_target_dir}/tools/testing"
  304. # Hack: after cleaning, copy over the scripts/module.lds file from the source tree. It will only exist on 5.10+
  305. # See https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1906131
  306. [[ -f "${kernel_work_dir}/scripts/module.lds" ]] &&
  307. run_host_command_logged cp -v "${kernel_work_dir}/scripts/module.lds" "${headers_target_dir}/scripts/module.lds"
  308. if [[ "${DEBUG}" == "yes" ]]; then
  309. # Check that no binaries are included by now. Expensive... @TODO: remove after me make sure.
  310. display_alert "Checking for binaries in kernel headers" "${headers_target_dir}" "debug"
  311. (
  312. cd "${headers_target_dir}" || exit 33
  313. find . -type f | grep -v -e "include/config/" -e "\.h$" -e ".c$" -e "Makefile$" -e "Kconfig$" -e "Kbuild$" -e "\.cocci$" | xargs file | grep -v -e "ASCII" -e "script text" -e "empty" -e "Unicode text" -e "symbolic link" -e "CSV text" -e "SAS 7+" || true
  314. )
  315. fi
  316. # Generate a control file
  317. # TODO: libssl-dev is only required if we're signing modules, which is a kernel .config option.
  318. cat <<- CONTROL_FILE > "${package_DEBIAN_dir}/control"
  319. Version: ${artifact_version}
  320. Maintainer: ${MAINTAINER} <${MAINTAINERMAIL}>
  321. Section: devel
  322. Package: ${package_name}
  323. Architecture: ${ARCH}
  324. Provides: linux-headers, linux-headers-armbian, armbian-$BRANCH
  325. Depends: make, gcc, libc6-dev, bison, flex, libssl-dev, libelf-dev
  326. Description: Armbian Linux $BRANCH headers ${artifact_version_reason:-"${kernel_version_family}"}
  327. This package provides kernel header files for ${kernel_version_family}
  328. .
  329. This is useful for DKMS and building of external modules.
  330. CONTROL_FILE
  331. # Make sure the target dir is clean/not-existing before installing.
  332. kernel_package_hook_helper "preinst" <(
  333. cat <<- EOT_PREINST
  334. if [[ -d "/usr/src/linux-headers-${kernel_version_family}" ]]; then
  335. echo "Cleaning pre-existing directory /usr/src/linux-headers-${kernel_version_family} ..."
  336. rm -rf "/usr/src/linux-headers-${kernel_version_family}"
  337. fi
  338. EOT_PREINST
  339. )
  340. # Make sure the target dir is removed before removing the package; that way we don't leave eventual compilation artifacts over there.
  341. kernel_package_hook_helper "prerm" <(
  342. cat <<- EOT_PRERM
  343. if [[ -d "/usr/src/linux-headers-${kernel_version_family}" ]]; then
  344. echo "Cleaning directory /usr/src/linux-headers-${kernel_version_family} ..."
  345. rm -rf "/usr/src/linux-headers-${kernel_version_family}"
  346. fi
  347. EOT_PRERM
  348. )
  349. kernel_package_hook_helper "postinst" <(
  350. cat <<- EOT_POSTINST
  351. cd "/usr/src/linux-headers-${kernel_version_family}"
  352. NCPU=\$(grep -c 'processor' /proc/cpuinfo)
  353. echo "Compiling kernel-headers tools (${kernel_version_family}) using \$NCPU CPUs - please wait ..."
  354. yes "" | make ARCH="${SRC_ARCH}" oldconfig
  355. make ARCH="${SRC_ARCH}" -j\$NCPU scripts
  356. make ARCH="${SRC_ARCH}" -j\$NCPU M=scripts/mod/
  357. # make ARCH="${SRC_ARCH}" -j\$NCPU modules_prepare # depends on too much other stuff.
  358. make ARCH="${SRC_ARCH}" -j\$NCPU tools/objtool
  359. echo "Done compiling kernel-headers tools (${kernel_version_family})."
  360. EOT_POSTINST
  361. )
  362. }