File ghc.spec of Package ghc

# spec file for package ghc
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
# 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

%ifnarch %{arm} s390x
%define with_libnuma 1
%define with_libnuma 0

%global unregisterised_archs s390 s390x riscv64
%define full_version 8.10.2

Name:           ghc
Version:        8.10.2
Release:        0
Source2:        ghc-rpmlintrc
Summary:        The Glorious Glasgow Haskell Compiler
License:        BSD-3-Clause
Group:          Development/Languages/Other
ExclusiveArch:  aarch64 %{arm} %{ix86} x86_64 ppc64 ppc64le riscv64 s390x
BuildRequires:  binutils-devel
BuildRequires:  gcc
BuildRequires:  ghc-bootstrap >= 8.6
BuildRequires:  ghc-rpm-macros-extra
BuildRequires:  glibc-devel
BuildRequires:  gmp-devel
BuildRequires:  libdw-devel
BuildRequires:  libelf-devel
BuildRequires:  libffi-devel
BuildRequires:  libtool
BuildRequires:  memory-constraints
BuildRequires:  ncurses-devel
BuildRequires:  pkg-config
BuildRequires:  xz
%ifarch aarch64 %{arm}
BuildRequires:  binutils-gold
%ifarch aarch64 %{arm} %{ix86} x86_64
%if 0%{?suse_version} >= 1550
BuildRequires:  llvm9-devel
BuildRequires:  clang9 
BuildRequires:  llvm-devel
BuildRequires:  clang 
%if %{undefined without_manual}
BuildRequires:  python3-Sphinx

%if %with_libnuma
BuildRequires:  libnuma-devel

BuildRequires:  ghc-bootstrap-helpers
PreReq:         update-alternatives

Requires:       ghc-compiler = %{version}-%{release}
Requires:       ghc-ghc-devel = %{version}-%{release}
Requires:       ghc-libraries = %{version}-%{release}

# PATCH-FIX-UPSTREAM Disable-unboxed-arrays.patch -- Do not use unboxed arrays on big-endian platforms. See Haskell Trac #15411.
Patch3:         Disable-unboxed-arrays.patch
# PATCH-FIX-UPSTREAM ghc-pie.patch - set linux as default PIE platform
Patch35:        ghc-pie.patch
# PATCH-FIX-OPENSUSE ghc-8.0.2-Cabal-dynlibdir.patch -- Fix shared library directory location.
Patch100:       ghc-8.0.2-Cabal-dynlibdir.patch
# PATCH-FIX-UPSTREAM buildpath-abi-stability.patch -- debian patch for more stable abi-1
Patch110:       buildpath-abi-stability.patch

Haskell is the standard purely functional programming language; the
current language version is Haskell 98, agreed in December 1998.

GHC is a state-of-the-art programming suite for Haskell.  Included is
an optimising compiler generating good code for a variety of
platforms, together with an interactive system for convenient, quick
development.  The distribution includes space and time profiling
facilities, a large collection of libraries, and support for various
language extensions, including concurrency, exceptions, and foreign
language interfaces (C, C++, etc).

A wide variety of Haskell related resources (tutorials, libraries,
specifications, documentation, compilers, interprbeters, references,
contact information, links to research groups) are available from the
Haskell home page at <>.

%package compiler
Summary:        GHC compiler and utilities
Group:          Development/Languages/Other
Requires:       gcc
Requires:       ghc-base-devel
Requires(post): update-alternatives
Requires(postun): update-alternatives
%ifarch aarch64 %{arm}
Requires:       binutils-gold
%ifarch aarch64 %{arm}
%if 0%{?suse_version} >= 1550
Requires:       clang9
Requires:       llvm9
Requires:       llvm
Requires:       clang 
%ifarch x86_64 %{ix86}
%if 0%{?suse_version} >= 1550
Suggests:       clang9 
Suggests:       llvm9
Suggests:       llvm
Suggests:       clang

%description compiler
This package contains the GHC compiler, tools and utilities.

The GHC libraries are provided by ghc-devel.
To install all of GHC install package ghc.

%global ghc_version_override %{version}

%global ghc_pkg_c_deps ghc-compiler = %{ghc_version_override}-%{release}

%if %with_libnuma
%define libnuma_dep ,libnuma-devel
%define libnuma_dep %{nil}

