# Template file for 'cgit'
_git_version=2.25.1
pkgname=cgit
version=1.2.3
revision=4
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="@19645e5106adac722941623462dfe2b85d8969610b753119444ed19b8e22a311
 @5061e83aa1c7cc5825a378bd1e35df1f4af412903486d2e2fceb6d8a064455cf"

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
}
