## START: Set by rpmautospec
## (rpmautospec version 0.3.0)
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 5;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# Generated by go2rpm 1.6.0
%bcond_without check

# https://git.sr.ht/~rjarry/aerc
%global goipath         git.sr.ht/~rjarry/aerc
Version:                0.14.0
%global topdir          %{name}-%{version}

%gometa

%global common_description %{expand:
Aerc is an email client that runs in your terminal. It's highly
efficient and extensible, perfect for the discerning hacker.}

%global golicenses      LICENSE
%global godocs          doc README.md

Name:           aerc
Release:        %autorelease
Summary:        Email client for your terminal

License:        MIT
URL:            %{gourl}
# The forge macros don't support Sourcehut.
# https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/209
Source:         %{gourl}/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
# doc: fix English typos
# https://git.sr.ht/~rjarry/aerc/commit/10b995f0196c8243132c3f435d4e11b3c9700e35
Patch:          0001-doc-fix-English-typos.patch
# filters: install them in $PREFIX/libexec/aerc/filters
# https://git.sr.ht/~rjarry/aerc/commit/04303172d4f96b284e0c915ce4a7b87e1439bb87
# Depends on previous patch. Slightly modified to remove CHANGELOG.md conflict.
Patch:          0002-filters-install-them-in-PREFIX-libexec-aerc-filters.patch

BuildRequires:  scdoc
BuildRequires:  desktop-file-utils
BuildRequires:  gnupg
BuildRequires:  notmuch-devel

Requires:       notmuch

%description
%{common_description}

%prep
%goprep
%autopatch -p1

# Disable building of aerc that we handle manually in the SPEC and
# preserve mtimes
sed -e 's|install: $(DOCS) aerc wrap|install: $(DOCS)|' \
    -e 's|install -m|install -pm|' \
    -i Makefile

# From go.mod replace statements:
# replace golang.org/x/crypto => github.com/ProtonMail/go-crypto v0.0.0-20200420072808-71bec3603bf3
# replace github.com/zenhack/go.notmuch => github.com/brunnre8/go.notmuch v0.0.0-20201126061756-caa2daf7093c
sed -i "s|golang.org/x/crypto|github.com/ProtonMail/go-crypto|" $(find . -name "*.go" -type f)
sed -i "s|github.com/zenhack/go.notmuch|github.com/brunnre8/go.notmuch|" $(find . -name "*.go" -type f)

%generate_buildrequires
%go_generate_buildrequires
echo 'golang(github.com/brunnre8/go.notmuch)'

%build
export BUILDTAGS=notmuch
export LDFLAGS="\
                -X main.Version=%{version} \
                -X main.Prefix=%{_prefix} \
                -X main.ShareDir=%{_datadir}/aerc \
                -X git.sr.ht/~rjarry/aerc/config.shareDir=%{_datadir} \
                -X git.sr.ht/~rjarry/aerc/config.libexecDir=%{_libexecdir} \
               "
%gobuild -o aerc %{goipath}
%gobuild -o wrap filters/wrap.go

%install
export PREFIX=%{_prefix}
%make_install
desktop-file-validate %{buildroot}/%{_datadir}/applications/aerc.desktop

%if %{with check}
%check
%gocheck
%endif

%files
%license LICENSE
%doc doc README.md
%{_bindir}/aerc
%{_datadir}/aerc/
%{_datadir}/applications/aerc.desktop
%{_libexecdir}/aerc/
%{_mandir}/man1/aerc-*.1.*
%{_mandir}/man1/aerc.1*
%{_mandir}/man5/aerc-*.5.*
%{_mandir}/man7/aerc-*.7.*

%changelog
* Wed Jan 18 2023 Fedora Release Engineering <releng@fedoraproject.org> 0.14.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Wed Jan 11 2023 Maxwell G <gotmax@e.email> 0.14.0-4
- Fix LDFLAGS to match upstream Makefile

* Wed Jan 11 2023 Maxwell G <gotmax@e.email> 0.14.0-3
- Add patch to correct filter install location

* Wed Jan 11 2023 Maxwell G <gotmax@e.email> 0.14.0-2
- Make %%files section consistent

* Wed Jan 11 2023 Maxwell G <gotmax@e.email> 0.14.0-1
- Update to 0.14.0. Fixes rhbz#2158200.

* Wed Nov 02 2022 Maxwell G <gotmax@e.email> 0.13.0-1
- Update to 0.13.0. Fixes rhbz#2136668.

* Mon Sep 26 2022 Maxwell G <gotmax@e.email> 0.12.0-5
- Handle go.mod replace statements

* Mon Sep 26 2022 Maxwell G <gotmax@e.email> 0.12.0-4
- Remove %%{_bindir} glob from %%files

* Mon Sep 26 2022 Maxwell G <gotmax@e.email> 0.12.0-3
- Change method of patching the Makefile

* Mon Sep 26 2022 Maxwell G <gotmax@e.email> 0.12.0-2
- Actually build the notmuch extension

* Mon Sep 26 2022 Maxwell G <gotmax@e.email> 0.12.0-1
- Update to 0.12.0. Fixes rhbz#2106151.

* Mon Sep 26 2022 Maxwell G <gotmax@e.email> 0.10.0-7
- Manually specify Source instead of using forge macros

* Wed Jul 20 2022 Fedora Release Engineering <releng@fedoraproject.org> 0.10.0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Tue Jul 19 2022 Maxwell G <gotmax@e.email> 0.10.0-5
- Rebuild for
  CVE-2022-{1705,32148,30631,30633,28131,30635,30632,30630,1962} in golang

* Sun Jul 03 2022 Robert-André Mauchin <zebob.m@gmail.com> 0.10.0-4
- Use auto buildrequires

* Sat Jun 18 2022 Robert-André Mauchin <zebob.m@gmail.com> 0.10.0-3
- Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327,
  CVE-2022-27191, CVE-2022-29526, CVE-2022-30629

* Fri Jun 17 2022 Robert-André Mauchin <zebob.m@gmail.com> 0.10.0-2
- Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327,
  CVE-2022-27191, CVE-2022-29526, CVE-2022-30629

* Tue May 10 2022 Robert-André Mauchin <zebob.m@gmail.com> 0.10.0-1
- Update to 0.10.0 Close: rhbz#2056300

* Tue Jan 25 2022 Robert-André Mauchin <zebob.m@gmail.com> 0.7.1-2
- Fix archive upload

* Tue Jan 25 2022 Robert-André Mauchin <zebob.m@gmail.com> 0.7.1-1
- Update to 0.7.1 Close: rhbz#2040890

* Wed Jan 19 2022 Fedora Release Engineering <releng@fedoraproject.org> 0.6.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Tue Dec 28 2021 Maxwell G <gotmax@e.email> 0.6.0-2
- Remove unnecessary %%%%commit macro

* Mon Dec 20 2021 Robert-André Mauchin <zebob.m@gmail.com> 0.6.0-1
- Update to 0.6.0 Close: rhbz#2031335

* Wed Jul 21 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.5.2-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Tue Jun 15 20:29:04 CEST 2021 Robert-André Mauchin <zebob.m@gmail.com> - 0.5.2-2.20210615git1687e55
- Initial package