#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi

VERSION=1.5.20
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
PKG=$TMP/package-libtool
rm -rf $PKG
mkdir -p $PKG
cd $TMP
rm -rf libtool-$VERSION
tar xjvf $CWD/libtool-$VERSION.tar.bz2
cd libtool-$VERSION
chown -R root.root .
CC=gcc \
LTCC=gcc \
CFLAGS=-O2 \
./configure \
  --prefix=/usr \
  $ARCH-slackware-linux
make
make install DESTDIR=$PKG
chown -R root.bin $PKG/usr/bin
( 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
)
rm -f $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*
mkdir -p $PKG/usr/doc/libtool-$VERSION
cp -a \
  AUTHORS COPYING INSTALL NEWS README THANKS TODO \
  $PKG/usr/doc/libtool-$VERSION
mkdir $PKG/install
cp $CWD/doinst.sh $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
makepkg -l y -c n $TMP/libtool-$VERSION-$ARCH-$BUILD.tgz

