%define pkg_name    ghc
%define pkg_version 8.6.3
# %define pkg_subversion b
%define pkg_release 1%{?_dist_release}

%ifarch %{ix86}
%define rpmarch i386
%endif
%ifarch x86_64
%define rpmarch x86_64
%endif


Summary: A state-of-the-art, open source, compiler and interactive environment for the functional language Haskell
Name:    %{pkg_name}
Version: %{pkg_version}
Release: %{pkg_release}

License: BSD-like
Group:   Applications/Languages
URL:     https://www.haskell.org/ghc

# Source0: %{name}-%{version}%{pkg_subversion}-src.tar.bz2
Source0: %{name}-%{version}-src.tar.xz
Source1: macros.ghc

# # https://phabricator.haskell.org/D4159
# # ghc-pkg: recompute `abi-depends` for updated packages
# Patch1: ghc-8.2.2-fix-shadowed_dependencies.patch

# # https://ghc.haskell.org/trac/ghc/ticket/15260
# # Xmobar crashes with segmentation fault
# Patch2: ghc.git-3ec1d931218e603ba1622faa2b52884b2477a7db.patch

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

BuildRequires: ghc
BuildRequires: gmp-devel
BuildRequires: libffi-devel
BuildRequires: ncurses-devel readline-devel freeglut-devel
BuildRequires: gtk2-devel
BuildRequires: python-sphinx

Requires: gmp-devel
Requires: libffi-devel
Requires: freeglut

Conflicts: ghc-bootstrap
Conflicts: haskell-platform-base

Vendor: Project Vine
Distribution: Vine Linux
Packager: ara_t


%description
The Glasgow Haskell Compiler (GHC) is a state-of-the-art, open source,
compiler and interactive environment for the functional language Haskell.
Highlights:
- GHC supports the entire Haskell 2010 language plus a wide variety of
  extensions.
- GHC has particularly good support for concurrency and parallelism,
   including support for Software Transactional Memory (STM).
- GHC generates fast code, particularly for concurrent programs.
- Take a look at GHC's performance on The Computer Language Benchmarks Game.
  GHC works on several platforms including Windows, Mac, Linux,
   most varieties of Unix, and several different processor architectures.
  There are detailed instructions for porting GHC to a new platform.
- GHC has extensive optimisation capabilities, including inter-module
  optimisation.
- GHC compiles Haskell code either directly to native code or using LLVM
  as a back-end.
  GHC can also generate C code as an intermediate target for porting to
  new platforms.
  The interactive environment compiles Haskell to bytecode,
   and supports execution of mixed bytecode/compiled programs.
- Profiling is supported, both by time/allocation and various kinds of heap
  profiling.
- GHC comes with several libraries, and thousands more are available on Hackage.
#'


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q
# %patch1 -p1 -b .fix-shadowed_dependencies
# %patch2 -p1 -b .fix-xmobar_segfault

%build
%{_configure} \
    --prefix=%{_prefix} \
    --libdir=%{_libdir} \
    --docdir=%{_docdir}/%{name}-%{version} \
    --with-system-libffi
%{__make} %{?_smp_mflags}

%install
%{make_install}
%{__cp} ANNOUNCE LICENSE \
        ${RPM_BUILD_ROOT}%{_docdir}/%{name}-%{version}

# macros for building haskell-platform-related packages
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_sysconfdir}/rpm
%{__sed} -e "s/@GHC_VERSION@/%{version}/" %{SOURCE1} \
 > ${RPM_BUILD_ROOT}/%{_sysconfdir}/rpm/macros.ghc

%clean
%{__rm} -rf ${RPM_BUILD_ROOT}

%post -p %{_syssbindir}/ldconfig
%postun -p %{_syssbindir}/ldconfig


%files
%defattr(-, root, root)
%{_bindir}/
%{_libdir}/ghc-%{version}/
%{_docdir}/ghc-%{version}/
%{_mandir}/man1/
%{_sysconfdir}/rpm/


%changelog
* Mon Dec 10 2018 Toshiaki Ara <ara_t@384.jp> 8.6.3-1
- update to 8.6.3
- drop Patch2 (fixed at upstream)

* Wed Aug 08 2018 Toshiaki Ara <ara_t@384.jp> 8.4.3-2
- add Patch2 (fixed that xmobar crashes with segmentation fault)

* Thu Jul 19 2018 Toshiaki Ara <ara_t@384.jp> 8.4.3-1
- update to 8.4.3
- drop Patch1 (fixed at upstream)

* Thu May 17 2018 Toshiaki Ara <ara_t@384.jp> 8.4.2-1
- update to 8.4.2
- add /etc/rpm/macros.ghc

* Sat Jan 06 2018 Toshiaki Ara <ara_t@384.jp> 8.2.2-1
- update to 8.2.2
- add Patch1 (ghc-8.2.2-fix-shadowed_dependencies.patch)

* Tue Jan 31 2017 Toshiaki Ara <ara_t@384.jp> 8.0.1-1
- update to 8.0.1
- add Requires: libffi-devel
- add Requires: freeglut
- add BuildRequires: python-sphinx for building HTML documents
- add Conflicts: ghc-bootstrap
- add Conflicts: haskell-platform-base
- delete BuildRequires: hscolour
- delete bindist subpackage

* Tue May 03 2016 Toshiaki Ara <ara_t@384.jp> 7.10.3-3
- add Requires: gmp-devel

* Mon Apr 11 2016 Toshiaki Ara <ara_t@384.jp> 7.10.3-2
- correct SPEC file

* Wed Feb 17 2016 Toshiaki Ara <ara_t@384.jp> 7.10.3-1
- update to 7.10.3
- add BuildRequires: texlive-collection-fontutils
- add Requires: libffi
- add Requires: freeglut
- provide binary tarball for building haskell-platform

* Sun Feb 14 2016 Toshiaki Ara <ara_t@384.jp> 7.6.3-5
- rebuild with ghc-7.6.3-4

* Sun Feb 14 2016 Toshiaki Ara <ara_t@384.jp> 7.6.3-4
- add Patchs to use --with-system-libffi option

* Fri Feb 12 2016 Toshiaki Ara <ara_t@384.jp> 7.6.3-3
- empty

* Mon Feb 08 2016 Toshiaki Ara <ara_t@384.jp> 7.6.3-2
- add BuildRequires: dblatex
- add BuildRequires: texlive-collection-bibtexextra
- add BuildRequires: docbook-utils docbook-utils-pdf docbook-style-xsl
- change BuildRequires from ghc-bootstrap to ghc

* Tue Feb 02 2016 Toshiaki Ara <ara_t@384.jp> 7.6.3-1
- new package
