#!/bin/bash

if [ -r /usr/share/aclocal/alsa-lib.m4 ]; then
  rm -f /usr/share/aclocal/alsa-lib.m4
fi
if [ -r /usr/local/share/aclocal/alsa-lib.m4 ]; then
  rm -f /usr/local/share/aclocal/alsa-lib.m4
fi
if [ -d ../alsa-lib ]; then
  echo "Building hard links with alsa-lib sources..."
  cd kernel
  pwd
  ln -fv ../../alsa-lib/src/pcm/pcm_misc.c pcm_misc.c
  ln -fv ../../alsa-lib/src/pcm/pcm_plugin_build.c pcm_oss_plugin.c
  cd plugin
  pwd
  ln -fv ../../../alsa-lib/src/pcm/plugin/interleave.c interleave.c
  ln -fv ../../../alsa-lib/src/pcm/plugin/linear.c linear.c
  ln -fv ../../../alsa-lib/src/pcm/plugin/mulaw.c mulaw.c
  ln -fv ../../../alsa-lib/src/pcm/plugin/rate.c rate.c
  ln -fv ../../../alsa-lib/src/pcm/plugin/voices.c voices.c
  cd ../..
fi
aclocal $ACLOCAL_FLAGS
autoconf
if [ $# -eq 0 ]; then
  echo "./configure --with-debug=full --with-isapnp=yes --with-sequencer=yes"
  ./configure --with-debug=full --with-isapnp=yes --with-sequencer=yes || exit 1
else
  echo "./configure $@"
  ./configure $@ || exit 1
fi
make dep
make
