2
0

xmake.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package("funchook")
  2. set_homepage("https://github.com/kubo/funchook")
  3. set_description("Hook function calls by inserting jump instructions at runtime.")
  4. set_license("GPL-2.0-or-later")
  5. add_urls("https://github.com/kubo/funchook/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/kubo/funchook.git")
  7. add_versions("v1.1.3", "4b0195e70524237e222dc34c53ac25e12677bb936e64eefe33189931688444c4")
  8. add_patches("*", "patches/fix-build-system-deps.patch", "a39c8441e991851b3b0994088100f1b0751ccba4f4cc0ede73f95968ac873597")
  9. add_patches("*", "patches/fix-function-visibility.patch", "5b505ad24332320f3970a6cb56b5f550b01b9c80aa14cea0fea74ac77f1fc8f3")
  10. add_configs("disasm", {description = "Disassembler engine.", default = nil, type = "string", values = {"capstone", "distorm", "zydis"}})
  11. if is_plat("windows", "mingw") then
  12. add_syslinks("psapi")
  13. else
  14. add_syslinks("dl")
  15. end
  16. add_deps("cmake")
  17. if is_subhost("windows") then
  18. add_deps("pkgconf")
  19. else
  20. add_deps("pkg-config")
  21. end
  22. on_check(function (package)
  23. if package:is_arch("arm.*") and not package:is_arch("aarch64", "arm64") then
  24. raise("package(funchook): Unsupported arch.")
  25. end
  26. end)
  27. on_load(function(package)
  28. if not package:config("disasm") then
  29. -- default disasm engine.
  30. if package:is_arch("arm64") then
  31. package:add("deps", "capstone")
  32. else
  33. package:add("deps", "distorm")
  34. end
  35. else
  36. if package:config("disasm") == "zydis" then
  37. -- the latest commit updated to 4.x, but we must use 3.x for the current version.
  38. package:add("deps", "zydis 3.2.1")
  39. else
  40. package:add("deps", package:config("disasm"))
  41. end
  42. end
  43. end)
  44. on_install("windows", "linux", "macosx", "mingw", "msys", "cross", function (package)
  45. local configs = {"-DFUNCHOOK_BUILD_TESTS=OFF"}
  46. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  47. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  48. table.insert(configs, "-DFUNCHOOK_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  49. table.insert(configs, "-DFUNCHOOK_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  50. if package:config("disasm") then
  51. if package:is_arch("arm64") then
  52. table.insert(configs, "-DFUNCHOOK_DISASM=capstone")
  53. else
  54. table.insert(configs, "-DFUNCHOOK_DISASM=" .. package:config("disasm"))
  55. end
  56. end
  57. import("package.tools.cmake").install(package, configs)
  58. if package:config("shared") and package:is_plat("windows") then
  59. io.replace(path.join(package:installdir("include"), "funchook.h"),
  60. "#define FUNCHOOK_EXPORT __declspec(dllexport)",
  61. "#define FUNCHOOK_EXPORT __declspec(dllimport)", {plain = true})
  62. end
  63. end)
  64. on_test(function (package)
  65. assert(package:check_csnippets({test = [[
  66. void test() {
  67. funchook_t *funchook = funchook_create();
  68. }
  69. ]]}, {configs = {languages = "c99"}, includes = "funchook.h"}))
  70. end)