#!/bin/bash

# Cross-compilation to ARM.  Adjust XBIN below according to your
# cross-compiler location.
#
# This script assumes that you have downloaded the libmad archive and
# unpacked it:
#
#   http://www.underbit.com/products/mad/
#

XBIN=/usr/local/arm/2.95.3/bin/
XGCC=$XBIN/arm-linux-gcc
XCPP=$XBIN/cpp

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 --host=arm CC=$XGCC CPP=$XCPP || exit 1
make || exit 1

echo ""

cp -v .libs/libmad.a ../libs/linux-arm-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

