xmake.lua 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package("libselinux")
  2. set_homepage("https://github.com/SELinuxProject/selinux")
  3. set_description("SELinux library and simple utilities.")
  4. add_urls("https://github.com/SELinuxProject/selinux/releases/download/$(version)/libselinux-$(version).tar.gz")
  5. add_versions("3.9", "e7ee2c01dba64a0c35c9d7c9c0e06209d8186b325b0638a0d83f915cc3c101e8")
  6. add_configs("utils", {description = "Build utilities.", default = true, type = "boolean"})
  7. add_configs("setrans", {description = "Enable selinux translation daemon support.", default = true, type = "boolean"})
  8. add_configs("rpm", {description = "Enable rpm_execcon support.", default = true, type = "boolean"})
  9. add_configs("bool", {description = "Enable selinux boolean support.", default = true, type = "boolean"})
  10. add_configs("x11", {description = "Enable X11 media context support.", default = true, type = "boolean"})
  11. add_configs("pcre2", {description = "Enable use of pcre2.", default = true, type = "boolean"})
  12. add_configs("lfs", {description = "Enable large file support.", default = true, type = "boolean"})
  13. on_load(function (package)
  14. package:add("deps", "libsepol >=" .. package:version_str())
  15. if package:config("pcre2") then
  16. package:add("deps", "pcre2")
  17. end
  18. end)
  19. on_install("linux", function (package)
  20. import("package.tools.make")
  21. local configs = {"PREFIX="}
  22. table.insert(configs, "DEBUG=" .. (package:is_debug() and "1" or "0"))
  23. table.insert(configs, "DESTDIR=" .. package:installdir())
  24. table.insert(configs, "DISABLE_SETRANS=" .. (package:config("setrans") and "n" or "y"))
  25. table.insert(configs, "DISABLE_RPM=" .. (package:config("rpm") and "n" or "y"))
  26. table.insert(configs, "DISABLE_BOOL=" .. (package:config("bool") and "n" or "y"))
  27. table.insert(configs, "DISABLE_X11=" .. (package:config("x11") and "n" or "y"))
  28. table.insert(configs, "USE_PCRE2=" .. (package:config("pcre2") and "y" or "n"))
  29. table.insert(configs, "USE_LFS=" .. (package:config("lfs") and "y" or "n"))
  30. local subdirs = {"include", "src"}
  31. if package:config("utils") then
  32. table.insert(subdirs, "utils")
  33. end
  34. table.insert(configs, "DISABLE_SHARED=" .. (package:config("shared") and "n" or "y"))
  35. if package:config("shared") then
  36. -- io.replace("src/Makefile", "all: $(LIBA)", "all:", {plain = true})
  37. io.replace("src/Makefile", "install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)", "", {plain = true})
  38. end
  39. -- fix pkg-config
  40. io.replace("src/Makefile", "s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):", "s:@prefix@:$(DESTDIR):; s:@libdir@:$(DESTDIR)$(LIBDIR):; s:@includedir@:$(DESTDIR)$(INCLUDEDIR):", {plain = true})
  41. local envs = make.buildenvs(package)
  42. local cflags = {}
  43. local ldflags = {}
  44. for _, dep in ipairs(package:orderdeps()) do
  45. local fetchinfo = dep:fetch()
  46. if fetchinfo then
  47. for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  48. table.insert(cflags, "-I" .. includedir)
  49. end
  50. for _, linkdir in ipairs(fetchinfo.linkdirs) do
  51. table.insert(ldflags, "-L" .. linkdir)
  52. end
  53. end
  54. end
  55. if package:config("pic") then
  56. table.insert(cflags, "-fPIC")
  57. end
  58. envs.CFLAGS = envs.CFLAGS .. " " .. table.concat(cflags, " ")
  59. envs.LDFLAGS = envs.LDFLAGS .. " " .. table.concat(ldflags, " ")
  60. table.insert(configs, "SUBDIRS=" .. table.concat(subdirs, " "))
  61. make.build(package, configs, {envs = envs})
  62. table.insert(configs, "install")
  63. make.make(package, configs, {envs = envs})
  64. end)
  65. on_test(function (package)
  66. assert(package:has_cfuncs("is_selinux_enabled", {includes = {"selinux/selinux.h"}}))
  67. end)