# Template file for 'bash'
pkgname=bash
version=5.1.004
revision=1
_bash_distver=${version%.*}
_bash_patchlevel=${version##*.}
_patchprefix="bash${_bash_distver/./}"
wrksrc="${pkgname}-${_bash_distver}"
build_style=gnu-configure
configure_args="--without-bash-malloc --with-curses --without-installed-readline"
make_build_args="TERMCAP_LIB=${XBPS_CROSS_BASE}/usr/lib/libncursesw.a"
hostmakedepends="bison"
makedepends="ncurses-devel"
short_desc="GNU Bourne Again Shell"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="GPL-3.0-or-later"
homepage="https://www.gnu.org/software/bash/bash.html"
distfiles="${GNU_SITE}/${pkgname}/${pkgname}-${_bash_distver}.tar.gz"

_url="${GNU_SITE}/bash/bash-${_bash_distver}-patches"
for _p in $(seq -w 001 $_bash_patchlevel); do
	distfiles+=" ${_url}/${_patchprefix}-${_p}"
	skip_extraction+=" ${_patchprefix}-${_p}"
done
unset _url
unset _p

checksum="cc012bc860406dcf42f64431bcd3d2fa7560c02915a601aba9cd597a39329baa
 ebb07b3dbadd98598f078125d0ae0d699295978a5cdaef6282fe19adef45b5fa
 15ea6121a801e48e658ceee712ea9b88d4ded022046a6147550790caf04f5dbe
 22f2cc262f056b22966281babf4b0a2f84cb7dd2223422e5dcd013c3dcbab6b1
 9aaeb65664ef0d28c0067e47ba5652b518298b3b92d33327d84b98b28d873c86"

make_dirs="/etc/bash/bashrc.d 755 root root"
conflicts="chroot-bash>=0"
register_shell="/usr/bin/bash /bin/bash"

alternatives="
 sh:sh:/usr/bin/bash
 sh:sh.1:/usr/share/man/man1/bash.1"

CFLAGS="-DSYS_BASHRC='\"/etc/bash/bashrc\"'"

post_patch() {
	local _p
	cd ${wrksrc}
	for _p in $(seq -w 001 ${_bash_patchlevel}); do
		msg_normal " Applying patch ${_patchprefix}-${_p}.\n"
		patch -sNp0 -i ${XBPS_SRCDISTDIR}/bash-$version/${_patchprefix}-${_p}
	done
}

do_check() {
	make tests
}

post_install() {
	rm -r ${DESTDIR}/usr/share/doc
	ln -s bash ${DESTDIR}/usr/bin/rbash
	vinstall ${FILESDIR}/bashrc 644 etc/bash
	vinstall ${FILESDIR}/bash.sh 644 etc/profile.d
}

bash-devel_package() {
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/bash
		vmove usr/lib/pkgconfig
	}
}
