From 0416fc87704f29badb669915ad78e1c3084e2fcd Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 6 Sep 2016 15:51:14 +0200 Subject: [PATCH] add support for build with sytem library --- config.m4 | 41 ++++++++++++++++++++++++++++++++++------- snappy.c | 6 +++++- tests/info.phpt | 2 +- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/config.m4 b/config.m4 index 94837ec..2d06e98 100644 --- a/config.m4 +++ b/config.m4 @@ -25,10 +25,40 @@ PHP_ARG_ENABLE(snappy, whether to enable snappy support, [ --enable-snappy Enable snappy support]) PHP_ARG_WITH(snappy-includedir, for snappy header, -[ --with-snappy-includedir=DIR snappy header files], yes) +[ --with-snappy-includedir=DIR snappy header files], no, no) if test "$PHP_SNAPPY" != "no"; then + AC_MSG_CHECKING([searching for libsnappy]) + + if test "$PHP_SNAPPY_INCLUDEDIR" != "no"; then + for i in $PHP_SNAPPY_INCLUDEDIR /usr/local /usr; do + if test -r $i/include/snappy-c.h; then + LIBSNAPPY_CFLAGS="-I$i/include" + LIBSNAPPY_LIBDIR="$i/$PHP_LIBDIR" + AC_MSG_RESULT(found in $i) + break + fi + done + if test -z "$LIBSNAPPY_LIBDIR"; then + AC_MSG_RESULT(not found) + AC_MSG_ERROR(Please reinstall the snappy library distribution) + fi + PHP_CHECK_LIBRARY(snappy, snappy_compress, + [ + PHP_ADD_LIBRARY_WITH_PATH(snappy, $LIBSNAPPY_LIBDIR, SNAPPY_SHARED_LIBADD) + AC_DEFINE(HAVE_LIBSNAPPY,1,[ ]) + ], [ + AC_MSG_ERROR(could not find usable libsnappy) + ], [ + -L$LIBSNAPPY_LIBDIR + ]) + + PHP_SUBST(SNAPPY_SHARED_LIBADD) + PHP_NEW_EXTENSION(snappy, snappy.c, $ext_shared,, $LIBSNAPPY_CFLAGS) + else + AC_MSG_RESULT(use bundled version) + dnl compiler C++: PHP_REQUIRE_CXX() @@ -121,10 +151,7 @@ if test "$PHP_SNAPPY" != "no"; then PHP_NEW_EXTENSION(snappy, snappy.c $SNAPPY_SOURCES, $ext_shared) - ifdef([PHP_INSTALL_HEADERS], - [ - PHP_INSTALL_HEADERS([ext/snappy/], [php_snappy.h]) - ], [ - PHP_ADD_MAKEFILE_FRAGMENT - ]) + PHP_ADD_BUILD_DIR($ext_builddir/snappy, 1) + PHP_ADD_INCLUDE([$ext_srcdir/snappy]) + fi fi diff --git a/snappy.c b/snappy.c index b76fae9..9ffba4b 100644 --- a/snappy.c +++ b/snappy.c @@ -9,7 +9,7 @@ #include "php_snappy.h" /* snappy */ -#include "snappy/snappy-c.h" +#include static ZEND_FUNCTION(snappy_compress); static ZEND_FUNCTION(snappy_uncompress); @@ -33,7 +33,11 @@ PHP_MINFO_FUNCTION(snappy) php_info_print_table_start(); php_info_print_table_row(2, "Snappy support", "enabled"); php_info_print_table_row(2, "Extension Version", SNAPPY_EXT_VERSION); +#ifdef HAVE_LIBSNAPPY + php_info_print_table_row(2, "Snappy Version", "system library"); +#else php_info_print_table_row(2, "Snappy Version", SNAPPY_LIB_VERSION); +#endif php_info_print_table_end(); } diff --git a/tests/info.phpt b/tests/info.phpt index 98939aa..f163823 100644 --- a/tests/info.phpt +++ b/tests/info.phpt @@ -14,5 +14,5 @@ snappy Snappy support => enabled Extension Version => %d.%d.%d -Snappy Version => %d.%d.%d +Snappy Version => %s %a