%global git_date 20210629
%global git_rev fa78a4f
%global git_revision    fa78a4f604e4d13d0bc74d6fad5c245019069501
%global progname        wordgrinder
%global srcpkgdir       %{progname}-%{git_revision}

Name:           wordgrinder
Version:        0.9.0.%{git_date}git%{git_rev}
Release:        1%{?dist}
Summary:        A command line word processor

License:        MIT
URL:            http://cowlark.com/wordgrinder
%global pkgid   %{name}-%{version}
Source:         https://github.com/davidgiven/%{name}/archive/%{git_revision}.tar.gz

BuildRequires:  gcc make ncurses-devel ninja-build
BuildRequires:  lua-devel lua-libs lua lua-filesystem
BuildRequires:  zlib-devel libXft-devel
BuildRequires:  vim-common
Requires:       ncurses lua-filesystem

%description
WordGrinder is a Unicode-aware character cell word processor that runs in a
terminal (or a Windows console). It is designed to get the hell out of your way
and let you get some work done.

WordGrinder is a word processor for processing words. It is not WYSIWYG. It is
not point and click. It is not a desktop publisher. It is not a text editor. It
does not do fonts and it barely does styles. What it does do is words. It's
designed for writing text. It gets out of your way and lets you type

%package gui
Summary: GUI version of WordGrinder
#Requires: %name = %version-%release
Obsoletes: wordgrinder-x11
BuildRequires: SDL2-devel SDL2_ttf-devel
%description gui
A GUI version of the WordGrinder word processor.

%prep

#%setup -q -n %{name}-%{version}
%setup -q -n %{srcpkgdir}

###############################################################################
%build

CFLAGS=-g PREFIX=$RPM_BUILD_ROOT/%{_prefix} OBJDIR=$RPM_BUILD_ROOT/tmp WANT_STRIPPED_BINARIES=no make %{?_smp_mflags}

###############################################################################
%install

make install PREFIX=$RPM_BUILD_ROOT/%{_prefix}
install -D -m 0644 %{_builddir}/%{srcpkgdir}/extras/wordgrinder.mime %{buildroot}%{_datadir}/mime/packages/wordgrinder.mime
install -D -m 0644 -T %{_builddir}/%{srcpkgdir}/extras/icon.png %{buildroot}%{_datadir}/icons/hicolor/256x256/apps/wordgrinder.png
install -D -m 0644 %{_builddir}/%{srcpkgdir}/extras/wordgrinder.desktop %{buildroot}%{_datadir}/applications/wordgrinder.desktop
install -D %{_builddir}/%{srcpkgdir}/bin/wordgrinder-builtin-ncurses-debug-unstripped %{buildroot}%{_bindir}/wordgrinder
install -D %{_builddir}/%{srcpkgdir}/bin/wordgrinder-builtin-sdl-release-unstripped %{buildroot}%{_bindir}/xwordgrinder
mkdir -p %{buildroot}%{_docdir}/%{name}/ && mv %{buildroot}/usr/doc/%{name}/* %{buildroot}%{_docdir}/%{name}/
mkdir -p %{buildroot}%_mandir/man1/ && mv %{buildroot}/usr/man/man1/* %{buildroot}%_mandir/man1/

%post
update-desktop-database &> /dev/null || :
touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :
touch --no-create %{_datadir}/mime/packages &>/dev/null || :

%postun
update-desktop-database &> /dev/null || :
if [ $1 -eq 0 ] ; then
    touch --no-create %{_datadir}/icons/hicolor &>/dev/null
    gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
    update-mime-database %{_datadir}/mime &> /dev/null || :
fi
%posttrans gui
%posttrans
gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
update-mime-database %{?fedora:-n} %{_datadir}/mime &> /dev/null || :

###############################################################################
%files
%license licenses/COPYING.WordGrinder
%_bindir/wordgrinder
%_docdir/wordgrinder/README.wg
%_mandir/man1/wordgrinder.1*

%files gui
%license licenses/COPYING.WordGrinder
%_bindir/xwordgrinder
%_mandir/man1/xwordgrinder.1*
%{_datadir}/applications/wordgrinder.desktop
%{_datadir}/icons/hicolor/256x256/apps/wordgrinder.png
%{_datadir}/mime/packages/wordgrinder.mime
%{_datadir}/mime-info/wordgrinder.mime
%{_datadir}/pixmaps/wordgrinder.png
###############################################################################
%changelog
* Tue Jun 29 2021 Ben Cotton <bcotton@fedoraproject.org> - 0.9.0.20210629gitfa78a4f-1
- Update to latest upstream snapshot

* Mon Jun 28 2021 Ben Cotton <bcotton@fedoraproject.org> - 0.9.0.20210628git6365688-2
- Use the "release" gui binary instead of "debug"

* Mon Jun 28 2021 Ben Cotton <bcotton@fedoraproject.org> - 0.9.0.20210628git6365688-1
- Update to latest upstream snapshot (start tracking 0.9.0 release using SDL)
- Rename graphical package from wordgrinder-x11 to wordgrinder-gui

* Sat Feb 06 2021 Ben Cotton <bcotton@fedoraproject.org> - 0.8.0.20210206git6f97e6a-1
- Update to latest upstream snapshot

* Mon Oct 19 2020 Ben Cotton <bcotton@fedoraproject.org> - 0.8.0.20201019gite8cc7e9-1
- Update to latest upstream snapshot
- Remove wordgrinder-x11's dependency on wordgrinder
- Add desktop files to xwordgrinder

* Sat Oct 17 2020 Ben Cotton <bcotton@fedoraproject.org> - 0.8.0.20201017git5cba17f-1
- Update to latest upstream snapshot

* Fri Oct 16 2020 Ben Cotton <bcotton@fedoraproject.org> - 0.8.0.20201016gitd42fc86-1
- Update to latest upstream snapshot

* Thu Oct 15 2020 Ben Cotton <bcotton@fedoraproject.org> - 0.8.0.20201015gite7efc05-1
- Update to latest upstream snapshot

* Wed Oct 14 2020 Ben Cotton <bcotton@fedoraproject.org> - 0.8.0.20201014git31afd78-1
- Update to latest upstream snapshot

* Tue Oct 13 2020 Ben Cotton <bcotton@fedoraproject.org> - 0.8.0.20201013git0ed98df-1
- Update to latest upstream snapshot

* Mon Oct 12 2020 Ben Cotton <bcotton@fedoraproject.org> - 0.8.0.20201012gitaaa32a3-1
- Build development version for Copr

* Fri Jan 31 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.2-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

* Sat Jul 27 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.2-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Sun Feb 03 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Fri Jan 04 2019 Ben Cotton <bcotton@fedoraproject.org> - 0.7.2-1
- Update to latest upstream release
- Remove unnecessary patch to build scripts

* Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

* Sun Nov 05 2017 Ben Cotton <bcotton@fedoraproject.org> - 0.7.1-1
- Update to latest upstream release
- Remove unneeded dependences, which allows us more build arches
- Split the X11 version into an optional subpackage

* Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.6-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild

* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.6-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Thu Jul 06 2017 Ben Cotton <bcotton@fedoraproject.org> - 0.6-4
- Fix debuginfo issues

* Thu Jul 06 2017 Ben Cotton <bcotton@fedoraproject.org> - 0.6-3
- Update the patch to build on Fedora 26

* Sun Jul 02 2017 Ben Cotton <bcotton@fedoraproject.org> - 0.6-2
- Change lua to a version supported by upstream (5.1)

* Wed Jun 07 2017 Ben Cotton <bcotton@fedoraproject.org> - 0.6-1
- Initial RPM release