aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-06-14 14:07:29 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-06-14 17:16:19 +0900
commite0049d573beb81a88777cfdb5634550308fc57f4 (patch)
treeb11998cd02210f05917a8874007257833c254bd0
parent2be699e74a7e95b3ea16b041870ed01fd334805d (diff)
downloadruby-openssl-e0049d573beb81a88777cfdb5634550308fc57f4.tar.gz
extconf.rb: simplify searching libraries logic
Clarify what it's doing. For non-Windows and MinGW platforms we can just give "crypto" and "ssl" to have_library.
-rw-r--r--ext/openssl/extconf.rb64
1 files changed, 33 insertions, 31 deletions
diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
index 250aabe4..8f604708 100644
--- a/ext/openssl/extconf.rb
+++ b/ext/openssl/extconf.rb
@@ -46,41 +46,43 @@ def find_openssl_library
return false unless have_header("openssl/ssl.h")
- libpath = $LIBPATH.dup
- libpath |= ENV["LIB"].split(File::PATH_SEPARATOR).map{|d| d.tr(File::ALT_SEPARATOR, File::SEPARATOR)} if $mswin
-
- result = false
- %w[crypto eay32].each do |base|
- libs = [base]
- if $mswin || $mingw
- libs << "lib" + libs.first
- if base == "crypto"
- libs << libs.first + "-[0-9][0-9]"
- libs << "lib" + libs.last
- end
- libs = Dir.glob(libs.map{|l| libpath.map{|d| File.join(d, l + ".*")}}.flatten).map{|path| File.basename(path, ".*")}.uniq
+ ret = have_library("crypto", "CRYPTO_malloc") &&
+ have_library("ssl", "SSL_new")
+ return ret if ret
+
+ if $mswin
+ # OpenSSL >= 1.1.0: libcrypto.lib and libssl.lib.
+ if have_library("libcrypto", "CRYPTO_malloc") &&
+ have_library("libssl", "SSL_new")
+ return true
end
- libs.each do |lib|
- result = have_library(lib, "CRYPTO_malloc")
- break if result
+
+ # OpenSSL <= 1.0.2: libeay32.lib and ssleay32.lib.
+ if have_library("libeay32", "CRYPTO_malloc") &&
+ have_library("ssleay32", "SSL_new")
+ return true
end
- break if result
- end
- return false unless result
-
- %w[ssl ssleay32].each do |base|
- libs = [base]
- if $mswin || $mingw
- libs << "lib" + libs.first
- if base == "ssl"
- libs << libs.first + "-[0-9][0-9]"
- libs << "lib" + libs.last
- end
+
+ # LibreSSL: libcrypto-##.lib and libssl-##.lib, where ## is the ABI version
+ # number. We have to find the version number out by scanning libpath.
+ libpath = $LIBPATH.dup
+ libpath |= ENV["LIB"].split(File::PATH_SEPARATOR)
+ libpath.map! { |d| d.tr(File::ALT_SEPARATOR, File::SEPARATOR) }
+
+ ret = [
+ ["crypto", "CRYPTO_malloc"],
+ ["ssl", "SSL_new"]
+ ].all? do |base, func|
+ result = false
+ libs = ["lib#{base}-[0-9][0-9]", "lib#{base}-[0-9][0-9][0-9]"]
libs = Dir.glob(libs.map{|l| libpath.map{|d| File.join(d, l + ".*")}}.flatten).map{|path| File.basename(path, ".*")}.uniq
+ libs.each do |lib|
+ result = have_library(lib, func)
+ break if result
+ end
+ result
end
- libs.each do |lib|
- return true if have_library(lib, "SSL_new")
- end
+ return ret if ret
end
return false
end