File ghc-HTTP.spec of Package ghc-HTTP

#
# spec file for package ghc-HTTP
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%global pkg_name HTTP
%global pkgver %{pkg_name}-%{version}
%bcond_with tests
Name:           ghc-%{pkg_name}
Version:        4000.4.1
Release:        1.1
Summary:        A library for client-side HTTP
License:        BSD-3-Clause
URL:            https://hackage.haskell.org/package/%{pkg_name}
Source0:        https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz
Source1:        https://hackage.haskell.org/package/%{pkg_name}-%{version}/revision/6.cabal#/%{pkg_name}.cabal
BuildRequires:  ghc-Cabal-devel
BuildRequires:  ghc-array-devel
BuildRequires:  ghc-array-prof
BuildRequires:  ghc-base-devel
BuildRequires:  ghc-base-prof
BuildRequires:  ghc-bytestring-devel
BuildRequires:  ghc-bytestring-prof
BuildRequires:  ghc-mtl-devel
BuildRequires:  ghc-mtl-prof
BuildRequires:  ghc-network-devel
BuildRequires:  ghc-network-prof
BuildRequires:  ghc-network-uri-devel
BuildRequires:  ghc-network-uri-prof
BuildRequires:  ghc-parsec-devel
BuildRequires:  ghc-parsec-prof
BuildRequires:  ghc-rpm-macros
BuildRequires:  ghc-time-devel
BuildRequires:  ghc-time-prof
BuildRequires:  ghc-transformers-devel
BuildRequires:  ghc-transformers-prof
BuildRequires:  ghc-rpm-macros
BuildRequires:  ghc-rpm-macros
BuildRequires:  ghc-rpm-macros
ExcludeArch:    %{ix86}
%if %{with tests}
BuildRequires:  ghc-HUnit-devel
BuildRequires:  ghc-HUnit-prof
BuildRequires:  ghc-deepseq-devel
BuildRequires:  ghc-deepseq-prof
BuildRequires:  ghc-httpd-shed-devel
BuildRequires:  ghc-httpd-shed-prof
BuildRequires:  ghc-pureMD5-devel
BuildRequires:  ghc-pureMD5-prof
BuildRequires:  ghc-split-devel
BuildRequires:  ghc-split-prof
BuildRequires:  ghc-test-framework-devel
BuildRequires:  ghc-test-framework-hunit-devel
BuildRequires:  ghc-test-framework-hunit-prof
BuildRequires:  ghc-test-framework-prof
%endif

%description
The HTTP package supports client-side web programming in Haskell. It lets you
set up HTTP connections, transmitting requests and processing the responses
coming back, all from within the comforts of Haskell. It\'s dependent on the
network package to operate, but other than that, the implementation is all
written in Haskell.

