%define pkg_name    xmonad
%define pkg_version 0.12
%define pkg_release 4%{?_dist_release}

%define ghc_version 7.10.3

Summary:     Lightweight X11 window manager written in Haskell
Summary(ja): Haskellで書かれたタイル型ウィンドウマネージャ
Name:    %{pkg_name}
Version: %{pkg_version}
Release: %{pkg_release}

License: BSD3
Group:   User Interface/Desktops
URL:     http://hackage.haskell.org

Source0: %{name}-%{version}.tar.gz
Source1: X11-1.6.1.2.tar.gz
Source2: extensible-exceptions-0.1.1.4.tar.gz
Source3: setlocale-1.0.0.3.tar.gz
Source4: utf8-string-1.0.1.1.tar.gz

Source100: packages
Source200: xmonad.desktop

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

BuildRequires: ghc haskell-platform-base cabal-install
BuildRequires: libffi-devel gmp-devel zlib-devel

BuildRequires: libghc-data-default-class
BuildRequires: libghc-dlist
BuildRequires: libghc-data-default

BuildRequires: xorg-x11-devel
BuildRequires: docbook-utils docbook-utils-pdf docbook-style-xsl
BuildRequires: hscolour

Requires: ghc
Requires: libghc-data-default

Vendor: Project Vine
Distribution: Vine Linux
Packager: Toshiaki Ara <ara_t@384.jp>


%description
Xmonad is a minimalist tiling window manager for X, written in Haskell.
Windows are managed using automatic layout algorithms, which can be dynamically
reconfigured. At any time windows are arranged so as to maximise the use of
screen real estate. All features of the window manager are accessible purely
from the keyboard: a mouse is entirely optional.
Xmonad is configured in Haskell, and custom layout algorithms may be implemented
 by the user in config files.
A principle of Xmonad is predictability: the user should know in advance
 precisely the window arrangement that will result from any action.

Please sample configure file as follows.
`cp %{_docdir}/%{name}/%{name}-%{version}/xmonad.hs ~/.xmonad/`


%description -l ja
XmonadはHaskellで書かれたタイル型ウィンドウマネージャです。
ウィンドウは自動的レイアウトアルゴリズムによって管理されており、
ウィンドウはいつでも最大化されて配置されます。
純粋にキーボード操作だけで操作することが可能であり、
マウスの使用は単にオプションです。
XmonadはHaskellで設定され、ユーザーが設定ファイルを書くことで
レイアウトをカスタマイズすることができます。

設定ファイルの例が
%{_docdir}/%{name}/%{name}-%{version}/xmonad.hs
にあるため、
~/.xmonad 以下にコピーして使用して下さい。


%prep
%{__rm} -rf ${RPM_BUILD_ROOT}
%setup -q
# Initialise the package db
ghc-pkg init %{_builddir}/package.conf

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

# install dependent packages
cd %{_builddir}
for pkg in `cat %{SOURCE100}`; do
  %{__tar} xzf %{_sourcedir}/${pkg}.tar.gz
  cd ${pkg}
  cabal configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir}/ghc-lib/%{name}/${pkg} \
    --libsubdir= \
    --datadir=%{_datadir}/%{name}/${pkg} \
    --datasubdir= \
    --docdir=%{_docdir}/%{name}/${pkg}

  cabal build
  cabal haddock
  cabal copy --destdir=${RPM_BUILD_ROOT}
  cabal register --inplace
  cabal register --gen-pkg-config=${PKG_CONF_DIR}/%{name}_${pkg}.conf
  cd ..
done

# build xmonad
cd %{_builddir}/%{name}-%{version}
cabal configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir}/ghc-lib/%{name}/%{name}-%{version} \
    --libsubdir= \
    --datadir=%{_datadir}/%{name}/%{name}-%{version} \
    --datasubdir= \
    --docdir=%{_docdir}/%{name}/%{name}-%{version}

cabal build
cabal haddock
cabal copy --destdir=${RPM_BUILD_ROOT}
cabal register --inplace
cabal register --gen-pkg-config=${PKG_CONF_DIR}/%{name}-%{version}.conf

%install
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_datadir}/man/man1
(cd ${RPM_BUILD_ROOT}%{_datadir}/%{name}/%{name}-%{version}/man
 %{__mv} xmonad.1 ${RPM_BUILD_ROOT}%{_datadir}/man/man1
 %{__mv} xmonad.1.html xmonad.hs \
  ${RPM_BUILD_ROOT}%{_docdir}/%{name}/%{name}-%{version}
)
%{__rm} -rf ${RPM_BUILD_ROOT}%{_datadir}/%{name}-%{version}/man

# xsession desktop entry
%{__mkdir_p} %{buildroot}%{_datadir}/xsessions/
%{__install} -m 644 %{SOURCE200} ${RPM_BUILD_ROOT}%{_datadir}/xsessions/

%{__cp} CHANGES.md LICENSE README.md STYLE \
 ${RPM_BUILD_ROOT}%{_docdir}/%{name}/%{name}-%{version}

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


%post
ghc-pkg recache

%postun
ghc-pkg recache


%files
%defattr(-, root, root)
%{_bindir}/
%{_libdir}/ghc-%{ghc_version}/
%{_libdir}/ghc-lib/
%{_datadir}/xsessions/
%{_docdir}/%{name}
%{_mandir}/man1/


%changelog
* Wed May 04 2016 Toshiaki Ara <ara_t@384.jp> 0.12-4
- rebuilt

* Tue Apr 12 2016 Toshiaki Ara <ara_t@384.jp> 0.12-3
- correct SPEC file

* Tue Mar 01 2016 Toshiaki Ara <ara_t@384.jp> 0.12-2
- rebuild under dependent rpm packages

* Sat Feb 27 2016 Toshiaki Ara <ara_t@384.jp> 0.12-1
- new package
