xmake.lua 5.3 KB

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