File ghc-Only.spec of Package ghc-Only

#
# spec file for package ghc-Only
#
# 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 Only
%global pkgver %{pkg_name}-%{version}
Name:           ghc-%{pkg_name}
Version:        0.1
Release:        1.1
Summary:        The 1-tuple type or single-value "collection"
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/2.cabal#/%{pkg_name}.cabal
BuildRequires:  ghc-Cabal-devel
BuildRequires:  ghc-base-devel
BuildRequires:  ghc-base-prof
BuildRequires:  ghc-deepseq-devel
BuildRequires:  ghc-deepseq-prof
BuildRequires:  ghc-rpm-macros
ExcludeArch:    %{ix86}

%description
This package provides a canonical anonymous 1-tuple type missing from Haskell
for attaching typeclass instances.

NOTE: There is also the </package/OneTuple OneTuple package> which by using a
boxed \'data\'-type provides a 1-tuple type which has laziness properties which
are more faithful to the ones of Haskell\'s native tuples; whereas the primary
purpose of \'Only\' is to provide the traditionally so named type-wrapper for
attaching typeclass instances.

%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
# Build using Cabal Setup but avoid passing -fobject-determinism to GHC,
# which may not be recognized on this target. Configure with only safe ghc-options.
cd %{pkg_name}-%{version}
# Ensure a clean dist directory
rm -rf dist || :
# Build Setup if necessary and provide a wrapper that filters out
# -fobject-determinism from any --ghc-options passed to Setup.
if [ -f Setup.hs -o -f Setup.lhs ]; then
  # Always (re)build Setup to ensure we can replace it with a wrapper
  ghc --make -package Cabal -no-user-package-db -dynamic Setup || true
  if [ -x Setup ]; then
    # Move compiled Setup aside and install a wrapper that strips the
    # -fobject-determinism token from --ghc-options arguments.
    if [ -x Setup.real ]; then
      rm -f Setup.real
    fi
    mv Setup Setup.real
    cat > Setup <<'EOF'
#!/bin/bash
# Wrapper to filter out -fobject-determinism from --ghc-options
# Handles both --ghc-options=VALUE and --ghc-options VALUE forms.
args=()
while [ "$#" -gt 0 ]; do
  case "$1" in
    --ghc-options=*)
      val="${1#--ghc-options=}"
      # remove occurrences of -fobject-determinism and collapse spaces
      val="$(echo "$val" | sed -e 's/-fobject-determinism//g' -e 's/  */ /g' -e 's/^ *//; s/ *$//')"
      if [ -n "$val" ]; then
        args+=("--ghc-options=$val")
      fi
      shift
      ;;
    --ghc-options)
      shift
      val="$1"
      val="$(echo "$val" | sed -e 's/-fobject-determinism//g' -e 's/  */ /g' -e 's/^ *//; s/ *$//')"
      if [ -n "$val" ]; then
        args+=("--ghc-options=$val")
      fi
      shift
      ;;
    *)
      args+=("$1")
      shift
      ;;
  esac
done
exec ./Setup.real "${args[@]}"
EOF
    chmod +x Setup
  fi
  # Configure without -fobject-determinism which some GHC builds do not accept
  LANG=C.utf8 ./Setup configure --prefix=/usr --libdir=/usr/lib64 --ghc --global --ghc-options="-fhide-source-paths" --enable-shared --enable-library-profiling
  LANG=C.utf8 ./Setup build
else
  true
fi

%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

%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