#!/bin/bash

# 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:
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:
# 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.
#

# 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

# Configure:
./configure \
  --prefix=/usr \
  --with-alsa \
  --disable-debugging \
  --build=$ARCH-slackware-linux-gnueabi || 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 || 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
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
