#!/bin/bash

NAME=cmake
SRCNAME="$NAME"
VER=2.8.3
PKG=/mnt/hda2/"$NAME"/pkg
CONFIGOPTS="--prefix=/usr/local"

if [ ! -f "$SRCNAME"-"$VER".tar.xz ]; then
	echo ""$SRCNAME"-"$VER".tar.xz not found, exiting.."
	exit 1
fi 
[ -d "$PKG" ] && rm -r "$PKG"
mkdir -p "$PKG"
[ -d "$SRCNAME"-"$VER" ] && rm -r "$SRCNAME"-"$VER"
tar xvf "$SRCNAME"-"$VER".tar.xz
cd "$SRCNAME"-"$VER"
./configure "$CONFIGOPTS" 
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
