#!/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=tk
VERSION=8.5.5

TMPDIR=/mnt/hda2/tk1-5611351654681584654
PKG="$TMPDIR"/pkg
LIST="$TMPDIR"/"$NAME".list
SRCDIR=/tmp




build_source() {
tar xzvf tk8.5.5-src.tar.gz -C "$TMPDIR"
cd "$TMPDIR"/tk8.5.5/unix
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig
./configure --prefix=/usr/local --enable-gcc --enable-shared --enable-xft
make 
make install MKLINKS_FLAGS="-s" INSTALL_ROOT=$PKG
rm -r "$PKG"/usr/local/man
rm -r "$PKG"/usr/local/lib/tk8.5/demos
rm -r "$PKG"/usr/local/lib/tk8.5/images
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."