xmake.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package("libsystemd")
  2. set_homepage("https://systemd.io")
  3. set_description("The systemd System and Service Manager.")
  4. add_urls("https://github.com/systemd/systemd/archive/refs/tags/$(version).tar.gz",
  5. "https://github.com/systemd/systemd.git")
  6. add_versions("v258.1", "8eb34eaf2f78330217280bd7a923578f37e28d3f3ac5168e336ebc9cad84a34d")
  7. add_versions("v258", "07a580cf21856f468f82b77b82973a926f42ccc696462459b53f8b88893dff8e")
  8. add_configs("udev", {description = "Build libudev.", default = true, type = "boolean"})
  9. add_configs("acl", {description = "Enable libacl support.", default = true, type = "boolean"})
  10. add_configs("audit", {description = "Enable libaudit support.", default = true, type = "boolean"})
  11. add_configs("blkid", {description = "Enable libblkid support.", default = true, type = "boolean"})
  12. add_configs("kmod", {description = "Enable support for loadable modules.", default = true, type = "boolean"})
  13. add_configs("pam", {description = "Enable PAM support.", default = true, type = "boolean"})
  14. add_configs("gcrypt", {description = "Enable gcrypt support.", default = true, type = "boolean"})
  15. add_configs("openssl", {description = "Enable openssl support.", default = "openssl3", type = "string", values = {false, "openssl", "openssl3"}})
  16. add_configs("p11kit", {description = "Enable p11kit support.", default = true, type = "boolean"})
  17. add_configs("xz", {description = "Enable xz compression support.", default = true, type = "boolean"})
  18. add_configs("lz4", {description = "Enable lz4 compression support.", default = true, type = "boolean"})
  19. add_configs("zstd", {description = "Enable zstd compression support.", default = true, type = "boolean"})
  20. add_configs("libmount", {description = "Enable lib support", default = true, type = "boolean"})
  21. add_configs("seccomp", {description = "Enable SECCOMP support.", default = true, type = "boolean"})
  22. add_configs("selinux", {description = "Enable SELinux support.", default = true, type = "boolean"})
  23. add_deps("python", {kind = "binary"})
  24. add_deps("libcap", "libxcrypt")
  25. on_load(function(package)
  26. if package:config("udev") then
  27. package:add("syslinks", "rt", "pthread")
  28. end
  29. function install_deps(opt, dep)
  30. dep = dep or opt
  31. if package:config(opt) then
  32. package:add("deps", dep)
  33. end
  34. end
  35. install_deps("acl")
  36. install_deps("audit")
  37. install_deps("kmod", "libkmod")
  38. install_deps("pam", "libpam")
  39. install_deps("gcrypt", "libgcrypt")
  40. install_deps("p11kit", "p11-kit")
  41. install_deps("xz")
  42. install_deps("lz4")
  43. install_deps("zstd")
  44. install_deps("seccomp", "libseccomp")
  45. install_deps("selinux", "libselinux")
  46. local openssl = package:config("openssl")
  47. if openssl and openssl ~= "disabled" then
  48. package:add("deps", openssl)
  49. end
  50. local util_linux_cfg = {}
  51. if package:config("blkid") then
  52. util_linux_cfg.libblkid = true
  53. end
  54. if package:config("libmount") then
  55. util_linux_cfg.libmount = true
  56. end
  57. if not table.empty(util_linux_cfg) then
  58. package:add("deps", "util-linux", {configs = util_linux_cfg})
  59. end
  60. end)
  61. on_install("linux", function (package)
  62. local buildscript = ""
  63. for _, line in ipairs(io.readfile("meson.build"):split("\n")) do
  64. if not line:startswith("runtest_env = custom_target(") then
  65. buildscript = buildscript .. line .. "\n"
  66. else
  67. break
  68. end
  69. end
  70. buildscript = buildscript:gsub("subdir%('catalog'%)", "")
  71. buildscript = buildscript:gsub("subdir%('po'%)", "")
  72. buildscript = buildscript:gsub("libsystemd = shared_library", "if static_libsystemd == 'false'\nlibsystemd = shared_library")
  73. buildscript = buildscript:gsub("libudev = shared_library", "if static_libudev == 'false'\nlibudev = shared_library")
  74. buildscript = buildscript:gsub("install_dir : libdir%)", "install_dir : libdir) endif")
  75. buildscript = buildscript:gsub("alias_target%b()", "")
  76. buildscript = buildscript .. "subdir('src/systemd')\n"
  77. if not package:config("udev") then
  78. buildscript = buildscript:gsub("subdir%('src/libudev'%)", "")
  79. buildscript = buildscript:gsub("static_libudev == 'false'", "false")
  80. buildscript = buildscript:gsub("static_libudev != 'false'", "false")
  81. end
  82. io.writefile("meson.build", buildscript)
  83. local configs = {"-Dtests=false"}
  84. table.insert(configs, "-Dmode=" .. (package:is_debug() and "developer" or "release"))
  85. if package:config("shared") then
  86. table.insert(configs, "-Dstatic-libsystemd=false")
  87. table.insert(configs, "-Dstatic-libudev=false")
  88. else
  89. table.insert(configs, "-Dstatic-libsystemd=" .. (package:config("pic") and "pic" or "no-pic"))
  90. table.insert(configs, "-Dstatic-libudev=" .. (package:config("pic") and "pic" or "no-pic"))
  91. end
  92. local sd_configs = {
  93. "acl", "audit", "blkid", "kmod", "pam", "gcrypt", "p11kit", "xz", "lz4", "zstd"
  94. }
  95. for _, sd_config in ipairs(sd_configs) do
  96. table.insert(configs, "-D" .. sd_config .. "=" .. (package:config(sd_config) and "enabled" or "disabled"))
  97. end
  98. io.replace("src/shared/meson.build", "install : true,", "build_by_default : false,", {plain = true})
  99. os.vrun("python -m pip install jinja2")
  100. local packagedeps = {"libcap"}
  101. if package:config("audit") then
  102. table.insert(packagedeps, "audit")
  103. end
  104. if package:config("gcrypt") then
  105. table.insert(packagedeps, "libgcrypt")
  106. table.insert(packagedeps, "libgpg-error")
  107. end
  108. local cflags = {}
  109. if package:config("kmod") then
  110. local info = package:dep("libkmod"):fetch()
  111. for _, includedir in ipairs(info.includedirs or info.sysincludedirs) do
  112. table.insert(cflags, "-I" .. includedir)
  113. end
  114. end
  115. import("package.tools.meson").install(package, configs, {packagedeps = packagedeps, cflags = cflags})
  116. end)
  117. on_test(function (package)
  118. assert(package:has_cfuncs("sd_watchdog_enabled", {includes = "systemd/sd-daemon.h"}))
  119. if package:config("udev") then
  120. assert(package:has_cfuncs("udev_new", {includes = "libudev.h"}))
  121. end
  122. end)