xmake.lua 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package("icu4c")
  2. set_homepage("http://site.icu-project.org/")
  3. set_description("C/C++ libraries for Unicode and globalization.")
  4. add_urls("https://github.com/unicode-org/icu/releases/download/release-$(version)-src.tgz", {version = function (version)
  5. return (version:gsub("%.", "-")) .. "/icu4c-" .. (version:gsub("%.", "_"))
  6. end})
  7. add_versions("77.1", "588e431f77327c39031ffbb8843c0e3bc122c211374485fa87dc5f3faff24061")
  8. add_versions("76.1", "dfacb46bfe4747410472ce3e1144bf28a102feeaa4e3875bac9b4c6cf30f4f3e")
  9. add_versions("75.1", "cb968df3e4d2e87e8b11c49a5d01c787bd13b9545280fc6642f826527618caef")
  10. add_versions("73.2", "818a80712ed3caacd9b652305e01afc7fa167e6f2e94996da44b90c2ab604ce1")
  11. add_versions("73.1", "a457431de164b4aa7eca00ed134d00dfbf88a77c6986a10ae7774fc076bb8c45")
  12. add_versions("72.1", "a2d2d38217092a7ed56635e34467f92f976b370e20182ad325edea6681a71d68")
  13. add_versions("71.1", "67a7e6e51f61faf1306b6935333e13b2c48abd8da6d2f46ce6adca24b1e21ebf")
  14. add_versions("70.1", "8d205428c17bf13bb535300669ed28b338a157b1c01ae66d31d0d3e2d47c3fd5")
  15. add_versions("69.1", "4cba7b7acd1d3c42c44bb0c14be6637098c7faf2b330ce876bc5f3b915d09745")
  16. add_versions("68.2", "c79193dee3907a2199b8296a93b52c5cb74332c26f3d167269487680d479d625")
  17. add_versions("68.1", "a9f2e3d8b4434b8e53878b4308bd1e6ee51c9c7042e2b1a376abefb6fbb29f2d")
  18. add_versions("64.2", "627d5d8478e6d96fc8c90fed4851239079a561a6a8b9e48b0892f24e82d31d6c")
  19. add_patches("69.1", path.join(os.scriptdir(), "patches", "69.1", "replace-py-3.patch"), "ae27a55b0e79a8420024d6d349a7bae850e1dd403a8e1131e711c405ddb099b9")
  20. add_patches("70.1", path.join(os.scriptdir(), "patches", "70.1", "replace-py-3.patch"), "6469739da001721122b62af513370ed62901caf43af127de3f27ea2128830e35")
  21. if is_plat("mingw") and is_subhost("msys") then
  22. add_extsources("pacman::icu")
  23. elseif is_plat("linux") then
  24. add_extsources("pacman::icu", "apt::libicu-dev")
  25. elseif is_plat("macosx") then
  26. add_extsources("brew::icu4c")
  27. end
  28. add_configs("tools", {description = "Build tools.", default = false, type = "boolean"})
  29. if is_plat("windows") then
  30. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  31. end
  32. if is_plat("linux") then
  33. add_syslinks("dl")
  34. end
  35. on_load(function (package)
  36. if package:is_plat("mingw", "msys", "cygwin") then
  37. package:add("patches", ">=69.1", path.join(os.scriptdir(), "patches", "72.1", "mingw.patch"), "9ddbe7f691224ccf69f8c0218f788f0a39ab8f1375cc9aad2cc92664ffcf46a5")
  38. end
  39. if package:is_cross() then
  40. package:add("deps", "icu4c~host", {kind = "binary", private = true})
  41. else
  42. package:addenv("PATH", "bin")
  43. end
  44. if package:is_plat("windows") then
  45. if package:config("tools") then
  46. package:add("deps", "python 3.x", {kind = "binary"})
  47. end
  48. if package:has_runtime("MTd", "MDd") then
  49. wprint("MTd/MDd runtime force to use debug package")
  50. package:config_set("debug", true)
  51. end
  52. end
  53. local libsuffix = package:is_debug() and package:is_plat("windows", "mingw", "msys", "cygwin") and "d" or ""
  54. package:add("links", "icutu" .. libsuffix, "icuio" .. libsuffix)
  55. if package:is_plat("windows", "mingw", "msys", "cygwin") then
  56. package:add("links", "icuin" .. libsuffix, "icuuc" .. libsuffix, "icudt" .. libsuffix)
  57. else
  58. package:add("links", "icui18n" .. libsuffix, "icuuc" .. libsuffix, "icudata" .. libsuffix)
  59. end
  60. end)
  61. on_install("windows", function (package)
  62. import("package.tools.msbuild")
  63. if not package:is_cross() and package:is_arch("arm64") then
  64. -- Build file always find pkgdata from bin64
  65. io.replace("source/extra/uconv/makedata.mak", "bin64", "binARM64", {plain = true})
  66. end
  67. if package:has_runtime("MT", "MTd") then
  68. local files = {
  69. "source/common/common.vcxproj",
  70. "source/i18n/i18n.vcxproj",
  71. "source/extra/uconv/uconv.vcxproj",
  72. "source/io/io.vcxproj",
  73. "source/stubdata/stubdata.vcxproj",
  74. }
  75. for _, vcxproj in ipairs(files) do
  76. io.replace(vcxproj, "MultiThreadedDLL", "MultiThreaded", {plain = true})
  77. io.replace(vcxproj, "MultiThreadedDebugDLL", "MultiThreadedDebug", {plain = true})
  78. end
  79. end
  80. local projectfiles = os.files("source/**.vcxproj")
  81. local sln = path.join("source", "allinone", "allinone.sln")
  82. table.join2(projectfiles, sln, os.files("source/**.props"))
  83. local suffix = package:is_arch("arm.*") and "ARM" or ""
  84. if package:is_arch64() then
  85. suffix = suffix .. "64"
  86. end
  87. if package:is_binary() then
  88. local configs = {
  89. sln,
  90. "/p:Configuration=Release",
  91. "/target:pkgdata,genrb"
  92. }
  93. msbuild.build(package, configs, {upgrade = projectfiles})
  94. os.vcp("bin" .. suffix .. "/*", package:installdir("bin"))
  95. return
  96. elseif package:is_cross() then
  97. local arch_prev = package:arch()
  98. package:arch_set(os.arch())
  99. local host_suffix = package:is_arch("arm.*") and "ARM" or ""
  100. if package:is_arch64() then
  101. host_suffix = host_suffix .. "64"
  102. end
  103. package:arch_set(arch_prev)
  104. os.vcp(package:dep("icu4c"):installdir("bin/*"), "bin" .. host_suffix .. "/")
  105. end
  106. local configs = {
  107. sln,
  108. "/p:SkipUWP=True",
  109. "/p:_IsNativeEnvironment=true",
  110. }
  111. if not package:config("tools") then
  112. table.insert(configs, "/target:common,i18n,uconv,io,stubdata")
  113. end
  114. msbuild.build(package, configs, {upgrade = projectfiles})
  115. os.vcp("include", package:installdir())
  116. os.vcp("bin" .. suffix .. "/*", package:installdir("bin"))
  117. os.vcp("lib" .. suffix .. "/*", package:installdir("lib"))
  118. end)
  119. on_install("@!windows and !wasm", function (package)
  120. if package:version() and package:is_plat("macosx") then
  121. local file_path = path.join("source", "common", "uposixdefs.h")
  122. if package:version():eq("77.1") then
  123. io.replace(
  124. file_path,
  125. "#ifdef _XOPEN_SOURCE",
  126. "#if 1 // #ifdef _XOPEN_SOURCE",
  127. {plain = true}
  128. )
  129. io.replace(
  130. file_path,
  131. "#define _POSIX_C_SOURCE 200809L",
  132. "// #define _POSIX_C_SOURCE 200809L",
  133. {plain = true}
  134. )
  135. end
  136. end
  137. import("package.tools.autoconf")
  138. os.cd("source")
  139. if is_host("macosx") then
  140. -- On Mac OS X, the echo command does not support the -n option
  141. -- @see https://unicode-org.atlassian.net/browse/ICU-22418
  142. local mkfiles = {"Makefile.in"}
  143. table.join2(mkfiles, os.files("config/mh-*"))
  144. for _, mkfile in ipairs(mkfiles) do
  145. io.replace(mkfile, "@echo%s+-n%s+\"", "@printf \"") -- replace @echo -n with @printf
  146. end
  147. end
  148. local configs = {"--disable-samples", "--disable-tests"}
  149. if package:is_debug() then
  150. table.insert(configs, "--enable-debug")
  151. table.insert(configs, "--disable-release")
  152. end
  153. if package:config("shared") then
  154. table.insert(configs, "--enable-shared")
  155. table.insert(configs, "--disable-static")
  156. else
  157. table.insert(configs, "--disable-shared")
  158. table.insert(configs, "--enable-static")
  159. end
  160. if package:is_plat("mingw", "msys", "cygwin") then
  161. table.insert(configs, "--with-data-packaging=dll")
  162. elseif package:is_plat("iphoneos") then
  163. table.insert(configs, "--disable-tools")
  164. end
  165. if package:is_cross() then
  166. table.insert(configs, "--with-cross-build=" .. path.unix(package:dep("icu4c"):installdir()))
  167. end
  168. local envs = {}
  169. local cxxflags = "-std=gnu++17"
  170. if package:is_plat("linux") and package:config("pic") ~= false then
  171. envs = autoconf.buildenvs(package, {cxflags = "-fPIC", cxxflags = cxxflags})
  172. else
  173. envs = autoconf.buildenvs(package, {cxxflags = cxxflags})
  174. end
  175. -- suppress ar errors when passing --toolchain=clang
  176. envs.ARFLAGS = nil
  177. autoconf.install(package, configs, {envs = envs})
  178. if not package:is_cross() then
  179. os.trycp("config/icucross.mk", package:installdir("config"))
  180. os.trycp("config/icucross.inc", package:installdir("config"))
  181. os.trycp("bin/icupkg*", package:installdir("bin"))
  182. end
  183. end)
  184. on_test(function (package)
  185. if package:is_library() then
  186. assert(package:has_cfuncs("ucnv_convert", {includes = "unicode/ucnv.h"}))
  187. end
  188. end)