# Template file for 'justbuild'
pkgname=justbuild
version=1.4.2
revision=1
create_wrksrc=yes
hostmakedepends="jo pandoc pkg-config python3 tar unzip wget grpc protobuf"
makedepends="abseil-cpp-devel c-ares-devel catch2 fmt-devel grpc-devel json-c++
 libarchive-devel libcurl-devel libgit2-devel openssl-devel re2-devel"
depends="python3"
short_desc="Generic build system supporting multi-repository builds"
maintainer="Leah Neukirchen <leah@vuxu.org>"
license="Apache-2.0"
homepage="https://github.com/just-buildsystem/justbuild/"
changelog="https://github.com/just-buildsystem/justbuild/blob/master/CHANGELOG.md"
distfiles="https://github.com/just-buildsystem/justbuild/archive/v${version}.tar.gz"
checksum=dfd9dfdc818ecdee80a073d3e6bb66dc49bcb872f3c49fe01c476f333ec73ca9
conflicts="just>=0"
nocross="not supported by bootstrapping"

case "$XBPS_TARGET_MACHINE" in
	*-musl) makedepends+=" libexecinfo-devel"
esac

CFLAGS="-Wno-error -Wno-deprecated-declarations"
CXXFLAGS="-Wno-error -Wno-deprecated-declarations"

do_build() {
	rm -rf just-work
	mkdir -p just-work
	export JUST_BUILD_CONF=$(jo \
		AR=/usr/bin/ar \
		COMPILER_FAMILY=gnu \
		CC=$CC \
		CXX=$CXX \
		CFLAGS=$(jo -a -- $CFLAGS) \
		ADD_CFLAGS=$(jo -a -- $CFLAGS) \
		CXXFLAGS=$(jo -a -- $CXXFLAGS) \
		ADD_CXXFLAGS=$(jo -a -- $CXXFLAGS) \
		LDFLAGS=$(jo -a -- $LDFLAGS) \
		SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH \
		VERSION_EXTRA_SUFFIX=-void
	)
	export NON_LOCAL_DEPS=$(jo -a \
		bazel_remote_apis \
		cli11 \
		com_github_microsoft_gsl \
		google_apis
	)
	sed -i "s/TaskSystem[(][0-9]*[)]/TaskSystem($XBPS_MAKEJOBS)/" \
		justbuild-${version}/bin/parallel-bootstrap-traverser.py

	PACKAGE=YES LOCALBASE=/usr python3 \
		justbuild-${version}/bin/bootstrap.py \
		justbuild-${version}/ $PWD/just-work

	./just-work/src/out-boot/bin/just install \
		-C $PWD/just-work/repo-conf.json \
		-D "$JUST_BUILD_CONF" \
		-o $PWD/just-work/out \
		--local-build-root $PWD/just-work/.just \
		'' just-mr

	for m in justbuild-${version}/share/man/*.md; do
		pandoc --standalone --to man -o ${m%.md}.man $m
	done
}

do_install() {
	vbin just-work/out/bin/just
	vbin just-work/out/src/other_tools/just_mr/just-mr
	vbin just-work/src/bin/just-import-git.py just-import-git

	eval vcompletion justbuild-${version}/share/just_complete.bash bash

	for m in justbuild-${version}/share/man/*.man; do
		vman $m ${m%.man}
	done
}
