%define pkg_name     haskell-platform
%define year_version 2015
%define pkg_version  7.10.3
%define pkg_release  3%{?_dist_release}

%define ghc_version 7.10.3
%define alex_version 3.1.4
%define happy_version 1.19.5

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


Summary: An advanced purely-functional programming language
Name:    %{pkg_name}
Version: %{year_version}.%{pkg_version}
Release: %{pkg_release}

License: BSD-like
Group:   Applications/Languages

Source0: %{name}-%{pkg_version}.tar.gz

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

BuildRequires: ghc
BuildRequires: gmp-devel zlib-devel freeglut-devel
BuildRequires: libffi-devel
BuildRequires: docbook-utils docbook-utils-pdf docbook-style-xsl
BuildRequires: hscolour

Requires: haskell-platform-base = %{version}
Requires: alex
Requires: happy
Requires: cabal-install
Requires: hscolour

Vendor: Project Vine
Distribution: Vine Linux
Packager: ara_t


%description
Haskell is a computer programming language.
In particular, it is a polymorphically statically typed, lazy, purely
functional language, quite different from most other programming languages.
The language is named for Haskell Brooks Curry, whose work in mathematical
logic serves as a foundation for functional languages.

This is a meta package for installing haskell-platform, alex, happy and
cabal-install.


%package base
Version:     %{version}
Summary:     base package of haskell-platform
Summary(ja): haskell-platformの基本パッケージ
License:     BSD-like
Group:       Applications/Languages

Requires: ghc = %{ghc_version}
Requires: freeglut
Requires: gmp-devel

%description base
Base package for haskell-platform without alex, cabal, happy and HsColour.


%package -n alex
Version:     %{alex_version}
Summary:     lexical analyser generator for Haskell
Summary(ja): Haskell用の構文解析器生成器
License:     BSD3
Group:       Applications/Text

%description -n alex
Alex is a tool for generating lexical analysers in Haskell,
given a description of the tokens to be recognised
in the form of regular expressions.
It is similar to the tool lex or flex for C/C++.

%description -l ja -n alex
AlexはHaskellで字句解析器を生成するツールで、
トークン群の記述を正規表現の形式で認識します。
C/C++用のlexやflexといったツールに似ています。


%package -n happy
Version:     %{happy_version}
Summary:     a parser generator system for Haskell
Summary(ja): Haskell 用の構文解析器生成器
License:     BSD3
Group:       Applications/Text

%description -n happy
Happy is a parser generator system for Haskell, similar to the tool 'yacc'
for C. Like 'yacc', it takes a file containing an annotated BNF specification
of a grammar and produces a Haskell module containing a parser for the grammar.

%description -l ja -n happy
HappyはHaskell用の構文解析器生成器のシステムで、C用ツールの'yacc'に似ています。
'yacc'の様に注釈付きのBNF形式の文法の仕様を含んだファイルを受け取って、
その文法の構文解析器を含んだHaskellモジュールを生成します。


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q -n %{name}-%{pkg_version}
%{__cat} etc/build.packages | \
    %{__sed} -e /hscolour/d | \
    %{__sed} -e /cabal-install/d > build.packages

%build
PKGCONFDIR=${RPM_BUILD_ROOT}%{_libdir}/ghc-%{ghc_version}/package.conf.d/%{name}
%{__mkdir_p} ${PKGCONFDIR}

export PATH=${RPM_BUILD_ROOT}%{_bindir}:${PATH}
export LANG=en_US.utf8

# build and install
cd packages
for pkg in `cat ../build.packages`; do
  cd ${pkg}
  ghc --make Setup
  if [ ${pkg} = "alex-%{alex_version}" ] || \
     [ ${pkg} = "happy-%{happy_version}" ]
  then
  ./Setup configure \
          --user \
          --prefix=%{_prefix} \
          --datadir=%{_datadir}/${pkg} \
          --datasubdir= \
          --docdir=%{_docdir}/${pkg}
  else
  ./Setup configure \
          --user \
          --prefix=%{_prefix} \
          --libdir=%{_libdir}/%{name}/${pkg} \
          --libsubdir= \
          --datadir=%{_datadir}/%{name}/${pkg} \
          --datasubdir= \
          --docdir=%{_docdir}/%{name}-%{year_version}.%{pkg_version}/${pkg}
  fi

  ./Setup build
  ./Setup haddock || :
  ./Setup copy --destdir=${RPM_BUILD_ROOT}
  ./Setup register --inplace
  ./Setup register --gen-pkg-config=${PKGCONFDIR}/${pkg}
  cd ..
done

%install
# copy document files each directory
%{__cp} LICENSE README \
 ${RPM_BUILD_ROOT}%{_docdir}/%{name}-%{year_version}.%{pkg_version}
%{__cp} packages/alex-%{alex_version}/{ANNOUNCE,README,TODO} \
 ${RPM_BUILD_ROOT}%{_docdir}/alex-%{alex_version}/
%{__cp} packages/happy-%{happy_version}/{ANNOUNCE,CHANGES,README,TODO} \
 ${RPM_BUILD_ROOT}%{_docdir}/happy-%{happy_version}/

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

%post base
cd %{_libdir}/ghc-%{ghc_version}/package.conf.d/%{name}
for conf in *
do
  ghc-pkg register --verbose=0 --force $conf 2> /dev/null
done

%preun base
cd %{_libdir}/ghc-%{ghc_version}/package.conf.d/%{name}
for conf in *
do
  ghc-pkg unregister --verbose=0 --force $conf 2> /dev/null
done


%files

%files base
%defattr(-, root, root)
%{_libdir}/ghc-%{ghc_version}/package.conf.d/%{name}
%{_libdir}/%{name}/
%{_datadir}/%{name}/
%{_docdir}/%{name}-%{year_version}.%{pkg_version}/

%files -n alex
%{_bindir}/alex
%{_datadir}/alex-%{alex_version}/
%{_docdir}/alex-%{alex_version}/

%files -n happy
%{_bindir}/happy
%{_datadir}/happy-%{happy_version}/
%{_docdir}/happy-%{happy_version}/


%changelog
* Tue May 03 2016 Toshiaki Ara <ara_t@384.jp> 7.10.3-3
- modify SPEC file without usage of cabal-install

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

* Fri Feb 19 2016 Toshiaki Ara <ara_t@384.jp> 7.10.3-1
- update to 7.10.3

* Mon Feb 15 2016 Toshiaki Ara <ara_t@384.jp> 2013.2.0.0-4
- delete subpackage cabal-install
- delete %{cabal_version} from Requires: cabal-install-%{cabal_version}
- add BuildRequires: libffi-devel

* Thu Feb 11 2016 Toshiaki Ara <ara_t@384.jp> 2013.2.0.0-3
- correct Requires

* Thu Feb 11 2016 Toshiaki Ara <ara_t@384.jp> 2013.2.0.0-2
- install Haskell libraries into %{_libdir}/ghc-lib
- add BuildRequires: hscolour
- devide insto subpackages

* Thu Feb 04 2016 Toshiaki Ara <ara_t@384.jp> 2013.2.0.0-1
- new package
