#!/bin/bash

cd $BLDDIR
rm -rf bash-$BASH_VER
tar -xf $SRCDIR/bash-$BASH_VER.tar.gz
cd bash-$BASH_VER
if [ $BASH_PATCHLEVEL -gt 000 ]; then
  for p in $(seq -w 001 $BASH_PATCHLEVEL); do
    patch -p0 < $SRCDIR/patches/bash-$BASH_VER/bash${BASH_VER/.}-$p
  done
fi

cat > config.cache << "EOF"
ac_cv_func_mmap_fixed_mapped=yes
ac_cv_func_strcoll_works=yes
ac_cv_func_working_mktime=yes
bash_cv_func_sigsetjmp=present
bash_cv_getcwd_malloc=yes
bash_cv_job_control_missing=present
bash_cv_printf_a_format=yes
bash_cv_sys_named_pipes=present
bash_cv_ulimit_maxfds=yes
bash_cv_under_sys_siglist=yes
bash_cv_unusable_rtsigs=no
gt_cv_int_divbyzero_sigfpe=yes
EOF

./configure --prefix=/tools \
    --build=${CHFS_HOST} --host=${CHFS_TARGET} \
    --without-bash-malloc --cache-file=config.cache
make
make install
ln -s bash /tools/bin/sh

cd $ROOT
