%bcond_without luajit

Summary:	addons for the OpenSMTPD SMTP server
Name:		opensmtpd-extras
Version:	6.7.1
Release:	3%{?dist}

License:	ISC
URL:		http://www.opensmtpd.org/

Source0:	https://github.com/OpenSMTPD/%{name}/archive/%{version}/opensmtpd-extras-%{version}.tar.gz


BuildRequires:	libtool
BuildRequires:	hiredis-devel
BuildRequires:  krb5-devel

%if 0%{?rhel} <= 7
BuildRequires:  postgresql-devel
%else
BuildRequires:  libpq-devel
%endif
BuildRequires:	sqlite-devel
BuildRequires:	mysql-devel
%if 0%{?rhel} >= 7
BuildRequires:  automake autoconf m4
BuildRequires:	libevent-devel
BuildRequires:	python3-devel
%global __py_name python3
%else
BuildRequires:  automake1.16 autoconf2.69 m4
BuildRequires:	libevent2-devel
BuildRequires:	python3.11-devel
%global __py_name python3.11
%endif

BuildRequires:	pkgconfig(openssl) >= 3.0


%if %{with luajit}
BuildRequires:	luajit-devel
%else
BuildRequires:	lua-devel
%endif

Requires: opensmtpd

%description
This package provides a subset of addons for OpenSMTPD, including
experimental ones. Please see each for a description of additional
dependencies.
* Tables:
+ ldap: support lookup against LDAP
+ mysql: support lookup against MySQL
+ passwd: support lookup in passwd-format tables
+ postgres: support lookup against PostgreSQL
+ redis: support lookup against a Redis server
+ socketmap: support lookups against sockets
+ sqlite: support lookup in SQLite tables

%prep
%autosetup -p1

%build

export REDIS_CPPFLAGS='-I /usr/include/hiredis'

%if 0%{?rhel} < 9
export CFLAGS="-I%{_includedir}/openssl3 -fPIC $CFLAGS"
%endif

./bootstrap

%configure \
    --prefix=/usr \
    --sysconfdir=/etc/smtpd \
    --with-pie \
    --with-mantype=man \
    --with-queue-ram \
    --with-scheduler-ram \
    --with-scheduler-stub \
    --with-table-ldap \
    --with-table-mysql \
	--with-table-passwd \
	--with-table-postgres \
	--with-table-redis \
	--with-table-socketmap \
	--with-table-sqlite \
	--with-table-stub \
%if %{with luajit}
	--with-lua-type=luajit \
%else
	--with-lua-type=lua \
%endif
    --with-python=%{_prefix} \
	--with-python-type=%{__py_name}

make %{?_smp_mflags}

%install
make install DESTDIR=%{buildroot}


%files
%{_libexecdir}/opensmtpd/queue-*
%{_libexecdir}/opensmtpd/scheduler-*
%{_libexecdir}/opensmtpd/table-*
%{_mandir}/man5/table-*.5.*


%changelog
* Fri Sep 13 2024 Raven <raven@sysadmins.ws> - 6.7.1-3
- rebuild for OpenSSL

* Wed Feb 28 2024 Raven <raven@sysadmins.ws> - 6.7.1-2
- fix rhel6 dependencies

* Wed Oct  4 2023 Raven <raven@sysadmins.ws> - 6.7.1-1
- Initial release
