xmake.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package("libiconv")
  2. set_homepage("https://www.gnu.org/software/libiconv")
  3. set_description("Character set conversion library.")
  4. set_urls("https://ftpmirror.gnu.org/gnu/libiconv/libiconv-$(version).tar.gz",
  5. "https://ftp.gnu.org/gnu/libiconv/libiconv-$(version).tar.gz")
  6. add_versions("1.17", "8f74213b56238c85a50a5329f77e06198771e70dd9a739779f4c02f65d971313")
  7. add_versions("1.16", "e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04")
  8. add_versions("1.15", "ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc8913178")
  9. if is_plat("macosx") then
  10. add_patches("1.15", path.join(os.scriptdir(), "patches", "1.15", "patch-utf8mac.diff"),
  11. "e8128732f22f63b5c656659786d2cf76f1450008f36bcf541285268c66cabeab")
  12. elseif is_plat("android") then
  13. add_patches("1.x", path.join(os.scriptdir(), "patches", "1.16", "makefile.in.patch"),
  14. "d09e4212040f5adf1faa5cf5a9a18f6f79d4cdce9affb05f2e75df2ea3b3d686")
  15. elseif is_plat("wasm") then
  16. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  17. end
  18. on_fetch("macosx", "linux", function (package, opt)
  19. if opt.system then
  20. if package:is_plat("linux") and package:has_tool("cc", "gcc", "gxx") then
  21. return {} -- on linux libiconv is already a part of glibc
  22. else
  23. return package:find_package("system::iconv", {includes = "iconv.h"})
  24. end
  25. end
  26. end)
  27. on_load(function (package)
  28. package:addenv("PATH", "bin")
  29. end)
  30. on_install("windows", "mingw", function (package)
  31. io.gsub("config.h.in", "%$", "")
  32. io.gsub("config.h.in", "# ?undef (.-)\n", "${define %1}\n")
  33. io.gsub("libcharset/config.h.in", "%$", "")
  34. io.gsub("libcharset/config.h.in", "# ?undef (.-)\n", "${define %1}\n")
  35. io.gsub("srclib/safe-read.c", "#include <unistd.h>", "")
  36. io.gsub("srclib/progreloc.c", "#include <unistd.h>", "")
  37. os.cp(path.join(os.scriptdir(), "port", "xmake.lua"), ".")
  38. import("package.tools.xmake").install(package, {
  39. relocatable = true,
  40. installprefix = package:installdir():gsub("\\", "\\\\"),
  41. vers = package:version_str()
  42. })
  43. end)
  44. on_install("macosx", "linux", "bsd", "cross", "android", "wasm", function (package)
  45. local configs = {"--disable-dependency-tracking", "--enable-extra-encodings", "--enable-relocatable"}
  46. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  47. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  48. if package:debug() then
  49. table.insert(configs, "--enable-debug")
  50. end
  51. if package:is_plat("android") then
  52. io.replace("./configure", "#define gid_t int", "")
  53. io.replace("./configure", "#define uid_t int", "")
  54. end
  55. os.vrunv("make", {"-f", "Makefile.devel", "CFLAGS=" .. (package:config("cflags") or "")})
  56. import("package.tools.autoconf").install(package, configs)
  57. end)
  58. on_test(function (package)
  59. if package:is_plat("linux", "bsd") or (package:is_plat("macosx") and not package:config("shared")) then
  60. os.vrun("iconv --version")
  61. end
  62. assert(package:check_csnippets({test = [[
  63. #include "iconv.h"
  64. void test() {
  65. char charset[5] = "12345";
  66. iconv_t cd = iconv_open("WCHAR_T", charset);
  67. }
  68. ]]}))
  69. end)