-%define _modname -
-%define _status -
-Summary: %{_modname} -
-Summary(pl.UTF-8): %{_modname} -
-Name: php-pecl-%{_modname}
+#
+# Conditional build:
+%bcond_without tests # build without tests
+
+%define php_name php%{?php_suffix}
+%define modname MODULE_NAME
+Summary: %{modname} -
+Summary(pl.UTF-8): %{modname} -
+Name: %{php_name}-pecl-%{modname}
Version: 1.0
Release: 1
-License: PHP 2.02
+License: PHP 3.01
Group: Development/Languages/PHP
-Source0: http://pecl.php.net/get/%{_modname}-%{version}.tgz
-URL: http://pecl.php.net/package/Modname/
-BuildRequires: php-devel >= 3:5.0.0
-BuildRequires: rpmbuild(macros) >= 1.344
+Source0: https://pecl.php.net/get/%{modname}-%{version}.tgz
+# Source0-md5: -
+URL: https://pecl.php.net/package/MODULE_NAME/
+BuildRequires: %{php_name}-cli
+BuildRequires: %{php_name}-devel
+BuildRequires: rpmbuild(macros) >= 1.666
+%if %{with tests}
+BuildRequires: %{php_name}-pcre
+%endif
%{?requires_php_extension}
-Requires: php-common >= 4:5.0.4
+Requires: %{php_name}-spl
+Provides: php(%{modname}) = %{version}
BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
%description
-In PECL status of this extension is: %{_status}.
-
%description -l pl.UTF-8
-To rozszerzenie ma w PECL status: %{_status}.
-
%prep
-%setup -q -c
-mv %{_modname}-%{version}/* .
+%setup -qc
+mv %{modname}-%{version}/* .
+
+cat <<'EOF' > run-tests.sh
+#!/bin/sh
+export NO_INTERACTION=1 REPORT_EXIT_STATUS=1 MALLOC_CHECK_=2
+exec %{__make} test \
+ PHP_EXECUTABLE=%{__php} \
+ PHP_TEST_SHARED_SYSTEM_EXTENSIONS="spl pdo session" \
+ RUN_TESTS_SETTINGS="-q $*"
+EOF
+chmod +x run-tests.sh
+
+xfail() {
+ local t=$1
+ test -f $t
+ cat >> $t <<-EOF
+
+ --XFAIL--
+ Skip
+ EOF
+}
+
+while read line; do
+ t=${line##*\[}; t=${t%\]}
+ xfail $t
+done << 'EOF'
+Test for blowfish compatibility [tests/blowfish.phpt]
+Bug #8040 (MCRYPT_MODE_* do not seem to exist) [tests/bug8040.phpt]
+EOF
%build
phpize
%configure
%{__make}
+# simple module load test
+%{__php} -n -q \
+ -d extension_dir=modules \
+ -d extension=%{php_extensiondir}/spl.so \
+ -d extension=%{modname}.so \
+ -m > modules.log
+grep %{modname} modules.log
+
+%if %{with tests}
+./run-tests.sh --show-diff
+%endif
+
%install
rm -rf $RPM_BUILD_ROOT
install -d $RPM_BUILD_ROOT%{php_sysconfdir}/conf.d
+install -d $RPM_BUILD_ROOT{%{php_sysconfdir}/conf.d,%{php_extensiondir}}
+install -d $RPM_BUILD_ROOT{%{php_sysconfdir}/conf.d,%{php_extensiondir},%{_examplesdir}/%{name}-%{version}}
%{__make} install \
- INSTALL_ROOT=$RPM_BUILD_ROOT \
- EXTENSION_DIR=%{php_extensiondir}
-cat <<'EOF' > $RPM_BUILD_ROOT%{php_sysconfdir}/conf.d/%{_modname}.ini
-; Enable %{_modname} extension module
-extension=%{_modname}.so
+ EXTENSION_DIR=%{php_extensiondir} \
+ INSTALL_ROOT=$RPM_BUILD_ROOT
+
+install -d $RPM_BUILD_ROOT%{php_sysconfdir}/conf.d
+cat <<'EOF' > $RPM_BUILD_ROOT%{php_sysconfdir}/conf.d/%{modname}.ini
+; Enable %{modname} extension module
+extension=%{modname}.so
EOF
+install -d $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version}
+cp -a examples/* $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version}
+
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(644,root,root,755)
%doc CREDITS EXPERIMENTAL
-%config(noreplace) %verify(not md5 mtime size) %{php_sysconfdir}/conf.d/%{_modname}.ini
-%attr(755,root,root) %{php_extensiondir}/%{_modname}.so
+%config(noreplace) %verify(not md5 mtime size) %{php_sysconfdir}/conf.d/%{modname}.ini
+%attr(755,root,root) %{php_extensiondir}/%{modname}.so
+%{_examplesdir}/%{name}-%{version}