File ghc-regex-base.spec of Package ghc-regex-base
#
# spec file for package ghc-regex-base
#
# 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 regex-base
%global pkgver %{pkg_name}-%{version}
Name: ghc-%{pkg_name}
Version: 0.94.0.3
Release: 0
Summary: Common "Text.Regex.*" API for Regex matching
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
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-containers-devel
BuildRequires: ghc-containers-prof
BuildRequires: ghc-rpm-macros
BuildRequires: ghc-text-devel
BuildRequires: ghc-text-prof
ExcludeArch: %{ix86}
%description
This package does not provide the ability to do regular expression matching.
Instead, it provides the type classes that constitute the abstract API that is
implemented by \'regex-*\' backends such as:
* <https://hackage.haskell.org/package/regex-posix regex-posix>
* <https://hackage.haskell.org/package/regex-parsec regex-parsec>
* <https://hackage.haskell.org/package/regex-dfa regex-dfa>
* <https://hackage.haskell.org/package/regex-tdfa regex-tdfa>
* <https://hackage.haskell.org/package/regex-pcre regex-pcre>
See also <https://wiki.haskell.org/Regular_expressions> for more information.
%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}
# Patch the .cabal file in the source to force lower optimization and smaller
# initial heap for GHC during compilation. This helps avoid out-of-memory
# failures in constrained build VMs (e.g. aarch64 builders with limited RAM).
pushd %{pkg_name}-%{version}
if ls *.cabal >/dev/null 2>&1; then
cabalfile=$(ls *.cabal | head -n1)
awk 'BEGIN{inlib=0;added=0}
/^library/ {print; inlib=1; next}
inlib && /^\s*[A-Za-z0-9-]+:/ { if(!added){print " ghc-options: -O0 -H32m"; added=1} print; next}
{print}
END{ if(inlib && !added) print " ghc-options: -O0 -H32m" }' "$cabalfile" > "$cabalfile".new && mv "$cabalfile".new "$cabalfile"
fi
popd
%build
# Avoid passing -fobject-determinism which is not recognised by the GHC used
# by the build environment. Reproduce minimal steps of %ghc_lib_build without
# the problematic ghc option and reduce optimization to lower memory usage.
cd %{pkg_name}-%{version}
# Create a small ghc wrapper that filters out the unsupported -fobject-determinism flag.
# Capture real ghc path before we modify PATH.
real_ghc=$(command -v ghc || true)
cat > ghc <<'EOF'
#!/bin/sh
REAL_GHC="__REAL_GHC__"
ORIG_ARGS=("$@")
set --
for a in "${ORIG_ARGS[@]}"; do
if [ "$a" = "-fobject-determinism" ]; then
continue
fi
set -- "$@" "$a"
done
exec "$REAL_GHC" "$@"
EOF
if [ -n "$real_ghc" ]; then
sed -i "s|__REAL_GHC__|$real_ghc|" ghc
else
sed -i "s|__REAL_GHC__|ghc|" ghc
fi
chmod +x ghc
# Prepend current directory to PATH so that our wrapper is used.
PATH="$(pwd):$PATH"
export PATH
ghc --make -package Cabal -no-user-package-db -dynamic Setup
# Disable library profiling to reduce compiler memory usage in constrained VMs.
# Configure with a small initial heap; further ghc-options are enforced in the
# .cabal file by the %prep patch above.
LANG=C.utf8 ./Setup configure --prefix=/usr --libdir=/usr/lib64 --docdir=/usr/share/licenses/ghc-regex-base '--libsubdir=$compiler/lib/$pkgid' '--datasubdir=$pkgid' '--libexecsubdir=$pkgid' --ghc --dynlibdir=/usr/lib64/ghc-9.10.2/lib --global '--ghc-options=-fhide-source-paths -H32m' -v --disable-library-profiling --enable-shared --htmldir=/usr/share/doc/packages/ghc-9.10.2/html/libraries/regex-base-0.94.0.3 --global
# Build using the options embedded in the .cabal file (patched above).
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 README.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