xmake.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package("elfutils")
  2. set_homepage("https://fedorahosted.org/elfutils/")
  3. set_description("Libraries and utilities for handling ELF objects")
  4. set_license("GPL-2.0")
  5. add_urls("https://github.com/xmake-mirror/elfutils/releases/download/elfutils-$(version)/elfutils-$(version).tar.bz2",
  6. "https://sourceware.org/elfutils/ftp/$(version)/elfutils-$(version).tar.bz2")
  7. add_versions("0.183", "c3637c208d309d58714a51e61e63f1958808fead882e9b607506a29e5474f2c5")
  8. add_versions("0.189", "39bd8f1a338e2b7cd4abc3ff11a0eddc6e690f69578a57478d8179b4148708c8")
  9. add_versions("0.190", "8e00a3a9b5f04bc1dc273ae86281d2d26ed412020b391ffcc23198f10231d692")
  10. add_patches("0.183", path.join(os.scriptdir(), "patches", "0.183", "configure.patch"), "7a16719d9e3d8300b5322b791ba5dd02986f2663e419c6798077dd023ca6173a")
  11. add_patches("0.189", path.join(os.scriptdir(), "patches", "0.189", "configure.patch"), "b4016a97e6aaad92b15fad9a594961b1fc77a6d054ebadedef9bb3a55e99a8f8")
  12. add_patches("0.190", path.join(os.scriptdir(), "patches", "0.190", "configure.patch"), "8118132b8499ba54b0dbed823295d17f79670060c2cee9f3a186ce966bed9a75")
  13. add_configs("libelf", {description = "Enable libelf", default = true, type = "boolean"})
  14. add_configs("libdw", {description = "Enable libdw", default = true, type = "boolean"})
  15. add_configs("libasm", {description = "Enable libasm", default = false, type = "boolean"})
  16. add_deps("m4", "zstd", "zlib")
  17. if on_source then
  18. on_source(function (package)
  19. if package:is_plat("android") then
  20. package:add("configs", "shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  21. end
  22. end)
  23. elseif is_plat("android") then
  24. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  25. end
  26. on_load(function(package)
  27. if package:is_plat("android") then
  28. package:add("deps", "libintl", "argp-standalone")
  29. end
  30. end)
  31. if on_check then
  32. -- https://github.com/xmake-io/xmake-repo/issues/3182
  33. on_check("android", function (package)
  34. local ndk = package:toolchain("ndk")
  35. local ndk_sdkver = ndk:config("ndk_sdkver")
  36. local ndkver = ndk:config("ndkver")
  37. assert(ndkver and tonumber(ndkver) < 26, "package(elfutils): need ndk version < 26 for android")
  38. assert(ndk_sdkver and tonumber(ndk_sdkver) <= 23, "package(elfutils): need ndk api level <= 23 for android")
  39. end)
  40. end
  41. on_install("linux", "android", function (package)
  42. local configs = {"--disable-dependency-tracking",
  43. "--disable-silent-rules",
  44. "--program-prefix=elfutils-",
  45. "--disable-symbol-versioning",
  46. "--disable-debuginfod",
  47. "--disable-libdebuginfod"}
  48. local cflags = {}
  49. for _, makefile in ipairs(os.files(path.join("*/Makefile.in"))) do
  50. io.replace(makefile, "-Wtrampolines", "", {plain = true})
  51. io.replace(makefile, "-Wimplicit-fallthrough=5", "", {plain = true})
  52. io.replace(makefile, "-Werror", "", {plain = true})
  53. if package:has_tool("cc", "clang") then
  54. io.replace(makefile, "-Wno-packed-not-aligned", "", {plain = true})
  55. end
  56. end
  57. local subdirs = {}
  58. if package:config("libelf") then
  59. table.insert(subdirs, "libelf")
  60. end
  61. if package:config("libdw") then
  62. table.join2(subdirs, "libcpu", "backends", "libebl", "libdwelf", "libdwfl", "libdw")
  63. end
  64. if package:config("libasm") then
  65. table.insert(subdirs, "libasm")
  66. end
  67. io.replace("Makefile.in", [[SUBDIRS = config lib libelf libcpu backends libebl libdwelf libdwfl libdw \
  68. libasm debuginfod src po doc tests]], "SUBDIRS = lib " .. table.concat(subdirs, " "), {plain = true})
  69. if package:is_plat("android") then
  70. io.replace("libelf/Makefile.in", "-Wl,--whole-archive $(libelf_so_LIBS) -Wl,--no-whole-archive", "$(libelf_so_LIBS)", {plain = true})
  71. io.replace("libdw/Makefile.in", "-Wl,--whole-archive $(libdw_so_LIBS) -Wl,--no-whole-archive", "$(libdw_so_LIBS)", {plain = true})
  72. io.replace("libasm/Makefile.in", "-Wl,--whole-archive $(libasm_so_LIBS) -Wl,--no-whole-archive", "$(libasm_so_LIBS)", {plain = true})
  73. table.insert(cflags, "-Wno-error=conditional-type-mismatch")
  74. table.insert(cflags, "-Wno-error=unused-command-line-argument")
  75. table.insert(cflags, "-Wno-error=implicit-function-declaration")
  76. table.insert(cflags, "-Wno-error=int-conversion")
  77. table.insert(cflags, "-Wno-error=gnu-variable-sized-type-not-at-end")
  78. table.insert(cflags, '-Dprogram_invocation_short_name=\\\"test\\\"')
  79. table.insert(cflags, '-D_GNU_SOURCE=1')
  80. end
  81. local packagedeps = {"zlib"}
  82. if package:is_plat("android") then
  83. table.join2(packagedeps, "libintl", "argp-standalone")
  84. end
  85. import("package.tools.autoconf").install(package, configs, {cflags = cflags,
  86. packagedeps = packagedeps})
  87. if package:config("shared") then
  88. os.rm(path.join(package:installdir("lib"), "*.a"))
  89. else
  90. os.rm(path.join(package:installdir("lib"), "*.so"))
  91. os.tryrm(path.join(package:installdir("lib"), "*.so.*"))
  92. end
  93. os.trycp("libelf/elf.h", package:installdir("include"))
  94. end)
  95. on_test(function (package)
  96. assert(package:has_cfuncs("elf_begin", {includes = "gelf.h"}))
  97. end)