%if %{defined ghclibdir}
%ghc_lib_subpackage -d Cabal-
%ghc_lib_subpackage -d array-
%ghc_lib_subpackage -d -c gmp-devel,libffi-devel,libdw-devel,libelf-devel%{libnuma_dep} base-
%ghc_lib_subpackage -d binary-
%ghc_lib_subpackage -d bytestring-
%ghc_lib_subpackage -d containers-
%ghc_lib_subpackage -d deepseq-
%ghc_lib_subpackage -d directory-
%ghc_lib_subpackage -d exceptions-0.10.4 
%ghc_lib_subpackage -d filepath-
%ghc_lib_subpackage -d -x ghc-%{ghc_version_override}
%ghc_lib_subpackage -d ghc-boot-%{ghc_version_override}
%ghc_lib_subpackage -d ghc-boot-th-%{ghc_version_override}
%ghc_lib_subpackage -d ghc-compact-
%ghc_lib_subpackage -d ghc-heap-%{ghc_version_override}
%ghc_lib_subpackage -d -x ghci-%{ghc_version_override}
%ghc_lib_subpackage -d haskeline-
%ghc_lib_subpackage -d hpc-
%ghc_lib_subpackage -d libiserv-%{ghc_version_override}
%ghc_lib_subpackage -d mtl-2.2.2
%ghc_lib_subpackage -d parsec-
%ghc_lib_subpackage -d pretty-
%ghc_lib_subpackage -d process-
%ghc_lib_subpackage -d stm-
%ghc_lib_subpackage -d template-haskell-
%ghc_lib_subpackage -d -c ncurses-devel terminfo-
%ghc_lib_subpackage -d text-
%ghc_lib_subpackage -d time-1.9.3
%ghc_lib_subpackage -d transformers-
%ghc_lib_subpackage -d unix-
%ghc_lib_subpackage -d xhtml-3000.2.2.1

%global version %{ghc_version_override}

%package libraries
Summary:        GHC development libraries meta package
Group:          Development/Libraries/Other
Requires:       ghc-compiler = %{version}-%{release}
Obsoletes:      ghc-devel < %{version}-%{release}
Provides:       ghc-devel = %{version}-%{release}
Obsoletes:      ghc-prof < %{version}-%{release}
Provides:       ghc-prof = %{version}-%{release}
%{?ghc_packages_list:Requires: %(echo %{ghc_packages_list} | sed -e "s/\([^ ]*\)-\([^ ]*\)/ghc-\1-devel = \2-%{release},/g")}

%description libraries
This is a meta-package for all the development library packages in GHC
except the ghc library, which is installed by the toplevel ghc metapackage.

%setup -q
%ifarch ppc64 s390 s390x
%patch3 -p1
%patch35 -p1
%patch100 -p1
%patch110 -p1

cat > mk/ <<EOF
%ifarch aarch64 %{arm}
BuildFlavour = perf-llvm
BuildFlavour = perf

# BuildFlavours are defined in mk/
cat mk/ >> mk/
# override some settings
cat >> mk/ << EOF
GhcLibWays = v %{!?ghc_without_shared:dyn} %{!?without_prof:p}
%if %{defined ghc_without_shared}
%ifarch  %{unregisterised_archs}
GhcUnregisterised    = YES
GhcWithNativeCodeGen = NO
SRC_HC_OPTS          = -O -H64m
GhcStage1HcOpts      = -O
GhcStage2HcOpts      = -O
GhcHcOpts            = -Rghc-timing
GhcLibHcOpts         = -O
SRC_HC_OPTS         += -optc-fno-builtin -optc-Wno-return-type
SRC_CC_OPTS         += -fno-builtin -Wno-return-type
%if %{defined without_haddock}
%if %{defined without_manual}
%if %{defined without_hscolour}

export CFLAGS="${CFLAGS:-%optflags}"
./configure --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} \
  --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} \
  --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} \
  --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} \
  --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} \

%if 0%{?suse_version} >= 1500
%ifarch %{unregisterised_archs}
%if 0%{?qemu_user_space_build}
%limit_build -m 15000
%limit_build -m 8000
%limit_build -m 2000
make %{?_smp_mflags}
make -j 2


for i in %{ghc_packages_list}; do
name=$(echo $i | sed -e "s/\(.*\)-.*/\1/")
ver=$(echo $i | sed -e "s/.*-\(.*\)/\1/")
%ghc_gen_filelists $name $ver
# TODO: containers have license in $name/$name
#echo "%%doc libraries/$name/LICENSE" >> ghc-$name.files

# ghc-base should own ghclibdir
echo "%dir %{ghclibdir}" >> ghc-base.files

%ghc_gen_filelists ghc %{ghc_version_override}
%ghc_gen_filelists ghci %{ghc_version_override}
%ghc_gen_filelists ghc-prim 0.6.1
%ghc_gen_filelists integer-gmp

%define merge_filelist()\
cat ghc-%1.files >> ghc-%2.files\
cat ghc-%1-devel.files >> ghc-%2-devel.files\
cp -p libraries/%1/LICENSE libraries/LICENSE.%1\
echo "%doc libraries/LICENSE.%1" >> ghc-%2.files

