%bcond_with php5
%bcond_with php74
%bcond_without php81
%bcond_without php82

%define modname clearsilver

Summary: ClearSilver extension for PHP
Summary(ja): PHP用ClearSilverモジュール
Name: php-ext-%{modname}
Version: 0.4
Release: 18%{_dist_release}
Group: programming
Vendor: Project Vine
Distribution: Vine Linux
Packager: tomop

License: The PHP License
URL: http://www.geodata.soton.ac.uk/software/php_clearsilver/
Source: php-%{modname}-%{version}.tar.gz
Patch0: php-clearsilver-0.4-php5.6.0.patch
Patch2: php-clearsilver-0.4-php7.2.0.patch
Patch3: php-clearsilver-0.4-php8.0.0.patch
BuildRequires: clearsilver, zlib-devel
BuildRoot: %{_tmppath}/%{name}-%{version}-root

%description
This module adds ClearSilver functions to PHP.

%description -l ja
このモジュールはPHPにClearSilverテンプレート機能を追加します。


%if %{with php5}
%package -n php5-ext-%{modname}
Summary: ClearSilver extension for PHP-5.6.x
Summary(ja): PHP-5.6用ClearSilverモジュール
Group: programming
BuildRequires: php5-devel
%if "%{?req_php5_api}" != ""
Requires: %{req_php5_api}
%endif
Obsoletes: php-ext-clearsilver < 0.4-7

%description -n php5-ext-%{modname}
This module adds ClearSilver functions to PHP.

%description -n php5-ext-%{modname} -l ja
このモジュールはPHPにClearSilverテンプレート機能を追加します。
%endif


%if %{with php74}
%package -n php74-ext-%{modname}
Summary: ClearSilver extension for PHP-7.4
Summary(ja): PHP-7.4用ClearSilverモジュール
Group: programming
BuildRequires: php74-devel
%if "%{?req_php74_api}" != ""
Requires: %{req_php74_api}
%endif

%description -n php74-ext-%{modname}
This module adds ClearSilver functions to PHP.

%description -n php74-ext-%{modname} -l ja
このモジュールはPHPにClearSilverテンプレート機能を追加します。
%endif


%if %{with php82}
%package -n php82-ext-%{modname}
Summary: ClearSilver extension for PHP-8.2
Summary(ja): PHP-8.2用ClearSilverモジュール
Group: programming
BuildRequires: php82-devel
%if "%{?req_php82_api}" != ""
Requires: %{req_php82_api}
%endif

%description -n php82-ext-%{modname}
This module adds ClearSilver functions to PHP.

%description -n php82-ext-%{modname} -l ja
このモジュールはPHPにClearSilverテンプレート機能を追加します。
%endif


%if %{with php81}
%package -n php81-ext-%{modname}
Summary: ClearSilver extension for PHP-8.1
Summary(ja): PHP-8.1用ClearSilverモジュール
Group: programming
BuildRequires: php81-devel
%if "%{?req_php81_api}" != ""
Requires: %{req_php81_api}
%endif

%description -n php81-ext-%{modname}
This module adds ClearSilver functions to PHP.

%description -n php81-ext-%{modname} -l ja
このモジュールはPHPにClearSilverテンプレート機能を追加します。
%endif


%debug_package


%prep
%setup -q -c -n php-%{modname}-%{version}

cp -a php-%{modname}-%{version}/{CREDITS,INSTALL,LICENSE,README,doc} ./

%if %{with php5}
cp -a php-clearsilver-%{version} php-clearsilver-%{version}-php5
pushd php-clearsilver-%{version}-php5
%patch0 -p1 -b .php56
popd
%endif

%if %{with php74}
cp -a php-clearsilver-%{version} php-clearsilver-%{version}-php74
pushd php-clearsilver-%{version}-php74
%patch0 -p1 -b .php56
%patch2 -p1 -b .php72
popd
%endif

%if %{with php82}
cp -a php-clearsilver-%{version} php-clearsilver-%{version}-php82
pushd php-clearsilver-%{version}-php82
%patch3 -p1 -b .php80
popd
%endif

%if %{with php81}
cp -a php-clearsilver-%{version} php-clearsilver-%{version}-php81
pushd php-clearsilver-%{version}-php81
%patch3 -p1 -b .php80
popd
%endif


%build
export CFLAGS="%{optflags} -Wno-format-security"

%if %{with php5}
pushd php-clearsilver-%{version}-php5
phpize5
aclocal
autoreconf -vif
%configure --with-php-config=/usr/bin/php-config5
%__make %{_smp_mflags}
popd
%endif

%if %{with php74}
pushd php-clearsilver-%{version}-php74
phpize74
aclocal
%configure --with-php-config=/usr/bin/php-config74
%__make %{_smp_mflags}
popd
%endif

%if %{with php82}
pushd php-clearsilver-%{version}-php82
phpize82
aclocal
%configure --with-php-config=/usr/bin/php-config82
%__make %{_smp_mflags}
popd
%endif

%if %{with php81}
pushd php-clearsilver-%{version}-php81
phpize81
aclocal
%configure --with-php-config=/usr/bin/php-config81
%__make %{_smp_mflags}
popd
%endif


