xmake.lua 6.7 KB

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