xmake.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package("linux-headers")
  2. set_homepage("https://kernel.org/")
  3. set_description("Header files of the Linux kernel")
  4. set_license("GPL-2.0-only")
  5. add_urls("https://cdn.kernel.org/pub/linux/kernel/$(version).tar.xz",
  6. "https://mirrors.edge.kernel.org/pub/linux/kernel/$(version).tar.xz",
  7. {version = function (version)
  8. return "v" .. version:major() .. ".x/linux-" .. version
  9. end})
  10. add_versions("4.20.9", "b5de28fd594a01edacd06e53491ad0890293e5fbf98329346426cf6030ef1ea6")
  11. add_versions("5.0.8", "11908044e8cce1e093141f8da594708d45d05d0381676ae9aa3d8aeaf7c85435")
  12. add_versions("5.9.16", "b0d7abae88e5f91893627c645e680a95c818defd1b4fcaf3e2afb4b2b6b4ab86")
  13. add_versions("5.10.46", "569122a39c6b325befb9ac1c07da0c53e6363b3baacd82081d131b06c1dc1415")
  14. add_versions("5.16.9", "1660e7228ec299c187c19739d115ded97f6b1be05a24986c4c443e7c5e8b744f")
  15. add_versions("5.19.1", "f4e27b926ea2c66b808db1f5706254cf92a8899e2108eedb0c3a7d12499aea55")
  16. add_configs("driver_modules", {description = "Enable driver modules files.", default = false, type = "boolean"})
  17. on_load(function (package)
  18. if package:config("driver_modules") then
  19. package:add("deps", "flex", "bison", "bc", "pkg-config")
  20. package:add("deps", "openssl", "elfutils", {private = true, host = true})
  21. else
  22. package:add("deps", "rsync")
  23. end
  24. end)
  25. on_fetch(function (package, opt)
  26. if opt.system and not package:is_cross() then
  27. import("lib.detect.find_path")
  28. local linux_headersdir = find_path("include/linux", "/usr/src/linux-headers-*")
  29. if linux_headersdir then
  30. -- parse version, linux-headers-5.11.0-41-generic, linux-headers-5.11.0-41
  31. local version = path.filename(linux_headersdir):match("linux%-headers%-(%d+%.%d+%.%d+).*")
  32. return {includedirs = path.join(linux_headersdir, "include"), version = version}
  33. end
  34. end
  35. end)
  36. on_install("linux", "cross", function (package)
  37. import("package.tools.make")
  38. if package:config("driver_modules") then
  39. local installdir = package:installdir()
  40. os.cp("*", installdir)
  41. if package:is_plat("cross") then
  42. local arch
  43. if package:is_arch("arm", "armv7") then
  44. arch = "arm"
  45. elseif package:is_arch("arm64", "arm64-v8a") then
  46. arch = "arm64"
  47. elseif package:is_arch("mips") then
  48. arch = "mips"
  49. elseif package:is_arch("ppc", "powerpc", "ppc64", "powerpc64") then
  50. arch = "powerpc"
  51. end
  52. assert(arch, "unknown arch(%s)!", package:arch())
  53. local cc = package:tool("cc")
  54. local cross = cc:gsub("%-gcc$", "-")
  55. make.make(package, {"ARCH=" .. arch, "CROSS_COMPILE=" .. cross, "allyesconfig"}, {curdir = installdir})
  56. make.make(package, {"ARCH=" .. arch, "CROSS_COMPILE=" .. cross, "modules_prepare"}, {curdir = installdir})
  57. else
  58. make.make(package, {"allyesconfig"}, {curdir = installdir})
  59. make.make(package, {"modules_prepare"}, {curdir = installdir})
  60. end
  61. os.rm(path.join(installdir, "source"))
  62. else
  63. os.vrunv("make", {"headers_install", "INSTALL_HDR_PATH=" .. package:installdir()})
  64. end
  65. end)
  66. on_test(function (package)
  67. assert(package:has_cincludes("linux/version.h"))
  68. end)