# Template file for 'gnucobol'
pkgname=gnucobol
version=3.2
revision=1
build_style=gnu-configure
build_helper=qemu
configure_args="--disable-hardening"
hostmakedepends="automake gettext-devel-tools libtool pkg-config"
makedepends="db-devel gmp-devel json-c-devel libxml2-devel ncurses-devel"
depends="gnucobol-libs>=${version}_${revision}"
checkdepends="curl perl which"
short_desc="GnuCOBOL (formerly OpenCOBOL) is a free COBOL compiler"
maintainer="Cthulhux <git@tuxproject.de>"
license="GPL-3.0-or-later"
homepage="https://www.gnu.org/software/gnucobol/"
distfiles="${GNU_SITE}/gnucobol/gnucobol-${version}.tar.xz"
checksum=3bb48af46ced4779facf41fdc2ee60e4ccb86eaa99d010b36685315df39c2ee2

pre_configure() {
	autoreconf -fi
}

post_configure() {
	if [ "${CROSS_BUILD}" ]; then
		vsed -i libtool \
			-e 's|exec \\"\\$progdir/\\$program\\"|exec /usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static \\"\\$progdir/\\$program\\"|'
	fi
}

post_build() {
	if [ "${CROSS_BUILD}" ]; then
		vsed -i bin/cob-config \
			-e "s|-I${XBPS_CROSS_BASE}/usr/include|-I/usr/include|"
	fi
}

do_check() {
	# Test fails because musl does not unload libraries, tracked upstream at https://sourceforge.net/p/gnucobol/bugs/906/
	if [ "${XBPS_TARGET_LIBC}" = "musl" ]; then
		vsed -i tests/testsuite -e "/^818;/d"
	fi
	TERM=xterm make check
	make test
}

gnucobol-libs_package() {
	short_desc+=" - runtime libraries"
	pkg_install() {
		vmove usr/lib/*.so.*
		vmove usr/lib/gnucobol
	}
}
