# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=distcc
pkgver=3.4
pkgrel=9
pkgdesc="Ddistributed C, C++, Obj C compiler"
url="https://github.com/distcc/distcc"
arch="all"
license="GPL-2.0-or-later"
_pump_deps="python3 py3-setuptools"
makedepends="autoconf automake popt-dev python3-dev $_pump_deps"
checkdepends="gdb procps"
options="!check" # tests are failing
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-pump-pyc $pkgname-pump $pkgname-openrc"
source="https://github.com/distcc/distcc/releases/download/v$pkgver/distcc-$pkgver.tar.gz
	distcc-hardened.patch
	gcc-10.patch
	dcc_gcc_rewrite_fqn-avoid-heap-corruption.patch
	distccd.initd
	distccd.confd
	"

prepare() {
	default_prepare
	update_config_sub

	./autogen.sh
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--without-gtk \
		--sysconfdir=/etc \
		--disable-Werror \
		--without-libiberty \
		--mandir=/usr/share/man

	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -D -m644 ../distccd.confd "$pkgdir"/etc/conf.d/distccd
	install -D -m755 ../distccd.initd "$pkgdir"/etc/init.d/distccd

	local d="$pkgdir/usr/lib/$pkgname/bin"
	mkdir -p "$d"
	ln -sf /usr/bin/$pkgname "$d"/cc
	ln -sf /usr/bin/$pkgname "$d"/gcc
	ln -sf /usr/bin/$pkgname "$d"/g++
	ln -sf /usr/bin/$pkgname "$d"/cpp
}

pump() {
	pkgdesc="pump mode for distcc a distributed compiler client and server"
	depends="$_pump_deps distcc=$pkgver-r$pkgrel"
	mkdir -p "$subpkgdir"/usr/lib "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/pump "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/lib/python* "$subpkgdir"/usr/lib/
}

sha512sums="
de09329fdfa25e08a9b9529190ddaa9ceccb34c8655692edb86f367a8db4a71b750c6e928cb8e5a670f51fbbc02fd1c8524f72e01b3ebaacc1106dc676d18eef  distcc-3.4.tar.gz
b53a0d6038504917fd41f549da4f5addaff6ebd198a5d9d3ee8d4654f843aab375da4017b40efe24b9d4c9881719030485e4f56724690ba271fb52dc48249a44  distcc-hardened.patch
4e55e0acda58e6f273c74e9d617de1a121debf820e915cf8aeb4d80907d427a058466bb2fd9126602aea7f861fd5fa1c2bede15e2a512923bc61e3ef163430d4  gcc-10.patch
9bc411107021d5f621304a73b0bfdec387d1b33121a325503cf4c9c4046924338ee1b4ef093b517249c3df31cf69cd9f19377df2edd6e81be1dac50a5bd0f3d5  dcc_gcc_rewrite_fqn-avoid-heap-corruption.patch
32d6669955754b004db8716c321703fcb50da31d8dfc1288b021834fe968e5f7c9eb40d8af34eba9b59becc07e315f65127d711bb0bc49df41c6b4b973864855  distccd.initd
fbb12522e489243475c735e055a72a19b176f1ad736dc810e1f085d8d9d79460ac7590a92bb9563f8b316437f67f6ca729330253f007d06011144a66fede5465  distccd.confd
"
