# Copyright     : Obarun
#------------------------
# Maintainer    : Eric Vidal <eric@obarun.org>
# Maintainer    : Jean-Michel T.Dydak <jean-michel@obarun.org>
# Maintainer    : YianIris <yianiris At disroot Dot org>
#----------------
# Obarun PkgSrc : https://git.obarun.org/pkg/obextra/syslog-ng
#--------------------------------------------------------------
# DESCRIPTION ]

pkgname=syslog-ng
pkgver=3.36.1
pkgrel=2
pkgdesc="Next-generation syslogd with advanced networking and filtering capabilities"
url='https://www.syslog-ng.com/products/open-source-log-management/'

track="releases/download/syslog-ng-$pkgver"
target="$pkgname-$pkgver"
source=(
    "https://github.com/balabit/syslog-ng/${track}/${target}.tar.gz"
    syslog-ng.conf
    syslog-ng.logrotate
)

#----------------------
# BUILD CONFIGURATION ]

makedepends=(
    'libxslt'
    'mongo-c-driver'
    'librabbitmq-c'
    'python'
    'libesmtp'
    'hiredis'
    'libdbi'
    'libmaxminddb'
    'net-snmp'
    'librdkafka'
    'libcap'
)

checkdepends=(
    'python-nose'
    'python-ply'
)

#------------------------
# INSTALL CONFIGURATION ]


depends=(
    'awk'
    'glib2'
    'libnsl'
    'json-c'
    'curl'
    'libnet'
    'openssl'
)

optdepends=(
    'logrotate: for rotating log files'
    'libdbi: for the SQL plugin'
    'librabbitmq-c: for the AMQP plugin'
    'mongo-c-driver: for the MongoDB plugin'
    'libesmtp: for the SMTP plugin'
    'hiredis: for the Redis plugin'
    'libmaxminddb: for the GeoIP2 plugin'
    'net-snmp: for the SNMP plugin'
    'librdkafka: for the Kafka C plugin'
    'python: for Python-based plugins'
)

backup=(
    'etc/syslog-ng/scl.conf'
    'etc/syslog-ng/syslog-ng.conf'
    'etc/logrotate.d/syslog-ng'
)

conflicts=(
    'eventlog'
)

replaces=(
    'eventlog'
)

#----------------
# BUILD CONTROL ]

_flags=(
    --prefix=/usr
    --sysconfdir=/etc/syslog-ng
    --libexecdir=/usr/libexec
    --sbindir=/usr/bin
    --localstatedir=/var/lib/syslog-ng
    --datadir=/usr/share
    --with-pidfile-dir=/run
    --disable-spoof-source
    --enable-ipv6
    --disable-systemd
    --with-systemdsystemunitdir=no
    --enable-manpages
    --enable-all-modules
    --disable-java
    --disable-java-modules
    --disable-riemann
    --disable-mqtt
    --with-python=3
    --with-jsonc=system
)

#--------
# BUILD ]

build() {
    cd $pkgname-$pkgver

    ## https://archlinux.org/todo/lto-fat-objects/
    export CFLAGS+=" -ffat-lto-objects"
    export CXXFLAGS+=" -ffat-lto-objects"

    ./autogen.sh
    ./configure "${_flags[@]}"
    make
}

#--------
# CHECK ]

check() {
  cd $pkgname-$pkgver
  make check || /usr/bin/true # unit test requires criterion
}

#----------
# PACKAGE ]

package() {

    make -C $pkgname-$pkgver DESTDIR="$pkgdir" install
    install -dm755 "$pkgdir"/var/lib/syslog-ng "$pkgdir"/etc/syslog-ng/patterndb.d
    install -Dm644 "$srcdir"/syslog-ng.conf "$pkgdir"/etc/syslog-ng/syslog-ng.conf
    install -Dm644 "$srcdir"/syslog-ng.logrotate "$pkgdir"/etc/logrotate.d/syslog-ng
    install -Dm644 "$srcdir"/$pkgname-$pkgver/contrib/systemd/syslog-ng@default -t "$pkgdir"/etc/default
}

#--------------------
# ARCH LICENSE AUTH ]

arch=(x86_64)
license=(GPL2 LGPL2.1)

sha512sums=('')
