AC_PREREQ(2.59)
AC_INIT(asrc/rate_asrcrate.c)
AM_INIT_AUTOMAKE(imx-alsa-plugins, 1.0.26)
AC_PREFIX_DEFAULT(/usr)

AC_CONFIG_HEADERS(config.h)
AC_CONFIG_MACRO_DIR([m4])

AC_PROG_CC
AC_PROG_INSTALL
AC_DISABLE_STATIC
AM_PROG_LIBTOOL
AC_HEADER_STDC

CC_NOUNDEFINED

PKG_CHECK_MODULES(ALSA, alsa >= 1.0.11)
AC_CHECK_LIB(asound, snd_pcm_ioplug_create,,
	     AC_ERROR([*** libasound has no external plugin SDK]), -ldl)

test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix=$prefix

dnl ALSA plugin directory
AC_ARG_WITH(plugindir,
    AS_HELP_STRING([--with-plugindir=dir],
	[path where ALSA plugin files are stored]),
    plugindir="$withval", plugindir="")
if test -z "$plugindir"; then
    eval dir="$libdir"
    case "$dir" in
    /*) ;;
    *) dir="$dir"
    esac
    plugindir="$dir/alsa-lib"
fi
AC_DEFINE_UNQUOTED(ALSA_PLUGIN_DIR, "$plugindir", [directory containing ALSA add-on modules])
ALSA_PLUGIN_DIR="$plugindir"
AC_SUBST(ALSA_PLUGIN_DIR)

dnl ALSA data directory
AC_ARG_WITH(alsadatadir,
    AS_HELP_STRING([--with-alsadatadir=dir],
	[path where ALSA data files are stored]),
    alsadatadir="$withval", alsadatadir="")
if test -z "$alsadatadir"; then
    eval dir="$datadir"
    case "$dir" in
    /*) ;;
    *) dir="$dir"
    esac
    alsadatadir="$dir/alsa"
fi
AC_DEFINE_UNQUOTED(ALSA_DATA_DIR, "$alsadatadir", [directory containing ALSA data files])
ALSA_DATA_DIR="$alsadatadir"
AC_SUBST(ALSA_DATA_DIR)

AC_CHECK_HEADERS([linux/mxc_asrc.h], [HAVE_ASRC_HEAD=yes], [HAVE_ASRC_HEAD=no])
if test "x$HAVE_ASRC_HEAD" = "xno"; then
    asrchead=`find /usr/src/ -name mxc_asrc.h | grep "/linux/mxc_asrc.h" | head -n 1 | sed -e 's,/linux/mxc_asrc.h,,'`
    if test "x$asrchead" != "x"; then
        ASRC_CFLAGS=-I$asrchead
    fi
fi
AC_SUBST(ASRC_CFLAGS)

SAVE_PLUGINS_VERSION

AC_DEFUN([CHECK_CODEC_ENABLE],
[
    AC_ARG_ENABLE($1,
        [AS_HELP_STRING([--enable-[$1]], [$2])],
        [use_[$1]=$enableval],
        [use_[$1]="no"])
    if test "$use_[$1]" = "yes"; then
        AM_CONDITIONAL(FSL_USE_[$3], true)
                echo -e "\nEnable [$3] option"
    else
        AM_CONDITIONAL(FSL_USE_[$3], false)
    fi
])

CHECK_CODEC_ENABLE([swpdm], [enable swpdm], [SWPDM])

AC_OUTPUT([
	Makefile
	asrc/Makefile
	swpdm/Makefile
	doc/Makefile
])

dnl Show the build conditions

echo
echo "Plugin directory: $ALSA_PLUGIN_DIR"
echo "ALSA_CFLAGS: $ALSA_CFLAGS"
echo "ALSA_LIBS: $ALSA_LIBS"
