From b632ca436c5d06defc87df8b2a4774680e9cf6ef Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 11 Feb 2015 02:08:50 +0000 Subject: digest: common configurations * ext/digest/digest_conf.rb (digest_conf): extract common configurations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/digest/digest_conf.rb | 20 ++++++++++++++++++++ ext/digest/md5/extconf.rb | 12 ++---------- ext/digest/md5/md5init.c | 2 +- ext/digest/rmd160/extconf.rb | 12 ++---------- ext/digest/rmd160/rmd160init.c | 2 +- ext/digest/sha1/extconf.rb | 12 ++---------- ext/digest/sha1/sha1init.c | 2 +- ext/digest/sha2/extconf.rb | 13 ++----------- 8 files changed, 31 insertions(+), 44 deletions(-) create mode 100644 ext/digest/digest_conf.rb (limited to 'ext/digest') diff --git a/ext/digest/digest_conf.rb b/ext/digest/digest_conf.rb new file mode 100644 index 0000000000..f2cb1f36e8 --- /dev/null +++ b/ext/digest/digest_conf.rb @@ -0,0 +1,20 @@ +def digest_conf(name, hdr = name, funcs = nil) + unless with_config("bundled-#{name}") + dir_config("openssl") + pkg_config("openssl") + require File.expand_path('../../openssl/deprecation', __FILE__) + if have_library("crypto") + funcs ||= name.upcase + funcs = Array(funcs) + hdr = "openssl/#{hdr}.h" + if funcs.all? {|func| OpenSSL.check_func("#{func}_Transform", hdr)} && + funcs.all? {|func| have_type("#{func}_CTX", hdr)} + $defs << "-D#{name.upcase}_USE_OPENSSL" + $objs << "#{name}ossl.#{$OBJEXT}" + return :ossl + end + end + end + $objs << "#{name}.#{$OBJEXT}" + return +end diff --git a/ext/digest/md5/extconf.rb b/ext/digest/md5/extconf.rb index dbef0878ca..5140325b8f 100644 --- a/ext/digest/md5/extconf.rb +++ b/ext/digest/md5/extconf.rb @@ -3,22 +3,14 @@ # $Id$ require "mkmf" +require File.expand_path("../../digest_conf", __FILE__) $defs << "-DHAVE_CONFIG_H" $INCFLAGS << " -I$(srcdir)/.." $objs = [ "md5init.#{$OBJEXT}" ] -if !with_config("bundled-md5") && - (dir_config("openssl") - pkg_config("openssl") - require File.expand_path('../../../openssl/deprecation', __FILE__) - have_library("crypto")) && - OpenSSL.check_func("MD5_Transform", "openssl/md5.h") - $objs << "md5ossl.#{$OBJEXT}" -else - $objs << "md5.#{$OBJEXT}" -end +digest_conf("md5") have_header("sys/cdefs.h") diff --git a/ext/digest/md5/md5init.c b/ext/digest/md5/md5init.c index 433fbbd250..93d01a2f41 100644 --- a/ext/digest/md5/md5init.c +++ b/ext/digest/md5/md5init.c @@ -2,7 +2,7 @@ /* $Id$ */ #include "digest.h" -#if defined(HAVE_OPENSSL_MD5_H) +#if defined(MD5_USE__OPENSSL) #include "md5ossl.h" #else #include "md5.h" diff --git a/ext/digest/rmd160/extconf.rb b/ext/digest/rmd160/extconf.rb index 64ffbd7dc8..49c26b0945 100644 --- a/ext/digest/rmd160/extconf.rb +++ b/ext/digest/rmd160/extconf.rb @@ -3,22 +3,14 @@ # $Id$ require "mkmf" +require File.expand_path("../../digest_conf", __FILE__) $defs << "-DNDEBUG" << "-DHAVE_CONFIG_H" $INCFLAGS << " -I$(srcdir)/.." $objs = [ "rmd160init.#{$OBJEXT}" ] -if !with_config("bundled-rmd160") && - (dir_config("openssl") - pkg_config("openssl") - require File.expand_path('../../../openssl/deprecation', __FILE__) - have_library("crypto")) && - OpenSSL.check_func("RIPEMD160_Transform", "openssl/ripemd.h") - $objs << "rmd160ossl.#{$OBJEXT}" -else - $objs << "rmd160.#{$OBJEXT}" -end +digest_conf("rmd160", "ripemd", "RIPEMD160") have_header("sys/cdefs.h") diff --git a/ext/digest/rmd160/rmd160init.c b/ext/digest/rmd160/rmd160init.c index 7c0c1a09db..7aa835ddfc 100644 --- a/ext/digest/rmd160/rmd160init.c +++ b/ext/digest/rmd160/rmd160init.c @@ -2,7 +2,7 @@ /* $Id$ */ #include "digest.h" -#if defined(HAVE_OPENSSL_RIPEMD_H) +#if defined(RMD160_USE_OPENSSL) #include "rmd160ossl.h" #else #include "rmd160.h" diff --git a/ext/digest/sha1/extconf.rb b/ext/digest/sha1/extconf.rb index c230270e1b..7528fb2de3 100644 --- a/ext/digest/sha1/extconf.rb +++ b/ext/digest/sha1/extconf.rb @@ -3,22 +3,14 @@ # $Id$ require "mkmf" +require File.expand_path("../../digest_conf", __FILE__) $defs << "-DHAVE_CONFIG_H" $INCFLAGS << " -I$(srcdir)/.." $objs = [ "sha1init.#{$OBJEXT}" ] -if !with_config("bundled-sha1") && - (dir_config("openssl") - pkg_config("openssl") - require File.expand_path('../../../openssl/deprecation', __FILE__) - have_library("crypto")) && - OpenSSL.check_func("SHA1_Transform", "openssl/sha.h") - $objs << "sha1ossl.#{$OBJEXT}" -else - $objs << "sha1.#{$OBJEXT}" -end +digest_conf("sha1", "sha") have_header("sys/cdefs.h") diff --git a/ext/digest/sha1/sha1init.c b/ext/digest/sha1/sha1init.c index bb4af1c1c2..72529fe0b7 100644 --- a/ext/digest/sha1/sha1init.c +++ b/ext/digest/sha1/sha1init.c @@ -2,7 +2,7 @@ /* $Id$ */ #include "digest.h" -#if defined(HAVE_OPENSSL_SHA_H) +#if defined(SHA1_USE_OPENSSL) #include "sha1ossl.h" #else #include "sha1.h" diff --git a/ext/digest/sha2/extconf.rb b/ext/digest/sha2/extconf.rb index ac35132250..142a7f7077 100644 --- a/ext/digest/sha2/extconf.rb +++ b/ext/digest/sha2/extconf.rb @@ -3,24 +3,15 @@ # $Id$ require "mkmf" +require File.expand_path("../../digest_conf", __FILE__) $defs << "-DHAVE_CONFIG_H" $INCFLAGS << " -I$(srcdir)/.." $objs = [ "sha2init.#{$OBJEXT}" ] -if !with_config("bundled-sha2") && - (dir_config("openssl") - pkg_config("openssl") - require File.expand_path('../../../openssl/deprecation', __FILE__) - have_library("crypto")) && - %w[SHA256 SHA512].all? {|d| OpenSSL.check_func("#{d}_Transform", "openssl/sha.h")} && - %w[SHA256 SHA512].all? {|d| have_type("#{d}_CTX", "openssl/sha.h")} - $objs << "sha2ossl.#{$OBJEXT}" - $defs << "-DSHA2_USE_OPENSSL" -else +unless digest_conf("sha2", "sha", %w[SHA256 SHA512]) have_type("u_int8_t") - $objs << "sha2.#{$OBJEXT}" end have_header("sys/cdefs.h") -- cgit v1.2.3