#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-gawk
VERSION=3.1.8
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf gawk-$VERSION
tar xjf $CWD/gawk-$VERSION.tar.bz2
cd gawk-$VERSION
chown -R root:root .
./configure \
 --prefix=/usr \
 --mandir=/usr/man \
 --infodir=/usr/info \
 --build=$TARGET
make || exit 1
make install DESTDIR=$PKG
( cd $PKG/usr/bin
  ln -sf gawk-$VERSION gawk
  ln -sf pgawk-$VERSION pgawk
)
mkdir -p $PKG/bin
mv $PKG/usr/bin/gawk* $PKG/bin
mv $PKG/usr/bin/awk $PKG/bin
( cd $PKG/usr/bin
 ln -sf ../../bin/awk .
 ln -sf ../../bin/gawk .
 ln -sf ../../bin/gawk-$VERSION .
)
chown -R root:bin $PKG/bin $PKG/usr/bin
( cd $PKG/usr/info
 rm dir
 gzip -9 *
)
( 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
)
( cd $PKG/usr/man/man1
 rm -f pgawk.1
 gzip -9 *
 ln -sf gawk.1.gz awk.1.gz
 ln -sf gawk.1.gz pgawk.1.gz
)
mkdir -p $PKG/usr/doc/gawk-$VERSION
cp -a ABOUT-NLS AUTHORS COPYING FUTURES INSTALL LIMITATIONS NEWS POSIX.STD PROBLEMS README README_d $PKG/usr/doc/gawk-$VERSION
find $PKG/usr/doc/gawk-$VERSION -type d -exec chmod 755 {} \;
find $PKG/usr/doc/gawk-$VERSION -type f -exec chmod 644 {} \;
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/gawk-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/gawk.build.log
