#!/bin/bash

# autofs.SlackBuild
# Heavily based on the original Slackware build script,
# Modified by Stuart Winter <mozes@slackware.com> for the Slackware porting Project.
# 08-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

# Extract source:
tar xvvf $CWD/$PKGNAM-$VERSION.tar.?z*
cd $PKGNAM-$VERSION || exit 1
slackhousekeeping

zcat $CWD/autofs-5.0.5-fix-libxml2-workaround-configure.patch.gz | patch -p1 || exit 1

# Create package framework:
mkdir -pm755 $PKG/usr/{sbin,doc/$PKGNAM-$VERSION,lib/autofs,man/man{5,8}}

# Install docs:
cp -fav COPYING COPYRIGHT NEWS README README.options TODO \
        multiserver_mount.patch samples $PKG/usr/doc/$PKGNAM-$VERSION

# Configure:
CFLAGS="$SLKCFLAGS" \
CPPFLAGS="$SLKCFLAGS" \
./configure \
   --prefix=/usr \
   --mandir=/usr/man \
   --with-openldap \
   --without-sasl \
   --build=$ARCH-slackware-linux-gnueabi || failconfig

# Build:
make $NUMJOBS || failmake

# Install:
make install DESTDIR=$PKG || exit 1
mv $PKG/etc/init.d $PKG/etc/rc.d
mv $PKG/etc/rc.d/autofs $PKG/etc/rc.d/rc.autofs.new
chmod 644 $PKG/etc/rc.d/rc.autofs.new

# Prep the config files:
( cd $PKG/etc
  for file in auto.master auto.misc autofs_ldap_auth.conf default/autofs ; do
    mv $file ${file}.new
  done
)

# Process docs:
mkdir -p $PKG/usr/doc/autofs-$VERSION
cp -a \
  COPYING* COPYRIGHT CREDITS INSTALL README* \
  samples \
  $PKG/usr/doc/autofs-$VERSION
( cd $PKG/usr/doc/autofs-$VERSION
  find . \( -name Makefile -o -name *.in \) -exec rm -f {} \;
  find . -type d -exec chmod 755 {} \;
  find . -type f -exec chmod 644 {} \;
)
changelogliposuction CHANGELOG $PKGNAM $VERSION

# If necessary, start the fakeroot server so we can set file/dir ownerships:
start_fakeroot

# Apply generic Slackware packaging policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown, slack644docs
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
