%global __requires_exclude perl

# The naming scheme in non-Mandriva-based distros
%if 0%{!?mklibname:1}
%define mklibname(ds)  lib%{1}%{?2:%{2}}%{-s:-static}%{-d:-devel}
%endif
%if 0%{!?mkrel:1}
%define mkrel(c) %{1}%{?dist}
%endif

%define prerel beta1

Summary:	Fast anti-spam filtering by Bayesian statistical analysis
Name:		bogofilter
Version:	1.3.0
Release:	%mkrel %{?prerel:0.%{prerel}.}1
License:	GPLv2+
Group:		Networking/Mail
URL:		https://bogofilter.sourceforge.net/
%if 0%{?prerel:1}
Source0:        https://gitlab.com/bogofilter/bogofilter/-/archive/%{name}-%{version}%{?prerel:.%{prerel}}/%{name}-%{name}-%{version}%{?prerel:.%{prerel}}.tar.bz2
%else
Source0:	https://prdownloads.sourceforge.net/bogofilter/%{name}-%{version}.tar.xz
%endif
BuildRequires:	pkgconfig(sqlite3)
BuildRequires:	flex
BuildRequires:  gcc, make
BuildRequires:  %{_bindir}/iconv
BuildRequires:  %{_bindir}/xmllint
BuildRequires:  %{_bindir}/xmlto
BuildRequires:	pkgconfig(gsl) >= 1.4
BuildRequires:	valgrind
BuildRequires:	openjade

%description
Bogofilter is a Bayesian spam filter. In its normal mode of
operation, it takes an email message or other text on standard
input, does a statistical check against lists of "good" and "bad"
words, and returns a status code indicating whether or not the
message is spam. Bogofilter is designed with fast algorithms, coded
directly in C, and tuned for speed, so it can be used for production
by sites that process a lot of mail.

%prep
%if 0%{?prerel:1}
%autosetup -p1 -n %{name}-%{name}-%{version}%{?prerel:.%{prerel}}/%{name}
./autogen.sh
%else
%autosetup -p1
%endif

%build

%configure \
    --disable-rpath \
    --with-database=sqlite3 \
    --without-included-gsl
exit

%make_build
iconv -f iso-8859-1 -t utf-8 \
 doc/bogofilter-faq-fr.html > doc/bogofilter-faq-fr.html.utf8
%{__mv} -f doc/bogofilter-faq-fr.html.utf8 \
 doc/bogofilter-faq-fr.html

%ifnarch armv7hl
# Some strange test failures that would need to be investigated but don't seem fatal
# 3/54 Failed:
#./outputs/dump.load-2.out ./checks.23370.20160529T004141/dump.load-2.txt differ: char 87, line 3
#FAIL: t.dump.load
#want: "7.2 6.20030303 10.20030304", have: "1.2 6.20030303 10.20030304"
#FAIL: t.nonascii.replace
#./outputs/bulkmode.out ./checks.24400.20160529T004148/bulk-double-2.out differ: char 80, line 3
#FAIL: t.bulkmode
%check
%{__make} %{?_smp_mflags} DESTDIR="%{buildroot}" check LC_CTYPE=C
%endif

%install
%make_install

mv %{buildroot}%{_sysconfdir}/bogofilter.cf.example %{buildroot}%{_sysconfdir}/bogofilter.cf

%if 0%{!?prerel:1}
# trio is embedded and has different AUTHORS, CHANGES, README
mkdir -p %{buildroot}%{_datadir}/doc/%{name}/trio
cp trio/CHANGES %{buildroot}%{_datadir}/doc/%{name}/trio/CHANGES
cp trio/AUTHORS %{buildroot}%{_datadir}/doc/%{name}/trio/AUTHORS
cp trio/README %{buildroot}%{_datadir}/doc/%{name}/trio/README
%endif

##include contrib, some may find it useful
for d in contrib ; do
  install -d %{buildroot}%{_datadir}/%{name}/$d
  files=$(find "$d" -maxdepth 1 -type f -print)
  for f in $files ; do
    case $f in
      *.c|*.o|*.obj|*/Makefile*) continue ;;
      *.1)
    cp -p $f %{buildroot}%{_mandir}/man1 ;;
      *)
    cp -p $f %{buildroot}%{_datadir}/%{name}/$d ;;
    esac
  done
done

%if 0%{?prerel:1}
%clean
rm -rf %{_builddir}/%{name}-%{name}-%{version}%{?prerel:.%{prerel}}
%endif

%files
%doc AUTHORS GETTING.STARTED Doxyfile NEWS
%doc README* OBITUARY TODO RELEASE.NOTES*
%doc bogofilter.cf.example
%doc doc/README* doc/bogofilter-SA*
%doc doc/integrating-* doc/*.html doc/*.xml
%doc contrib/README*
%if 0%{!?prerel:1}
%doc %{_datadir}/doc/%{name}/trio
%endif
%config(noreplace) %{_sysconfdir}/bogofilter.cf
%{_bindir}/*
%{_datadir}/bogofilter
%{_mandir}/man1/*