xmake.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package("openssh")
  2. set_kind("binary")
  3. set_description("OpenSSH is a complete implementation of the SSH protocol (version 2) for secure remote login, command execution and file transfer.")
  4. set_license("BSD-2-Clause")
  5. add_urls("https://cloudflare.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-$(version).tar.gz",
  6. "https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-$(version).tar.gz",
  7. "https://mirror.leaseweb.com/pub/OpenBSD/OpenSSH/portable/openssh-$(version).tar.gz",
  8. "https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-$(version).tar.gz",
  9. "https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-$(version).tar.gz")
  10. add_versions("10.0p2", "021a2e709a0edf4250b1256bd5a9e500411a90dddabea830ed59cef90eb9d85c")
  11. add_configs("libcrypto", {description = "Select a crypto backend.", type = "string", default = "openssl3", values = {"builtin", "libressl", "openssl", "openssl3"}})
  12. add_configs("zlib", {description = "Enable compression support.", type = "boolean", default = true})
  13. add_configs("kerberos5", {description = "Enable Kerberos 5 support.", type = "boolean", default = false})
  14. add_configs("largefile", {description = "Enable support for large files.", type = "boolean", default = true})
  15. add_configs("pkcs11", {description = "Enable PKCS#11 support.", type = "boolean", default = true})
  16. add_configs("security_key", {description = "Enable U2F/FIDO support.", type = "boolean", default = true})
  17. add_configs("strip", {description = "Enable calling strip(1) on install.", type = "boolean", default = true})
  18. add_configs("etc_default_login", {description = "Enable using PATH from /etc/default/login.", type = "boolean", default = true})
  19. add_configs("fd_passing", {description = "Enable file descriptor passsing.", type = "boolean", default = true})
  20. add_configs("lastlog", {description = "If detected, enable use of lastlog.", type = "boolean", default = true})
  21. add_configs("utmp", {description = "If detected, enable use of utmp.", type = "boolean", default = true})
  22. add_configs("utmpx", {description = "If detected, enable use of utmpx.", type = "boolean", default = true})
  23. add_configs("wtmp", {description = "If detected, enable use of utmpx.", type = "boolean", default = true})
  24. add_configs("wtmpx", {description = "If detected, enable use of utmpx.", type = "boolean", default = true})
  25. add_configs("libutil", {description = "Enable use of libutil. (login() etc.)", type = "boolean", default = true})
  26. add_configs("pututline", {description = "Enable use of pututline() etc. (uwtmp)", type = "boolean", default = true})
  27. add_configs("pututxline", {description = "Enable use of pututxline() etc. (uwtmpx)", type = "boolean", default = true})
  28. add_configs("stackprotect", {description = "Use compiler's stack protection.", type = "boolean", default = nil})
  29. add_configs("hardening", {description = "Use toolchain hardening flags.", type = "boolean", default = nil})
  30. add_configs("retpoline", {description = "Enable retpoline spectre mitigation.", type = "boolean", default = nil})
  31. add_configs("linux_memlock_onfault", {description = "Enables memory locking on Linux.", type = "boolean", default = nil})
  32. add_configs("security_key_builtin", {description = "Include builtin U2F/FIDO support.", type = "boolean", default = nil})
  33. add_configs("security_key_standalone", {description = "Build standalone sk-libfido2 SecurityKeyProvider.", type = "boolean", default = nil})
  34. add_configs("ssl_engine", {description = "Enable OpenSSL (hardware) ENGINE support.", type = "boolean", default = nil})
  35. add_configs("prngd_port", {description = "Read entropy from PRNGD/EGD TCP localhost:PORT", type = "number", default = nil})
  36. add_configs("prngd_socket", {description = "Read entropy from PRNGD/EGD socket FILE.", type = "string", default = nil})
  37. add_configs("pam", {description = "Enable PAM support.", type = "boolean", default = nil})
  38. add_configs("pam_service", {description = "Specify PAM service name.", type = "string", default = nil})
  39. add_configs("privsep_user", {description = "Specify non-privileged user for privilege separation.", type = "string", default = nil})
  40. add_configs("sandbox", {description = "Specify privilege separation sandbox.", type = "string", default = nil, values = {"no", "capsicum", "darwin", "rlimit", "seccomp_filter"}})
  41. add_configs("selinux", {description = "Enable SELinux support.", type = "boolean", default = nil})
  42. add_configs("privsep_path", {description = "Path for privilege separation chroot.", type = "string", default = nil})
  43. add_configs("xauth", {description = "Specify path to xauth program.", type = "string", default = nil})
  44. add_configs("maildir", {description = "Specify your system mail directory.", type = "string", default = nil})
  45. add_configs("shadow", {description = "Enable shadow password support.", type = "boolean", default = nil})
  46. add_configs("ipaddr_display", {description = "Use ip address instead of hostname in $DISPLAY.", type = "boolean", default = nil})
  47. add_configs("default_path", {description = "Specify default $PATH environment for server.", type = "string", default = nil})
  48. add_configs("superuser_path", {description = "Specify different path for super-user.", type = "string", default = nil})
  49. add_configs("ip4in6", {description = "Check for and convert IPv4 in IPv6 mapped addresses.", type = "boolean", default = nil})
  50. add_configs("bsd_auth", {description = "Enable BSD auth support.", type = "boolean", default = nil})
  51. add_configs("pid_dir", {description = "Specify location of sshd.pid file.", type = "string", default = nil})
  52. add_configs("lastlog_dir", {description = "Specify lastlog location common locations.", type = "string", default = nil})
  53. on_load(function (package)
  54. if package:is_plat("msys") then
  55. package:add("deps", "autotools")
  56. -- patches from: https://github.com/msys2/MSYS2-packages/tree/master/openssh
  57. package:add("patches", "*", "patches/8.9p1/msys2-drive-name-in-path.patch", "903b3eee51e492a125cab9c724ad967450307d53e457f025e4432b81cb145af5")
  58. package:add("patches", "*", "patches/8.9p1/msys2-setkey.patch", "24dacf56b359f9fef584fbf50e7d7993e73bac52dbe8a0ff5e5f13071a22bb42")
  59. package:add("patches", "*", "patches/8.9p1/msys2.patch", "3fb221882d0cb8554c641a4c7a6684badc98329a8a17dbc42e64594037e5d128")
  60. end
  61. local libcrypto = package:config("libcrypto")
  62. if libcrypto ~= "builtin" then
  63. package:add("deps", libcrypto)
  64. end
  65. if package:config("zlib") then
  66. package:add("deps", "zlib")
  67. end
  68. if package:config("kerberos5") then
  69. package:add("deps", "krb5")
  70. end
  71. if package:config("privsep_path") == nil then
  72. package:config_set("privsep_path", package:installdir("var/empty"):gsub("\\", "/"))
  73. end
  74. end)
  75. -- about msys2 support:
  76. -- @see https://github.com/xmake-io/xmake-repo/pull/8092#discussion_r2342822821
  77. on_install("@linux", "@bsd", "@macosx", "@cygwin", function (package)
  78. import("package.tools.autoconf")
  79. local configs = {}
  80. local ldflags = {}
  81. local features_enabled_by_default = {
  82. "largefile", "pkcs11", "security-key", "strip", "etc-default-login", "fd-passing",
  83. "lastlog", "utmp", "utmpx", "wtmp", "wtmpx", "libutil", "pututline", "pututxline",
  84. }
  85. for _, feature in ipairs(features_enabled_by_default) do
  86. if not package:config(feature:gsub("-", "_")) then
  87. table.insert(configs, "--disable-" .. feature)
  88. end
  89. end
  90. local packages_boolean = {
  91. "stackprotect", "hardening", "retpoline", "linux-memlock-onfault",
  92. "pie", "security-key-builtin","security-key-standalone", "ssl-engine",
  93. "pam", "selinux", "shadow", "ipaddr-display", "bsd-auth"
  94. }
  95. local packages_string = {
  96. "prngd-socket", "pam-service", "privsep-user",
  97. "sandbox", "privsep-path", "xauth", "default-path",
  98. "superuser-path", "pid-dir"
  99. }
  100. for _, package_boolean in ipairs(packages_boolean) do
  101. local value = package:config(package_boolean:gsub("-", "_"))
  102. if value ~= nil then
  103. table.insert(configs, ("--with-%s=%s"):format(package_boolean, value and "yes" or "no"))
  104. end
  105. end
  106. for _, package_string in ipairs(packages_string) do
  107. local value = package:config(package_string:gsub("-", "_"))
  108. if value ~= nil then
  109. table.insert(configs, ("--with-%s=%s"):format(package_string, value))
  110. end
  111. end
  112. local libcrypto = package:config("libcrypto")
  113. if libcrypto == "builtin" then
  114. table.insert(configs, "--without-openssl")
  115. else
  116. table.insert(configs, ("--with-ssl-dir=%s"):format(package:dep(libcrypto):installdir():gsub("\\", "/")))
  117. end
  118. if package:config("zlib") then
  119. table.insert(configs, ("--with-zlib=%s"):format(package:dep("zlib"):installdir():gsub("\\", "/")))
  120. end
  121. if package:config("kerberos5") then
  122. table.insert(configs, ("--with-kerberos5=%s"):format(package:dep("krb5"):installdir():gsub("\\", "/")))
  123. end
  124. if package:config("ip4in6") then
  125. table.insert(configs, "--with-4in6")
  126. end
  127. if package:config("prngd_port") then
  128. table.insert(configs, "--with-prngd-port=" .. tostring(package:config("prngd_port")))
  129. end
  130. if package:config("lastlog_dir") then
  131. table.insert(configs, "--with-lastlog=" .. package:config("lastlog"))
  132. end
  133. -- fix 'working libcrypto not found' problem.
  134. if package:config("libcrypto"):startswith("openssl") and package:is_plat("bsd") then
  135. table.insert(ldflags, "-pthread")
  136. end
  137. local envs = autoconf.buildenvs(package, {ldflags = ldflags})
  138. -- @see https://github.com/msys2/MSYS2-packages/blob/master/openssh/PKGBUILD
  139. if package:is_plat("msys") then
  140. os.rm("configure")
  141. envs.MSYSTEM = "CYGWIN"
  142. envs.ac_cv_func_setproctitle = "no"
  143. table.insert(configs, "--build=" .. os.getenv("MINGW_CHOST"))
  144. end
  145. autoconf.install(package, configs, {envs = envs})
  146. end)
  147. on_test(function (package)
  148. local suffix = is_host("windows") and ".exe" or ""
  149. assert(os.isexec(package:installdir("sbin/sshd" .. suffix)), "sshd not found!")
  150. end)