# Template file for 'cln'
pkgname=cln
version=1.3.6
revision=1
build_style=gnu-configure
makedepends="gmp-devel"
short_desc="Class library (C++) for numbers"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-2.0-only"
homepage="https://www.ginac.de/CLN/"
distfiles="${DEBIAN_SITE}/main/c/cln/cln_${version}.orig.tar.bz2"
checksum=f492530e8879bda529009b6033e1923c8f4aae843149fc28c667c20b094d984a

case "$XBPS_TARGET_MACHINE" in
arm*|aarch64*) CPPFLAGS="-DNO_ASM";;
esac

pre_configure() {
	if [ "$CROSS_BUILD" ]; then
		local ENDIAN="UNKNOWN"
		local LBITS=$XBPS_TARGET_WORDSIZE
		local LBYTES=$(($XBPS_TARGET_WORDSIZE / 8))
		local INTPARAM_H=${wrksrc}/include/cln/intparam.h
		local FLOATPARAM_H=${wrksrc}/include/cln/floatparam.h

		if [ "$XBPS_TARGET_ENDIAN" = "be" ]; then
			ENDIAN="BIG"
		fi
		if [ "$XBPS_TARGET_ENDIAN" = "le" ]; then
			ENDIAN="LITTLE"
		fi

		# Make substitutions in intparam.h
		sed ${FILESDIR}/intparam.h \
			-e "s;@LBITS@;$LBITS;g" \
			-e "s;@LBYTES@;$LBYTES;g" \
			-e "s;@ENDIAN@;$ENDIAN;g" \
			-e "s;@endian@;${ENDIAN,,};g" \
		> ${INTPARAM_H}

		# No substitutions in floatparam.h
		cat ${FILESDIR}/floatparam.h \
		> ${FLOATPARAM_H}

		configure_args+=" cl_cv_file_intparam_h=$INTPARAM_H"
		configure_args+=" cl_cv_file_floatparam_h=$FLOATPARAM_H"
	fi
}

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