#!/bin/bash
# Heavily based on the Slackware 12.1 SlackBuild
# By kobaiachi
# http://libnet.sourceforge.net

CWD=`pwd`

if ["$TMP" = ""]; then
TMP=/tmp
fi

PKG=$TMP/libnet-1.1.2.1
NAME=libnet
VERSION=1.1.2.1
ARCH=i486
BUILD=1sv

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

echo "| Start SlackBuild $NAME-$VERSION |"
cd $TMP
tar xzvf $CWD/$NAME.tar.gz
cd $NAME
CFLAGS="-O2 -march=i486 -mtune=i686" \
./configure --prefix=/usr \
--program-prefix= \
--program-suffix= \
--build=i486-slackware-linux
make
make install DESTDIR=$PKG
mkdir -p $PKG/usr/bin
cp libnet-config $PKG/usr/bin
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -dP doc/* $PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/usr/doc/$NAME-$VERSION/html
cp -a  doc/html/* $PKG/usr/doc/$NAME-$VERSION/html
mkdir -p $PKG/usr/man/man3
cp -a doc/man/man3/* $PKG/usr/man/man3
strip -g $PKG/usr/lib/*.a
gzip -9 $PKG/usr/man/*/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION
cd $PKG
chown -R root:root .
requiredbuilder -v -y -s $CWD $PKG
makepkg  -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
rm -rf $TMP/$NAME
rm -fr $PKG
fi

