#!/bin/bash
# http://www.breakfastquay.com/rubberband/
# An audio time-stretching and pitch-shifting package
#
# script  : til (rob.til.freedman~AT~gmail.com)
REPO=http://zenwalk.pinguix.com/user-accounts/tilderb/extra/ap/rubberband
set -x -u -e
#
name=rubberband
version=1.5.0
build=${build:-66.1}
arch=${arch:-i686}

cpu=pentium-m
cpu=${cpu:-i686}

pkgname=$name-$version
package=$pkgname-$arch-$build

PKG_SRC="http://www.breakfastquay.com/rubberband/files/$pkgname.tar.bz2
$REPO/build-rubberband.sh"

PKG_DEP="cxxlibs,fftw,flac,gcc,gcc-g++,libogg,libsamplerate,libsndfile,libvorbis,vamp-plugin-sdk"

PKG_URL=http://www.breakfastquay.com/rubberband/
#
#
CWD=`pwd`
TMP=${TMP:-$CWD/tmp}
SRC=$TMP/$pkgname
PKG=$TMP/$package

# prepare build directory
[ -d $SRC ] && rm -fr $SRC
[ -d $PKG ] && rm -fr $PKG

mkdir -p $PKG/{install,usr/{src,doc}/$pkgname}

tar xjf $CWD/$pkgname.tar.bz2 -C $TMP
cd $SRC
./configure --help >$CWD/configure--help

#patch -p1 < $CWD/Makefile.in.patch

CFLAGS="-O2 -march=$arch -mtune=$cpu" \
CXXFLAGS="-O2 -march=$arch -mtune=$cpu" \
  ./configure --prefix=/usr

make || exit 1
make install DESTDIR=$PKG

# docs
cp -a README.* CHANGELOG COPYING $PKG/usr/doc/$pkgname/
echo "$PKG_URL/license.html" >$PKG/usr/doc/$pkgname/license.html

# strip symbols
find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF | cut -f 1 -d : |\
  xargs -r strip --strip-unneeded 2> /dev/null

find $PKG | xargs file | grep "current ar archive" | cut -s -f 1 -d : |\
  xargs -r strip --strip-debug 2> /dev/null

# 
cp -a $CWD/build-rubberband.sh $PKG/usr/src/$pkgname

# Create the slack-desc
#         |----handy-ruler------------------------------------------------------|
cat << EOF > $PKG/install/slack-desc
rubberband: rubberband  (An audio time-stretching and pitch-shifting package)
rubberband:
rubberband: Rubber Band is an audio time-stretching and pitch-shifting library
rubberband: and utility designed for musical applications. 
rubberband: It allows you to change the tempo and pitch of an audio recording 
rubberband: independently of one another.
rubberband:
rubberband: This is the GPL'led version - commercial edition available.
rubberband: http://www.breakfastquay.com/rubberband/license.html
EOF

cd $PKG
fakeroot /sbin/makepkg -l y -c n $CWD/$package.txz

cd $CWD
echo $PKG_DEP >$package.dep
#depfinder $PKG >$package.dep
echo "$PKG_SRC" >$package.src
md5sum $package.txz >$package.md5
