xmake.lua 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package("openssl3")
  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")
  6. add_versions("3.3.2", "4cda357946f9dd5541b565dba35348d614288e88aeb499045018970c789c9d61")
  7. add_versions("3.3.1", "307284f39bfb7061229c57e263e707655aa80aa9950bf6def28ed63fec91a726")
  8. add_versions("3.0.14", "9590b9ae18c4de183be74dfc9da5be1f1e8f85dd631a78bc74c0ebc3d7e27a93")
  9. add_versions("3.0.7", "fcb37203c6bf7376cfd3aeb0be057937b7611e998b6c0d664abde928c8af3eb7")
  10. add_versions("3.0.6", "9b45be41df0d6e9cf9e340a64525177662f22808ac69aee6bfb29c511284dae4")
  11. add_versions("3.0.5", "4313c91fb0412e6a600493eb7c59bd555c4ff2ea7caa247a98c8456ad6f9fc74")
  12. add_versions("3.0.4", "5b690a5c00e639f3817e2ee15c23c36874a1f91fa8c3a83bda3276d3d6345b76")
  13. add_versions("3.0.3", "9bc56fd035f980cf74605264b04d84497df657c4f7ca68bfa77512e745f6c1a6")
  14. add_versions("3.0.2", "ce3cbb41411731852e52bf96c06f097405c81ebf60ba81e0b9ca05d41dc92681")
  15. add_versions("3.0.1", "53d8121af1c33c62a05a5370e9ba40fcc237717b79a7d99009b0c00c79bd7d78")
  16. add_versions("3.0.0", "1bdb33f131af75330de94475563c62d6908ac1c18586f7f4aa209b96b0bfc2f9")
  17. on_fetch("fetch")
  18. -- https://security.stackexchange.com/questions/173425/how-do-i-calculate-md2-hash-with-openssl
  19. add_configs("md2", {description = "Enable MD2 on OpenSSl3 or not", default = false, type = "boolean"})
  20. on_load(function (package)
  21. if not package:is_precompiled() then
  22. if package:is_plat("windows") then
  23. package:add("deps", "nasm")
  24. -- the perl executable found in GitForWindows will fail to build OpenSSL
  25. -- see https://github.com/openssl/openssl/blob/master/NOTES-PERL.md#perl-on-windows
  26. package:add("deps", "strawberry-perl", {system = false})
  27. -- check xmake tool jom
  28. import("package.tools.jom", {try = true})
  29. if jom then
  30. package:add("deps", "jom", {private = true})
  31. end
  32. elseif package:is_plat("android") and is_subhost("windows") and os.arch() == "x64" then
  33. -- when building for android on windows, use msys2 perl instead of strawberry-perl to avoid configure issue
  34. package:add("deps", "msys2", {configs = {msystem = "MINGW64", base_devel = true}, private = true})
  35. end
  36. end
  37. -- @note we must use package:is_plat() instead of is_plat in description for supporting add_deps("openssl", {host = true}) in python
  38. if package:is_plat("windows") then
  39. package:add("links", "libssl", "libcrypto")
  40. else
  41. package:add("links", "ssl", "crypto")
  42. end
  43. if package:is_plat("windows", "mingw") then
  44. package:add("syslinks", "ws2_32", "user32", "crypt32", "advapi32")
  45. elseif package:is_plat("linux", "bsd", "cross") then
  46. package:add("syslinks", "pthread", "dl")
  47. end
  48. if package:is_plat("linux", "mingw") and package:is_arch("x86_64") then
  49. package:add("linkdirs", "lib64")
  50. end
  51. if package:is_plat("linux") then
  52. package:add("extsources", "apt::libssl-dev")
  53. end
  54. end)
  55. on_install("windows", function (package)
  56. import("package.tools.jom", {try = true})
  57. import("package.tools.nmake")
  58. local configs = {"Configure", "no-tests"}
  59. local target
  60. if package:is_arch("x86", "i386") then
  61. target = "VC-WIN32"
  62. elseif package:is_arch("arm64") then
  63. target = "VC-WIN64-ARM"
  64. elseif package:is_arch("arm.*") then
  65. target = "VC-WIN32-ARM"
  66. else
  67. target = "VC-WIN64A"
  68. end
  69. table.insert(configs, target)
  70. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  71. table.insert(configs, "--prefix=" .. package:installdir())
  72. table.insert(configs, "--openssldir=" .. package:installdir())
  73. if package:config("md2") then
  74. table.insert(configs, "enable-md2")
  75. end
  76. if jom then
  77. table.insert(configs, "no-makedepend")
  78. table.insert(configs, "/FS")
  79. end
  80. os.vrunv("perl", configs)
  81. if jom then
  82. jom.build(package)
  83. jom.make(package, {"install_sw"})
  84. else
  85. nmake.build(package)
  86. nmake.make(package, {"install_sw"})
  87. end
  88. end)
  89. on_install("mingw", function (package)
  90. local configs = {"Configure", "no-tests"}
  91. table.insert(configs, package:is_arch("i386", "x86") and "mingw" or "mingw64")
  92. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  93. local installdir = package:installdir()
  94. -- Use MSYS2 paths instead of Windows paths
  95. if is_subhost("msys") then
  96. installdir = installdir:gsub("(%a):[/\\](.+)", "/%1/%2"):gsub("\\", "/")
  97. end
  98. table.insert(configs, "--prefix=" .. installdir)
  99. table.insert(configs, "--openssldir=" .. installdir)
  100. if package:config("md2") then
  101. table.insert(configs, "enable-md2")
  102. end
  103. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  104. buildenvs.RC = package:build_getenv("mrc")
  105. if is_subhost("msys") then
  106. local rc = buildenvs.RC
  107. if rc then
  108. rc = rc:gsub("(%a):[/\\](.+)", "/%1/%2"):gsub("\\", "/")
  109. buildenvs.RC = rc
  110. end
  111. end
  112. -- fix 'cp: directory fuzz does not exist'
  113. if package:config("shared") then
  114. os.mkdir("fuzz")
  115. end
  116. os.vrunv("perl", configs, {envs = buildenvs})
  117. import("package.tools.make").build(package)
  118. import("package.tools.make").make(package, {"install_sw"})
  119. end)
  120. on_install("linux", "macosx", "bsd", function (package)
  121. -- https://wiki.openssl.org/index.php/Compilation_and_Installation#PREFIX_and_OPENSSLDIR
  122. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  123. local configs = {"--openssldir=" .. package:installdir(),
  124. "--prefix=" .. package:installdir()}
  125. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  126. if package:debug() then
  127. table.insert(configs, "--debug")
  128. end
  129. if package:config("md2") then
  130. table.insert(configs, "enable-md2")
  131. end
  132. os.vrunv("./config", configs, {envs = buildenvs})
  133. local makeconfigs = {CFLAGS = buildenvs.CFLAGS, ASFLAGS = buildenvs.ASFLAGS}
  134. import("package.tools.make").build(package, makeconfigs)
  135. import("package.tools.make").make(package, {"install_sw"})
  136. if package:config("shared") then
  137. os.tryrm(path.join(package:installdir("lib"), "*.a"), path.join(package:installdir("lib64"), "*.a"))
  138. end
  139. end)
  140. on_install("cross", "android", function (package)
  141. local target_arch = "generic32"
  142. if package:is_arch("x86_64") then
  143. target_arch = "x86_64"
  144. elseif package:is_arch("i386", "x86") then
  145. target_arch = "x86"
  146. elseif package:is_arch("arm64", "arm64-v8a") then
  147. target_arch = "aarch64"
  148. elseif package:is_arch("arm.*") then
  149. target_arch = "armv4"
  150. elseif package:is_arch(".*64") then
  151. target_arch = "generic64"
  152. end
  153. local target_plat = "linux"
  154. if package:is_plat("macosx") then
  155. target_plat = "darwin64"
  156. target_arch = "x86_64-cc"
  157. end
  158. local target = target_plat .. "-" .. target_arch
  159. local configs = {target,
  160. "-DOPENSSL_NO_HEARTBEATS",
  161. "no-shared",
  162. "no-threads",
  163. "--openssldir=" .. package:installdir():gsub("\\", "/"),
  164. "--prefix=" .. package:installdir():gsub("\\", "/")}
  165. if package:config("md2") then
  166. table.insert(configs, "enable-md2")
  167. end
  168. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  169. if package:is_cross() and package:is_plat("android") and is_subhost("windows") then
  170. buildenvs.CFLAGS = buildenvs.CFLAGS:gsub("\\", "/")
  171. buildenvs.CXXFLAGS = buildenvs.CXXFLAGS:gsub("\\", "/")
  172. buildenvs.CPPFLAGS = buildenvs.CPPFLAGS:gsub("\\", "/")
  173. buildenvs.ASFLAGS = buildenvs.ASFLAGS:gsub("\\", "/")
  174. os.vrunv("perl", table.join("./Configure", configs), {envs = buildenvs})
  175. else
  176. os.vrunv("./Configure", configs, {envs = buildenvs})
  177. end
  178. local makeconfigs = {CFLAGS = buildenvs.CFLAGS, ASFLAGS = buildenvs.ASFLAGS}
  179. import("package.tools.make").build(package, makeconfigs)
  180. import("package.tools.make").make(package, {"install_sw"})
  181. end)
  182. on_test(function (package)
  183. assert(package:has_cfuncs("SSL_new", {includes = "openssl/ssl.h"}))
  184. end)