#!/bin/bash
# Script to make a  tcel extension from source
# For Tinycore

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

NAME=mpg123
VERSION=1.7.0

SOURCE="$NAME"-"$VERSION".tar.bz2

PKG="$TMPDIR"/pkg
DEV="$TMPDIR"/dev
LIST="$TMPDIR"/"$NAME".list
LIST1="$TMPDIR"/"$NAME".list1
SRCDIR=/tmp




build_source() {
tar xjvf "$SOURCE"
cd "$NAME"-"$VERSION"
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig

./configure --prefix=/usr/local --with-cpu=i486 --with-optimization=2
	 
make
touch /tmp/mark
make install
cd /
find usr/local -newer /tmp/mark -not -type d > /tmp/list
tar -T /tmp/list -czvf /tmp/"$NAME"-"$VERSION".tcel
tar xzvf /tmp/"$NAME"-"$VERSION".tcel -C "$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
find usr/local -not -type d > /tmp/list
[ -f /tmp/"$NAME"-"$VERSION".tcel ] && rm /tmp/"$NAME"-"$VERSION".tcel
tar -T /tmp/list -czvf /home/tc/"$NAME"-"$VERSION".tcel



#rm -r "#PKG"/usr/local/share
#mv "$PKG"/usr/local/include "$DEV"/usr/local/
#mv "$PKG"/usr/local/lib/{*.a,*.la} "$DEV"/usr/local/lib/
#mv "$PKG"/usr/local/lib/gstreamer-0.10/{*.a,*.la} "$DEV"/usr/local/lib/gstreamer-0.10/
#mv "$PKG"/usr/local/lib/pkgconfig "$DEV"/usr/local/lib/
}




#make_extension() {


#tar -T /tmp/list -czvf /home/tc/"$NAME"-"$VERSION".tcel
#cd "$DEV"
#find . -not -type d > "$LIST1"
#tar -T "$LIST1" -czvf /home/tc/"$NAME"-"$VERSION"-devs.tce

#}

mkdir -p "$PKG" || exit 1
mkdir -p "$DEV"/usr/local/lib/gstreamer-0.10 || exit 1

build_source || exit 1
#make_extension || exit 1
echo ""$NAME"-"$VERSION".tcel is now in your home directory."
