NAME=bash
VERSION=3.2.15
SOURCE=($MIRROR_GNU/bash/bash-${VERSION%.*}.tar.gz )
OPTIMIZE=${OPTIMIZE:-"-Os -pipe"}
BUILD=${BUILD:-1}

# Official patches - using some bash scripting: ;-)
for ((I=1; I <= ${VERSION##*.}; I++)); do
	PATCH[$((I - 1))]=$MIRROR_GNU/bash/bash-${VERSION%.*}-patches/bash${VERSION:0:1}${VERSION:2:1}-$(printf '%03u' $I)
done


build() {
	_explode 0
	cd bash-*
	
	# Official patches
	for I in "${PATCH[@]}"; do
		_patch $I -p2
	done
	
	# These options would be nice to use but let's try to not break
	# anyones installation (yet;):
	# --with-curses --with-installed-readline
	# UPDATE: Since ncurses have now been in /lib for awhile,
	# I dare to add --with-curses.
	_configure --with-curses
	make -j$MAKEJOBS
	make install DESTDIR=$PKG
	
	if [ "$PREFIX" = "/usr" ]; then
		mkdir -p $PKG/bin
		mv $PKG$BINDIR/bash $PKG/bin/bash
		ln -s /bin/bash $PKG$BINDIR/bash
	fi

	# We don't include the "bashbug" script.
	rm -f $PKG$BINDIR/bashbug $PKG$MANDIR/man1/bashbug.1
	_doc 0 bash-$VERSION  AUTHORS CHANGES COMPAT COPYING INSTALL \
			MANIFEST NEWS NOTES README Y2K doc/FAQ doc/INTRO
	cd doc
	groff -ms -Tascii article.ms > $PKG$DOCDIR/bash-$VERSION/article.txt
	# bash.1 is already installed by "make install"
	cp -a builtins.1 rbash.1 $PKG$MANDIR/man1

	# Add bash to /etc/shells if needed. NOTE: I'm dropping the
	# Slackware's feature to package bash as bin/bash2.new which
	# gets renamed to bin/bash. I'm aware of possible unwanted
	# side-effects such as getting completely rid of the bash binary
	# if admin upgradepkgs back to Slackware's bash package... but
	# hey, we really should clean up things, dropping this is just
	# more risky than most of the cleanups. :-|  --Larhzu
	cat << "EOF" > $PKG/install/doinst.sh
if [ ! -r etc/shells ]; then
	touch etc/shells
	chmod 644 etc/shells
fi
if fgrep "/bin/bash" etc/shells 1> /dev/null 2> /dev/null ; then
	true
else
	echo "/bin/bash" >> etc/shells
fi
EOF

	_chfix
	_chgrp_bin
}
