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


export CFLAGS="-march=i686 -O2 -pipe"
export CXXFLAGS="-march=i686 -O2 -pipe"

set -e

NAME=audacious
VERSION=1.5.1

SOURCE="$NAME"-"$VERSION".tgz
TMPDIR=/usr/local/"$NAME"21654
PKG="$TMPDIR"/pkg
DEV="$TMPDIR"/dev
LIST="$TMPDIR"/"$NAME".list

SRCDIR=/tmp





build_source() {
	tar xzvf "$SOURCE" -C "$TMPDIR"
	cd "$TMPDIR"/"$NAME"-"$VERSION"
	export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
	./configure --prefix=/usr/local --disable-nls
		
	make
	make install DESTDIR="$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
	# At this point manually divide package and dev files.
}






if [ -e "$TMPDIR" ]; then
  rm -rf "$TMPDIR" 
fi
mkdir -p "$PKG" || exit 1
mkdir -p "$DEV"/usr/local/lib
build_source || exit 1

echo "Done."