#!/bin/sh
# http://www.atheme.org/Projects/Libmowgli
# script by: til <rob D0T til D0T freedman AT googlemail D0T com>
REPO=http://zenwalk.pinguix.com/user-accounts/tilderb
#
set -u -e -x

#libmowgli
version=0.7.1
build=66.1
arch=i486
tune=i686

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

PKG_SRC="$REPO/extra/l/build-libmowgli.sh
http://mirror.billymays.us/libmowgli/libmowgli-$version.tgz"

CWD=`pwd`
TMP=${TMP:-$CWD/tmp}
PKG=$TMP/$package
SRC=$TMP/$pkgname

[ -d $SRC ] && rm -fr $SRC
[ -d $PKG ] && rm -fr $PKG

### every package should have it
mkdir -p $PKG/{install,usr/{src,doc}/$pkgname}
#
mkdir $SRC
tar xf $CWD/$pkgname.tgz --strip-components=1 -C $SRC
cd $SRC

cd $SRC
./configure --help >$CWD/configure-help

CFLAGS="-O2 -march=$arch -mtune=$tune" \
CXXFLAGS="-O2 -march=$arch -mtune=$tune" \
./configure \
   --prefix=/usr 
#  --disable-static || exit 1

make || exit 1
make install DESTDIR=$PKG

# helperline
(cd $PKG;find . -printf "%M %u:%g %p %l\n" >$CWD/make.installed)

cp -a AUTHORS COPYING README $PKG/usr/doc/$pkgname
cd $PKG

# strip symbols
find . | xargs file | grep "executable\|shared object" | grep ELF |\
	cut -f 1 -d :| xargs -r strip --strip-unneeded

find . | xargs file | grep "current ar archive" |\
	cut -f 1 -d : | xargs -r strip -g

#        |-----handy-ruler------------------------------------------------------|
cat << EOF > install/slack-desc
libmowgli: libmowgli (is a class library)
libmowgli:
libmowgli: libmowgli is a class library containing performance and usability
libmowgli: oriented extensions to C.
libmowgli:
libmowgli: It is designed to work in conjunction with GTK+'s GLib, but also
libmowgli: functions well as a standalone library.
EOF

cp $CWD/build-libmowgli.sh usr/src/$pkgname
fakeroot /sbin/makepkg -l y -c n $CWD/$package.txz

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