xmake.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. end
  38. end
  39. -- @note we must use package:is_plat() instead of is_plat in description for supporting add_deps("openssl", {host = true}) in python
  40. if package:is_plat("windows") then
  41. package:add("links", "libssl", "libcrypto")
  42. else
  43. package:add("links", "ssl", "crypto")
  44. end
  45. if package:is_plat("windows", "mingw") then
  46. package:add("syslinks", "ws2_32", "user32", "crypt32", "advapi32")
  47. elseif package:is_plat("linux", "cross") then
  48. package:add("syslinks", "pthread", "dl")
  49. end
  50. if package:is_plat("linux") then
  51. package:add("extsources", "apt::libssl-dev")
  52. end
  53. end)
  54. on_install("windows", function (package)
  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. os.vrunv("perl", configs)
  71. local runenvs = import("package.tools.nmake").buildenvs(package)
  72. local nmake = import("lib.detect.find_tool")("nmake", {envs = runenvs})
  73. os.vrunv(nmake.program, {"install_sw"}, {envs = runenvs})
  74. end)
  75. on_install("mingw", function (package)
  76. local configs = {"Configure", "no-tests"}
  77. table.insert(configs, package:is_arch("i386", "x86") and "mingw" or "mingw64")
  78. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  79. local installdir = package:installdir()
  80. -- Use MSYS2 paths instead of Windows paths
  81. if is_subhost("msys") then
  82. installdir = installdir:gsub("(%a):[/\\](.+)", "/%1/%2"):gsub("\\", "/")
  83. end
  84. table.insert(configs, "--prefix=" .. installdir)
  85. table.insert(configs, "--openssldir=" .. installdir)
  86. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  87. buildenvs.RC = package:build_getenv("mrc")
  88. if is_subhost("msys") then
  89. local rc = buildenvs.RC
  90. if rc then
  91. rc = rc:gsub("(%a):[/\\](.+)", "/%1/%2"):gsub("\\", "/")
  92. buildenvs.RC = rc
  93. end
  94. end
  95. -- fix 'cp: directory fuzz does not exist'
  96. if package:config("shared") then
  97. os.mkdir("fuzz")
  98. end
  99. os.vrunv("perl", configs, {envs = buildenvs})
  100. import("package.tools.make").build(package)
  101. import("package.tools.make").make(package, {"install_sw"})
  102. end)
  103. on_install("linux", "macosx", "bsd", "cross", "android", function (package)
  104. -- https://wiki.openssl.org/index.php/Compilation_and_Installation#PREFIX_and_OPENSSLDIR
  105. local configs = {}
  106. if package:is_cross() then
  107. local target_plat, target_arch
  108. if package:is_plat("macosx") then
  109. target_plat = "darwin64"
  110. target_arch = package:is_arch("arm64") and "arm64-cc" or "x86_64-cc"
  111. else
  112. target_plat = "linux"
  113. if package:is_arch("x86_64") then
  114. target_arch = "x86_64"
  115. elseif package:is_arch("i386", "x86") then
  116. target_arch = "x86"
  117. elseif package:is_arch("arm64", "arm64-v8a") then
  118. target_arch = "aarch64"
  119. elseif package:is_arch("arm.*") then
  120. target_arch = "armv4"
  121. elseif package:is_arch(".*64") then
  122. target_arch = "generic64"
  123. else
  124. target_arch = "generic32"
  125. end
  126. end
  127. table.insert(configs, target_plat .. "-" .. target_arch)
  128. if package:is_plat("cross", "android") then
  129. table.insert(configs, "-DOPENSSL_NO_HEARTBEATS")
  130. table.insert(configs, "no-threads")
  131. end
  132. end
  133. table.insert(configs, "--openssldir=" .. package:installdir():gsub("\\", "/"))
  134. table.insert(configs, "--prefix=" .. package:installdir():gsub("\\", "/"))
  135. table.insert(configs, package:config("shared") and "shared" or "no-shared")
  136. if package:debug() then
  137. table.insert(configs, "--debug")
  138. end
  139. local buildenvs = import("package.tools.autoconf").buildenvs(package)
  140. if package:is_cross() then
  141. if is_host("windows") and package:is_plat("android") then
  142. buildenvs.CFLAGS = buildenvs.CFLAGS:gsub("\\", "/")
  143. buildenvs.CXXFLAGS = buildenvs.CXXFLAGS:gsub("\\", "/")
  144. buildenvs.CPPFLAGS = buildenvs.CPPFLAGS:gsub("\\", "/")
  145. buildenvs.ASFLAGS = buildenvs.ASFLAGS:gsub("\\", "/")
  146. end
  147. os.vrunv("perl", table.join("./Configure", configs), {envs = buildenvs})
  148. else
  149. os.vrunv("./config", configs, {shell = true, envs = buildenvs})
  150. end
  151. import("package.tools.make").build(package)
  152. import("package.tools.make").make(package, {"install_sw"})
  153. if package:config("shared") then
  154. os.tryrm(path.join(package:installdir("lib"), "*.a"))
  155. end
  156. end)
  157. on_test(function (package)
  158. assert(package:has_cfuncs("SSL_new", {includes = "openssl/ssl.h"}))
  159. end)