File ghc-megaparsec.spec of Package ghc-megaparsec
#
# spec file for package ghc-megaparsec
#
# 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 megaparsec
%global pkgver %{pkg_name}-%{version}
Name: ghc-%{pkg_name}
Version: 9.7.0
Release: 0
Summary: Monadic parser combinators
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: 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-case-insensitive-devel
BuildRequires: ghc-case-insensitive-prof
BuildRequires: ghc-containers-devel
BuildRequires: ghc-containers-prof
BuildRequires: ghc-deepseq-devel
BuildRequires: ghc-deepseq-prof
BuildRequires: ghc-mtl-devel
BuildRequires: ghc-mtl-prof
BuildRequires: ghc-parser-combinators-devel
BuildRequires: ghc-parser-combinators-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}
%description
This is an industrial-strength monadic parser combinator library.
Megaparsec is a feature-rich package that tries to find a nice balance between
speed, flexibility, and quality of parse errors.
%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}
%build
# The default %ghc_lib_build macro injects a -fobject-determinism ghc option
# which is not recognised by the older ghc used in some build environments
# (for example ghc-9.10.2). To avoid the unrecognised flag we reproduce the
# essential parts of the build here while omitting -fobject-determinism and
# keeping other flags intact.
cp /usr/share/ghc-rpm-macros/Setup.hs .
# Remove any occurrence of -fobject-determinism coming from the shared Setup.hs
sed -i 's/-fobject-determinism//g' Setup.hs
# Create a small ghc wrapper in the build dir that strips the
# -fobject-determinism flag when invoking the real /usr/bin/ghc.
# This wrapper removes the token anywhere it appears (including inside
# --ghc-options=... arguments) so that older ghc versions do not see it.
cat > ghc-filter <<\'EOF\'
#!/bin/sh
# Wrapper to filter out -fobject-determinism which older ghc does not accept
# Also remove occurrences from common environment variables used by Cabal
# and ensure we forward the cleaned arguments to the real ghc.
clean_arg() {
printf '%s' "$1" | sed 's/-fobject-determinism//g' | sed 's/ */ /g' | sed 's/^ *//; s/ *$//'
}
newargs=""
for a in "$@"; do
cleaned=$(clean_arg "$a")
[ -z "$cleaned" ] && continue
esc=$(printf '%s' "$cleaned" | sed 's/"/\\"/g')
newargs="$newargs \"$esc\""
done
# Clean common env vars
for ev in GHC_OPTIONS CABALFLAGS EXTRA_HC_OPTS; do
val=$(eval "printf '%s' \"\${$ev}\"")
if [ -n "$val" ]; then
cleaned=$(clean_arg "$val")
eval "export $ev=\"$cleaned\""
fi
done
# Execute the real ghc with the filtered arguments
# Use exec to replace the shell
eval exec /usr/bin/ghc $newargs
EOF
chmod +x ghc-filter
# Prepend build dir to PATH so the wrapper is used for ghc invocations
PATH="$PWD":$PATH
export PATH
# Provide wrapper as "ghc"
mv ghc-filter ghc
# Also provide a symlink matching the versioned ghc executable name
# so invocations of ghc-9.10.2 use the wrapper as well.
ln -s ghc ghc-9.10.2
# Also set GHC environment variable so Cabal/Setup uses the wrapper explicitly
export GHC="$PWD/ghc"
# Ensure Setup uses our wrapper by passing --with-ghc
ghc --make -package Cabal -no-user-package-db -dynamic Setup
LANG=C.utf8
./Setup configure --with-ghc="$PWD/ghc" --prefix=/usr --libdir=/usr/lib64 --docdir=/usr/share/licenses/ghc-megaparsec \
\\'--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/megaparsec-9.7.0 --global
./Setup build
%install
%ghc_lib_install
%post devel
%ghc_pkg_recache
%postun devel
%ghc_pkg_recache
%files -f %{name}.files
%license LICENSE.md
%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.md
%files -n ghc-%{pkg_name}-prof -f ghc-%{pkg_name}-prof.files
%changelog