File ghc-terminal-size.spec of Package ghc-terminal-size
#
# spec file for package ghc-terminal-size
#
# 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 terminal-size
%global pkgver %{pkg_name}-%{version}
Name: ghc-%{pkg_name}
Version: 0.3.4
Release: 1.1
Summary: Get terminal window height and width
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/1.cabal#/%{pkg_name}.cabal
BuildRequires: ghc-Cabal-devel
BuildRequires: ghc-base-devel
BuildRequires: ghc-base-prof
BuildRequires: ghc-rpm-macros
ExcludeArch: %{ix86}
%description
Get terminal window height and width without ncurses dependency.
%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
# Create a ghc wrapper early in %prep so any invocation of Setup during
# the build uses it from PATH. The wrapper strips -fobject-determinism when
# passed either as a separate argument or embedded inside --ghc-options=...
mkdir -p "$PWD"/ghcwrap/bin
cat > "$PWD"/ghcwrap/bin/ghc <<'EOF_GHC_WRAPPER'
#!/bin/sh
# Filter out -fobject-determinism from arguments and forward to real ghc
newargs=""
for a in "$@"; do
# Remove the substring if present (covers --ghc-options=... cases)
clean=$(printf "%s" "$a" | sed 's/-fobject-determinism//g' | tr -s ' ')
# Skip empty results
[ -z "$clean" ] && continue
# Quote each argument to preserve spaces
newargs="$newargs \"$clean\""
done
# Execute the real ghc with filtered arguments
eval exec /usr/bin/ghc $newargs
EOF_GHC_WRAPPER
chmod +x "$PWD"/ghcwrap/bin/ghc
# Provide a small "Setup" wrapper early so the build machinery detects an
# executable Setup and does not attempt to compile Setup.hs (which may
# embed unsupported flags). The wrapper also ensures PATH includes our
# ghc wrapper so any ghc invocations are filtered.
cat > Setup <<'EOF_SETUP'
#!/bin/sh
export PATH="$PWD"/ghcwrap/bin:$PATH
ARGS=""
for a in "$@"; do
# remove the substring -fobject-determinism if present
clean=$(printf "%s" "$a" | sed 's/-fobject-determinism//g' | tr -s ' ')
[ -z "$clean" ] && continue
ARGS="$ARGS \"$clean\""
done
# Execute runhaskell with the filtered arguments
# Use eval to properly expand quoted arguments
eval exec runhaskell Setup.hs $ARGS
EOF_SETUP
chmod +x Setup
%build
# Call the Setup wrapper (it forwards to runhaskell with filtering)
./Setup configure --prefix=/usr --libdir=/usr/lib64 --docdir=/usr/share/licenses/ghc-terminal-size --ghc --global
./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.markdown README.markdown
%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