%global _hardened_build 1
%global with_modperl 1
%global __python %{__python3}
%global with_modpython 1

Name:           znc
Version:        1.8.0
Release:        1%{?dist}
Summary:        An advanced IRC bouncer
Group:          System Environment/Daemons
License:        ASL 2.0
URL:            http://znc.in
Source0:        %{url}/releases/%{name}-%{version}.tar.gz
BuildRequires:  automake
BuildRequires:  c-ares-devel
BuildRequires:  cyrus-sasl-devel
BuildRequires:  gcc-c++
BuildRequires:  gettext-devel
BuildRequires:  libicu-devel
BuildRequires:  openssl-devel >= 0.9.8
BuildRequires:  perl(ExtUtils::Embed)
Obsoletes:      znc-extra <= %{version}-%{release}
Requires(pre):  shadow-utils
BuildRequires:  systemd
%{?systemd_requires}


%description
ZNC is an IRC bouncer with many advanced features like detaching,
multiple users, per channel playback buffer, SSL, IPv6, transparent
DCC bouncing, Perl and C++ module support to name a few.


%package devel
Summary:        Development files needed to compile ZNC modules
Group:          Development/Libraries
Requires:       %{name} = %{version}-%{release} pkgconfig
Requires:       openssl-devel c-ares-devel glibc-devel libicu-devel%{?_isa}
BuildRequires: pkgconfig
%description devel
All includes and program files you need to compile your own znc
modules.


%package modtcl
Summary:       TCL module for ZNC
Group:         Development/Libraries
BuildRequires: tcl-devel
Requires:      %{name} = %{version}-%{release}
Requires:      tcl
%description modtcl
TCL module for ZNC


%package modperl
Summary:       perl module for ZNC
Group:         Development/Libraries
BuildRequires: perl-devel
#BuildRequires: perl-generators
BuildRequires: swig
Requires:      %{name} = %{version}-%{release}
Requires:      perl-interpreter
Provides:      perl(ZNC::Module) = %{version}-%{release}
%description modperl
perl module for ZNC


%package modpython
Summary:       python3 module for ZNC
Group:         Development/Libraries
BuildRequires: python3-devel
BuildRequires: swig
Requires:      %{name} = %{version}-%{release}
Requires:      python3
%description modpython
python3 module for ZNC


%prep
%setup -q
#%__perl -pi.add_release -e 's|(?<="ZNC \%1\.3f)|-%{release}|' znc.cpp
#chmod -x modules/q.cpp


%build
%configure \
     --with-module-prefix=%{_libdir}/znc \
     --with-systemdsystemunitdir=%{_unitdir} \
     --enable-perl \
     --enable-python \
     --enable-ipv6 --enable-cyrus --enable-tcl
%__make %{?_smp_mflags}


%install
%__make install DESTDIR="%{buildroot}"
mkdir -p %buildroot%{_unitdir}
install -d "%{buildroot}%{_sharedstatedir}/znc"


%clean
%__rm -Rf "%{buildroot}"


%pre
getent group znc >/dev/null || groupadd -r znc
getent passwd znc >/dev/null || \
    useradd -r -g znc -d /var/lib/znc -s /sbin/nologin \
    -c "Account for ZNC to run as" znc


%post
%systemd_post znc.service


%postun
%systemd_postun_with_restart znc.service


%preun
%systemd_preun znc.service


%files
%doc LICENSE README.md
%{_bindir}/znc
%{_mandir}/man1/*
%dir %{_libdir}/znc
%{_libdir}/znc/admindebug.so
%{_libdir}/znc/adminlog.so
%{_libdir}/znc/alias.so
%{_libdir}/znc/autoattach.so
%{_libdir}/znc/autocycle.so
%{_libdir}/znc/autoop.so
%{_libdir}/znc/autoreply.so
%{_libdir}/znc/autovoice.so
%{_libdir}/znc/awaynick.so
%{_libdir}/znc/awaystore.so
%{_libdir}/znc/block_motd.so
%{_libdir}/znc/blockuser.so
%{_libdir}/znc/bouncedcc.so
%{_libdir}/znc/buffextras.so
%{_libdir}/znc/cert.so
%{_libdir}/znc/certauth.so
%{_libdir}/znc/chansaver.so
%{_libdir}/znc/clearbufferonmsg.so
%{_libdir}/znc/clientnotify.so
%{_libdir}/znc/controlpanel.so
%{_libdir}/znc/crypt.so
%{_libdir}/znc/ctcpflood.so
%{_libdir}/znc/cyrusauth.so
%{_libdir}/znc/dcc.so
%{_libdir}/znc/disconkick.so
%{_libdir}/znc/fail2ban.so
%{_libdir}/znc/flooddetach.so
%{_libdir}/znc/identfile.so
%{_libdir}/znc/imapauth.so
%{_libdir}/znc/keepnick.so
%{_libdir}/znc/kickrejoin.so
%{_libdir}/znc/lastseen.so
%{_libdir}/znc/listsockets.so
%{_libdir}/znc/log.so
%{_libdir}/znc/missingmotd.so
%{_libdir}/znc/modules_online.so
%{_libdir}/znc/nickserv.so
%{_libdir}/znc/notes.so
%{_libdir}/znc/notify_connect.so
#%{_libdir}/znc/partyline.so
%{_libdir}/znc/perform.so
#%{_libdir}/znc/q.so
%{_libdir}/znc/raw.so
%{_libdir}/znc/route_replies.so
%{_libdir}/znc/sample.so
%{_libdir}/znc/samplewebapi.so
%{_libdir}/znc/sasl.so
%{_libdir}/znc/savebuff.so
%{_libdir}/znc/schat.so
%{_libdir}/znc/send_raw.so
%{_libdir}/znc/shell.so
%{_libdir}/znc/simple_away.so
%{_libdir}/znc/stickychan.so
%{_libdir}/znc/stripcontrols.so
%{_libdir}/znc/watch.so
%{_libdir}/znc/webadmin.so
%{_datadir}/znc/
%{_unitdir}/znc.service
%attr(-,znc,znc) %{_sharedstatedir}/znc/


%files devel
%{_bindir}/znc-buildmod
%{_libdir}/pkgconfig/%{name}.pc
%{_includedir}/znc/


%files modtcl
%{_libdir}/znc/modtcl.so


%files modperl
%{_libdir}/znc/modperl/
%{_libdir}/znc/modperl.so
%{_libdir}/znc/perleval.pm


%files modpython
%{_libdir}/znc/modpython/
%{_libdir}/znc/modpython.so
%{_libdir}/znc/pyeval.py
%{_libdir}/znc/__pycache__/


%changelog