A basic API for issuing single HTTP requests + receiving responses is provided.
On top of that, a session-level abstraction is also on offer (the
\'BrowserAction\' monad); it taking care of handling the management of persistent
connections, proxies, state (cookies) and authentication credentials required
to handle multi-step interactions with a web server.

The representation of the bytes flowing across is extensible via the use of a
type class, letting you pick the representation of requests and responses that
best fits your use. Some pre-packaged, common instances are provided for you
(\'ByteString\', \\\'String\').

Here\'s an example use:

> > do > rsp <- Network.HTTP.simpleHTTP (getRequest "http://www.haskell.org/")
> -- fetch document and return it (as a \\\'String\">.) > fmap (take 100)
(getResponseBody rsp) > > do > (_, rsp) > <- Network.Browser.browse $ do >
setAllowRedirects True -- handle HTTP redirects > request $ getRequest
"http://www.haskell.org/" > return (take 100 (rspBody rsp))

__Note:__ This package does not support HTTPS connections. If you need HTTPS,
take a look at the following packages:

* <http://hackage.haskell.org/package/http-streams http-streams>

* <http://hackage.haskell.org/package/http-client http-client> (in combination
with <http://hackage.haskell.org/package/http-client-tls http-client-tls>)

* <http://hackage.haskell.org/package/req req>

* <http://hackage.haskell.org/package/wreq wreq>.

%package devel
Summary:        Haskell %{pkg_name} library development files
Requires:       %{name} = %{version}-%{release}
Requires:       ghc-compiler = %{ghc_version}
Requires(post): ghc-compiler = %{ghc_version}
Requires(postun): ghc-compiler = %{ghc_version}

%description devel
This package provides the Haskell %{pkg_name} library development files.

%package -n ghc-%{pkg_name}-doc
Summary:        Haskell %{pkg_name} library documentation
Requires:       ghc-filesystem
BuildArch:      noarch

%description -n ghc-%{pkg_name}-doc
This package provides the Haskell %{pkg_name} library documentation.

%package -n ghc-%{pkg_name}-prof
Summary:        Haskell %{pkg_name} profiling library
Requires:       ghc-%{pkg_name}-devel = %{version}-%{release}
Supplements:    (ghc-%{pkg_name}-devel and ghc-prof)

%description -n ghc-%{pkg_name}-prof
This package provides the Haskell %{pkg_name} profiling library.

%prep
%autosetup -n %{pkg_name}-%{version}
cp -p %{SOURCE1} %{pkg_name}.cabal

# If the distribution contains Setup.lhs or Setup.hs, move them out of the way
# and provide a small wrapper named `Setup` which invokes the original Setup
# via runhaskell after stripping packaging-added problematic ghc flags such
# as -fobject-determinism and -fhide-source-paths. This prevents the build
# system from automatically compiling Setup.lhs/Setup.hs into a binary that
# would otherwise ignore our sanitisation.
if [ -f Setup.lhs ]; then
  mv Setup.lhs Setup.lhs.orig
fi
if [ -f Setup.hs ]; then
  mv Setup.hs Setup.hs.orig
fi
# Remove any pre-existing compiled Setup binary to ensure our wrapper is used
if [ -f Setup ]; then
  rm -f Setup
fi
cat > Setup <<'SH'
#!/bin/sh
newargs=""
for a in "$@"; do
  case "$a" in
    --ghc-options=*)
      opts="${a#--ghc-options=}"
      cleaned=""
      for tok in $opts; do
        if [ "$tok" = "-fobject-determinism" ] || [ "$tok" = "-fhide-source-paths" ]; then
          continue
        fi
        cleaned="$cleaned $tok"
      done
      cleaned="$(echo $cleaned | xargs)"
      if [ -n "$cleaned" ]; then
        newargs="$newargs --ghc-options=$cleaned"
      fi
      ;;
    -fobject-determinism|-fhide-source-paths)
      ;;
    *)
      newargs="$newargs $a"
      ;;
  esac
done
# Prefer running the original Setup via runhaskell if present
if [ -f Setup.lhs.orig ]; then
  exec runhaskell Setup.lhs.orig $newargs
elif [ -f Setup.hs.orig ]; then
  exec runhaskell Setup.hs.orig $newargs
else
  # Fallback: try to run any remaining Setup
  exec ./Setup.bin $newargs
fi
SH
chmod +x Setup

%build
# Use explicit configure/build steps here to avoid passing packaging-provided
# ghc-options such as -fobject-determinism which older GHC versions may not
# recognise. This keeps the spec minimal and prevents build failures on aarch64
# due to unrecognised GHC flags coming from the build macros.
%{__bash} -c '
set -euo pipefail
# Create a ghc wrapper early so any invocation (including rpmbuild automatic
# compilation of Setup) passes through it and has problematic flags stripped.
fakebin="$(mktemp -d)"
realghc="$(command -v ghc || true)"
if [ -n "$realghc" ]; then
  realname="$(basename "$realghc")"
  # Create wrappers for the canonical name and the specific installed name
  for name in "$realname" ghc; do
    cat > "$fakebin/$name" <<'GHCWRAP'
