xmake.lua 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package("binutils")
  2. set_kind("binary")
  3. set_homepage("https://www.gnu.org/software/binutils/binutils.html")
  4. set_description("GNU binary tools for native development")
  5. set_license("GPL-2.0")
  6. set_urls("https://ftp.gnu.org/gnu/binutils/binutils-$(version).tar.xz",
  7. "https://mirrors.ustc.edu.cn/gnu/binutils/binutils-$(version).tar.xz",
  8. "https://mirror.csclub.uwaterloo.ca/gnu/binutils/binutils-$(version).tar.xz")
  9. add_versions("2.45", "c50c0e7f9cb188980e2cc97e4537626b1672441815587f1eab69d2a1bfbef5d2")
  10. add_versions("2.41", "ae9a5789e23459e59606e6714723f2d3ffc31c03174191ef0d015bdf06007450")
  11. add_versions("2.38", "e316477a914f567eccc34d5d29785b8b0f5a10208d36bbacedcc39048ecfe024")
  12. add_versions("2.34", "f00b0e8803dc9bab1e2165bd568528135be734df3fabf8d0161828cd56028952")
  13. if is_plat("mingw") and is_subhost("msys") then
  14. add_extsources("pacman::binutils")
  15. elseif is_plat("linux") then
  16. add_extsources("pacman::binutils", "apt::binutils")
  17. elseif is_plat("macosx") then
  18. add_extsources("brew::binutils")
  19. end
  20. on_fetch("@linux", "@macosx", "@msys", function (package, opt)
  21. if opt.system then
  22. if package:is_binary() then
  23. local tools = {"ld", "ranlib", "objcopy"}
  24. for _, tool in ipairs(tools) do
  25. if not package:find_tool(tool) then
  26. return
  27. end
  28. end
  29. return {}
  30. elseif package:is_library() then
  31. local libs = {"bfd", "ctf", "opcodes"}
  32. local result
  33. for _, lib in ipairs(libs) do
  34. local libinfo = package:find_package("system::" .. lib)
  35. if libinfo then
  36. result = result or {links = {}}
  37. table.insert(result.links, libinfo.links)
  38. end
  39. end
  40. return result
  41. end
  42. end
  43. end)
  44. add_deps("bison")
  45. on_install("@linux", "@macosx", "@msys", function (package)
  46. local configs = {"--disable-debug",
  47. "--disable-dependency-tracking",
  48. "--enable-deterministic-archives",
  49. "--infodir=" .. package:installdir("share/info"),
  50. "--mandir=" .. package:installdir("share/man"),
  51. "--disable-werror",
  52. "--enable-interwork",
  53. "--enable-multilib",
  54. "--enable-64-bit-bfd",
  55. "--enable-targets=all"}
  56. if package:is_plat("linux") then
  57. table.insert(configs, "--with-sysroot=/")
  58. table.insert(configs, "--enable-gold")
  59. table.insert(configs, "--enable-plugins")
  60. end
  61. -- fix 'makeinfo' is missing on your system.
  62. io.replace("binutils/Makefile.in", "SUBDIRS =[^\n]-po", "SUBDIRS =")
  63. io.replace("gas/Makefile.in", "INFO_DEPS =[^\n]-%.info", "INFO_DEPS =")
  64. if package:version():le("2.34") then
  65. -- fix multiple definition of `program_name'
  66. io.replace("binutils/srconv.c", "char *program_name;", "extern char *program_name;", {plain = true})
  67. io.replace("binutils/sysdump.c", "char *program_name;", "extern char *program_name;", {plain = true})
  68. io.replace("binutils/coffdump.c", "char * program_name;", "extern char *program_name;", {plain = true})
  69. end
  70. -- fix fdopen conflicts
  71. if package:is_plat("macosx") then
  72. io.replace("zlib/zutil.h", "ifndef fdopen", "if !defined(fdopen) && (__DARWIN_C_LEVEL < 198808L)", {plain = true})
  73. end
  74. import("package.tools.autoconf").install(package, configs)
  75. end)
  76. on_test(function (package)
  77. os.vrun("strings --version")
  78. end)