File ghc-skylighting-format-ansi.spec of Package ghc-skylighting-format-ansi

#
# spec file for package ghc-skylighting-format-ansi
#
# Copyright (c) 2023 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 skylighting-format-ansi
%global pkgver %{pkg_name}-%{version}
Name:           ghc-%{pkg_name}
Version:        0.1
Release:        0
Summary:        ANSI formatter for skylighting syntax highlighting library
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-ansi-terminal-devel
BuildRequires:  ghc-ansi-terminal-prof
BuildRequires:  ghc-base-devel
BuildRequires:  ghc-base-prof
BuildRequires:  ghc-binary-devel
BuildRequires:  ghc-binary-prof
BuildRequires:  ghc-colour-devel
BuildRequires:  ghc-colour-prof
BuildRequires:  ghc-containers-devel
BuildRequires:  ghc-containers-prof
BuildRequires:  ghc-skylighting-core-devel
BuildRequires:  ghc-skylighting-core-prof
BuildRequires:  ghc-text-devel
BuildRequires:  ghc-text-prof
ExcludeArch:    %{ix86}

%description
This module allows tokens produced by skylighting-core to be rendered as ANSI
colored text.

%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}
# Provide a minimal Setup.hs so that the distribution macros do not copy
# their own Setup.hs (which injects --ghc-options that some GHCs do not
# support). Placing Setup.hs here ensures the build uses a simple
# default Setup implementation.
cat > Setup.hs <<'EOF'
import Distribution.Simple
main = defaultMain
EOF

%build
# Use a simple Setup.hs and run configure/build without injecting
# additional ghc options that some ghc versions may not recognize.
# This avoids passing flags like -fobject-determinism which are not
# supported by older ghc releases.
# Overwrite any existing Setup.hs to ensure we control the configure
# behavior and avoid distribution macros injecting unsupported flags.
cat > Setup.hs <<'EOF'
import Distribution.Simple
main = defaultMain
EOF

# Create a small ghc wrapper to filter out unsupported ghc flags that
# may be injected by distribution macros (e.g. -fobject-determinism).
# This is a minimal and local workaround: we prepend a bin/ directory
# to PATH so that this wrapper is used during the build only.
mkdir -p ./bin
cat > ./bin/ghc <<'EOF'
#!/bin/sh
# Wrapper to filter out unsupported GHC flags
REAL_GHC=/usr/bin/ghc
if [ ! -x "$REAL_GHC" ]; then
  REAL_GHC=$(command -v ghc 2>/dev/null || true)
fi
if [ -z "$REAL_GHC" ]; then
  echo "ERROR: real ghc not found" >&2
  exit 1
fi
# Build command as an array of safe arguments
args=()
for a in "$@"; do
  case "$a" in
    *-fobject-determinism*|*-fhide-source-paths*)
      # drop unsupported flags (also covers combined args)
      ;;
    *)
      args+=("$a")
      ;;
  esac
done
# Exec real ghc with filtered arguments
exec "$REAL_GHC" "${args[@]}"
EOF
chmod +x ./bin/ghc
# Ensure our wrapper is used first
export PATH="$PWD/bin:$PATH"

# Configure and build using the simple Setup script. We intentionally
# avoid using --ghc-options here to prevent unsupported flags from
# being passed to ghc. Explicitly pass an empty --ghc-options and
# also request the Setup script to use our wrapper via --with-ghc.
runhaskell Setup.hs configure --ghc-options='' --with-ghc=$PWD/bin/ghc --prefix=/usr --libdir=/usr/lib64 --docdir=/usr/share/doc/packages/%{name} --datasubdir=%{pkg_name} --libexecsubdir=%{pkg_name} --ghc --dynlibdir=/usr/lib64 -v
runhaskell Setup.hs build

%install
rm -rf %{buildroot}
# Install into the staged buildroot. Again, avoid passing extra ghc
# options during the installation step.
runhaskell Setup.hs copy --destdir=%{buildroot} --prefix=/usr

%post devel
%ghc_pkg_recache

%postun devel
%ghc_pkg_recache

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

%files devel -f %{name}-devel.files
%doc 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
openSUSE Build Service is sponsored by