SUMMARY="The GNU Bourne Again Shell"
DESCRIPTION="Bash is an sh-compatible command language interpreter that \
executes commands read from the standard input or from a file. Bash also \
incorporates useful features from the Korn and C shells (ksh and csh)."
HOMEPAGE="https://www.gnu.org/software/bash/"
COPYRIGHT="1987-2020 Free Software Foundation, Inc."
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://ftpmirror.gnu.org/bash/bash-5.1.tar.gz"
for i in {001..016}; do
	eval "SOURCE_URI_$i=\"https://ftpmirror.gnu.org/bash/bash-5.1-patches/bash51-$i#noarchive\""
done
CHECKSUM_SHA256="cc012bc860406dcf42f64431bcd3d2fa7560c02915a601aba9cd597a39329baa"
CHECKSUM_SHA256_001="ebb07b3dbadd98598f078125d0ae0d699295978a5cdaef6282fe19adef45b5fa"
CHECKSUM_SHA256_002="15ea6121a801e48e658ceee712ea9b88d4ded022046a6147550790caf04f5dbe"
CHECKSUM_SHA256_003="22f2cc262f056b22966281babf4b0a2f84cb7dd2223422e5dcd013c3dcbab6b1"
CHECKSUM_SHA256_004="9aaeb65664ef0d28c0067e47ba5652b518298b3b92d33327d84b98b28d873c86"
CHECKSUM_SHA256_005="cccbb5e9e6763915d232d29c713007a62b06e65126e3dd2d1128a0dc5ef46da5"
CHECKSUM_SHA256_006="75e17d937de862615c6375def40a7574462210dce88cf741f660e2cc29473d14"
CHECKSUM_SHA256_007="acfcb8c7e9f73457c0fb12324afb613785e0c9cef3315c9bbab4be702f40393a"
CHECKSUM_SHA256_008="f22cf3c51a28f084a25aef28950e8777489072628f972b12643b4534a17ed2d1"
CHECKSUM_SHA256_009="e45cda953ab4b4b4bde6dc34d0d8ca40d1cc502046eb28070c9ebcd47e33c3ee"
CHECKSUM_SHA256_010="a2c8d7b2704eeceff7b1503b7ad9500ea1cb6e9393faebdb3acd2afdd7aeae2a"
CHECKSUM_SHA256_011="58191f164934200746f48459a05bca34d1aec1180b08ca2deeee3bb29622027b"
CHECKSUM_SHA256_012="10f189c8367c4a15c7392e7bf70d0ff6953f78c9b312ed7622303a779273ab98"
CHECKSUM_SHA256_013="c7acb66df435d284304c16ca83a5265f9edd9368612095b01a733d45c77ed5ad"
CHECKSUM_SHA256_014="6a4ee0c81b437b96279a792c1efcec4ba56f009195a318083db6b53b096f83d0"
CHECKSUM_SHA256_015="1b37692ef1f6cc3dcec246773443276066e6b1379868f8c14e01f4dfd4df80f0"
CHECKSUM_SHA256_016="8899144f76a5db1fb41a89ed881c9f19add95728dd71db324f772ef225c5384f"

SOURCE_DIR="bash-5.1"
PATCHES="
	bash-kill_by_name.patch
	bash-5.0.patchset
	"

ARCHITECTURES="all"

PROVIDES="
	bash = $portVersion
	cmd:bash = $portVersion
	cmd:bashbug = $portVersion
	cmd:sh
	"
REQUIRES="
	haiku
	lib:libhistory
	lib:libreadline
	lib:libncursesw
	lib:libintl
	lib:libiconv
	"

BUILD_REQUIRES="
	haiku_devel
	devel:libhistory >= 8
	devel:libreadline >= 8
	devel:libncursesw
	devel:libintl
	"
BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:awk
	cmd:bison
	cmd:cmp
	cmd:gcc
	cmd:make
	cmd:patch
	cmd:sed
	"

GLOBAL_WRITABLE_FILES="settings/bashrc keep-old"

PATCH()
{
	cd $sourceDir
	for i in {001..016}; do
		echo "Applying patch $i..."
		eval f=\$sourceDir$i/bash51-$i
		sed -e "s|\.\./bash-5.1/||" "$f" | patch -p0
	done

	# store bash settings under ~/config/settings
	find -type f -name "*.c" -o -name "*.def" -o -name "*.h" -o -name "*.1" \
		| xargs sed -i -e 's,~/\.,~/config/settings/,g'
}

BUILD()
{
	runConfigure ./configure \
		--without-bash-malloc --with-installed-readline
	make $jobArgs
}

INSTALL()
{
	make install-strip
	ln -s bash $binDir/sh

	# Use bash-completion, if available
	cat <<'EOF' > $settingsDir/bashrc
#!/bin/bash
[[ $PS1 && -f /system/data/bash-completion/bash_completion ]] && \
    . /system/data/bash-completion/bash_completion
EOF
}


TEST()
{
	make check
}
