%define pkg_name    pandoc-crossref
%define pkg_version 0.2.1.3
%define pkg_release 2%{?_dist_release}

%define pandoc_version 1.17.1

Summary:  Library and executable for using citeproc with pandoc
Name:    %{pkg_name}
Version: %{pkg_version}
Release: %{pkg_release}

License:  BSD3
Group:    Applications/Text
URL:      http://hackage.haskell.org

Source0: %{name}-%{version}.tar.gz
Source1: base-unicode-symbols-0.2.2.4.tar.gz
Source2: data-accessor-0.2.2.7.tar.gz
Source3: data-accessor-transformers-0.2.1.7.tar.gz
Source4: roman-numerals-0.5.1.5.tar.gz
Source5: utility-ht-0.0.11.tar.gz
Source6: data-accessor-template-0.2.1.12.tar.gz
Source100: packages

BuildRoot: %{_tmppath}/%{pkg_name}-%{version}-root

BuildRequires: ghc haskell-platform-base cabal-install
BuildRequires: libffi-devel gmp-devel zlib-devel

BuildRequires: libghc-data-default-class
BuildRequires: libghc-dlist
BuildRequires: libghc-data-default
BuildRequires: libghc-aeson
BuildRequires: libghc-http-client-tls
BuildRequires: yaml
BuildRequires: libghc-build-pandoc
BuildRequires: pandoc-libs = %{pandoc_version}

BuildRequires: docbook-utils docbook-utils-pdf docbook-style-xsl
BuildRequires: hscolour

Requires: pandoc = %{pandoc_version}

Vendor: Project Vine
Distribution: Vine Linux
Packager: ara_t


%description
pandoc-crossref is a pandoc filter for numbering figures, equations, tables
 and cross-references to them. Input file (like demo.md) can be converted into
 html, latex, pdf, md or other formats.
Optionally, you can use cleveref for latex/pdf output,
 e.g. cleveref pdf, cleveref latex, and listings package,
 e.g. listings pdf, listings latex.

You can also enable per-chapter numbering (as with --chapters for latex output).
You need to specify -M chapters for non-latex/pdf output however.
 Examples: html, markdown, latex, pdf.


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q

%build
# Initialise the package db
ghc-pkg init %{_builddir}/package.conf

# install dependent packages
cd %{_builddir}
for pkg in `cat %{_sourcedir}/packages`; do
  %{__tar} xzf %{_sourcedir}/${pkg}.tar.gz
  cd ${pkg}
  cabal configure
  cabal build
  cabal copy
  cabal register --inplace
  cd ..
done

# build pandoc-crossref
cd %{name}-%{version}
cabal configure \
      --prefix=%{_prefix} \
      --libdir=%{_libdir}/%{name}-%{version} \
      --libsubdir= \
      --datadir=%{_datadir}/%{name}-%{version} \
      --datasubdir= \
      --docdir=%{_docdir}/%{name}-%{version}

cabal build
cabal haddock || :
cabal copy --destdir=${RPM_BUILD_ROOT}

%install
%{__rm} -rf ${RPM_BUILD_ROOT}%{_libdir}
%{__mv} ${RPM_BUILD_ROOT}%{_datadir}/%{name}-%{version}/*.md \
 ${RPM_BUILD_ROOT}%{_docdir}/%{name}-%{version}/
%{__mv} ${RPM_BUILD_ROOT}%{_docdir}/%{name}-%{version}/html/*.md \
 ${RPM_BUILD_ROOT}%{_docdir}/%{name}-%{version}/

%clean
%{__rm} -rf ${RPM_BUILD_ROOT}


%files
%defattr(-, root, root)
%{_bindir}/pandoc-crossref
%{_docdir}/%{name}-%{version}/


%changelog
* Sun Jun 19 2016 Toshiaki Ara <ara_t@384.jp> 0.2.1.3-2
- rebuild under pandoc-1.17.1

* Sun Jun 05 2016 Toshiaki Ara <ara_t@384.jp> 0.2.1.3-1
- update to 0.2.1.3

* Fri May 06 2016 Toshiaki Ara <ara_t@384.jp> 0.2.1.1-1
- new package (devide from pandoc)

