#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://festvox.org
# Packager Andrea Sciucca Gohanz ( gohanz at infinito.it)
# http://www.slacky.it



CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/usr/share
fi
PKG=/tmp/package-speech_tools
NAME=speech_tools
VERSION=1.2.96-beta
ARCH=${ARCH:-i686}
BUILD=2as

SOURCE=http://festvox.org/packed/festival/latest/$NAME-$VERSION.tar.gz

if [ ! -e $NAME-$VERSION.tar.gz ]; then
wget -c $SOURCE
fi



if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
 mkdir -p $PKG
fi

cd $TMP
tar xvzf $CWD/$NAME-$VERSION.tar.gz

echo -e "\E[0;32m+-------------------------------------------+\E[0;0m"
echo -e "\E[0;32m| Start SlackBuild $NAME-$VERSION |\E[0;0m"
echo -e "\E[0;32m+-------------------------------------------+\E[0;0m"

cd $NAME

find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;

./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
--program-prefix= \
--program-suffix= \


# The shared Lib cause a compilation problem on 12.0 removed!
#(  cd config 
#sed -i "s|# SHARED=1|SHARED=1|g" config
#)

make

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
 INSTALL README  \
 $PKG/usr/doc/$NAME-$VERSION


mkdir -p $PKG/usr/bin
find     $TMP/$NAME/bin/ -perm -755    -exec cp  {} $PKG/usr/bin \;

mkdir -p $PKG/usr/share/$NAME/config
mkdir -p $PKG/usr/share/$NAME/lib/siod
mkdir -p $PKG/usr/lib

cp -a      $TMP/$NAME/lib/lib*    $PKG/usr/lib
cp -a      $TMP/$NAME/lib/lib*    $PKG/usr/share/$NAME/lib
cp -a      $TMP/$NAME/lib/siod/*  $PKG/usr/share/$NAME/lib/siod
cp -a  -r  $TMP/$NAME/config/*    $PKG/usr/share/$NAME/config
cp -a  -r  $TMP/$NAME/base_class  $PKG/usr/share/$NAME
cp -a  -r  $TMP/$NAME/include     $PKG/usr/share/$NAME

mkdir -p $PKG/usr/share/$NAME/example_data
cp -a    $TMP/$NAME/lib/example_data/*   $PKG/usr/share/$NAME/example_data

( cd $PKG
find -iname 'Makefile'            -exec rm -f {} \;
find -iname 'config.in'           -exec rm -f {} \;
)

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null 
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs strip -g 2> /dev/null
)

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild

cd $PKG
chown -R root:root .
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-1.2.96_beta-$ARCH-$BUILD.tgz
