# Template file for 'cgit'
_git_version=2.54.0
pkgname=cgit
version=1.3.1
revision=1
create_wrksrc=yes
hostmakedepends="asciidoc"
makedepends="zlib-devel"
checkdepends="perl tidy5 unzip lzip zstd xz tar which"
short_desc="Hyperfast web frontend for git repositories written in C"
maintainer="Duncaen <duncaen@voidlinux.org>"
license="GPL-2.0-only"
homepage="https://git.zx2c4.com/cgit/"
distfiles="https://git.zx2c4.com/cgit/snapshot/cgit-${version}.tar.xz
 https://www.kernel.org/pub/software/scm/git/git-${_git_version}.tar.xz"
checksum="@0f2e2013c5a03328ee2cb2bf54c0cb06b2cfbc5f8f2fa12e5f2fde0e395d276e
 @f073e2d5e12f1a4f65c4076284871ff22ef2832ab3455c4a53c52d92c60fda90"

post_extract() {
	rmdir cgit-$version/git
	mv git-$_git_version git
	mv cgit-$version/* cgit-$version/.??* .
	rmdir cgit-$version

	# bug: https://inbox.vuxu.org/cgit/87v8m8pnen.fsf@vuxu.org/
	vsed -i '/HAVE_LINUX_SENDFILE = YesPlease/d' cgit.mk
}

do_configure() {
	cat <<-EOF >cgit.conf
	prefix=/usr
	NO_OPENSSL=Yes
	CGIT_DATA_PATH=/usr/share/webapps/cgit
	CGIT_SCRIPT_PATH=/usr/libexec/cgit
	# cgit build git with NO_CURL for all but not tests,
	# make the whole git rebuilt with different flags
	NO_CURL=Yes
	CC = $CC
	AR = $AR
	TAR = bsdtar
	CFLAGS = $CFLAGS
	LDFLAGS = $LDFLAGS
	HOST_CPU = ${XBPS_TARGET_MACHINE%-musl}
	DC_SHA1 = Yes
	NO_GETTEXT = Yes
	NO_PYTHON = Yes
	NO_EXPAT = Yes
	# Don't build git-perl script, test requires perl still run
	NO_PERL = Yes
	NO_TCLTK = Yes
	EOF
	if [ "$XBPS_TARGET_LIBC" = musl ]; then
		# Copy settings from git
		cat <<-EOF >>cgit.conf
		ICONV_OMITS_BOM = Yes
		# This option will use a vendored regex engine
		NO_REGEX = NeedsStartEnd
		EOF
	fi
	cp cgit.conf git/config.mak
}


do_build() {
	if ! grep -q "^GIT_VER = $_git_version\$" Makefile; then
		msg_error "$pkgver: update _git_version to match upstream Makefile.\n"
	fi
	make ${makejobs} all doc-man
}

do_check() {
	make test
}

do_install() {
	make DESTDIR=${DESTDIR} install install-man

	ln -s /usr/libexec/cgit/cgit.cgi ${DESTDIR}/usr/share/webapps/cgit/cgit.cgi
}
