File ghc.spec of Package ghc

# spec file for package ghc
# Copyright (c) 2014 SUSE LINUX Products 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

%global unregisterised_archs ppc64 ppc64le s390 s390s

%ifarch %{unregisterised_archs}
%global ghc_without_shared 1

Name:           ghc
Version:        7.6.3
Release:        0
Url:  {version}/%{name}-%{version}-src.tar.bz2
Summary:        The Glorious Glasgow Haskell Compiler
License:        BSD-3-Clause
Group:          Development/Languages/Other
ExclusiveArch:  %{ix86} x86_64 ppc ppc64 ppc64le

BuildRequires:  ghc-bootstrap >= 7.0
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  binutils-devel
BuildRequires:  gcc
BuildRequires:  ghc-rpm-macros-extra
BuildRequires:  glibc-devel
BuildRequires:  gmp-devel
BuildRequires:  libelf-devel
BuildRequires:  libffi-devel
BuildRequires:  ncurses-devel
BuildRequires:  pkg-config
%if %{undefined without_manual}
%if 0%{suse_version} >= 1220
BuildRequires:  dblatex
BuildRequires:  docbook-utils
BuildRequires:  docbook-xsl-stylesheets
BuildRequires:  libxslt
PreReq:         update-alternatives
Requires:       ghc-compiler = %{version}-%{release}
Requires:       ghc-ghc-devel = %{version}-%{release}
Requires:       ghc-libraries = %{version}-%{release}
Source1:        ghc-rpmlintrc
# PATCH-FIX-UPSTREAM ghc-use-system-libffi.patch - See Haskell trac #4496 and #5743; backport of our patch accepted upstream for next major release.
Patch:          ghc-use-system-libffi.patch
# PATCH-FIX-UPSTREAM ghc-suse-as-needed.patch - temporary fix for Haskell trac #7062, ghc libraries do not work with as_needed and new-dtags both enabled
Patch1:         ghc-suse-as-needed.patch
# PATCH-FIX-UPSTREAM Cabal-fix-dynamic-exec-for-TH.patch - Fedora patch 10
Patch2:         Cabal-fix-dynamic-exec-for-TH.patch
# PATCH-FIX-UPSTREAM ghc-7.6.3-LlvmCodeGen-no-3.3-warning.patch - Fedora patch 14: Silence warning about llvm 3.3
Patch3:         ghc-7.6.3-LlvmCodeGen-no-3.3-warning.patch
# PATCH-FIX-UPSTREAM ghc-avoid-empty-llvm-used-definitions.patch - Backport of commit db9b63105a54, fixes Haskell trac #7996
Patch4:         ghc-avoid-empty-llvm-used-definitions.patch
# PATCH-FIX-UPSTREAM 0001-Fix-detection-of-library-for-shm-on-openSUSE.patch - Fix test for librt and shm_* detection. Backported patch sent upstream 2013-09-24, Haskell trac #8350.
Patch5:         0001-Fix-detection-of-library-for-shm-on-openSUSE.patch
# PATCH-FIX-UPSTREAM - Fix test for setitimer. Backported patch sent upstream 2013-09-24, Haskell trac #8352
# PATCH-FIX-UPSTREAM - Fix Haskell trac #8134.
Patch7:         ghc-fix-infinite-loop-big-endian.patch
# PATCH-FIX-UPSTREAM - Add target datalayout for llvm on powerpc 64.
Patch8:         llvm-powerpc64-datalayout.patch
# PATCH-FIX-OPENSUSE - Remove versions in library docdirs. Required for compatibility with ghc-rpm-macros 1.0 and up. Can be removed once we move to ghc 7.8.x. Fedora patch 16.
Patch9:         ghc-cabal-unversion-docdir.patch
Patch10:        ghc-ppc64le.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-build

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
# This Requires fixes an issue in ghc's runtime system (rts) when
# locale files are missing. RTS loops and a memory leak eventually
# exhausts all memory and the program crashes. See Haskell trac #7695. 
Requires:       glibc-locale
Requires(post): update-alternatives
Requires(postun): update-alternatives

%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 _use_internal_dependency_generator 0
%global __find_provides %{_rpmconfigdir}/ --provides %{buildroot}%{ghclibdir}
%global __find_requires %{_rpmconfigdir}/ --requires %{buildroot}%{ghclibdir}

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

