# needs launching memcached
%bcond_with test

%define build_targets 74 80
%define extname memcached

%global gitdate 20210320
%global githash 19a02bb5bfaeb520b857a2d64172f7d2a9615fb3

%define srcdir php-%{extname}-%{?githash:%{githash}}%{!?githash:%{version}}

Summary: memcached extension for PHP
Summary(ja): PHP用memcached拡張
Name: php-ext-memcached
Version: 3.1.5%{?gitdate:.git%{gitdate}}
Release: 1%{_dist_release}
Group: programming
Vendor: Project Vine
Distribution: Vine Linux
Packager: tomop

License: The PHP License
%if %{?githash:1}%{!?githash:0}
Source: https://github.com/php-memcached-dev/php-memcached/archive/%{githash}.tar.gz
%else
Source: https://github.com/php-memcached-dev/php-memcached/archive/v3.1.5.tar.gz#/php-%{extname}-%{version}.tar.gz
%endif
BuildRequires: libmemcached-devel
BuildRequires: zlib-devel
BuildRoot: %{_tmppath}/%{name}-%{version}-root

%description
This module enable to access memcached in PHP scripts.

%description -l ja
このモジュールは、PHPスクリプト中でmemcachedにアクセスできるようにします。


%package -n php74-ext-%{extname}
Summary: memcached extension for PHP-7.4
Summary(ja): PHP-7.4用memcached拡張
Group: programming
BuildRequires: php74-devel
%if "%{?req_php74_api}" != ""
Requires: %{req_php74_api}
%endif

%description -n php74-ext-%{extname}
This module enable to access memcached in PHP scripts.

%description -n php74-ext-%{extname} -l ja
このモジュールは、PHPスクリプト中でmemcachedにアクセスできるようにします。


%package -n php80-ext-%{extname}
Summary: memcached extension for PHP-8.0
Summary(ja): PHP-8.0用memcached拡張
Group: programming
BuildRequires: php80-devel
%if "%{?req_php80_api}" != ""
Requires: %{req_php80_api}
%endif

%description -n php80-ext-%{extname}
This module enable to access memcached in PHP scripts.

%description -n php80-ext-%{extname} -l ja
このモジュールは、PHPスクリプト中でmemcachedにアクセスできるようにします。


%debug_package


%prep
%setup -T -c -a 0 -n %{srcdir}
pushd %{srcdir}

mkdir -p ../docs
cp -f CREDITS LICENSE README* ChangeLog ../docs/
popd

for v in %{build_targets}; do
cp -a %{srcdir} php${v}
done


%build
for v in %{build_targets}; do
pushd php${v}
phpize${v}
%configure --with-php-config=php-config${v}
%__make %{?_smp_mflags}
popd
done


%install
cat > memcached.ini <<EOF
; Enable memcached extension module
extension=memcached.so

EOF

cat %{srcdir}/memcached.ini >> memcached.ini

for v in %{build_targets}; do
pushd php${v}

mkdir -p %{buildroot}%{_libdir}/php${v}/
mkdir -p %{buildroot}%{_sysconfdir}/php${v}/php.d
%makeinstall INSTALL_ROOT=%{buildroot}

install -m644 ../memcached.ini %{buildroot}%{_sysconfdir}/php${v}/php.d/memcached.ini

cat > ../files.php${v} <<EOF
%%defattr(-,root,root)
%%doc docs/*
%{_libdir}/php${v}/*
%%config(noreplace) %{_sysconfdir}/php${v}/php.d/*
EOF

popd
done


%check
%if %{with test}
for v in %{build_targets}; do
pushd php${v}
NO_INTERACTION=yes TEST_PHPDBG_EXECUTABLE=/usr/bin/phpdbg${v} make test
popd
done
%endif


%files -n php74-ext-%{extname} -f files.php74
%files -n php80-ext-%{extname} -f files.php80


%changelog
* Sat Mar 20 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.1.5.20210320
- moved to git HEAD.
- dropped Patch0: fixed in upstream.

* Sat Dec 19 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.1.5.20201219
- moved to git HEAD.
- added php80 support.
- dropped php73 support.

* Thu Dec 19 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.1.5-1
- new upstream release.
- added php74 support.

* Fri Dec 21 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.1.1-1
- new upstream release.
- dropped Patch1: fixed in upstream.
- drooped php72 support.

* Sat Dec 08 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.0.5-1
- added php73 support.

* Wed Dec 20 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.0.4-1
- new upstream release.

* Thu Mar 16 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.0.3-1
- initial build for Vine Linux.