##
##  syslog-ng.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_sl_major 3.3
%define       V_sl_minor 5
%define       V_ol_major 0.3
%define       V_ol_minor 18
%define       V_el_major 0.2
%define       V_el_minor 12

#   package information
Name:         syslog-ng
Summary:      Syslog Daemon
URL:          http://www.balabit.com/products/syslog-ng/
Vendor:       Balázs Scheidler
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        System
License:      GPL
Version:      %{V_sl_major}.%{V_sl_minor}
Release:      20120713

#   list of sources
Source0:      http://www.balabit.com/downloads/files/syslog-ng/sources/%{V_sl_major}.%{V_sl_minor}/source/syslog-ng_%{V_sl_major}.%{V_sl_minor}.tar.gz
Source1:      http://www.balabit.com/downloads/files/libol/%{V_ol_major}/libol-%{V_ol_major}.%{V_ol_minor}.tar.gz
Source2:      http://www.balabit.com/downloads/files/eventlog/%{V_el_major}/eventlog_%{V_el_major}.%{V_el_minor}.tar.gz
Source3:      rc.syslog-ng
Source4:      syslog-ng.conf

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, flex, bison, gcc, pkgconfig
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  glib, openssl, pcre
PreReq:       glib, openssl, pcre

%description
    syslog-ng is a syslogd(8) replacement, but with new functionality
    for the new generation. The original syslogd allows messages only
    to be sorted based on priority/facility pairs; syslog-ng adds the
    possibility to filter based on message contents using regular
    expressions. The new configuration scheme is intuitive and powerful.
    Forwarding logs over TCP and remembering all forwarding hops makes
    it ideal for firewalled environments.

%track
    prog syslog-ng:libol = {
        version   = %{V_ol_major}.%{V_ol_minor}
        url       = http://www.balabit.com/downloads/files/libol/
        regex     = (0\.\d+)
        url       = http://www.balabit.com/downloads/files/libol/__NEWVER__/
        regex     = libol-(__VER__)\.tar\.gz
    }
    prog syslog-ng:eventlog = {
        version   = %{V_el_major}.%{V_el_minor}
        url       = http://www.balabit.com/downloads/files/eventlog/
        regex     = (0\.\d+)
        url       = http://www.balabit.com/downloads/files/eventlog/__NEWVER__/
        regex     = eventlog_(__VER__)\.tar\.gz
    }
    prog syslog-ng:syslog-ng = {
        version   = %{V_sl_major}.%{V_sl_minor}
        url       = http://www.balabit.com/downloads/files/syslog-ng/sources/stable/src/
        regex     = syslog-ng-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2

%build
    #   configure and build libol
    ( cd libol-%{V_ol_major}.%{V_ol_minor}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CPPFLAGS="%{l_cppflags}" \
      LDFLAGS="%{l_ldflags}" \
      ./configure \
          --prefix=%{l_prefix} \
          --disable-shared
      %{l_make} %{l_mflags -O}
    ) || exit $?

    #   configure and build eventlog
    ( cd eventlog-%{V_el_major}.%{V_el_minor}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CPPFLAGS="%{l_cppflags}" \
      LDFLAGS="%{l_ldflags}" \
      ./configure \
          --prefix=%{l_prefix} \
          --disable-shared
      %{l_make} %{l_mflags -O}
    ) || exit $?

    #   configure and build syslog-ng
    %{l_shtool} subst \
        -e 's;-Wl,-Bdynamic;;' \
        -e 's;-Wl,-Bstatic;;' \
        configure
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    EVTLOG_CFLAGS="-I`pwd`/eventlog-%{V_el_major}.%{V_el_minor}/src" \
    EVTLOG_LIBS="-L`pwd`/eventlog-%{V_el_major}.%{V_el_minor}/src/.libs -levtlog" \
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --datadir=%{l_prefix}/share
    %{l_make} %{l_mflags -O}

%install
    #   install syslog-ng
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    strip $RPM_BUILD_ROOT%{l_prefix}/sbin/* >/dev/null 2>&1 || true

    #   install additional files
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/syslog-ng \
        $RPM_BUILD_ROOT%{l_prefix}/var/syslog-ng
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.syslog-ng} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE syslog-ng.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/syslog-ng/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/syslog-ng/*'

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} syslog-ng status 2>/dev/null`
    [ ".$syslog_ng_active" = .yes ] && %{l_rc} syslog-ng restart
    exit 0

%preun
    #   before erase, stop service and remove log files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} syslog-ng stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/syslog-ng/* >/dev/null 2>&1 || true
    exit 0