%if %{defined ghclibdir}
%ghc_lib_subpackage Cabal 1.16.0
%ghc_lib_subpackage array
%ghc_lib_subpackage -c gmp-devel,libffi-devel base
%ghc_lib_subpackage binary
%ghc_lib_subpackage bytestring
%ghc_lib_subpackage containers
%ghc_lib_subpackage deepseq
%ghc_lib_subpackage directory
%ghc_lib_subpackage filepath
%define ghc_pkg_obsoletes ghc-bin-package-db-devel <{release}
%ghc_lib_subpackage -x ghc %{ghc_version_override}
%undefine ghc_pkg_obsoletes
%ghc_lib_subpackage haskell2010
%ghc_lib_subpackage haskell98
%ghc_lib_subpackage hoopl
%ghc_lib_subpackage hpc
%ghc_lib_subpackage old-locale
%ghc_lib_subpackage old-time
%ghc_lib_subpackage pretty
%ghc_lib_subpackage process
%ghc_lib_subpackage template-haskell
%ghc_lib_subpackage time
%ghc_lib_subpackage unix

%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
rm -r ghc-tarballs/{mingw,mingw64,perl}
%patch -p1 -b .libffi
rm -r ghc-tarballs/libffi
%patch1 -p1 -b .suse
%patch2 -p1 -b .TH
%patch3 -p1 -b .llvm-version
%patch4 -p1 -b .llvm-empty
%patch5 -p1 -b .shm
%patch6 -p1 -b .comma
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1

# required for patch and patch1
#autoreconf -fi

# required for patch5 and patch6 and will run autoreconf for patch and patch1
perl boot

# Check if bootstrap is required, i.e. version is different from ghc's version
# Note: Cannot use ghc_version macro here as we defined version override earlier
%if "%version" != "%(ghc --numeric-version)"
%define ghc_boot 1
cat > mk/ <<EOF
GhcLibWays = v
%ifarch %{unregisterised_archs}
./configure --prefix=%{_builddir}/ghc-boot --with-system-libffi \
make %{?_smp_mflags}
make install
make clean

cat > mk/ <<EOF
%ifnarch %{unregisterised_archs}
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}
%ifarch  %{unregisterised_archs}
GhcUnregisterised    = YES
GhcWithNativeCodeGen = NO
SRC_HC_OPTS          = -O -H64m
GhcStage1HcOpts      = -O
GhcStage2HcOpts      = -O2
GhcHcOpts            = -Rghc-timing
GhcLibHcOpts         = -O2
SplitObjs            = NO
%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} \
  %{?ghc_boot:--with-ghc=%{_builddir}/ghc-boot/bin/ghc} \
  --with-system-libffi \

make %{?_smp_mflags}


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
echo "%doc libraries/$name/LICENSE" >> ghc-$name.files

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

%ghc_gen_filelists bin-package-db
%ghc_gen_filelists ghc %{ghc_version_override}
%ghc_gen_filelists ghc-prim
%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
%merge_filelist bin-package-db ghc

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

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


# 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*
update-alternatives --install %{_bindir}/runhaskell runhaskell %{_bindir}/runghc     500
update-alternatives --install %{_bindir}/hsc2hs     hsc2hs     %{_bindir}/hsc2hs-ghc 500

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


%files compiler
%ghost %attr(755,root,root) %{_bindir}/hsc2hs
%ghost %attr(755,root,root) %{_bindir}/runhaskell
%ifnarch %{unregisterised_archs}
%dir %{ghclibdir}/package.conf.d
%ghost %{ghclibdir}/package.conf.d/package.cache
%dir %{_datadir}/doc/ghc
%dir %{ghcdocbasedir}
%dir %{ghcdocbasedir}/libraries
%if %{undefined without_haddock}
%if %{undefined without_manual}
%if 0%{suse_version} >= 1220
%ghost %{ghcdocbasedir}/libraries/doc-index*.html
%ghost %{ghcdocbasedir}/libraries/haddock-util.js
%ghost %{ghcdocbasedir}/libraries/index*.html
%ghost %{ghcdocbasedir}/libraries/minus.gif
%ghost %{ghcdocbasedir}/libraries/plus.gif
%if %{suse_version} >= 1230
%ghost %{_sysconfdir}/alternatives/hsc2hs
%ghost %{_sysconfdir}/alternatives/runhaskell

%files libraries