#!/bin/bash

# sendmail-cf.SlackBuild
# by Stuart Winter <mozes@slackware.com> for the Slackware porting Project.
# Almost entirely based on the original Slackware build script by Patrick Volkerding.
# 19-Jun-2004

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

# Paths to skeleton port's source & real Slackware source tree:
slackset_var_cwds

# The 'sendmail-cf' package uses the "sendmail" package source tree, so
# switch it:
CWD="${CWD/sendmail-cf/sendmail}"
echo "Master source: $CWD"

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

# Path to sendmail source (built by sendmail.SlackBuild)
SMS=$TMPBUILD/../build-sendmail/

( cd $SMS/sendmail-$VERSION ; find . -name "*~" -print -exec rm {} \; )
cd $PKG
mkdir -p usr/share/sendmail/cf
cd usr/share/sendmail/cf
cp -a $SMS/sendmail-$VERSION/cf/README .
cp -a $TMPBUILD/package-sendmail/usr/share/sendmail/README.linux .
for dir in cf domain feature hack m4 mailer ostype sh siteconfig ; do
  cp -a $SMS/sendmail-$VERSION/cf/$dir .
done

# Replace the sendmail Build script with a simple (working) one:
cp -a $PKG/usr/share/sendmail/cf/cf/Build $PKG/usr/share/sendmail/cf/cf/Build.orig
zcat $CWD/Build.gz > $PKG/usr/share/sendmail/cf/cf/Build
chown -R root:root *

# Install package description:
mkdir -p $PKG/install
install -m644 $CWD/slack-desc.sendmail-cf $PKG/install/slack-desc

# Slackware policies:
cd $PKG
#slackstriprpaths     # strip rpaths
slack_delete_lafiles # delete usr/lib{,64}/*.la
slackgzpages -i # compress man & info pages and delete usr/info/dir
slack644docs    # ensure /usr/doc has the correct ownerships & permissions

# Otherwise it's set to the name of the package in /extra:
export PKGSTORE="${PKGSTORE/sendmail-cf/sendmail}"
slackmp         # run makepkg -l y -c n

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