%install
rm -rf %{buildroot}
%if %{with php5}
pushd php-clearsilver-%{version}-php5
mkdir -p %{buildroot}%{_libdir}/php5/
mkdir -p %{buildroot}%{_sysconfdir}/php5/php.d

install -m755 modules/%{modname}.so %{buildroot}%{_libdir}/php5/

cat > %{buildroot}%{_sysconfdir}/php5/php.d/%{modname}.ini <<EOF
; Enable %{modname} extension module
extension=%{modname}.so
EOF
popd
%endif

%if %{with php74}
pushd php-clearsilver-%{version}-php74
mkdir -p %{buildroot}%{_libdir}/php74/
mkdir -p %{buildroot}%{_sysconfdir}/php74/php.d

install -m755 modules/%{modname}.so %{buildroot}%{_libdir}/php74/

cat > %{buildroot}%{_sysconfdir}/php74/php.d/%{modname}.ini <<EOF
; Enable %{modname} extension module
extension=%{modname}.so
EOF
popd
%endif

%if %{with php82}
pushd php-clearsilver-%{version}-php82
mkdir -p %{buildroot}%{_libdir}/php82/
mkdir -p %{buildroot}%{_sysconfdir}/php82/php.d

install -m755 modules/%{modname}.so %{buildroot}%{_libdir}/php82/

cat > %{buildroot}%{_sysconfdir}/php82/php.d/%{modname}.ini <<EOF
; Enable %{modname} extension module
extension=%{modname}.so
EOF
popd
%endif


%if %{with php81}
pushd php-clearsilver-%{version}-php81
mkdir -p %{buildroot}%{_libdir}/php81/
mkdir -p %{buildroot}%{_sysconfdir}/php81/php.d

install -m755 modules/%{modname}.so %{buildroot}%{_libdir}/php81/

cat > %{buildroot}%{_sysconfdir}/php81/php.d/%{modname}.ini <<EOF
; Enable %{modname} extension module
extension=%{modname}.so
EOF
popd
%endif


%check
%if %{with php5}
pushd php-clearsilver-%{version}-php5
make test NO_INTERACTION=1
popd
%endif

%if %{with php74}
pushd php-clearsilver-%{version}-php74
make test TEST_PHPDBG_EXECUTABLE=/usr/bin/phpdbg74 NO_INTERACTION=1
popd
%endif

%if %{with php82}
pushd php-clearsilver-%{version}-php82
make test TEST_PHPDBG_EXECUTABLE=/usr/bin/phpdbg82 NO_INTERACTION=1
popd
%endif

%if %{with php81}
pushd php-clearsilver-%{version}-php81
make test TEST_PHPDBG_EXECUTABLE=/usr/bin/phpdbg81 NO_INTERACTION=1
popd
%endif


%clean
rm -rf %{buildroot}


%if %{with php5}
%files -n php5-ext-%{modname}
%defattr(-,root,root)
%doc CREDITS INSTALL LICENSE README doc
%{_libdir}/php5/*
%{_sysconfdir}/php5/php.d/*
%endif

%if %{with php74}
%files -n php74-ext-%{modname}
%defattr(-,root,root)
%doc CREDITS INSTALL LICENSE README doc
%{_libdir}/php74/*
%{_sysconfdir}/php74/php.d/*
%endif

%if %{with php82}
%files -n php82-ext-%{modname}
%defattr(-,root,root)
%doc CREDITS INSTALL LICENSE README doc
%{_libdir}/php82/*
%{_sysconfdir}/php82/php.d/*
%endif

%if %{with php81}
%files -n php81-ext-%{modname}
%defattr(-,root,root)
%doc CREDITS INSTALL LICENSE README doc
%{_libdir}/php81/*
%{_sysconfdir}/php81/php.d/*
%endif


%changelog
* Fri Mar 17 2023 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-18
- added php82 support.
- dropped php80 support.
- disabled php74 support.

* Fri Nov 26 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-17
- added php81 support.

* Sat Dec 19 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-16
- added php80 support.
- dropped php73 support.

* Thu Dec 19 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-15
- added php74 support.

* Wed Sep 04 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-14
- disabled php5/php72 support.

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

* Fri Dec 22 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-12
- updated Patch0.
- updated Patch2.
- dropped Patch1: included in Patch0.
- enabled %%check.

* Thu Dec 21 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-11
- updated Patch2.

* Tue Dec 19 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-10
- dropped support for php71.
- added support for php72.

* Thu Mar 16 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-9
- added support for php71.

* Thu Nov  5 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-8
- fixed summary.
- fixed php70 stuff.

* Thu Nov  5 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-7
- added CGI functions.
- added support for php70.

* Fri Apr 10 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-6
- rebuilt with php5-5.6.7.

* Thu Jan 09 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-5
- rebuilt with current environment.

* Tue Jun 25 2013 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-4
- added a patch for PHP 5.5.0.

* Sun Apr 29 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-3
- converted encoding to UTF-8.

* Sat Apr 28 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-2
- added an API version macro to "Requires:".

* Sat Dec 12 2009 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4-1
- new upstream release.
 
* Fri Jul 10 2009 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.1-2
- fixed for php-5.3.0.

* Mon Apr 28 2008 Tomohiro 'Tomo-p' KATO <tomop@teamgedoh.net> 0.1-1
- initial build.

