# Template file for 'ksh'
pkgname=ksh
version=2020.0.0
revision=1
wrksrc="ast-${version}"
build_style=meson
configure_args="-Dbuild-api-tests=false -Dbuild-api-tests-only=true"
short_desc="AT&T's Korn shell (ksh93)"
maintainer="Leah Neukirchen <leah@vuxu.org>"
license="EPL-1.0"
homepage="http://www.kornshell.com/"
distfiles="https://github.com/att/ast/archive/${version}.tar.gz"
checksum=76597c96c4f94423b9225b5de50ea54be08d5bbaa1e0e594a7eec603bd60ecaf
nocross=yes

register_shell="/bin/ksh"
alternatives="
 ksh:ksh:/usr/bin/ksh93
 ksh:ksh.1:/usr/share/man/man1/ksh93.1
"

build_options="static"
if [ "$build_option_static" ]; then
	LDFLAGS+=" -static"
fi

case "$XBPS_TARGET_MACHINE" in
*-musl)
	makedepends+=" musl-fts-devel"
esac

post_extract() {
	sed -i -e 's/= library/= static_library/'  \
		-e 's/install: true/install: false/' src/lib/*/meson.build
	sed -i 's/vpoi/void*/g' src/cmd/ksh93/include/name.h
	if [ "$build_option_static" ]; then
		# Drop tests that use .so
		sed -i '/some tests/,$d' src/cmd/ksh93/meson.build
		sed -i '/libsample_files/,$d' src/lib/libdll/meson.build
	fi
}
post_install() {
	mv ${DESTDIR}/usr/bin/ksh ${DESTDIR}/usr/bin/ksh93
	mv ${DESTDIR}/usr/share/man/man1/ksh.1 ${DESTDIR}/usr/share/man/man1/ksh93.1
	vmkdir usr/share/ksh
	vcopy src/cmd/ksh93/fun usr/share/ksh/functions
	vlicense LICENSE
}
