File ghc-digest.spec of Package ghc-digest

#
# spec file for package ghc-digest
#
# Copyright (c) 2024 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 digest
%global pkgver %{pkg_name}-%{version}
Name:           ghc-%{pkg_name}
Version:        0.0.2.1
Release:        0
Summary:        CRC32 and Adler32 hashes for bytestrings
License:        BSD-2-Clause
URL:            https://hackage.haskell.org/package/%{pkg_name}
Source0:        https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz
BuildRequires:  gcc-c++
BuildRequires:  ghc-Cabal-devel
BuildRequires:  ghc-base-devel
BuildRequires:  ghc-base-prof
BuildRequires:  ghc-bytestring-devel
BuildRequires:  ghc-bytestring-prof
BuildRequires:  ghc-rpm-macros
BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(zlib)
ExcludeArch:    %{ix86}

%description
This package provides efficient hash implementations for strict and lazy
bytestrings. For now, CRC32 and Adler32 are supported; they are implemented as
FFI bindings to efficient code from zlib.

%package devel
Summary:        Haskell %{pkg_name} library development files
Requires:       %{name} = %{version}-%{release}
Requires:       ghc-compiler = %{ghc_version}
Requires:       pkgconfig
Requires:       pkgconfig(zlib)
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}

%build
# Use explicit build steps to avoid passing unsupported ghc flags such as
# -fobject-determinism to older ghc versions. Build Setup first and then
# configure and build without the problematic flag.
ghc --make -package Cabal -no-user-package-db -dynamic Setup
# Create a lightweight ghc wrapper that filters out unsupported flags
# (notably -fobject-determinism) injected by the build environment, then
# prepend it to PATH so Setup calls will use it when invoking ghc.
mkdir -p ./ghc-wrapper
cat > ./ghc-wrapper/ghc <<'SH'
#!/bin/sh
# Robustly filter out unsupported ghc flags (like -fobject-determinism)
# even when they appear inside combined arguments such as
# --ghc-options="-fobject-determinism -fhide-source-paths" or
# -optghc=-fobject-determinism. We remove any occurrence of the token
# "fobject-determinism" from arguments before invoking the real ghc.
newargs=""
for a in "$@"; do
  cleaned="$a"
  # Remove exact token occurrences
  cleaned="${cleaned//-fobject-determinism/}"
  cleaned="${cleaned//fobject-determinism/}"
  # Remove occurrences inside -optghc=...
  cleaned="${cleaned//-optghc=-fobject-determinism/}"
  # Remove leftover repeated '=' if present (e.g. --ghc-options=)
  cleaned="${cleaned//==/=}"
  # Collapse multiple spaces and trim
  cleaned="$(printf "%s" "$cleaned" | sed -E 's/[[:space:]]+/ /g; s/^ //; s/ $//')"
  if [ -n "$cleaned" ]; then
    # Preserve argument quoting
    newargs="$newargs \"${cleaned}\""
  fi
done
# Execute the real ghc with filtered arguments
eval "exec /usr/bin/ghc $newargs"
SH
# Also provide a versioned ghc wrapper because some build scripts call ghc-<version>
cat > ./ghc-wrapper/ghc-9.10.2 <<'SH'
#!/bin/sh
# Wrapper for ghc-9.10.2 that delegates to /usr/bin/ghc after filtering
# unsupported flags (same logic as ghc wrapper above).
newargs=""
for a in "$@"; do
  cleaned="$a"
  cleaned="${cleaned//-fobject-determinism/}"
  cleaned="${cleaned//fobject-determinism/}"
  cleaned="${cleaned//-optghc=-fobject-determinism/}"
  cleaned="${cleaned//==/=}"
  cleaned="$(printf "%s" "$cleaned" | sed -E 's/[[:space:]]+/ /g; s/^ //; s/ $//')"
  if [ -n "$cleaned" ]; then
    newargs="$newargs \"${cleaned}\""
  fi
done
exec /usr/bin/ghc $newargs
SH
chmod +x ./ghc-wrapper/ghc ./ghc-wrapper/ghc-9.10.2
# Export GHC to ensure Setup uses our wrapper even if it tries to invoke a
# specific ghc path/name. Also prefix PATH so unversioned calls pick up wrapper.
GHC="$PWD/ghc-wrapper/ghc" PATH="$PWD/ghc-wrapper:$PATH" LANG=C.utf8 ./Setup configure --prefix=/usr --libdir=/usr/lib64 --docdir=/usr/share/licenses/ghc-digest '--libsubdir=$compiler/lib/$pkgid' '--datasubdir=$pkgid' '--libexecsubdir=$pkgid' --ghc --dynlibdir=/usr/lib64/ghc-9.10.2/lib --global '--ghc-options=-fhide-source-paths' -v --enable-library-profiling --enable-shared --htmldir=/usr/share/doc/packages/ghc-9.10.2/html/libraries/digest-0.0.2.1 --global
LANG=C.utf8 ./Setup build

%install
%ghc_lib_install

%post devel
%ghc_pkg_recache

%postun devel
%ghc_pkg_recache

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

%files devel -f %{name}-devel.files
%doc CHANGELOG.md

%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