#!/bin/bash

# uucp.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <stuart@armedslack.org>
# 14-Jul-2004

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$SLACKSOURCE/n/uucp
export PORTCWD=$PWD

# Temporary build locations:
export TMPBUILD=$TMP/build-$PACKAGE
export PKG=$TMP/package-$PACKAGE
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

# Determine the CFLAGS for the known architectures:
case $PORTARCH in
   armv3)   export ARCH_CFLAGS="-O2 -march=armv3 -mtune=xscale" ;;
   powerpc) export ARCH_CFLAGS="-O2" ;;
   sparc)   export ARCH_CFLAGS="-O2" ;;
   *)       export ARCH_CFLAGS="-O2" ;;
esac

# Extract source:
tar zxvf $CWD/$PACKAGE-$VERSION.tar.gz
cd $PACKAGE-$VERSION
slackhousekeeping


# Extract source:
tar zxvvf $CWD/$PACKAGE-$VERSION.tar.gz
cd $PACKAGE-$VERSION

# Apply patches:
zcat $CWD/policy.h.diff.gz | patch -p1 --verbose

# Configure:
CFLAGS="$ARCH_CFLAGS" \
./configure \
  --prefix=/usr \
  --with-oldconfigdir=/etc/uucp/oldconfig \
  --with-newconfigdir=/etc/uucp || failconfig

# Build:
make || failmake

# Start fakeroot server:
start_fakeroot

# Explode the package framework:
( cd $PKG && explodepkg $CWD/_uucp.tar.gz )

# Install:
make install DESTDIR=$PKG || failinstall
( cd $PKG && slackchown )

# Setuid uucp binaries may only be run by members of the uucp group:
( cd $PKG/usr/bin
  chgrp uucp cu uucp uuname uustat uux
  chmod 4554 cu uucp uuname uustat uux
  cd ../sbin
  chgrp uucp uucico uuxqt
  chmod 4554 uucico uuxqt )

# Slackware policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slack644docs    # set docs perms
slackdesc       # install slack-desc and doinst.sh

# Build the package:
if [ $PORTARCH = armv3 ]; then
   slackmp      # run makepkg
 else
   makepkg -l y -c n $PKGSTORE/$PKGSERIES/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz
fi

# Perform any final checks on the package:
cd $PKG
slackhlinks     # search for any hard links
