%define pkg_name    http-client-tls
%define pkg_version 0.2.2
%define pkg_release 3%{?_dist_release}

%define ghc_version 7.10.3

Summary: Haskell libraries: %{pkg_name} and dependent libraries
Name:    libghc-%{pkg_name}
Version: %{pkg_version}
Release: %{pkg_release}

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

Source0: %{pkg_name}-%{version}.tar.gz
Source1: base64-bytestring-1.0.0.1.tar.gz
Source2: blaze-builder-0.4.0.1.tar.gz
Source3: byteable-0.1.1.tar.gz
Source4: cereal-0.5.1.0.tar.gz
Source5: cookie-0.4.1.6.tar.gz
Source6: hourglass-0.2.10.tar.gz
Source7: http-types-0.9.tar.gz
Source8: memory-0.11.tar.gz
Source9: asn1-types-0.3.2.tar.gz
Source10: asn1-encoding-0.9.3.tar.gz
Source11: asn1-parse-0.9.4.tar.gz
Source12: cryptonite-0.13.tar.gz
Source13: mime-types-0.1.0.6.tar.gz
Source14: pem-0.2.2.tar.gz
Source15: socks-0.5.4.tar.gz
Source16: streaming-commons-0.1.15.1.tar.gz
Source17: http-client-0.4.27.tar.gz
Source18: x509-1.6.3.tar.gz
Source19: x509-store-1.6.1.tar.gz
Source20: x509-system-1.6.3.tar.gz
Source21: x509-validation-1.6.3.tar.gz
Source22: tls-1.3.4.tar.gz
Source23: connection-0.2.5.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-data-default-class

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

Requires: ghc haskell-platform-base cabal-install
Requires: libghc-data-default-class


Vendor: Project Vine
Distribution: Vine Linux
Packager: ara_t


%description
Haskell libraries: %{pkg_name} and dependent libraries


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q -n %{pkg_name}-%{version}

%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/%{pkg_name}/${pkg} \
    --libsubdir= \
    --datadir=%{_datadir}/%{pkg_name}/${pkg} \
    --datasubdir= \
    --docdir=%{_docdir}/%{pkg_name}/${pkg}

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

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

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

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

%{__cp} LICENSE \
        ${RPM_BUILD_ROOT}%{_docdir}/%{pkg_name}/%{pkg_name}-%{version}

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

%post
ghc-pkg recache

%postun
ghc-pkg recache


%files
%defattr(-, root, root)
%{_libdir}/ghc-%{ghc_version}/
%{_libdir}/ghc-lib/
%{_datadir}/


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

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

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