# Build recipe for logrotate.
#
# Copyright (c) 2017 Alan Beadle, <ab.beadle@gmail.com>.
# Copyright (c) 2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=logrotate
version=3.21.0
release=1

# Define a category for the output of the package name
pkgcategory=tools

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=https://github.com/logrotate/logrotate/releases/download/${version}/${tarname}

description="
Utility to rotate system logs automatically.

The logrotate utility is designed to simplify the administration of
log files on a system which generates a lot of log files.  Logrotate
allows for the automatic rotation compression, removal and mailing of
log files.  Logrotate can be set to handle a log file daily, weekly,
monthly or when the log file gets to a certain size.
"

homepage=https://github.com/logrotate/logrotate
license=GPLv2+

# Source documentation
docs="ChangeLog.md COPYING README.md"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS -static" \
     $configure_args \
     --mandir=$mandir \
     --with-compress-command="/usr/bin/lzip -9"\
     --with-uncompress-command="/usr/bin/lzip -d" \
     --with-compress-extension=.lz \
     --with-default-mail-command=/usr/bin/mail \
     --with-acl \
     --without-selinux \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    mkdir -p "${destdir}/etc/logrotate.d" "${destdir}/etc/cron.daily"

    cp -p examples/logrotate.conf "${destdir}/etc"
    chmod 644 "${destdir}/etc/logrotate.conf"

    # To make use of the compression by default
    sed -i "s|#compress|compress|" "${destdir}/etc/logrotate.conf"

    touch "${destdir}/etc/.graft-config"

    cp -p "${worktree}/archive/logrotate/logrotate.cron" \
          "${destdir}/etc/cron.daily/logrotate"
    chmod 755 "${destdir}/etc/cron.daily/logrotate"

    # Compress man pages
    lzip -9 "${destdir}/${mandir}"/man?/*

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

