#!/bin/sh
# Script to make a bash .tce extension source
# Requires the compiletc.dsl extension


CFLAGS="-march=i686 -02 -pipe"
CXXFLAGS="-march=i686 -02 -pipe"

NAME=bash
VERSION=3.2
DOWNLOAD=http://ftp.gnu.org/gnu/bash/
SOURCE=$NAME-$VERSION.tar.gz
MD5SUM=00bfa16d58e034e3c2aa27f390390d30
TMPDIR=/tmp/"$NAME"15687
PKG=/$TMPDIR/pkg
LIST=$TMPDIR/$NAME.list
SRCDIR=/tmp
DIALOG=dialog

download() {
cd $SRCDIR
if [ -e "$SOURCE" ]; then
if [ $(md5sum "$SOURCE" | cut -c1-32) != "$MD5SUM" ]; then
rm $SOURCE
fi
fi
if [ ! -e "$SOURCE" ]; then
wget $DOWNLOAD/$SOURCE
fi
if [ $(md5sum "$SOURCE" | cut -c1-32) = "$MD5SUM" ]; then
echo "md5sum passed."
else
echo "Download failed. aborting"
exit 1;
fi
}

build_source() {
tar xzvf $SRCDIR/$SOURCE -C $TMPDIR
cd $TMPDIR/$NAME-$VERSION

touch configure
./configure --prefix=/usr --exec-prefix= --mandir=/usr/man --disable-nls --with-curses --without-bash-malloc
make -j1
make DESTDIR=$PKG install
ln -s bash $PKG/bin/sh
rm -r $PKG/usr/man
strip --strip-unneeded $PKG/bin/bash

}

make_extension() {
cd $PKG
find . -not -type d > $LIST
tar -T $LIST -czvf /home/dsl/$NAME-$VERSION.tce
cd $TMPDIR
}


if [ -e $TMPDIR ]; then
rm -rf $TMPDIR
fi
mkdir -p $PKG &&
download &&
build_source &&
make_extension &&
echo "$NAME-$VERSION.tce is now in your home directory."
