diff options
author | Remi Collet <remi@remirepo.net> | 2017-11-09 15:44:45 +0100 |
---|---|---|
committer | Remi Collet <remi@remirepo.net> | 2017-11-09 15:44:45 +0100 |
commit | e4055c16c0de103b2893290b36e5aa815e4d0186 (patch) | |
tree | e3e98312f727a84e602bb2f018fbd5eb51e9dfe9 |
New package (gh#88)
-rw-r--r-- | .gitignore | 8 | ||||
-rw-r--r-- | 6.patch | 121 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | REFLECTION | 27 | ||||
-rwxr-xr-x | makesrc.sh | 27 | ||||
-rw-r--r-- | php-brotli.spec | 226 |
6 files changed, 413 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc9aa8c --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +clog +package-*.xml +*.tgz +*.tar.gz +*.tar.xz +*.tar.xz.asc +*.src.rpm +*/*rpm @@ -0,0 +1,121 @@ +From 50e219b0df0d66357dfd504475a041b545d9330d Mon Sep 17 00:00:00 2001 +From: Remi Collet <remi@remirepo.net> +Date: Thu, 9 Nov 2017 14:31:44 +0100 +Subject: [PATCH] allow to use system broti library + +--- + config.m4 | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++---------- + php_brotli.h | 1 - + 2 files changed, 56 insertions(+), 12 deletions(-) + +diff --git a/config.m4 b/config.m4 +index c7f7a4c..5010df0 100644 +--- a/config.m4 ++++ b/config.m4 +@@ -1,38 +1,83 @@ + dnl config.m4 for extension brotli + +-dnl Check PHP version: ++dnl Check PHP version ID: + AC_MSG_CHECKING(PHP version) + if test ! -z "$phpincludedir"; then +- PHP_VERSION=`grep 'PHP_VERSION ' $phpincludedir/main/php_version.h | sed -e 's/.*"\([[0-9\.]]*\)".*/\1/g' 2>/dev/null` ++ PHP_VERSION_ID=`grep 'PHP_VERSION_ID' $phpincludedir/main/php_version.h | sed -e 's/.* \([[0-9]]*\)/\1/g' 2>/dev/null` + elif test ! -z "$PHP_CONFIG"; then +- PHP_VERSION=`$PHP_CONFIG --version 2>/dev/null` ++ PHP_VERSION_ID=`$PHP_CONFIG --vernum 2>/dev/null` + fi + +-if test x"$PHP_VERSION" = "x"; then ++if test x"$PHP_VERSION_ID" = "x"; then + AC_MSG_WARN([none]) + else +- PHP_MAJOR_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/g' 2>/dev/null` +- PHP_MINOR_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/g' 2>/dev/null` +- PHP_RELEASE_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/g' 2>/dev/null` +- AC_MSG_RESULT([$PHP_VERSION]) ++ AC_MSG_RESULT($PHP_VERSION_ID) + fi + +-if test $PHP_MAJOR_VERSION -lt 5; then ++if test $PHP_VERSION_ID -lt 50000; then + AC_MSG_ERROR([need at least PHP 5 or newer]) + fi + + PHP_ARG_ENABLE(brotli, whether to enable brotli support, + [ --enable-brotli Enable brotli support]) + ++PHP_ARG_WITH(libbrotli, whether to use system brotli library, ++[ --with-libbrotli=DIR Use libbrotli], no, no) ++ + if test "$PHP_BROTLI" != "no"; then + ++ BROTLI_MIN_VERSION=0.6 ++ ++ if test "$PHP_LIBBROTLI" != "no"; then ++ AC_PATH_PROG(PKG_CONFIG, pkg-config, no) ++ ++ AC_MSG_CHECKING(for libbrotlienc) ++ if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libbrotlienc; then ++ if $PKG_CONFIG libbrotlienc --atleast-version $BROTLI_MIN_VERSION; then ++ LIBBROTLIENC_CFLAGS=`$PKG_CONFIG libbrotlienc --cflags` ++ LIBBROTLIENC_LIBS=`$PKG_CONFIG libbrotlienc --libs` ++ LIBBROTLIENC_VERSION=`$PKG_CONFIG libbrotlienc --modversion` ++ AC_MSG_RESULT(from pkgconfig: version $LIBBROTLIENC_VERSION found) ++ else ++ AC_MSG_ERROR(system libbrotlienc must be upgraded to version >= $BROTLI_MIN_VERSION) ++ fi ++ else ++ AC_MSG_ERROR(system libbrotlienc not found) ++ fi ++ PHP_EVAL_INCLINE($LIBBROTLIENC_CFLAGS) ++ PHP_EVAL_LIBLINE($LIBBROTLIENC_LIBS, BROTLI_SHARED_LIBADD) ++ ++ AC_MSG_CHECKING(for libbrotlidec) ++ if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libbrotlidec; then ++ if $PKG_CONFIG libbrotlidec --atleast-version $BROTLI_MIN_VERSION; then ++ LIBBROTLIDEC_CFLAGS=`$PKG_CONFIG libbrotlidec --cflags` ++ LIBBROTLIDEC_LIBS=`$PKG_CONFIG libbrotlidec --libs` ++ LIBBROTLIDEC_VERSION=`$PKG_CONFIG libbrotlidec --modversion` ++ AC_MSG_RESULT(from pkgconfig: version $LIBBROTLIDEC_VERSION found) ++ else ++ AC_MSG_ERROR(system libbrotlienc must be upgraded to version >= $BROTLI_MIN_VERSION) ++ fi ++ else ++ AC_MSG_ERROR(system libbrotlienc not found) ++ fi ++ PHP_EVAL_INCLINE($LIBBROTLIDEC_CFLAGS) ++ PHP_EVAL_LIBLINE($LIBBROTLIDEC_LIBS, BROTLI_SHARED_LIBADD) ++ AC_DEFINE_UNQUOTED(BROTLI_LIB_VERSION, "$LIBBROTLIDEC_VERSION", [system library version]) ++ else ++ AC_MSG_CHECKING(for brotli) ++ AC_MSG_RESULT(use bundled copy) ++ AC_DEFINE_UNQUOTED(BROTLI_LIB_VERSION, "1.0.1", [bundled library version]) ++ + BROTLI_COMMON_SOURCES="brotli/c/common/dictionary.c" + BROTLI_ENC_SOURCES="brotli/c/enc/backward_references.c brotli/c/enc/backward_references_hq.c brotli/c/enc/bit_cost.c brotli/c/enc/block_splitter.c brotli/c/enc/brotli_bit_stream.c brotli/c/enc/cluster.c brotli/c/enc/compress_fragment.c brotli/c/enc/compress_fragment_two_pass.c brotli/c/enc/dictionary_hash.c brotli/c/enc/encode.c brotli/c/enc/entropy_encode.c brotli/c/enc/histogram.c brotli/c/enc/literal_cost.c brotli/c/enc/memory.c brotli/c/enc/metablock.c brotli/c/enc/static_dict.c brotli/c/enc/utf8_util.c" + BROTLI_DEC_SOURCES="brotli/c/dec/bit_reader.c brotli/c/dec/decode.c brotli/c/dec/huffman.c brotli/c/dec/state.c" ++ fi + +- PHP_SUBST(BROTLI_SHARED_LIBADD) ++ PHP_SUBST(BROTLI_SHARED_LIBADD) + +- PHP_NEW_EXTENSION(brotli, brotli.c $BROTLI_COMMON_SOURCES $BROTLI_ENC_SOURCES $BROTLI_DEC_SOURCES, $ext_shared) ++ PHP_NEW_EXTENSION(brotli, brotli.c $BROTLI_COMMON_SOURCES $BROTLI_ENC_SOURCES $BROTLI_DEC_SOURCES, $ext_shared) + ++ if test -n "$BROTLI_COMMON_SOURCES" ; then + PHP_ADD_INCLUDE([$ext_srcdir/brotli/c/include]) ++ fi + fi +diff --git a/php_brotli.h b/php_brotli.h +index 4405001..773af76 100644 +--- a/php_brotli.h ++++ b/php_brotli.h +@@ -6,7 +6,6 @@ extern "C" { + #endif + + #define BROTLI_EXT_VERSION "0.5.0" +-#define BROTLI_LIB_VERSION "1.0.1" + + extern zend_module_entry brotli_module_entry; + #define phpext_brotli_ptr &brotli_module_entry diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..91b0fd5 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +SRCDIR := $(shell pwd) +NAME := $(shell basename $(SRCDIR)) +include ../../common/Makefile + diff --git a/REFLECTION b/REFLECTION new file mode 100644 index 0000000..c5acc3c --- /dev/null +++ b/REFLECTION @@ -0,0 +1,27 @@ +Extension [ <persistent> extension #77 brotli version 0.5.0 ] { + + - Constants [3] { + Constant [ integer BROTLI_GENERIC ] { 0 } + Constant [ integer BROTLI_TEXT ] { 1 } + Constant [ integer BROTLI_FONT ] { 2 } + } + + - Functions { + Function [ <internal:brotli> function brotli_compress ] { + + - Parameters [3] { + Parameter #0 [ <required> $data ] + Parameter #1 [ <optional> $quality ] + Parameter #2 [ <optional> $mode ] + } + } + Function [ <internal:brotli> function brotli_uncompress ] { + + - Parameters [2] { + Parameter #0 [ <required> $data ] + Parameter #1 [ <optional> $max ] + } + } + } +} + diff --git a/makesrc.sh b/makesrc.sh new file mode 100755 index 0000000..ea1e7e8 --- /dev/null +++ b/makesrc.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +NAME=$(basename $PWD) +OWNER=$(sed -n '/^%global gh_owner/{s/.* //;p}' $NAME.spec) +PROJECT=$(sed -n '/^%global gh_project/{s/.* //;p}' $NAME.spec) +VERSION=$(sed -n '/^Version:/{s/.* //;p}' $NAME.spec) +COMMIT=$(sed -n '/^%global gh_commit/{s/.* //;p}' $NAME.spec) +SHORT=${COMMIT:0:7} + +echo -e "\nCreate git snapshot\nName=$NAME, Owner=$OWNER, Project=$PROJECT, Version=$VERSION\n" + +echo "Cloning..." +rm -rf $PROJECT-$COMMIT +git clone --recursive https://github.com/$OWNER/$PROJECT.git $PROJECT-$COMMIT + +echo "Getting commit..." +pushd $PROJECT-$COMMIT +git checkout $COMMIT +popd + +echo "Archiving..." +tar czf $NAME-$VERSION-$SHORT.tgz --exclude .git $PROJECT-$COMMIT + +echo "Cleaning..." +rm -rf $PROJECT-$COMMIT + +echo "Done." diff --git a/php-brotli.spec b/php-brotli.spec new file mode 100644 index 0000000..b995a0d --- /dev/null +++ b/php-brotli.spec @@ -0,0 +1,226 @@ +# remirepo spec file for php-brotli +# +# Copyright (c) 2017 Remi Collet +# License: CC-BY-SA +# http://creativecommons.org/licenses/by-sa/4.0/ +# +# Please, preserve the changelog entries +# +%if 0%{?scl:1} +%global sub_prefix %{scl_prefix} +%scl_package php-brotli +%else +%global pkg_name %{name} +%endif + +%if 0%{?fedora} >= 25 +%global with_libbrotli 1 +%else +%global with_libbrotli 0 +%endif + +%global gh_commit dd31e7026e320a6647c2a8ce98943dbfb8cf2060 +%global gh_short %(c=%{gh_commit}; echo ${c:0:7}) +%global gh_owner kjdev +%global gh_project php-ext-brotli +#global gh_date 20160608 +%global pecl_name brotli +%global with_zts 0%{!?_without_zts:%{?__ztsphp:1}} +%global ini_name 40-%{pecl_name}.ini + +Summary: Brotli Extension for PHP +Name: %{?sub_prefix}php-%{pecl_name} +Version: 0.5.0 +%if 0%{?gh_date:1} +Release: 0.3.%{gh_date}git%{gh_short}%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +%else +Release: 1%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +%endif +License: MIT +Group: Development/Languages +URL: https://github.com/%{gh_owner}/%{gh_project} +Source0: %{pkg_name}-%{version}-%{gh_short}.tgz +# retrieve a recursive git snapshot with submodule +Source1: makesrc.sh + +# https://github.com/kjdev/php-ext-brotli/pull/6 +Patch0: https://patch-diff.githubusercontent.com/raw/kjdev/php-ext-brotli/pull/6.patch + +BuildRequires: %{?scl_prefix}php-devel +%if %{?with_libbrotli} +BuildRequires: brotli-devel >= 0.6.0 +%else +Provides: bundled(brotli) = 1.0.1 +%endif + +Requires: %{?scl_prefix}php(zend-abi) = %{php_zend_api} +Requires: %{?scl_prefix}php(api) = %{php_core_api} +%{?_sclreq:Requires: %{?scl_prefix}runtime%{?_sclreq}%{?_isa}} + +%if "%{?vendor}" == "Remi Collet" && 0%{!?scl:1} && 0%{?rhel} +%if "%{php_version}" > "5.6" +Obsoletes: php56u-%{pecl_name} <= %{version} +Obsoletes: php56w-%{pecl_name} <= %{version} +%endif +%if "%{php_version}" > "7.0" +Obsoletes: php70u-%{pecl_name} <= %{version} +Obsoletes: php70w-%{pecl_name} <= %{version} +%endif +%if "%{php_version}" > "7.1" +Obsoletes: php71u-%{pecl_name} <= %{version} +Obsoletes: php71w-%{pecl_name} <= %{version} +%endif +%if "%{php_version}" > "7.2" +Obsoletes: php72u-%{pecl_name} <= %{version} +Obsoletes: php72w-%{pecl_name} <= %{version} +%endif +%endif + +%if 0%{?fedora} < 20 && 0%{?rhel} < 7 +# Filter shared private +%{?filter_provides_in: %filter_provides_in %{_libdir}/.*\.so$} +%{?filter_setup} +%endif + + +%description +This extension allows Brotli compression. + +Package built for PHP %(%{__php} -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')%{?scl: as Software Collection (%{scl} by %{?scl_vendor}%{!?scl_vendor:rh})}. + + +%prep +%setup -qc +mv %{gh_project}-%{gh_commit} NTS + +cd NTS +%patch0 -p1 + +# replace symlink +rm LICENSE +mv brotli/LICENSE . + +%if %{?with_libbrotli} +# Use the system library +mv brotli tests +%endif + +# Sanity check, really often broken +extver=$(sed -n '/#define BROTLI_EXT_VERSION/{s/.* "//;s/".*$//;p}' php_brotli.h) +if test "x${extver}" != "x%{version}%{?gh_date:-dev}"; then + : Error: Upstream extension version is ${extver}, expecting %{version}%{?gh_date:-dev}. + exit 1 +fi +cd .. + +%if %{with_zts} +# duplicate for ZTS build +cp -pr NTS ZTS +%endif + +# Drop in the bit of configuration +cat << 'EOF' | tee %{ini_name} +; Enable '%{summary}' extension module +extension = %{pecl_name}.so +EOF + + +%build +%{?dtsenable} + +cd NTS +%if %{?with_libbrotli} +mv tests/brotli brotli +%endif +%{_bindir}/phpize +%configure \ + --with-php-config=%{_bindir}/php-config \ +%if %{?with_libbrotli} + --with-libbrotli \ +%endif + --with-libdir=%{_lib} \ + --enable-brotli +make %{?_smp_mflags} + +%if %{with_zts} +cd ../ZTS +%if %{?with_libbrotli} +mv tests/brotli brotli +%endif +%{_bindir}/zts-phpize +%configure \ + --with-php-config=%{_bindir}/zts-php-config \ +%if %{?with_libbrotli} + --with-libbrotli \ +%endif + --with-libdir=%{_lib} \ + --enable-brotli +make %{?_smp_mflags} +%endif + + +%install +%{?dtsenable} + +# Install the NTS stuff +make -C NTS install INSTALL_ROOT=%{buildroot} +install -D -m 644 %{ini_name} %{buildroot}%{php_inidir}/%{ini_name} + +%if %{with_zts} +# Install the ZTS stuff +make -C ZTS install INSTALL_ROOT=%{buildroot} +install -D -m 644 %{ini_name} %{buildroot}%{php_ztsinidir}/%{ini_name} +%endif + + + +%check +cd NTS +: Minimal load test for NTS extension +%{__php} --no-php-ini \ + --define extension=%{buildroot}%{php_extdir}/%{pecl_name}.so \ + --modules | grep %{pecl_name} + +: Upstream test suite for NTS extension +TEST_PHP_EXECUTABLE=%{__php} \ +TEST_PHP_ARGS="-n -d extension=%{buildroot}%{php_extdir}/%{pecl_name}.so" \ +NO_INTERACTION=1 \ +REPORT_EXIT_STATUS=1 \ +%{__php} -n run-tests.php --show-diff || : ignore + +%if %{with_zts} +cd ../ZTS +: Minimal load test for ZTS extension +%{__ztsphp} --no-php-ini \ + --define extension=%{buildroot}%{php_ztsextdir}/%{pecl_name}.so \ + --modules | grep %{pecl_name} + +: Upstream test suite for ZTS extension +TEST_PHP_EXECUTABLE=%{__ztsphp} \ +TEST_PHP_ARGS="-n -d extension=%{buildroot}%{php_ztsextdir}/%{pecl_name}.so" \ +NO_INTERACTION=1 \ +REPORT_EXIT_STATUS=1 \ +%{__ztsphp} -n run-tests.php --show-diff +%endif + + +%files +%{!?_licensedir:%global license %%doc} +%license NTS/LICENSE +%doc NTS/README.md + +%config(noreplace) %{php_inidir}/%{ini_name} +%{php_extdir}/%{pecl_name}.so + +%if %{with_zts} +%config(noreplace) %{php_ztsinidir}/%{ini_name} +%{php_ztsextdir}/%{pecl_name}.so +%endif + + +%changelog +* Thu Nov 9 2017 Remi Collet <remi@remirepo.net> - 0.5.0-1 +- new package, version 0.5.0, bundled libbrotli 1.0.1 +- add patch to build with system libbrotli + open https://github.com/kjdev/php-ext-brotli/pull/6 + |