#!/bin/sh
REAL_GHC="'"$realghc"'"
args=""
for a in "$@"; do
  case "$a" in
    -fobject-determinism|-fhide-source-paths)
      ;; # drop problematic flags
    --ghc-options=*)
      opts="${a#--ghc-options=}"
      cleaned=""
      for tok in $opts; do
        if [ "$tok" = "-fobject-determinism" ] || [ "$tok" = "-fhide-source-paths" ]; then
          continue
        fi
        cleaned="$cleaned $tok"
      done
      cleaned="$(echo $cleaned | xargs)"
      if [ -n "$cleaned" ]; then
        args="$args --ghc-options=$cleaned"
      fi
      ;;
    *)
      args="$args $a"
      ;;
  esac
done
exec "$realghc" $args
GHCWRAP
    chmod +x "$fakebin/$name"
  done
  export PATH="$fakebin:$PATH"
fi
cd %{pkg_name}-%{version}
# Prefer running the Setup.lhs via runhaskell to avoid any compiled Setup
# binary picking up packaging-added ghc-options. Support both Setup.lhs
# and Setup.hs if present; fall back to ./Setup when neither are available.
LANG=C.utf8
if [ -f Setup.lhs.orig ]; then
  runhaskell Setup.lhs.orig --version
  runhaskell Setup.lhs.orig configure --prefix=/usr --libdir=/usr/lib64 --docdir=/usr/share/licenses/ghc-HTTP "--libsubdir=$compiler/lib/$pkgid" "--datasubdir=$pkgid" "--libexecsubdir=$pkgid" --ghc --dynlibdir=/usr/lib64/ghc-9.10.2/lib --ghc-options="" --global -v --enable-library-profiling --enable-shared --htmldir=/usr/share/doc/packages/ghc-9.10.2/html/libraries/HTTP-4000.4.1
  runhaskell Setup.lhs.orig build
elif [ -f Setup.hs.orig ]; then
  runhaskell Setup.hs.orig --version
  runhaskell Setup.hs.orig configure --prefix=/usr --libdir=/usr/lib64 --docdir=/usr/share/licenses/ghc-HTTP "--libsubdir=$compiler/lib/$pkgid" "--datasubdir=$pkgid" "--libexecsubdir=$pkgid" --ghc --dynlibdir=/usr/lib64/ghc-9.10.2/lib --ghc-options="" --global -v --enable-library-profiling --enable-shared --htmldir=/usr/share/doc/packages/ghc-9.10.2/html/libraries/HTTP-4000.4.1
  runhaskell Setup.hs.orig build
else
  # Last resort: use ./Setup but explicitly clear ghc-options
  ./Setup --version || true
  ./Setup configure --prefix=/usr --libdir=/usr/lib64 --docdir=/usr/share/licenses/ghc-HTTP "--libsubdir=$compiler/lib/$pkgid" "--datasubdir=$pkgid" "--libexecsubdir=$pkgid" --ghc --dynlibdir=/usr/lib64/ghc-9.10.2/lib --ghc-options="" --global -v --enable-library-profiling --enable-shared --htmldir=/usr/share/doc/packages/ghc-9.10.2/html/libraries/HTTP-4000.4.1
  ./Setup build
fi
'

%install
%ghc_lib_install

%check
%cabal_test

%post devel
%ghc_pkg_recache

%postun devel
%ghc_pkg_recache

%files -f %{name}.files
%license LICENSE

%files devel -f %{name}-devel.files
%doc CHANGES

%files -n ghc-%{pkg_name}-doc -f ghc-%{pkg_name}-doc.files
%license LICENSE

%files -n ghc-%{pkg_name}-prof -f ghc-%{pkg_name}-prof.files

%changelog
openSUSE Build Service is sponsored by