#!/bin/sh
# Set initial variables:

. /etc/pkghelpers

PKGNAM=parted
VERSION=${VERSION:-1.8.7}
BUILD=${BUILD:-1}

pkghelpers_env

rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf ${PKGNAM}-${VERSION}
tar xjvf $CWD/${PKGNAM}-$VERSION.tar.bz2 || exit 1
cd ${PKGNAM}-$VERSION

zcat $CWD/parted.configure.diff.gz | patch -p0 --verbose --backup --suffix=.orig || exit 1

# Make sure ownerships and permissions are sane:
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 {} \;

CFLAGS=$SLKCFLAGS \
./configure \
  --prefix=/usr \
	--libdir=/usr/lib$LIBSUFFIX \
  --mandir=/usr/man \
  --infodir=/usr/info \
  --enable-shared=yes \
  --enable-static=no \
  --with-readline \
  --build=$ARCH-$DISTRO-linux

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

# Add a documentation directory:
mkdir -p ${PKG}/usr/doc/${PKGNAM}-$VERSION
cp -a \
  AUTHORS BUGS COPYING NEWS README THANKS TODO \
  doc/{API,FAT} doc/USER.jp \
  $PKG/usr/doc/parted-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
pkghelpers_fixup
pkghelpers_makepkg