# Template file for 'anope'
pkgname=anope
version=2.0.15
revision=1
build_style=cmake
make_cmd=make
configure_args="-DINSTDIR=../install -DRUNGROUP=_anope -DDEFUMASK=077
 -DUSE_PCH=OFF"
hostmakedepends="gettext"
short_desc="Set of IRC Services designed for flexibility and ease of use"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-2.0-only"
homepage="https://www.anope.org/"
changelog="https://raw.githubusercontent.com/anope/anope/2.0/docs/Changes"
distfiles="https://github.com/anope/anope/archive/refs/tags/${version}.tar.gz"
checksum=389dd91ac02a523a48e357f64c5f536ad604adf3a819e5ecfea8c04ebd85857c

system_accounts="_anope"
make_dirs="
 /etc/anope 755 root root
 /var/lib/anope 755 _anope _anope
 /var/log/anope 755 _anope _anope"

if [ "$XBPS_TARGET_LIBC" = musl ]; then
	makedepends+=" gettext-devel"
	LDFLAGS="-lintl"
fi

export CMAKE_GENERATOR="Unix Makefiles"

pre_configure() {
	# prevent cmake from building include/version and running
	# because it breaks cross compiling (cmake can't differentiate
	# between CXX and CXX_FOR_HOST)
	rm -v include/CMakeLists.txt
}

pre_build() {
	# replace removed include/version functionality
	(
		source src/version.sh
		echo "#define VERSION_EXTRA \"$VERSION_EXTRA\""
		echo "#define VERSION_MAJOR $VERSION_MAJOR"
		echo "#define VERSION_MINOR $VERSION_MINOR"
		echo "#define VERSION_PATCH $VERSION_PATCH"
	) > build/include/version.h
	echo "#define BUILD ${revision}" > build/include/build.h
}

do_install() {
	cd build
	make install

	cd ${wrksrc}/install

	vbin bin/anopesmtp
	vbin bin/services anopeservices

	for conffile in conf/*example.conf; do
		vsconf ${conffile}
	done

	vmkdir /usr/share/anope
	vcopy data/* /usr/share/anope

	vmkdir /usr/lib/anope
	vcopy lib/modules /usr/lib/anope

	vcopy locale /usr/share

	vsv anope
}
