%define pkg_name    yaml
%define pkg_version 0.8.16
%define pkg_release 3%{?_dist_release}

%define ghc_version 7.10.3

Summary: Support for parsing and rendering YAML documents
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: fail-4.9.0.0.tar.gz
Source2: mmorph-1.0.6.tar.gz
Source3: tagged-0.8.3.tar.gz
Source4: semigroups-0.18.1.tar.gz
Source5: transformers-base-0.4.4.tar.gz
Source6: monad-control-1.0.0.5.tar.gz
Source7: lifted-base-0.2.3.6.tar.gz
Source8: enclosed-exceptions-1.0.1.1.tar.gz
Source9: resourcet-1.1.7.2.tar.gz
Source10: conduit-1.2.6.2.tar.gz

Source100: packages

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

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

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

Requires: ghc haskell-platform-base cabal-install
Requires: libghc-dlist
Requires: libghc-aeson

Vendor: Project Vine
Distribution: Vine Linux
Packager: ara_t


%description
This package includes the full libyaml C library version 0.1.5
 by Kirill Simonov in the package so you don't need to worry
 about any non-Haskell dependencies.

The package is broken down into two primary modules.
"Data.Yaml" provides a high-level interface based around the JSON datatypes
 provided by the @aeson@ package.
"Text.Libyaml" provides a lower-level, streaming interface.
For most users, "Data.Yaml" is recommended.
#'

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

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

PKG_CONF_DIR=${RPM_BUILD_ROOT}%{_libdir}/ghc-%{ghc_version}/package.conf.d
%{__mkdir_p} ${PKG_CONF_DIR}

# install dependent packages
cd %{_builddir}
for pkg in `cat %{SOURCE100}`; do
  %{__tar} xzf %{_sourcedir}/${pkg}.tar.gz
  cd ${pkg}
  cabal configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir}/ghc-lib/%{name}/${pkg} \
    --libsubdir= \
    --datadir=%{_datadir}/%{name}/${pkg} \
    --datasubdir= \
    --docdir=%{_docdir}/%{name}/${pkg}

  cabal build
  cabal haddock || : # avoid Error
  cabal copy --destdir=${RPM_BUILD_ROOT}
  cabal register --inplace
  cabal register --gen-pkg-config=${PKG_CONF_DIR}/%{name}_${pkg}.conf
  cd ..
done

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

cabal build
cabal haddock
cabal copy --destdir=${RPM_BUILD_ROOT}
cabal register --inplace
cabal register --gen-pkg-config=${PKG_CONF_DIR}/%{name}-%{version}.conf

%install
cabal copy --destdir=${RPM_BUILD_ROOT}

%{__cp} ChangeLog.md LICENSE README.md \
        ${RPM_BUILD_ROOT}%{_docdir}/%{name}/%{name}-%{version}

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

%post
ghc-pkg recache

%postun
ghc-pkg recache


%files
%defattr(-, root, root)
%{_bindir}/
%{_libdir}/ghc-%{ghc_version}/
%{_libdir}/ghc-lib/
%{_docdir}/%{name}/


%changelog
* Wed May 04 2016 Toshiaki Ara <ara_t@384.jp> 0.8.16-3
- rebuilt

* Tue Apr 12 2016 Toshiaki Ara <ara_t@384.jp> 0.8.16-2
- correct SPEC file

* Tue Mar 01 2016 Toshiaki Ara <ara_t@384.jp> 0.8.16-1
- new package
