#!/bin/bash
ulimit -s unlimited
shopt -s extglob

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

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

# 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:
# madplay optimises to -O2 by default so we don't need to override it.
# Specifying -march=armv3 causes the build to fail on ARM - it tries to use
# smul instructions which don't exist on armv3.
# Nov 2008: compiling for base of armv4 does not exhibit this problem.
#

# Extract source:
tar xvvf $CWD/$PKGNAM-$VERSION.tar.!(*sign|*asc|*sig)
cd $PKGNAM-$VERSION || exit 1
slackhousekeeping

# Apply patches:
zcat $CWD/madplay-0.15.2b-fix-segfault.patch.gz | patch -p1 --verbose || exit 1

# Refresh to support latest architectures:
slackupdatelibtool

# Configure:
./configure \
   --prefix=/usr \
   --with-alsa \
   --disable-debugging \
   --build=${SLK_ARCH_BUILD} || failconfig

# Add in any optimisations (rather than overriding the sensible defaults with ./configure
# and breaking compilation for ARM)
#sed -i 's/^CFLAGS.*=\(.*\)$/CFLAGS = '"$ARCH_CFLAGS"' \1/' Makefile
#exit 1

# Build:
make $NUMJOBS || make || failmake

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

# Install docs:
mkdir -p $PKG/usr/doc/$PKGNAM-$VERSION
cp -a \
  CHANGES COPYING* COPYRIGHT CREDITS README* TODO VERSION \
  $PKG/usr/doc/madplay-$VERSION

# Slackware policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slack_delete_lafiles # delete usr/lib{,64}/*.la
#slackstriprpaths     # strip rpaths
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown (root:bin), slack644docs
slackdesc       # install slack-desc and doinst.sh
slackmp         # makepkg -l y -c n

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