xmake.lua 6.9 KB

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