xmake.lua 3.6 KB

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