%{!?make_build:   %global make_build   make %{?_smp_mflags}}
%{!?make_install: %global make_install make install DESTDIR=%{buildroot} INSTALL="/usr/bin/install -p"}

Name: fzy
Summary: A better fuzzy finder
Version: 1.0
Release: 0%{?dist}.2sunshine
License: MIT
URL: https://github.com/jhawthorn/fzy
Source0: https://github.com/jhawthorn/fzy/releases/download/%{version}/%{name}-%{version}.tar.gz
BuildRequires: gcc

%description
fzy is a fast, simple fuzzy text selector for the terminal with an advanced
scoring algorithm.

%prep
%if 0%{?autosetup}
%autosetup
%else
%setup -q
%(grep -E '^Patch[0-9]+:' %{_specdir}/%{name}.spec | sed -r 's/^P/%p/;s/:[      ]+/ -p1 -b ./;s/.patch$//')
%endif

%build
%make_build CFLAGS="%{optflags} -std=c99"

%check
make test

%install
%make_install PREFIX=%{_prefix}
install -p -m644 %{name}.1 %{buildroot}/%{_mandir}/man1/

%files
%{!?_licensedir:%global license %%doc}
%license LICENSE
%doc README.md CHANGELOG.md ALGORITHM.md
%{_bindir}/%{name}
%{_mandir}/man1/%{name}.1*

%changelog
* Mon Jul 29 2019 Moritz Barsnick <moritz+rpm@barsnick.net> 1.0-0.2sunshine
- force support for C99, as gcc < 5 doesn't support it by default

* Mon Jul 29 2019 Moritz Barsnick <moritz+rpm@barsnick.net> 1.0-0.1sunshine
- update to 1.0
- add proper Source URL
- use more macros
- package LICENSE and documenation
- install man page a second time in order to preserve modification time
- provide fallbacks for the %%autosetup, %%make_build, %%make_install
  and %%license macros
- propagate system CFLAGS
- add BR: gcc

* Sun Oct 29 2017 Alex Blackie <alexblackie@fedoraproject.org> - 0.9-1
- Initial addition of RPM spec.