%merge_filelist integer-gmp base
%merge_filelist ghc-prim base

%if %{undefined ghc_without_shared}
echo %%dir %{ghclibdir}/rts >> ghc-base.files
ls %{buildroot}%{ghclibdir}/rts/libHS*.so >> ghc-base.files
sed -i -e "s|^%{buildroot}||g" ghc-base.files
echo %%dir %{ghclibdir}/rts >> ghc-base-devel.files
ls -d %{buildroot}%{ghclibdir}/rts/libHS*.a  %{buildroot}%{ghclibdir}/package.conf.d/rts.conf %{buildroot}%{ghclibdir}/include >> ghc-base-devel.files
sed -i -e "s|^%{buildroot}||g" ghc-base-devel.files

# these are handled as alternatives
mkdir -p %{buildroot}%{_sysconfdir}/alternatives
for i in hsc2hs runhaskell; do
  if [ -x %{buildroot}%{_bindir}/$i-ghc ]; then
    rm %{buildroot}%{_bindir}/$i
    mv %{buildroot}%{_bindir}/$i{,-ghc}
  ln -s -f %{_sysconfdir}/alternatives/$i %{buildroot}%{_bindir}/$i
  touch %{buildroot}%{_sysconfdir}/alternatives/$i

find %{buildroot}%{ghclibdocdir} -name LICENSE -exec rm '{}' ';'

# Actually, I took this from Jens Petersen's Fedora package
# stolen from ghc6/debian/rules:
# Do some very simple tests that the compiler actually works
rm -rf testghc
mkdir testghc
echo 'main = putStrLn "Foo"' > testghc/foo.hs
inplace/bin/ghc-stage2 testghc/foo.hs -o testghc/foo
[ "$(testghc/foo)" = "Foo" ]
# doesn't seem to work inplace:
#[ "$(inplace/bin/runghc testghc/foo.hs)" = "Foo" ]
rm testghc/*
echo 'main = putStrLn "Foo"' > testghc/foo.hs
inplace/bin/ghc-stage2 testghc/foo.hs -o testghc/foo -O2
[ "$(testghc/foo)" = "Foo" ]
rm testghc/*
%if %{undefined ghc_without_shared}
echo 'main = putStrLn "Foo"' > testghc/foo.hs
#inplace/bin/ghc-stage2 testghc/foo.hs -o testghc/foo -dynamic
#[ "$(testghc/foo)" = "Foo" ]
rm testghc/*

%post compiler
# Alas, GHC, Hugs and nhc all come with different set of tools in addition to
# a runFOO:
#   * GHC:  hsc2hs
#   * Hugs: hsc2hs, cpphs
#   * nhc:  cpphs
# Therefore it is currently not possible to use --slave below to form link
# groups under a single name 'runhaskell'. Either these tools should be
# disentangled from the Haskell implementations or all implementations should
# have the same set of tools. *sigh*
%{_sbindir}/update-alternatives --install %{_bindir}/runhaskell runhaskell %{_bindir}/runghc     500
%{_sbindir}/update-alternatives --install %{_bindir}/hsc2hs     hsc2hs     %{_bindir}/hsc2hs-ghc 500

%preun compiler
if test "$1" = 0; then
  %{_sbindir}/update-alternatives --remove runhaskell %{_bindir}/runghc
  %{_sbindir}/update-alternatives --remove hsc2hs     %{_bindir}/hsc2hs-ghc

%license LICENSE

%files compiler
%license LICENSE
%ghost %{_sysconfdir}/alternatives/hsc2hs
%ghost %{_sysconfdir}/alternatives/runhaskell
%dir %{ghclibdir}
%dir %{ghclibdir}/bin
%dir %{ghclibdir}/package.conf.d
%ghost %{ghclibdir}/package.conf.d/package.cache
%ghost %{ghclibdir}/package.conf.d/package.cache.lock
%dir %{_datadir}/doc/ghc-%{version}
%dir %{ghcdocbasedir}
%dir %{ghcdocbasedir}/libraries
%if %{undefined without_manual}
%if %{undefined without_haddock}
%if %{undefined without_manual}
%ghost %{ghcdocbasedir}/libraries/doc-index*.html
%ghost %{ghcdocbasedir}/libraries/haddock-bundle.min.js
%ghost %{ghcdocbasedir}/libraries/haddock-util.js
%ghost %{ghcdocbasedir}/libraries/index*.html
%ghost %{ghcdocbasedir}/libraries/minus.gif
%ghost %{ghcdocbasedir}/libraries/plus.gif

%files libraries
%license LICENSE