# Maintainer: Markus Fritsche <mfritsche@reauktion.de>
# Based on Arch Linux ARM's distcc PKGBUILD, rebuilt with --with-avahi
# so Zeroconf-announced compile servers are discoverable on the LAN.
#
# Why this exists: the ALARM aarch64 distcc binary package is built
# without --with-avahi, so the distccd --zeroconf flag is a no-op.
# The Arch x86_64 package is fine. This package replaces distcc on
# ALARM hosts with an avahi-aware build.

pkgname=distcc-avahi
_pkgname=distcc
pkgver=3.4
pkgrel=15
pkgdesc="Distributed compilation service for C, C++ and Objective-C (with Avahi/Zeroconf support)"
arch=('x86_64' 'aarch64')
url="https://github.com/distcc/distcc"
license=('GPL-2.0-only')
depends=('popt' 'python' 'avahi')
makedepends=('autoconf' 'automake' 'libtool' 'pkgconf' 'python-setuptools')
optdepends=('gtk3: for distccmon')
provides=("distcc=${pkgver}")
conflicts=('distcc')
replaces=('distcc')
backup=('etc/conf.d/distccd')
source=(
    "https://github.com/distcc/distcc/releases/download/v${pkgver}/distcc-${pkgver}.tar.gz"
    "distccd.conf"
    "distccd.service"
    "distcc.tmpfiles"
)
sha256sums=(
    'SKIP'  # pin when first built in CI
    'SKIP'
    'SKIP'
    'SKIP'
)

prepare() {
    cd "${_pkgname}-${pkgver}"
    autoreconf -fiv
}

build() {
    cd "${_pkgname}-${pkgver}"
    ./configure \
        --prefix=/usr \
        --sysconfdir=/etc \
        --mandir=/usr/share/man \
        --with-auth \
        --with-avahi \
        --without-libiberty \
        --enable-rfc2553 \
        --with-docdir="/usr/share/doc/${pkgname}"
    make
    make -C doc
}

check() {
    cd "${_pkgname}-${pkgver}"
    # Upstream test suite is flaky under makepkg; skip unless CHECK=1.
    [ "${CHECK:-0}" = "1" ] && make check || true
}

package() {
    cd "${_pkgname}-${pkgver}"
    make DESTDIR="${pkgdir}" prefix=/usr install
    install -Dm644 ../distccd.conf    "${pkgdir}/etc/conf.d/distccd"
    install -Dm644 ../distccd.service "${pkgdir}/usr/lib/systemd/system/distccd.service"
    install -Dm644 ../distcc.tmpfiles "${pkgdir}/usr/lib/tmpfiles.d/distcc.conf"
}
