#!/bin/bash

# This script assumes that you have downloaded the libmad archive and
# unpacked it:
#
#   http://www.underbit.com/products/mad/
#

set libmad*

[ -z "$1" ] && {
    echo "libmad* directory not found"; exit 1
}
[ ! -z "$2" ] && {
    echo "More than one libmad* directory found:"
    ls -ld libmad*
    exit 1
}

cd $1 || { echo "Can't move to $1 directory"; exit 1; }

./configure || exit 1
make || exit 1

echo ""

cp -v .libs/libmad.a ../libs/linux-libmad.a || {
    echo libmad.a missing; exit 1; }

cp -v mad.h ../libs/ || {
    echo Header file missing; exit 1; }

make clean >/dev/null 2>&1

echo DONE

