perl-Sereal-Encoder/Sereal-3.002_001-Prefer-external-miniz-library-in-Sereal-Encoder.patch
Petr Písař d8a37ec1aa Import
2014-10-30 07:42:57 +01:00

82 lines
2.5 KiB
Diff

From 1dbf60cb0a2c2dffda36c88b984cb92a5b303432 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Wed, 15 Oct 2014 15:52:18 +0200
Subject: [PATCH 2/2] Prefer external miniz library in Sereal::Encoder
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This patch checks for presence of miniz library and header file and
if they are available, they will be used to link to the
Sereal::Encoder XS module. Otherwise the bundled miniz code will be
used.
<https://github.com/Sereal/Sereal/issues/72>
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
Perl/Encoder/Makefile.PL | 16 +++++++++++++++-
Perl/Encoder/srl_encoder.c | 4 ++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/Perl/Encoder/Makefile.PL b/Perl/Encoder/Makefile.PL
index ce0e8d7..6ec37ff 100644
--- a/Perl/Encoder/Makefile.PL
+++ b/Perl/Encoder/Makefile.PL
@@ -26,6 +26,7 @@ inc::Sereal::BuildTools::generate_constant_includes($module) if $in_source_repo;
our $OPTIMIZE;
my $libs = '';
+my $objects = '$(BASEEXT)$(OBJ_EXT) srl_encoder$(OBJ_EXT)';
my $defines = join " ", map "-D$_", grep exists $ENV{$_},
qw(NOINLINE DEBUG MEMDEBUG NDEBUG ENABLE_DANGEROUS_HACKS);
@@ -76,6 +77,19 @@ if ($have_csnappy) {
$defines .= " $ctz" if $ctz;
}
+# Prefer external miniz library over the bundled one.
+my $have_miniz = Devel::CheckLib::check_lib(
+ lib => 'miniz',
+ header => 'miniz.h'
+);
+
+if ($have_miniz) {
+ $libs .= ' -lminiz';
+ $defines .= ' -DHAVE_MINIZ';
+} else {
+ $objects .= ' miniz$(OBJ_EXT)';
+}
+
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile1(
@@ -117,7 +131,7 @@ WriteMakefile1(
DEFINE => $defines,
INC => '-I.', # e.g., '-I. -I/usr/include/other'
OPTIMIZE => $OPTIMIZE,
- OBJECT => '$(O_FILES)',
+ OBJECT => $objects,
test => {
TESTS => "t/*.t t/*/*/*.t",
},
diff --git a/Perl/Encoder/srl_encoder.c b/Perl/Encoder/srl_encoder.c
index cc87623..7756b03 100644
--- a/Perl/Encoder/srl_encoder.c
+++ b/Perl/Encoder/srl_encoder.c
@@ -58,7 +58,11 @@ extern "C" {
#include "snappy/csnappy_compress.c"
#endif
+#if defined(HAVE_MINIZ)
+#include <miniz.h>
+#else
#include "miniz.h"
+#endif
/* The ENABLE_DANGEROUS_HACKS (passed through from ENV via Makefile.PL) enables
* optimizations that may make the code so cozy with a particular version of the
--
1.9.3