xmake.lua 8.3 KB

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