#!/bin/sh
# Script to make a pyao .tce extension from source
# Requires python-2.5.2.tce compiletc.tce and python-2.5.2-devs.tce

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

NAME=pyvorbis
VERSION=1.4
DOWNLOAD=http://ekyo.nerim.net/software/pyogg
SOURCE=$NAME-$VERSION.tar.gz
MD5SUM=b4921e792c0a74f75b9d3057df10ee7c 
TMPDIR=/tmp/"$NAME"21654
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"
mkdir -p "$PKG"/usr/local/lib/python2.5/site-packages/
python config_unix.py
python setup.py build
python setup.py install --root="$PKG"

cd "$PKG"
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"-"$VERSION".tce
}

rm -rf "$TMPDIR" &&
mkdir -p "$PKG" &&
download &&
build_source &&
make_extension &&
echo ""$NAME"-"$VERSION".tce is now in your home directory."