xmake.lua 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package("openssl")
  2. set_homepage("https://www.openssl.org/")
  3. set_description("A robust, commercial-grade, and full-featured toolkit for TLS and SSL.")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_$(version).zip", {version = function (version)
  6. return version:gsub("^(%d+)%.(%d+)%.(%d+)-?(%a*)$", "%1_%2_%3%4")
  7. end, excludes = "*/fuzz/*"})
  8. add_versions("1.1.1-w", "c543d84c06e909bfa862d5256f6d9dad502352a580b1193ae262874e4be4d7f7")
  9. add_versions("1.1.1-t", "9422774f3ce0f9cb4db5d862efbf43b4fcc096b37b4ac7157e7c5172113a8a22")
  10. add_patches("1.1.1-t", path.join(os.scriptdir(), "patches", "1.1.1t.diff"), "8009edde46e5577213212ec68f8a40451ceb514fddd892240b1465213b7d2d11")
  11. add_versions("1.1.1-s", "aa76dc0488bc67f5c964d085e37a0f5f452e45c68967816a336fa00f537f5cc5")
  12. add_versions("1.1.1-r", "20af2fac5dff04e71c2f2d6729ee84befbea741e3aaeba18a1a541e04f3f1997")
  13. add_versions("1.1.1-q", "df86e6adcff1c91a85cef139dd061ea40b7e49005e8be16522cf4864bfcf5eb8")
  14. add_patches("1.1.1-q", path.join(os.scriptdir(), "patches", "1.1.1q.diff"), "cfe6929f9db2719e695be0b61f8c38fe8132544c5c58ca8d07383bfa6c675b7b")
  15. add_versions("1.1.1-p", "7fe975ffe91d8343ebd021059eeea3c6b1d236c3826b3a08ef59fcbe75069f5b")
  16. add_patches("1.1.1-p", path.join(os.scriptdir(), "patches", "1.1.1p.diff"), "f102fed5867e143ae3ace1febd0b2725358c614c86328e68022f1ea21491b42c")
  17. add_versions("1.1.1-o", "1cd761790cf576e7f45c17798c47064f0f6756d4fcdbc1e657b0a4d9c60f3a52")
  18. add_versions("1.1.1-n", "614d69141fd622bc3db2adf7c824eaa19c7e532937b2cd7144b850d692f9f150")
  19. add_versions("1.1.1-m", "dab2287910427d82674618d512ba2571401539ca6ed12ab3c3143a0db9fad542")
  20. add_versions("1.1.1-l", "23d8908e82b63af754018256a4eb02f13965f10067969f6a63f497960c11dbeb")
  21. add_versions("1.1.1-k", "255c038f5861616f67b527434475d226f5fe00522fbd21fafd3df32019edd202")
  22. add_versions("1.1.1-h", "0a976b769bdb26470971a184f5263d0c3256152d5671ed7287cf17acc4698afc")
  23. add_versions("1.1.0-l", "a305d4af4b442ad61ba3d7e82905d09bfbd80424e132e10df4899d064aa47ce2")
  24. add_versions("1.0.2-u", "493f8b34574d0cf8598adbdec33c84b8a06f0617787c3710d20827c01291c09c")
  25. add_versions("1.0.0", "9b67e5ad1a4234c1170ada75b66321e914da4f3ebaeaef6b28400173aaa6b378")
  26. on_fetch("fetch")
  27. on_load(function (package)
  28. if not package:is_precompiled() then
  29. if package:is_plat("android") and is_subhost("windows") and os.arch() == "x64" then
  30. -- when building for android on windows, use msys2 perl instead of strawberry-perl to avoid configure issue
  31. package:add("deps", "msys2", {configs = {msystem = "MINGW64", base_devel = true}, private = true})
  32. elseif is_subhost("windows") and not package:is_precompiled() then
  33. package:add("deps", "nasm", { private = true })
  34. -- the perl executable found in GitForWindows will fail to build OpenSSL
  35. -- see https://github.com/openssl/openssl/blob/master/NOTES-PERL.md#perl-on-windows
  36. package:add("deps", "strawberry-perl", { system = false, private = true })
  37. -- check xmake tool jom
  38. import("package.tools.jom", {try = true})
  39. if jom then
  40. package:add("deps", "jom", {private = true})
  41. end
  42. end
  43. end
  44. -- @note we must use package:is_plat() instead of is_plat in description for supporting add_deps("openssl", {host = true}) in python
  45. if package:is_plat("windows") then
  46. package:add("links", "libssl", "libcrypto")
  47. else
  48. package:add("links", "ssl", "crypto")
  49. end
  50. if package:is_plat("windows", "mingw") then
  51. package:add("syslinks", "ws2_32", "user32", "crypt32", "advapi32")
  52. elseif package:is_plat("linux", "cross") then
  53. package:add("syslinks", "pthread", "dl")
  54. end
  55. if package:is_plat("linux") then
  56. package:add("extsources", "apt::libssl-dev")
  57. end
  58. end)
  59. on_install("windows", function (package)
  60. import("package.tools.jom", {try = true})
  61. import("package.tools.nmake")
  62. local configs = {"Configure", "no-tests"}
  63. local target
  64. if package:is_arch("x86", "i386") then
  65. target = "VC-WIN32"
  66. elseif package:is_arch("arm64") then
  67. target = "VC-WIN64-ARM"
  68. elseif package:is_arch("arm.*") then
  69. target = "VC-WIN32-ARM"
  70. else
  71. target = "VC-WIN64A"
  72. end
  73. table.insert(configs, target)
  74. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  75. table.insert(configs, "--prefix=" .. package:installdir())
  76. table.insert(configs, "--openssldir=" .. package:installdir())
  77. if jom then
  78. table.insert(configs, "no-makedepend")
  79. table.insert(configs, "/FS")
  80. end
  81. os.vrunv("perl", configs)
  82. if jom then
  83. jom.build(package)
  84. jom.make(package, {"install_sw"})
  85. else
  86. nmake.build(package)
  87. nmake.make(package, {"install_sw"})
  88. end
  89. end)
  90. on_install("mingw", function (package)
  91. local configs = {"Configure", "no-tests"}
  92. table.insert(configs, package:is_arch("i386", "x86") and "mingw" or "mingw64")
  93. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  94. local installdir = package:installdir()
  95. -- Use MSYS2 paths instead of Windows paths
  96. if is_subhost("msys") then
  97. installdir = installdir:gsub("(%a):[/\\](.+)", "/%1/%2"):gsub("\\", "/")
  98. end
  99. table.insert(configs, "--prefix=" .. installdir)
  100. table.insert(configs, "--openssldir=" .. installdir)
  101. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  102. buildenvs.RC = package:build_getenv("mrc")
  103. if is_subhost("msys") then
  104. local rc = buildenvs.RC
  105. if rc then
  106. rc = rc:gsub("(%a):[/\\](.+)", "/%1/%2"):gsub("\\", "/")
  107. buildenvs.RC = rc
  108. end
  109. end
  110. -- fix 'cp: directory fuzz does not exist'
  111. if package:config("shared") then
  112. os.mkdir("fuzz")
  113. end
  114. os.vrunv("perl", configs, {envs = buildenvs})
  115. import("package.tools.make").build(package)
  116. import("package.tools.make").make(package, {"install_sw"})
  117. end)
  118. on_install("linux", "macosx", "bsd", "cross", "android", function (package)
  119. -- https://wiki.openssl.org/index.php/Compilation_and_Installation#PREFIX_and_OPENSSLDIR
  120. local configs = {}
  121. if package:is_cross() then
  122. local target_plat, target_arch
  123. if package:is_plat("macosx") then
  124. target_plat = "darwin64"
  125. target_arch = package:is_arch("arm64") and "arm64-cc" or "x86_64-cc"
  126. else
  127. target_plat = "linux"
  128. if package:is_arch("x86_64") then
  129. target_arch = "x86_64"
  130. elseif package:is_arch("i386", "x86") then
  131. target_arch = "x86"
  132. elseif package:is_arch("arm64", "arm64-v8a") then
  133. target_arch = "aarch64"
  134. elseif package:is_arch("arm.*") then
  135. target_arch = "armv4"
  136. elseif package:is_arch(".*64") then
  137. target_arch = "generic64"
  138. else
  139. target_arch = "generic32"
  140. end
  141. end
  142. table.insert(configs, target_plat .. "-" .. target_arch)
  143. if package:is_plat("cross", "android") then
  144. table.insert(configs, "-DOPENSSL_NO_HEARTBEATS")
  145. table.insert(configs, "no-threads")
  146. end
  147. end
  148. table.insert(configs, "--openssldir=" .. package:installdir():gsub("\\", "/"))
  149. table.insert(configs, "--prefix=" .. package:installdir():gsub("\\", "/"))
  150. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  151. if package:debug() then
  152. table.insert(configs, "--debug")
  153. end
  154. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  155. if package:is_cross() then
  156. if is_host("windows") and package:is_plat("android") then
  157. buildenvs.CFLAGS = buildenvs.CFLAGS:gsub("\\", "/")
  158. buildenvs.CXXFLAGS = buildenvs.CXXFLAGS:gsub("\\", "/")
  159. buildenvs.CPPFLAGS = buildenvs.CPPFLAGS:gsub("\\", "/")
  160. buildenvs.ASFLAGS = buildenvs.ASFLAGS:gsub("\\", "/")
  161. end
  162. os.vrunv("perl", table.join("./Configure", configs), {envs = buildenvs})
  163. else
  164. os.vrunv("./config", configs, {shell = true, envs = buildenvs})
  165. end
  166. import("package.tools.make").build(package)
  167. import("package.tools.make").make(package, {"install_sw"})
  168. if package:config("shared") then
  169. os.tryrm(path.join(package:installdir("lib"), "*.a"))
  170. end
  171. end)
  172. on_test(function (package)
  173. assert(package:has_cfuncs("SSL_new", {includes = "openssl/ssl.h"}))
  174. end)