File ghc-attoparsec.spec of Package ghc-attoparsec
#
# spec file for package ghc-attoparsec
#
# 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 attoparsec
%global pkgver %{pkg_name}-%{version}
%bcond_with tests
Name: ghc-%{pkg_name}
Version: 0.14.4
Release: 0
Summary: Fast combinator parsing for bytestrings and text
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-containers-devel
BuildRequires: ghc-containers-prof
BuildRequires: ghc-deepseq-devel
BuildRequires: ghc-deepseq-prof
BuildRequires: ghc-rpm-macros
BuildRequires: ghc-scientific-devel
BuildRequires: ghc-scientific-prof
BuildRequires: ghc-text-devel
BuildRequires: ghc-text-prof
BuildRequires: ghc-transformers-devel
BuildRequires: ghc-transformers-prof
ExcludeArch: %{ix86}
%if %{with tests}
BuildRequires: ghc-QuickCheck-devel
BuildRequires: ghc-QuickCheck-prof
BuildRequires: ghc-quickcheck-unicode-devel
BuildRequires: ghc-quickcheck-unicode-prof
BuildRequires: ghc-tasty-devel
BuildRequires: ghc-tasty-prof
BuildRequires: ghc-tasty-quickcheck-devel
BuildRequires: ghc-tasty-quickcheck-prof
BuildRequires: ghc-vector-devel
BuildRequires: ghc-vector-prof
%endif
%description
A fast parser combinator library, aimed particularly at dealing efficiently
with network protocols and complicated text/binary file formats.
%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
%build
# Use an explicit build sequence to avoid passing -fobject-determinism which
# some GHC versions (notably 9.10.2 on certain architectures) do not
# recognise. This replaces the generic %ghc_lib_build macro with a minimal
# equivalent that omits that flag.
cd %{pkg_name}-%{version}
# Build the Setup program using the installed Cabal library
ghc --make -package Cabal -no-user-package-db -dynamic Setup
# Replace the generated Setup with a small wrapper that strips
# any occurrences of -fobject-determinism from arguments before
# invoking the real Setup program. This ensures the configure step
# cannot pass the problematic flag to ghc.
mv Setup Setup.real
cat > Setup <<'EOF'
#!/bin/sh
# Wrapper to remove occurrences of -fobject-determinism from arguments
real="$(dirname "$0")/Setup.real"
# Use a small perl filter to robustly remove occurrences of -fobject-determinism
# from --ghc-options=... and from standalone -fobject-determinism arguments.
exec perl -e '
my $real = shift;
my @new;
foreach my $a (@ARGV) {
next if $a eq "-fobject-determinism";
if ($a =~ /^--ghc-options=(.*)/) {
my $val = $1;
$val =~ s/-fobject-determinism//g;
$val =~ s/\s+/ /g;
$val =~ s/^\s+|\s+$//g;
next if $val eq "";
push @new, "--ghc-options=$val";
} else {
push @new, $a;
}
}
exec $real, @new or die "exec failed: $!";
' "$real" "$@"
EOF
chmod +x Setup
# Create a ghc wrapper in the build directory and put it on PATH so any
# invocation of ghc during configure/build will have -fobject-determinism
# stripped. This is a defensive measure in case the flag is injected by
# cabal setup internals rather than passed through setup arguments.
cat > ghc <<'EOF'
#!/usr/bin/env perl
use strict;
use warnings;
my $real = '/usr/bin/ghc';
my @new;
foreach my $a (@ARGV) {
next if $a eq '-fobject-determinism';
if ($a =~ /^--ghc-options=(.*)/) {
my $val = $1;
$val =~ s/-fobject-determinism//g;
$val =~ s/\s+/ /g;
$val =~ s/^\s+|\s+$//g;
next if $val eq '';
push @new, "--ghc-options=$val";
} else {
push @new, $a;
}
}
exec $real, @new or die "exec failed: $!";
EOF
chmod +x ghc
# Prepend the build directory to PATH so our ghc wrapper is used
PATH="$PWD:$PATH"
export PATH
LANG=C.utf8
# Configure without -fobject-determinism; keep -fhide-source-paths as before
./Setup configure --prefix=/usr --libdir=/usr/lib64 --docdir=/usr/share/licenses/ghc-attoparsec \
'--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/%{pkg_name}-%{version} --global
./Setup build
%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 README.markdown changelog.md examples
%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