#!/bin/bash

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

# Record toolchain & other info for the build log:
slackbuildinfo

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

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

# Determine the CFLAGS for the known architectures:
case $ARCH in
   arm)     export SLKCFLAGS="-O2 -march=armv4t"
            export LIBDIRSUFFIX="" ;;
   *)       export SLKCFLAGS="-O2" ;;
esac

# Extract source:
tar xvvf $CWD/$PKGNAM-$VERSION.tar.gz
cd $PKGNAM-$VERSION
slackhousekeeping

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

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

# Build:
make $NUMJOBS || 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
slackmp         # run makepkg -l y -c n

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