%define pkg_name    xmonad
%define pkg_version 0.15
%define pkg_release 1%{?_dist_release}

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: packages
Source1: xmonad.desktop

# # Patch for building ghc-8.4
# Source2: xmonad-0.13_using_ghc-8.4.patch

Source11: X11-1.9.tar.gz
Source12: X11.cabal
Source13: extensible-exceptions-0.1.1.4.tar.gz
Source14: extensible-exceptions.cabal
Source15: setlocale-1.0.0.8.tar.gz
Source16: setlocale.cabal
Source17: utf8-string-1.0.1.1.tar.gz
Source18: utf8-string.cabal
Source19: xmonad-0.15.tar.gz
Source20: xmonad.cabal

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

BuildRequires: ghc haskell-platform
BuildRequires: libffi-devel gmp-devel zlib-devel

BuildRequires: libghc-data-default-class
BuildRequires: libghc-dlist
BuildRequires: libghc-old-locale
BuildRequires: libghc-data-default
BuildRequires: libghc-semigroups

BuildRequires: xorg-x11-devel
BuildRequires: libXrandr-devel libXinerama-devel
BuildRequires: libXScrnSaver-devel
BuildRequires: docbook-utils docbook-utils-pdf docbook-style-xsl

Requires: libXrandr-devel libXinerama-devel
Requires: libXScrnSaver-devel
Requires: haskell-platform-dep
Requires: libghc-data-default-class
Requires: libghc-dlist
Requires: libghc-old-locale
Requires: libghc-data-default
Requires: libghc-semigroups


Vendor: Project Vine
Distribution: Vine Linux
Packager: ara_t


%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}

%build
%ghc_pkg_init

cd %{_builddir}
for pkg in `sed '$d' %{SOURCE0}`; do
    %{__tar} xzf %{_sourcedir}/${pkg}.tar.gz
    pushd ${pkg}
        %ghc_fix_dependencies ${pkg}
        %cabal_configure2 %{name} ${pkg}
        %cabal_build
        %cabal_haddock
        %cabal_copy_resister %{name}_${pkg}
    popd
done

# build xmonad
for pkg in `tail -n 1 %{SOURCE0}`; do
    %{__tar} xzf %{_sourcedir}/${pkg}.tar.gz
    pushd ${pkg}
        %ghc_fix_dependencies ${pkg}
        %cabal_configure2 %{name} %{name}-%{version}
        %cabal_build
        %cabal_haddock
        %cabal_copy_resister %{pkg_name}-%{version}
    popd
done


%install
%{__mkdir_p} ${RPM_BUILD_ROOT}%{_datadir}/man/man1

# copy man file
pushd %{_builddir}/%{name}-%{version}/man
    %{__mv} xmonad.1 ${RPM_BUILD_ROOT}%{_datadir}/man/man1
    %{__mv} xmonad.1.html xmonad.1.markdown xmonad.hs \
     ${RPM_BUILD_ROOT}%{_docdir}/%{name}/%{name}-%{version}
popd

%{__rm} -rf ${RPM_BUILD_ROOT}%{_datadir}/%{name}-%{version}/man

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

# copy documents
pushd %{_builddir}/%{name}-%{version}
    %{__cp} CHANGES.md LICENSE README.md STYLE \
     ${RPM_BUILD_ROOT}%{_docdir}/%{name}/%{name}-%{version}
popd

%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
* Mon Dec 17 2018 Toshiaki Ara <ara_t@384.jp> 0.15-1
- update to 0.15
- build using ghc-8.6.3

* Wed Aug 08 2018 Toshiaki Ara <ara_t@384.jp> 0.14-2
- add Requires: libXScrnSaver-devel

* Wed Aug 08 2018 Toshiaki Ara <ara_t@384.jp> 0.14-1
- update to 0.14
- add BuildRequires: libXScrnSaver-devel for X11-1.9
- drop Patch2

* Fri Jul 20 2018 Toshiaki Ara <ara_t@384.jp> 0.13-3
- build using ghc-8.4.3

* Fri May 18 2018 Toshiaki Ara <ara_t@384.jp> 0.13-2
- rebuild using ghc-8.4.2
- add Patch for building with ghc-8.4 (Source2)
- add BuildRequires: libghc-old-locale
- add BuildRequires: libghc-semigroups
- rewrite using macro

* Tue Jan 09 2018 Toshiaki Ara <ara_t@384.jp> 0.13-1
- update to 0.13
- build using ghc-8.2.2

* Fri Feb 03 2017 Toshiaki Ara <ara_t@384.jp> 0.12-5
- rebuild using ghc-8.0.1

* 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
