#!/bin/bash

# autoconf213.SlackBuild
# by Stuart Winter <mozes@slackware.com>
# July 2014.

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

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

# Detect whether we're building for /patches:
# This function sets the variable 'SLACKPATCHING'
slack_findpkgstore_is_stablerelease

# 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 $PORTCWD/sources/autoconf213.tar.xz
cd autoconf* || exit 1
slackhousekeeping

# Apply debian patches:
tar xvvf $PORTCWD/sources/*debian*
for i in debian/patches/*patch ; do
  auto_apply_patch $i || exit 1
done
auto_apply_patch $PORTCWD/sources/destdir.patch.xz

# Configure:
./configure \
   --prefix=/usr \
   --libdir=/usr/lib${LIBDIRSUFFIX} \
   --infodir=/usr/info \
   --mandir=/usr/man \
   --host=${SLK_ARCH_HOST} \
   --build=${SLK_ARCH_BUILD} || failconfig

# Build:
make $NUMJOBS || make || exit 1

# Install into package:
make install DESTDIR=$PKG || exit 1

# Add the versioned symlinks, as some scripts look for them:
( cd $PKG/usr/bin
  for i in autoconf autoheader autoreconf autoupdate ifnames autoscan; do
     ln -vfs ${i} ${i}2.13
  done )

# 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

# We store this in a versioned directory:
export PKGSTORE="${PKGSTORE/autoconf/autoconf213}"

slackmp         # run makepkg -l y -c n

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