##
##  ghc-zlib.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         ghc-zlib
Summary:      Haskell ZLib Compression Library
URL:          http://hackage.haskell.org/cgi-bin/hackage-scripts/package/zlib
Vendor:       Duncan Coutts
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Language
License:      BSD
Version:      0.5.3.2
Release:      20120122

#   list of sources
Source0:      http://hackage.haskell.org/packages/archive/zlib/%{version}/zlib-%{version}.tar.gz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, ghc
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  zlib
PreReq:       zlib

%description
    This Haskell package provides a pure interface for compressing and
    decompressing streams of data represented as lazy ByteStrings. It
    uses the zlib C library so it has high performance. It supports
    the "zlib", "gzip" and "raw" compression formats. It provides a
    convenient high level API suitable for most tasks and for the few
    cases where more control is needed it provides access to the full
    zlib feature set.

%track
    prog ghc-zlib = {
        version   = %{version}
        url       = http://hackage.haskell.org/cgi-bin/hackage-scripts/package/zlib
        regex     = zlib-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n zlib-%{version}

%build
    cp %{l_prefix}/lib/ghc/package.conf .
    %{l_prefix}/bin/runhaskell Setup configure \
        --prefix=$RPM_BUILD_ROOT%{l_prefix} \
        --libdir=$RPM_BUILD_ROOT%{l_prefix}/lib/ghc \
        --libsubdir="zlib-%{version}" \
        --ghc \
        --with-compiler=%{l_prefix}/bin/ghc \
        --with-hc-pkg=%{l_prefix}/bin/ghc-pkg \
        --extra-include-dirs=%{l_prefix}/include \
        --extra-lib-dirs=%{l_prefix}/lib \
        --package-db=`pwd`/package.conf \
        --global \
        --disable-shared
    %{l_prefix}/bin/runhaskell Setup build

%install
    %{l_prefix}/bin/runhaskell Setup install
    %{l_shtool} install -c -m 644 \
        -e "s;$RPM_BUILD_ROOT%{l_prefix};%{l_prefix};g" \
        dist/installed-pkg-config \
        $RPM_BUILD_ROOT%{l_prefix}/lib/ghc/zlib-%{version}/
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

%post
    if [ $1 -eq 1 ]; then
        $RPM_INSTALL_PREFIX/bin/ghc-pkg register \
            $RPM_INSTALL_PREFIX/lib/ghc/zlib-%{version}/installed-pkg-config
    elif [ $1 -ge 2 ]; then
        $RPM_INSTALL_PREFIX/bin/ghc-pkg update \
            $RPM_INSTALL_PREFIX/lib/ghc/zlib-%{version}/installed-pkg-config
    fi

%preun
    if [ $1 -eq 0 ]; then
        $RPM_INSTALL_PREFIX/bin/ghc-pkg unregister zlib-%{version}
    fi

