#!/bin/sh
# Set initial variables:
PKGNAM=tcsh
VERSION=6.15.00
BUILD=${BUILD:-1}

. /etc/pkghelpers
pkghelpers_env

rm -rf $PKG
mkdir -p $PKG
cd $TMP
rm -rf tcsh-$VERSION
tar xjvf $CWD/tcsh-$VERSION.tar.bz2 || exit 1
cd tcsh-$VERSION

# The LS_COLORS variable shared by tcsh has new options in recent
# versions of coreutils that cause tcsh to exit, so disable the
# built-in color ls:
zcat $CWD/tcsh.nobuiltincolorls.diff.gz | patch -p1 --verbose || exit 1

chown -R root:root .
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=  \
  $ARCH-$DISTRO-linux
make -j12 || exit 1
mkdir -p $PKG/etc
mkdir -p $PKG/bin
cat tcsh > $PKG/bin/tcsh
chmod 755 $PKG/bin/tcsh
mkdir -p $PKG/usr/man/man1
cat tcsh.man | gzip -9c > $PKG/usr/man/man1/tcsh.1.gz
echo '.so man1/tcsh.1' | gzip -9c > $PKG/usr/man/man1/csh.1.gz
mkdir -p $PKG/usr/doc/tcsh-$VERSION
cp -a \
  BUGS FAQ Fixes NewThings Ported README README.imake WishList Y2K \
  $PKG/usr/doc/tcsh-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh

# Build the package:
cd $PKG
pkghelpers_fixup
pkghelpers_makepkg