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


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

NAME=valgrind
VERSION=3.4.1

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

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




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

./configure --prefix=/usr/local --disable-nls
make
make DESTDIR="$PKG" install
rm -r "$PKG"/usr/local/share
rm -r "$PKG"/usr/local/man
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".tce

}

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

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