%bcond_with ruby

Summary: A fast, powerful, and language-neutral HTML template system.
Summary(ja): 高速、パワフルで言語中立なHTMLテンプレートシステム
Name: clearsilver
Version: 0.10.5
Release: 14%{_dist_release}
Group: programming
Vendor: Project Vine
Distribution: Vine Linux

# Technically, the license is "Neotonic ClearSilver", but it is a copy of 
# ASL 1.1 with the trademarks as the only difference.
License:        ASL 1.1
URL: http://clearsilver.net/
Source0: http://clearsilver.net/downloads/%{name}-%{version}.tar.gz

Patch0: clearsilver-0.10.5-conf.patch
Patch1: clearsilver-0.10.5-regression.patch
Patch2: clearsilver-0.10.5-CVE-2011-4357.patch
Patch3: clearsilver-ruby-1.9.patch
Patch4: clearsilver-ruby-2.2.patch
# GCC 5 compatibility, bug #1190760
Patch5: clearsilver-0.10.5-gcc5.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: perl
BuildRequires: perl-generators
BuildRequires: perl(ExtUtils::MakeMaker)
%if %{with ruby}
BuildRequires: ruby
BuildRequires: ruby-devel >= 1.9.3
%endif
BuildRequires: zlib-devel
BuildRequires: libxcrypt-devel

%description
ClearSilver is a fast, powerful, and language-neutral template system.
It is designed to make it easy to create template driven static or
dynamic websites.

%description -l ja
Clearsilver は高速、強力で言語中立なテンプレートシステムです。
テンプレート駆動の静的あるいは動的な Web サイトの構築を
容易にすることを目指して設計されています。


%package        devel
Summary:        header files and development library for ClearSilver
Summary(ja):    ClearSilverのヘッダファイル・開発ライブラリ
Group:          programming
Requires:       clearsilver = %{version}-%{release}

%description    devel
%{summary}.


%package     -n perl-%{name}
Summary:        Perl interface to the ClearSilver HTML templating system
Requires:       perl >= 2:5.34.0

%description -n perl-%{name}
%{summary}.


%if %{with ruby}
%package     -n ruby-%{name}
Summary:        Ruby interface to the ClearSilver HTML templating system

%description -n ruby-%{name}
%{summary}.
%endif


%debug_package


%prep
%setup -q
%patch0 -p1 -b .conf
%patch1 -p1
%patch2 -p1
%if %{with ruby}
%patch3 -p1
%patch4 -p1
%endif
%patch5 -p2

touch configure
sed -i -r 's|(\$\(RUBY\) install.rb config) (--.*)|\1 --rb-dir="$(DESTDIR)%{ruby_vendorlibdir}" --so-dir="$(DESTDIR)%{ruby_vendorarchdir}" \2|' ruby/Makefile


%build
%configure \
%if ! %{with ruby}
 --disable-ruby \
%endif
 --disable-csharp

%ifarch x86_64
perl -pi -e 's/^(TARGETS =.+) test/$1/' cs/Makefile
%endif

make %{?_smp_mflags} OPTIMIZE="$RPM_OPT_FLAGS"
cd perl && %{__perl} Makefile.PL INSTALLDIRS=vendor && cd ..
ld -z relro -shared -fPIC --build-id -lc --whole-archive \
	-o libclearsilver.so.0.0.0 \
	./libs/libneo_cgi.a \
	./libs/libneo_cs.a \
	./libs/libneo_utl.a


%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=${RPM_BUILD_ROOT} install

install -m755 libclearsilver.so.0.0.0 %{buildroot}%{_libdir}/
ln -sf libclearsilver.so.0.0.0 %{buildroot}%{_libdir}/libclearsilver.so.0.0
ln -sf libclearsilver.so.0.0.0 %{buildroot}%{_libdir}/libclearsilver.so.0
ln -sf libclearsilver.so.0.0.0 %{buildroot}%{_libdir}/libclearsilver.so

find $RPM_BUILD_ROOT -type f -name .packlist -exec rm -f {} ';'
find $RPM_BUILD_ROOT -type f -name perllocal.pod -exec rm -f {} ';'
find $RPM_BUILD_ROOT -type f -name '*.bs' -a -size 0 -exec rm -f {} ';'
find $RPM_BUILD_ROOT -type d -depth -exec rmdir {} 2>/dev/null ';'
chmod -R u+w $RPM_BUILD_ROOT/*


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root)
%license CS_LICENSE LICENSE
%doc INSTALL README
%{_bindir}/*
%{_libdir}/*.so.*

%files devel
%{_includedir}/ClearSilver/
%{_libdir}/*.a
%{_libdir}/*.so
%{_mandir}/man*/*.gz

%files -n perl-clearsilver
%doc CS_LICENSE LICENSE
%defattr(-,root,root,-)
%{perl_vendorarch}/auto/ClearSilver/
%{perl_vendorarch}/ClearSilver.pm

%if %{with ruby}
%files -n ruby-clearsilver
%{ruby_vendorarchdir}/*.so
%{ruby_vendorlibdir}/*.rb
%endif


%changelog
* Wed Nov 02 2022 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.10.5-14
- built shared library.

* Sat Nov 20 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.10.5-13
- rebuilt with perl-5.34.0.
- dropped python support.

* Sat May 18 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.10.5-12
- rebuilt with perl-5.26.
- added BR:libxcrypt-devel.

* Tue Dec 19 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.10.5-11
- added Patch5 for gcc5.
- disabled ruby stuff.

* Sat Sep 12 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.10.5-10
- rebuild with ruby-2.2.3
- add Patch4 (clearsilver-ruby-2.2.patch) from fedora

* Wed Dec 17 2014 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 0.10.5-9
- rebuilt with perl 5.16.3 and ruby 2.1.5

* Sun Dec 08 2013 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.10.5-8
- rebuilt with ruby-2.0.0.353.

* Thu Oct 25 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 0.10.5-7
- rebuild with ruby-1.9.3
- add patch3 to build with ruby-1.9
- add patch2 for CVE-2011-4357

* Sat Feb 25 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.10.5-6
- rebuilt with python-2.7.

* Sun May 15 2011 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.10.5-5
- rebuilt with perl-5.12.3 and python-2.6.

* Mon Jun 22 2009 Shu KONNO <owa@bg.wakwak.com> 0.10.5-4
- applied new versioning policy, spec in utf-8

* Mon Jul 21 2008 Shu KONNO <owa@bg.wakwak.com> 0.10.5-3
- rebuilt with python-2.5.2
- added clearsilver-0.10.5-conf.patch

* Tue Apr 29 2008 Tomohiro 'Tomo-p' KATO <tomop@teamgedoh.net> 0.10.5-2
- rebuilt with perl-5.10.0.

* Mon Apr 28 2008 Tomohiro 'Tomo-p' KATO <tomop@teamgedoh.net> 0.10.5-1
- x86_64: make to skip testing.

* Fri Nov 09 2007 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.10.5-0vl4
- add --disable-csharp for configure script

* Tue Aug 28 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.10.5-0vl2
- initial build for Vine Linux
