#!/bin/sh
# Build diffutils for Slackware.
PKGNAM=diffutils
VERSION=2.8.1
BUILD=${BUILD:-3}

. /etc/pkghelpers
pkghelpers_env

rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf diffutils-$VERSION
tar xzvf $CWD/diffutils-$VERSION.tar.gz
cd diffutils-$VERSION

chown -R root:root .
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;

zcat $CWD/diffutils-sdiff-no-waitpid.patch.gz | patch -p1 || exit 1
# Prevent ruining sdiff.1 by touching it so it won't "regenerate":
touch man/sdiff.1

CFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --program-prefix="" \
  --program-suffix="" \
  $ARCH-$DISTRO-linux

make -j12 || exit 1
make install DESTDIR=$PKG || exit 1

mkdir -p $PKG/usr/doc/diffutils-$VERSION
cp -a \
  ABOUT-NLS AUTHORS COPYING INSTALLME NEWS README THANKS \
  $PKG/usr/doc/diffutils-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh

cd $PKG
pkghelpers_fixup
pkghelpers_makepkg