##
##  hugs.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 version
%define       V_base           98
%define       V_rel_year       2006
%define       V_rel_month_num  09
%define       V_rel_month_name Sep
%define       V_pkg_unix       1.0.20060515
%define       V_pkg_network    1.0.20060515
%define       V_pkg_parsec     2.0.20060515
%define       V_pkg_mtl        1.0.20060515
%define       V_pkg_haxml      1.15.20060515

#   package information
Name:         hugs
Summary:      Haskell User's Gofer System (HUGS)
URL:          http://www.haskell.org/hugs/
Vendor:       Mark P. Jones et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Language
License:      BSD-style
Version:      %{V_base}.%{V_rel_year}%{V_rel_month_num}
Release:      20080101

#   list of sources
Source0:      http://cvs.haskell.org/Hugs/downloads/%{V_rel_year}-%{V_rel_month_num}/hugs%{V_base}-%{V_rel_month_name}%{V_rel_year}.tar.gz
Source1:      http://cvs.haskell.org/Hugs/downloads/%{V_rel_year}-%{V_rel_month_num}/packages/unix-%{V_pkg_unix}.tar.gz
Source2:      http://cvs.haskell.org/Hugs/downloads/%{V_rel_year}-%{V_rel_month_num}/packages/network-%{V_pkg_network}.tar.gz
Source3:      http://cvs.haskell.org/Hugs/downloads/%{V_rel_year}-%{V_rel_month_num}/packages/parsec-%{V_pkg_parsec}.tar.gz
Source4:      http://cvs.haskell.org/Hugs/downloads/%{V_rel_year}-%{V_rel_month_num}/packages/mtl-%{V_pkg_mtl}.tar.gz
Source5:      http://cvs.haskell.org/Hugs/downloads/%{V_rel_year}-%{V_rel_month_num}/packages/HaXml-%{V_pkg_haxml}.tar.gz
Patch0:       hugs.patch

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

%description
    Hugs 98 is a functional programming system based on Haskell 98, the
    de facto standard for non-strict functional programming languages.
    Hugs 98 provides an almost complete implementation of Haskell 98,
    including lazy evaluation, higher order functions, and pattern
    matching; a wide range of built-in types, from characters to
    bignums, and lists to functions, with comprehensive facilities for
    defining new datatypes and type synonyms; an advanced polymorphic
    type system with type and constructor class overloading; all of the
    features of the Haskell 98 expression and pattern syntax including
    lambda, case, conditional and let expressions, list comprehensions,
    do-notation, operator sections, and wildcard, irrefutable and
    `as' patterns; an implementation of the Haskell 98 primitives for
    monadic I/O, with support for simple interactive programs, access
    to text files, handle-based I/O, and exception handling; an almost
    complete implementation of the Haskell module system. Hugs 98 also
    supports a number of advanced and experimental extensions including
    multi-parameter classes, extensible records, rank-2 polymorphism,
    existentials, scoped type variables, and restricted type synonyms.
    Hugs is the successor to Gofer.

%track
    prog hugs = {
        version   = %{V_base}-%{V_rel_month_name}%{V_rel_year}
        url       = http://cvs.haskell.org/Hugs/pages/downloading.htm
        regex     = hugs(\d+-[^-]+\d+)\.tar\.gz
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %setup -q -T -D -a 3
    %setup -q -T -D -a 4
    %setup -q -T -D -a 5
    %patch -p0 -d hugs%{V_base}-%{V_rel_month_name}%{V_rel_year}

%build
    #   build HUGS
    ( cd hugs%{V_base}-%{V_rel_month_name}%{V_rel_year}
      export GREP="grep"
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags}" \
      CPPFLAGS="%{l_cppflags}" \
      LDFLAGS="%{l_ldflags}" \
      ./configure \
          --prefix=%{l_prefix} \
          --enable-internal-prims \
          --enable-timer \
          --enable-ffi
      %{l_make} %{l_mflags -O}
    ) || exit $?

%install
    #   install HUGS
    ( cd hugs%{V_base}-%{V_rel_month_name}%{V_rel_year}
      %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    ) || exit $?

    #   provide reasonably Cabal build environment
    for tool in hsc2hs cpphs; do
        %{l_shtool} install -c -m 755 \
            -e "s;%{l_prefix};$RPM_BUILD_ROOT%{l_prefix};g" \
            $RPM_BUILD_ROOT%{l_prefix}/bin/$tool-hugs \
            $RPM_BUILD_ROOT%{l_prefix}/bin/$tool
    done
    export PATH=$RPM_BUILD_ROOT%{l_prefix}/bin:$PATH
    export HUGSDIR=$RPM_BUILD_ROOT%{l_prefix}/lib/hugs

    #   install common Cabal extensions
    for extension in \
        unix-%{V_pkg_unix} \
        network-%{V_pkg_network} \
        parsec-%{V_pkg_parsec} \
        mtl-%{V_pkg_mtl} \
        HaXml-%{V_pkg_haxml}; do
        ( cd $extension
          export GREP="grep"
          runhugs -98 Setup.hs configure --hugs --prefix=%{l_prefix}
          runhugs -98 Setup.hs build
          runhugs -98 Setup.hs copy --destdir=$RPM_BUILD_ROOT
        ) || exit $?
    done

    #   cleanup after Cabal extension installations
    for tool in hsc2hs cpphs; do
        rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/$tool
    done

    #   strip down installation
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

