xmake.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package("libxml2")
  2. set_homepage("http://xmlsoft.org/")
  3. set_description("The XML C parser and toolkit of Gnome.")
  4. set_license("MIT")
  5. set_urls("http://xmlsoft.org/sources/libxml2-$(version).tar.gz",
  6. "https://ftp.osuosl.org/pub/blfs/conglomeration/libxml2/libxml2-$(version).tar.gz")
  7. add_urls("https://gitlab.gnome.org/GNOME/libxml2.git")
  8. add_versions("2.9.9", "94fb70890143e3c6549f265cee93ec064c80a84c42ad0f23e85ee1fd6540a871")
  9. add_versions("2.9.10", "aafee193ffb8fe0c82d4afef6ef91972cbaf5feea100edc2f262750611b4be1f")
  10. add_versions("2.9.12", "c8d6681e38c56f172892c85ddc0852e1fd4b53b4209e7f4ebf17f7e2eae71d92")
  11. add_patches("2.9.12", path.join(os.scriptdir(), "patches", "2.9.12", "msvc.patch"), "b978048ad1caf9c63e3b2eee685ea2e586812d80deb1e47b18ad2cae36edd201")
  12. add_configs("iconv", {description = "Enable libiconv support.", default = false, type = "boolean"})
  13. add_configs("python", {description = "Enable the python interface.", default = false, type = "boolean"})
  14. add_includedirs("include/libxml2")
  15. if is_plat("windows") then
  16. add_syslinks("ws2_32")
  17. else
  18. add_links("xml2")
  19. end
  20. if is_plat("linux") then
  21. add_extsources("pkgconfig::libxml-2.0", "apt::libxml2-dev", "pacman::libxml2")
  22. add_syslinks("m")
  23. end
  24. on_load("windows", "macosx", "linux", "iphoneos", "android", function (package)
  25. if package:is_plat("windows") then
  26. if not package:config("shared") then
  27. package:add("defines", "LIBXML_STATIC")
  28. end
  29. else
  30. if package:gitref() then
  31. package:add("deps", "autoconf", "automake", "libtool", "pkg-config")
  32. end
  33. end
  34. if package:config("python") then
  35. if not package:is_plat(os.host()) then
  36. raise("libxml2 python interface does not support cross-compilation")
  37. end
  38. if not package:config("iconv") then
  39. raise("libxml2 python interface requires iconv to be enabled")
  40. end
  41. package:add("deps", "python 3.x", {private = true})
  42. end
  43. if package:config("iconv") then
  44. package:add("deps", "libiconv")
  45. end
  46. end)
  47. on_install("windows", function (package)
  48. os.cd("win32")
  49. local args = {"configure.js", "iso8859x=yes", "zlib=no", "compiler=msvc"}
  50. table.insert(args, "cruntime=/" .. package:config("vs_runtime"))
  51. table.insert(args, "debug=" .. (package:debug() and "yes" or "no"))
  52. table.insert(args, "iconv=" .. (package:config("iconv") and "yes" or "no"))
  53. table.insert(args, "python=" .. (package:config("python") and "yes" or "no"))
  54. table.insert(args, "prefix=" .. package:installdir())
  55. if package:config("iconv") then
  56. table.insert(args, "include=" .. package:dep("libiconv"):installdir("include"))
  57. table.insert(args, "lib=" .. package:dep("libiconv"):installdir("lib"))
  58. end
  59. os.vrunv("cscript", args)
  60. import("package.tools.nmake").install(package, {"/f", "Makefile.msvc"})
  61. os.tryrm(path.join(package:installdir("bin"), "run*.exe"))
  62. os.tryrm(path.join(package:installdir("bin"), "test*.exe"))
  63. os.tryrm(path.join(package:installdir("lib"), "libxml2_a_dll.lib"))
  64. if package:config("shared") then
  65. os.tryrm(path.join(package:installdir("lib"), "libxml2_a.lib"))
  66. else
  67. os.tryrm(path.join(package:installdir("lib"), "libxml2.lib"))
  68. os.tryrm(path.join(package:installdir("bin"), "libxml2.dll"))
  69. end
  70. package:addenv("PATH", package:installdir("bin"))
  71. if package:config("python") then
  72. os.cd("../python")
  73. io.replace("setup.py", "/opt/include", package:dep("libiconv"):installdir("include"):gsub("\\", "\\\\"), {plain = true})
  74. io.replace("setup.py", "WITHDLLS = 1", "WITHDLLS = 0", {plain = true})
  75. if not package:config("shared") then
  76. io.replace("setup.py", "libdirs = [", format("libdirs = [\n'%s',", package:dep("libiconv"):installdir("lib"):gsub("\\", "\\\\")), {plain = true})
  77. io.replace("setup.py", "platformLibs = []", "platformLibs = ['iconv','wsock32','ws2_32']", {plain = true})
  78. io.replace("setup.py", "\"xml2\"", "\"xml2_a\"", {plain = true})
  79. io.replace("setup.py", "macros = []", "macros = [('LIBXML_STATIC','1')]", {plain = true})
  80. else
  81. os.cp(path.join(package:installdir("bin"), "libxml2.dll"), path.join(package:installdir("lib"), "site-packages", "libxml2.dll"))
  82. end
  83. os.vrun("python setup.py install --prefix=\"" .. package:installdir() .. "\"")
  84. package:addenv("PYTHONPATH", path.join(package:installdir("lib"), "site-packages"))
  85. end
  86. end)
  87. on_install("macosx", "linux", "iphoneos", "android", function (package)
  88. local configs = {"--disable-dependency-tracking",
  89. "--without-lzma",
  90. "--without-zlib"}
  91. if package:config("shared") then
  92. table.insert(configs, "--enable-shared=yes")
  93. table.insert(configs, "--enable-static=no")
  94. else
  95. table.insert(configs, "--enable-shared=no")
  96. table.insert(configs, "--enable-static=yes")
  97. end
  98. if package:config("iconv") then
  99. local iconvdir
  100. local iconv = package:dep("libiconv"):fetch()
  101. if iconv then
  102. iconvdir = table.wrap(iconv.sysincludedirs or iconv.includedirs)[1]
  103. end
  104. if iconvdir then
  105. table.insert(configs, "--with-iconv=" .. path.directory(iconvdir))
  106. else
  107. table.insert(configs, "--with-iconv")
  108. end
  109. else
  110. table.insert(configs, "--without-iconv")
  111. end
  112. if package:config("python") then
  113. table.insert(configs, "--with-python")
  114. else
  115. table.insert(configs, "--without-python")
  116. end
  117. if package:config("pic") ~= false then
  118. table.insert(configs, "--with-pic")
  119. end
  120. import("package.tools.autoconf").install(package, configs)
  121. package:addenv("PATH", package:installdir("bin"))
  122. if package:config("python") then
  123. os.cd("python")
  124. io.replace("setup.py", "\"/usr/include\",\n\"/usr/local/include\",\n\"/opt/include\",", "\"" .. package:dep("libiconv"):installdir("include") .. "\",", {plain = true})
  125. if not package:config("shared") then
  126. io.replace("setup.py", "libdirs = [", format("libdirs = [\n'%s',", package:dep("libiconv"):installdir("lib")), {plain = true})
  127. io.replace("setup.py", "platformLibs = [\"m\",\"z\"]", "platformLibs = [\"iconv\",\"m\"]", {plain = true})
  128. else
  129. io.replace("setup.py", "platformLibs = [\"m\",\"z\"]", "platformLibs = [\"m\"]", {plain = true})
  130. end
  131. os.vrun("python setup.py install --prefix=\"" .. package:installdir() .. "\"")
  132. local pythonver = package:dep("python"):version()
  133. package:addenv("PYTHONPATH", path.join(package:installdir("lib"), format("python%s.%s", pythonver:major(), pythonver:minor()), "site-packages"))
  134. end
  135. end)
  136. on_test(function (package)
  137. if package:config("python") then
  138. os.vrun("python3 -c \"import libxml2\"")
  139. end
  140. assert(package:has_cfuncs("xmlNewNode", {includes = {"libxml/parser.h", "libxml/tree.h"}}))
  141. end)