%global commit0 0cacf284a292728ea6afe62cf81d0425d763b750
%global shortcommit0 %(c=%{commit0}; echo ${c:0:7})

%global varnishver 5.1.3
%global vabi 6.0
%global vabistrict 05c5ac6b9
#% global vplus  -plus
#% global vbranch .v4.1plus
%global vbranch .v5.1

Name: vmod-rtstatus
Summary: Real-Time status module for Varnish
Version: 1.2.1
Release: 0.3.20170126git%{?shortcommit0}%{?vbranch}%{?dist}
License: BSD
Group: System Environment/Daemons
URL: https://github.com/varnish/libvmod-rtstatus
Source0: https://github.com/varnish/lib%{name}/archive/%{commit0}.tar.gz#/lib%{name}-%{version}.tar.gz
buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

# source tarball built like this:
#  git clone https://github.com/varnish/libvmod-rtstatus.git
#  cd libvmod-rtstatus
#  git checkout 4.1
#  git checkout 0cacf28
#  ./autogen.sh && ./configure && make && make dist

# Fixes broken json when varnish has ran for some time under pressure
Patch1: vmod-rtstatus-1.0.1_fix_broken_json.patch
Patch2: vmod-rtstatus-1.2.1.fix_json_tool.patch

requires: varnish = %varnishver
requires: varnishabi-%vabi
requires: varnishabi-strict-%vabistrict

buildrequires: make
buildrequires: gcc
buildrequires: pkgconfig
#buildrequires: python-docutils
buildrequires: varnish = %varnishver
buildrequires: varnish%{?vplus}-libs-devel = %varnishver
buildrequires: python-simplejson
%if 0%{?el5}
BuildRequires: python26
%endif

%description
Real Time status page for Varnish

%prep
%setup -q -n lib%{name}-%{version}
%patch2

%build
export RST2MAN=/bin/true
%configure \
  --docdir=%{?_pkgdocdir}%{!?_pkgdocdir:%{_docdir}/%{name}-%{version}}
# We have to remove rpath - not allowed in Fedora
# (This problem only visible on 64 bit arches)
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g;
        s|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool

#make %{?_smp_mflags}
make %{?_smp_mflags}


%check
make check


%install
# Clean buildroot on older el variants
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
# None of these for fedora/epel
find %{buildroot}/%{_libdir}/ -name '*.la' -exec rm -f {} ';'
find %{buildroot}/%{_libdir}/ -name  '*.a' -exec rm -f {} ';'


%clean
rm -rf %{buildroot}


%files
%defattr(-,root,root,-)
%{_libdir}/varnish*/vmods/
%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7
%license LICENSE
%endif
%doc LICENSE README.rst COPYING CHANGES.rst
%{_mandir}/man3/*.3*

%changelog
* Wed Aug 30 2017 Ingvar Hagelund <ingvar@redpill-linpro.com> - 1.2.1-0.3.20170126git0cacf28
- Build against varnish-5.1.3

* Thu Jan 26 2017 Ingvar Hagelund <ingvar@redpill-linpro.com> - 1.2.1-0.1.20170126git0cacf28
- Updated to latest 4.1 branch
- Built against varnish-5.0.0
- Included CHANGES.rst as doc
- added patch and requirement for python-simplejson instead of json_pp for test05

* Thu Jun 23 2016 Ingvar Hagelund <ingvar@redpill-linpro.com> - 1.0.1-0.4.20160623gitc02d69d
- Updated to latest 4.1 branch
- Added a patch fixing broken json in some circumstances
- Including COPYING and LICENSE as doc, as they are installed by the makefile

* Tue May 24 2016 Ingvar Hagelund <ingvar@redpill-linpro.com> - 1.0.1-0.3.20160524git3fa94e7
- Updated to latest 4.1 branch

* Wed Feb 03 2016 Ingvar Hagelund <ingvar@redpill-linpro.com> - 1.0.1-0.2.20160203git8b5c1bc
- Rebuilt 4.1 branch for varnish-4.1.1

* Mon Nov 02 2015 Ingvar Hagelund <ingvar@redpill-linpro.com> - 1.0.1-0.1.git.92d1618
- Wrapped for copr/fedora