# Template file for 'ntl'
pkgname=ntl
version=11.6.0
revision=1
build_wrksrc="src"
build_style=configure
build_helper=qemu
hostmakedepends="perl libtool autoconf automake"
makedepends="gmp-devel gf2x-devel"
short_desc="Library for doing Number Theory"
maintainer="Gonzalo Tornaría <tornaria@cmat.edu.uy>"
license="LGPL-2.1-or-later"
homepage="https://libntl.org"
changelog="https://github.com/libntl/ntl/releases"
distfiles="https://github.com/libntl/ntl/archive/refs/tags/v${version}.tar.gz"
checksum=30e29eb21c5da6db031fc7dc5b1a6c728f226c7128e922421247157bc89ecd86

build_options="native_build"

if [ "$CROSS_BUILD" ]; then
	export RUNTEST="/usr/bin/qemu-$XBPS_TARGET_QEMU_MACHINE-static"
fi

pre_configure() {
	# project uses libtool without autoconf, which is not really viable
	# since autoconf is supposed to configure libtool.
	mkdir -p hack
	cat <<-EOF >hack/configure.ac
	AC_INIT
	LT_INIT
	AC_CONFIG_MACRO_DIRS([m4])
	AC_LANG([C])
	AC_LANG([C++])
	LT_LANG([C])
	LT_LANG([C++])
	AC_OUTPUT
	EOF
	(cd hack;  autoreconf -fi; libtoolize -i; ./configure --host=$XBPS_CROSS_TRIPLET --build=$XBPS_TRIPLET --with-libtool-sysroot=$XBPS_CROSS_BASE)
}

do_configure() {
	# see http://www.shoup.net/ntl/doc/tour-unix.html
	./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS" LIBTOOL="./hack/libtool" \
		PREFIX="/usr" SHARED="on" NTL_GF2X_LIB="on" \
		NATIVE="$(vopt_if native_build 'on' 'off')"
}

ntl-devel_package() {
	depends="${sourcepkg}>=${version}_${revision} ${makedepends}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove usr/share
	}
}
