summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/digest/digest_conf.rb20
-rw-r--r--ext/digest/md5/extconf.rb12
-rw-r--r--ext/digest/md5/md5init.c2
-rw-r--r--ext/digest/rmd160/extconf.rb12
-rw-r--r--ext/digest/rmd160/rmd160init.c2
-rw-r--r--ext/digest/sha1/extconf.rb12
-rw-r--r--ext/digest/sha1/sha1init.c2
-rw-r--r--ext/digest/sha2/extconf.rb13
9 files changed, 36 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index 98c376d..c7952d3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Feb 11 11:08:48 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/digest/digest_conf.rb (digest_conf): extract common
+ configurations.
+
Wed Feb 11 11:01:33 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/json/generator/generator.c (generate_json): get rid of
diff --git a/ext/digest/digest_conf.rb b/ext/digest/digest_conf.rb
new file mode 100644
index 0000000..f2cb1f3
--- /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 dbef087..5140325 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 433fbbd..93d01a2 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 64ffbd7..49c26b0 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 7c0c1a0..7aa835d 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 c230270..7528fb2 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 bb4af1c..72529fe 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 ac35132..142a7f7 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")