#!/bin/sh
#
#A Bash Script used to  Build a TGZ SlackWare package: opencore-amr
#
#by dragon.z@email.it

PRGNAM=opencore-amr
VERSION=0.1.2
#PKGVERSION=
ARCH=`uname -m` 
BUILD=${BUILD:-1pc}
SLKCFLAGS="-O2 -march=i486 -mtune=$ARCH"
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=$CWD/tmp/pct
fi
# structure where package will be created) 
PKG=$TMP/pkg-$PRGNAM

rm -rf $PKG
mkdir -p $TMP $PKG
cd $TMP 
rm -rf $PRGNAM

tar xzvf $CWD/$PRGNAM-$VERSION.tar.gz || exit 1
cd $TMP/$PRGNAM-$VERSION || exit 1

chown -R root:root .
chmod -R u+w,go+r-w,a-s .

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure || exit 1
make || exit 1

make install DESTDIR=$PKG || exit 1
#doc
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a README doc/* $PKG/usr/doc/$PRGNAM-$VERSION
find $PKG/usr/doc/$PRGNAM-$VERSION -type f -exec chmod 0644 {} \;

#if [ -d $PKG/usr/local/man/man1 ]; then
# ( cd $PKG/usr/local/man/man1
#    find . -type f -exec gzip -9 {} \;
#    for i in `find . -type l` ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
#  )
#fi

mkdir -p $PKG/install
cat << EOF > $PKG/install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in.  You must
# make exactly 11 lines for the formatting to be correct.  It's also
# customary to leave one space after the ':'.

    	    |-----handy-ruler------------------------------------------------------|

opencore-amr: OpenCORE Adaptive Multi Rate(AMR) speech codec library implementation
opencore-amr: 
opencore-amr: This library contains an implementation of the 3GPP TS 26.073 
opencore-amr: specification for he Adaptive Multi Rate (AMR) speech codec and an
opencore-amr: implementation for the 3GPP TS 26.173 specification for the Adaptive
opencore-amr: Multi-Rate - Wideband (AMR-WB)speech decoder. The implementation is 
opencore-amr: derived from the OpenCORE framework, part of the Google Android 
opencore-amr: project.
opencore-amr: This library is Licensed under the Apache License, Version 2.0.
opencore-amr: 
opencore-amr: http://opencore-amr.sourceforge.net/
EOF

if [ -e $CWD/doinst.sh.gz ]; then
  zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
fi

cd $PKG
/sbin/makepkg -l y -c n $TMP/$PRGNAM-$VERSION-$ARCH-$BUILD.tgz
mv -f $TMP/$PRGNAM-$VERSION-$ARCH-$BUILD.tgz $CWD
