#!/bin/bash
# Script to make a tcl .tcel extension from source

export CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe"
set -e

NAME=tcl
VERSION=8.5.5
SOURCE="$NAME"-"$VERSION".tar.gz
TMPDIR=/mnt/hda2/tcl-561874684654
PKG="$TMPDIR"/pkg
LIST="$TMPDIR"/"$NAME".list
SRCDIR=/tmp




build_source() {
tar xzvf tcl8.5.5-src.tar.gz -C "$TMPDIR"
cd "$TMPDIR"/tcl8.5.5/unix
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig
./configure --prefix=/usr/local
make 
make install DESTDIR="$PKG"
rm -r "$PKG"/usr/local/man
find . | xargs file | grep "executable" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip -g 2> /dev/null
}





make_extension() {
cd "$PKG"
find . -not -type d > "$LIST"
tar -T "$LIST" -czvf /home/tc/"$NAME".tcel
}

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