#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT([xbmc], [11.0], [http://trac.xbmc.org])
AC_CONFIG_HEADERS([xbmc/config.h])
AH_TOP([#pragma once])
m4_include([m4/ax_python_devel.m4])

AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign])
AC_CANONICAL_HOST

tolower(){
  echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
}

# check for library basenames
AC_DEFUN([XB_FIND_SONAME],
[
  if [[ "$host_vendor" != "apple" ]]; then
    AC_MSG_CHECKING([for lib$2 soname])
    $1_SONAME=$( $CC -print-file-name=lib$2.so | \
      while read output; do objdump -p $output | \
        grep "SONAME" | \
        sed -e 's/  *SONAME  *//'; done 2> /dev/null )
  else
    AC_MSG_CHECKING([for lib$2 dylib])
    gcc_lib_path=[`$CC -print-search-dirs 2>/dev/null | fgrep libraries: | sed 's/[^=]*=\(.*\)/\1/' | sed 's/:/ /g'`]
    env_lib_path=[`echo $LDFLAGS | sed 's/-L[ ]*//g'`]
    if test "$cross_compiling" = yes; then
      host_lib_path=""
    else
      host_lib_path="/usr/lib /usr/local/lib"
    fi
    for path in $gcc_lib_path $env_lib_path $host_lib_path; do
      lib=[`ls -- $path/lib$2.dylib 2>/dev/null`]
      if test x$lib != x; then
        # we want the path/name that is embedded in the dylib 
        $1_SONAME=[`otool -L $lib | grep -v lib$2.dylib | grep lib$2 | awk '{V=1; print $V}'`]
        $1_SONAME=[`basename $$1_SONAME`]
      fi
    done
  fi
  if [[ -z "$$1_SONAME" ]]; then
    AC_MSG_RESULT([no])
    if test -z "$3" || test "x${$3}" = "xyes"; then
      AC_MSG_ERROR([Unable to determine soname of lib$2 library])
    else
      AC_MSG_WARN([Unable to determine soname of lib$2 library])
      $3=no
      AC_MSG_WARN([lib$2 support disabled])
    fi
  else
    AC_MSG_RESULT([$$1_SONAME])
    AC_SUBST($1_SONAME)
  fi
])

# General message strings
configure_debug="ERROR: this is a configure debug statement"
missing_library="Could not find a required library. Please see the README for your platform."
missing_headers="Could not find some required headers. Please see the README for your platform."
missing_program="Could not find a required program. Please see the README for your platform."
xrandr_not_found="== Could not find libXRandR. SDL will be used for resolution support. =="
xrandr_disabled="== XRandR support disabled. SDL will be used for resolution support. =="
goom_enabled="== GOOM enabled. =="
goom_disabled="== GOOM disabled. =="
pulse_not_found="== Could not find libpulse. PulseAudio support disabled. =="
pulse_disabled="== PulseAudio support manually disabled. =="
dvdcss_enabled="== DVDCSS support enabled. =="
dvdcss_disabled="== DVDCSS support disabled. =="
hal_not_found="== Could not find hal. HAL support disabled. =="
halstorage_not_found="== Could not find hal-storage. HAL support disabled. =="
hal_disabled="== HAL support disabled. =="
avahi_not_found="== Could not find libavahi-common or libavahi-client. Avahi support disabled. =="
avahi_disabled="== Avahi support disabled. =="
vdpau_not_found="== Could not find libvdpau. VDPAU support disabled. =="
vdpau_disabled="== VDPAU support manually disabled. =="
vaapi_not_found="== Could not find libva. VAAPI support disabled. =="
vaapi_disabled="== VAAPI support manually disabled. =="
crystalhd_not_found="== Could not find libcrystalhd. CrystalHD support disabled. =="
crystalhd_disabled="== CrystalHD support manually disabled. =="
vdadecoder_enabled="== VDADecoder support enabled. =="
vdadecoder_disabled="== VDADecoder support manually disabled. =="
vtbdecoder_enabled="== VTBDecoder support enabled. =="
vtbdecoder_disabled="== VTBDecoder support manually disabled. =="
openmax_disabled="== OpenMax support manually disabled. =="
openmax_not_found="== Could not find libnvomx. OpenMax support disabled. =="
ssh_not_found="== Could not find libssh. SSH FTP VFS support disabled. =="
librtmp_not_found="== Could not find libRTMP. RTMP support disabled. =="
librtmp_disabled="== RTMP support disabled. =="
libnfs_not_found="== Could not find libnfs. NFS support disabled. =="
libnfs_disabled="== NFS support disabled. =="


# External library message strings
external_libraries_enabled="== Use of all supported external libraries enabled. =="
external_libraries_disabled="== Use of all supported external libraries disabled. =="
external_ffmpeg_enabled="== Use of external ffmpeg enabled. =="
external_ffmpeg_disabled="== Use of external ffmpeg disabled. =="
ffmpeg_vdpau_not_supported="== External ffmpeg doesn't support VDPAU. VDPAU support disabled. =="
dashes="------------------------"
final_message="\n  XBMC Configuration:"
final_message="\n$dashes$final_message\n$dashes"


AC_ARG_ENABLE([debug],
  [AS_HELP_STRING([--enable-debug],
  [enable debugging information (default is yes)])],
  [use_debug=$enableval],
  [use_debug=yes])

AC_ARG_WITH([arch],
  [AS_HELP_STRING([--with-arch],
  [build with given arch passing to internal ffmpeg (default is no, needed for crosscompiling)])],
  [use_arch=$withval],
  [use_arch=no])

AC_ARG_WITH([cpu],
  [AS_HELP_STRING([--with-cpu],
  [build with given cpu passing to ffmpeg (default is no)])],
  [use_cpu=$withval],
  [use_cpu=no])

AC_ARG_ENABLE([optimizations],
  [AS_HELP_STRING([--enable-optimizations],
  [enable optimization (default is yes)])],
  [use_optimizations=$enableval],
  [use_optimizations=yes])

AC_ARG_ENABLE([gl],
  [AS_HELP_STRING([--enable-gl],
  [enable OpenGL rendering (default is yes)])],
  [use_gl=$enableval],
  [use_gl=yes])

AC_ARG_ENABLE([gles],
  [AS_HELP_STRING([--enable-gles],
  [enable OpenGLES rendering (default is no)])],
  [use_gles=$enableval],
  [use_gles=no])

AC_ARG_ENABLE([vdpau],
  [AS_HELP_STRING([--enable-vdpau],
  [enable VDPAU decoding (default is auto)])],
  [use_vdpau=$enableval],
  [use_vdpau=auto])

AC_ARG_ENABLE([vaapi],
  [AS_HELP_STRING([--enable-vaapi],
  [enable VAAPI decoding (default is auto)])],
  [use_vaapi=$enableval],
  [use_vaapi=auto])

AC_ARG_ENABLE([crystalhd],
  [AS_HELP_STRING([--enable-crystalhd],
  [enable CrystalHD decoding (default is auto)])],
  [use_crystalhd=$enableval],
  [use_crystalhd=auto])

AC_ARG_ENABLE([vdadecoder],
  [AS_HELP_STRING([--enable-vdadecoder],
  [enable VDADecoder decoding (default is auto)])],
  [use_vdadecoder=$enableval],
  [use_vdadecoder=auto])

AC_ARG_ENABLE([vtbdecoder],
  [AS_HELP_STRING([--enable-vtbdecoder],
  [enable VTBDecoder decoding (default is auto)])],
  [use_vtbdecoder=$enableval],
  [use_vtbdecoder=auto])

AC_ARG_ENABLE([openmax],
  [AS_HELP_STRING([--enable-openmax],
  [enable OpenMax decoding (default is auto, requires OpenGLES)])],
  [use_openmax=$enableval],
  [use_openmax=auto])

AC_ARG_ENABLE([tegra],
  [AS_HELP_STRING([--enable-tegra],
  [enable Tegra2 arm (default is no)])],
  [use_tegra=$enableval],
  [use_tegra=no])

AC_ARG_ENABLE([profiling],
  [AS_HELP_STRING([--enable-profiling],
  [enable gprof profiling (default is no)])],
  [use_profiling=$enableval],
  [use_profiling=no])

AC_ARG_ENABLE([joystick],
  [AS_HELP_STRING([--enable-joystick],
  [enable SDL joystick support (default is yes)])],
  [use_joystick=$enableval],
  [use_joystick=yes])

AC_ARG_ENABLE([xrandr],
  [AS_HELP_STRING([--enable-xrandr],
  [enable XRandR support (default is yes)])],
  [use_xrandr=$enableval],
  [use_xrandr=yes])

AC_ARG_ENABLE([goom],
  [AS_HELP_STRING([--enable-goom],
  [enable GOOM visualisation (default is no)])],
  [use_goom=$enableval],
  [use_goom=no])

AC_ARG_ENABLE([ccache],
  [AS_HELP_STRING([--enable-ccache],
  [enable building with ccache feature (default is auto)])],
  [use_ccache=$enableval],
  [use_ccache=auto])

AC_ARG_ENABLE([pulse],
  [AS_HELP_STRING([--enable-pulse],
  [enable PulseAudio support (default is auto)])],
  [use_pulse=$enableval],
  [use_pulse=auto])

AC_ARG_ENABLE([rtmp],
  [AS_HELP_STRING([--enable-rtmp],
  [enable RTMP support via librtmp (default is auto)])],
  [use_librtmp=$enableval],
  [use_librtmp=auto])

AC_ARG_ENABLE([nfs],
  [AS_HELP_STRING([--enable-nfs],
  [enable NFS support via libnfs (default is auto)])],
  [use_libnfs=$enableval],
  [use_libnfs=auto])


AC_ARG_ENABLE([ffmpeg_libvorbis],
  [AS_HELP_STRING([--enable-ffmpeg-libvorbis],
  [enable FFmpeg vorbis encoding (default is no)])],
  [use_ffmpeg_libvorbis=$enableval],
  [use_ffmpeg_libvorbis=no])

AC_ARG_ENABLE([dvdcss],
  [AS_HELP_STRING([--enable-dvdcss],
  [enable DVDCSS support (default is yes)])],
  [use_dvdcss=$enableval],
  [use_dvdcss=yes])

AC_ARG_ENABLE([mid],
  [AS_HELP_STRING([--enable-mid],
  [enable MID support (default is no)])],
  [use_mid=$enableval],
  [use_mid=no])

AC_ARG_ENABLE([hal],
  [AS_HELP_STRING([--disable-hal],
  [disable HAL support (default is enabled if hal and hal-storage is found)])],
  [use_hal=$enableval],
  [use_hal=yes])

AC_ARG_ENABLE([avahi],
  [AS_HELP_STRING([--disable-avahi],
  [disable Avahi support (default is enabled if libavahi-common and libavahi-client is found)])],
  [use_avahi=$enableval],
  [use_avahi=yes])

AC_ARG_ENABLE([non-free],
  [AS_HELP_STRING([--disable-non-free],
  [disable componentents with non-compliant licenses])],
  [use_nonfree=$enableval],
  [use_nonfree=yes])

AC_ARG_ENABLE([asap-codec],
  [AS_HELP_STRING([--enable-asap-codec],
  [enable ASAP ADPCM support])],
  [use_asap=$enableval],
  [use_asap=no])

AC_ARG_ENABLE([webserver],
  [AS_HELP_STRING([--disable-webserver],
  [disable webserver])],
  [use_webserver=$enableval],
  [use_webserver=yes])

AC_ARG_ENABLE([optical-drive],
  [AS_HELP_STRING([--disable-optical-drive],
  [disable optical drive])],
  [use_optical_drive=$enableval],
  [use_optical_drive=yes])

AC_ARG_ENABLE([libbluray],
  [AS_HELP_STRING([--enable-libbluray],
  [enable libbluray support])],
  [use_libbluray=$enableval],
  [use_libbluray=auto])

AC_ARG_ENABLE([texturepacker],
  [AS_HELP_STRING([--enable-texturepacker],
  [enable texturepacker support (default is yes)])],
  [use_texturepacker=$enableval],
  [use_texturepacker=auto])

AC_ARG_WITH([lirc-device],
  [AS_HELP_STRING([--with-lirc-device=file],
  [specify the default LIRC device (default is /dev/lircd)])],
  [lirc_device=$withval],
  [lirc_device=/dev/lircd])
AC_DEFINE_UNQUOTED([LIRC_DEVICE], ["$lirc_device"], [Default LIRC device])

### External libraries options
AC_ARG_ENABLE([external-libraries],
  [AS_HELP_STRING([--enable-external-libraries],
  [enable use of all supported external libraries (default is no) 'Linux only'])],
  [use_external_libraries=$enableval],
  [use_external_libraries=no])

AC_ARG_ENABLE([external-ffmpeg],
  [AS_HELP_STRING([--enable-external-ffmpeg],
  [enable use of external ffmpeg libraries (default is no) 'Linux only'])],
  [use_external_ffmpeg=$enableval],
  [use_external_ffmpeg=$use_external_libraries])

### End of external library options

if test "x$host_vendor" != "xapple"; then
  DEFAULT_COMPILE_FLAGS="-fPIC -DPIC -D_REENTRANT"
  DEFAULT_COMPILE_FLAGS="$DEFAULT_COMPILE_FLAGS -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
fi

# Checks for programs.
PASSED_CXXFLAGS=$CXXFLAGS # Hack to override autoconf default values
AC_PROG_CXX
CXXFLAGS="$PASSED_CXXFLAGS $DEFAULT_COMPILE_FLAGS"
PASSED_CFLAGS=$CFLAGS # Hack to override autoconf default values
AC_PROG_CC
AC_PROG_LIBTOOL
CFLAGS="$PASSED_CFLAGS $DEFAULT_COMPILE_FLAGS"
AC_PROG_AWK
AC_PROG_LN_S
AC_PROG_MAKE_SET
MAKE="${MAKE:-make}"

# host detection and setup
case $host in
  i*86*-linux-gnu*)
     ARCH="i486-linux"
     AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_LINUX -D_LINUX")
     ;;
  x86_64-*-linux-gnu*)
     ARCH="x86_64-linux"
     AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_LINUX -D_LINUX")
     ;;
  arm-apple-darwin*)
     use_joystick=no
     use_vdadecoder=no
     use_vtbdecoder=yes
     use_optical_drive=no
     use_dvdcss=no
     use_gles=yes
     use_cpu=cortex-a8
     check_sdl_arch=[`file /opt/local/lib/libSDL_image.dylib | awk '{V=7; print $V}'`]
     if test "x$check_sdl_arch" = "xi386"; then
       use_texturepacker_native=yes
       USE_TEXTUREPACKER_NATIVE_ROOT="/opt/local"
     else
       use_texturepacker=no
     fi
     ARCH="arm-osx"
     use_arch="arm"
     AC_SUBST(ARCH_DEFINES, "-D_ARMEL")
     PYTHON_VERSION="2.6"
     PYTHON_LDFLAGS="-L${prefix}/lib -lpython2.6"
     PYTHON_CPPFLAGS="-I${prefix}/include/python2.6"
     PYTHON_SITE_PKG="${prefix}/lib/python2.6/site-packages"
     PYTHON_NOVERSIONCHECK="no-check"
     AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_DARWIN -DTARGET_DARWIN_IOS -D_LINUX")
     ;;
  *86-apple-darwin*)
     use_joystick=no
     use_vtbdecoder=no
     use_texturepacker_native=yes
     USE_TEXTUREPACKER_NATIVE_ROOT="$prefix"
     ARCH="x86-osx"
     AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_DARWIN -DTARGET_DARWIN_OSX -D_LINUX")
     ;;
  powerpc-apple-darwin*)
     use_joystick=no
     use_vdadecoder=no
     use_vtbdecoder=no
     use_crystalhd=no
     ARCH="powerpc-osx"
     use_arch="ppc"
     AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_DARWIN -DTARGET_DARWIN_OSX -D_LINUX")
     ;;
  powerpc-*-linux-gnu*)
     ARCH="powerpc-linux"
     AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_LINUX -D_LINUX -D_POWERPC")
     ;;
  powerpc64-*-linux-gnu*)
     ARCH="powerpc64-linux"
     AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_LINUX -D_LINUX -D_POWERPC64")
     ;;
  arm*-*-linux-gnu*)
     use_texturepacker=no
     ARCH="arm"
     use_arch="arm"
     AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_LINUX -D_LINUX -D_ARMEL")
     ;;
  *)
     AC_MSG_ERROR(unsupported host ($host))
esac
AC_SUBST([ARCH])

# platform debug flags
if test "$use_debug" = "yes"; then
  final_message="$final_message\n  Debugging:\tYes"
  if test "$use_profiling" = "yes"; then
    final_message="$final_message\n  Profiling:\tYes"
    DEBUG_FLAGS="-g -pg -D_DEBUG -Wall"
  else
    final_message="$final_message\n  Profiling:\tNo"
    DEBUG_FLAGS="-g -D_DEBUG -Wall"
  fi
else
  final_message="$final_message\n  Debugging:\tNo"
  if test "$use_profiling" = "yes"; then
    final_message="$final_message\n  Profiling:\tYes"
    DEBUG_FLAGS="-pg -DNDEBUG=1"
  else
    final_message="$final_message\n  Profiling:\tNo"
    DEBUG_FLAGS="-DNDEBUG=1"
  fi
fi
CFLAGS="$CFLAGS $DEBUG_FLAGS"
CXXFLAGS="$CXXFLAGS $DEBUG_FLAGS"


if test "$use_optimizations" = "yes"; then
  final_message="$final_message\n  Optimization:\tYes"
  CXXFLAGS="$CXXFLAGS -O2"
  CFLAGS="$CFLAGS -O2"
else
  final_message="$final_message\n  Optimization:\tNo"
fi


# platform specific flags
if test "$host_vendor" = "apple" ; then
  # standard xbmc paths
  INCLUDES="$INCLUDES -I\$(abs_top_srcdir)/xbmc/osx"
  if test "$use_arch" != "arm"; then
    LIBS="$LIBS -framework IOKit"
    LIBS="$LIBS -framework Cocoa"
    LIBS="$LIBS -framework AppKit"
    LIBS="$LIBS -framework Carbon"
    LIBS="$LIBS -framework CoreAudio"
    LIBS="$LIBS -framework QuickTime"
    LIBS="$LIBS -framework AudioUnit"
    LIBS="$LIBS -framework Foundation"
    LIBS="$LIBS -framework CoreServices"
    LIBS="$LIBS -framework CoreVideo"
    LIBS="$LIBS -framework CoreAudio"
    LIBS="$LIBS -framework AudioToolbox"
    LIBS="$LIBS -framework CoreFoundation"
    LIBS="$LIBS -framework DiskArbitration"
    LIBS="$LIBS -framework ApplicationServices"
  fi
elif test "$use_arch" = "arm"; then
  CFLAGS="$CFLAGS -mfloat-abi=softfp -mno-apcs-stack-check"
  CXXFLAGS="$CXXFLAGS -mfloat-abi=softfp -mno-apcs-stack-check"
  FFMPEG_EXTRACFLAGS="-mfloat-abi=softfp"
  if test "$use_tegra" = "yes"; then
    # Compile for ARMv7a architecture, need to test gcc for vfpv3-d16 support 
    SAVE_CFLAGS="$CFLAGS"
    CFLAGS="-mfpu=vfpv3-d16"
    AC_COMPILE_IFELSE(
      [AC_LANG_SOURCE([int foo;])],
      [ CFLAGS="$SAVE_CFLAGS -Wno-psabi -Wa,-march=armv7a -mtune=cortex-a9 -mfpu=vfpv3-d16 -mthumb-interwork"
        CXXFLAGS="$CXXFLAGS -Wno-psabi -Wa,-march=armv7a -mtune=cortex-a9 -mfpu=vfpv3-d16 -mthumb-interwork"
        FFMPEG_EXTRACFLAGS+=" -mtune=cortex-a9 -mfpu=vfpv3-d16"
        use_cpu=cortex-a9],
      [ CFLAGS="$SAVE_CFLAGS -Wa,-march=armv6 -mtune=cortex-a8 -mthumb-interwork"
        CXXFLAGS="$CXXFLAGS -Wa,-march=armv6 -mtune=cortex-a8 -mthumb-interwork"    
        use_cpu=cortex-a8])
  else
    # Compile for ARMv7a architecture, CortexA8 cpu and NEON coprocessor
    CFLAGS+=" -Wa,-march=armv7a -mcpu=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad"
    CXXFLAGS+=" -Wa,-march=armv7a -mcpu=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad"
    FFMPEG_EXTRACFLAGS+=" -mfpu=neon"
  fi
fi

# Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_CHOWN
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_ERROR_AT_LINE
AC_FUNC_FSEEKO
AC_PROG_GCC_TRADITIONAL
AC_FUNC_LSTAT
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
AC_FUNC_MEMCMP
AC_FUNC_MKTIME
AC_FUNC_MMAP
# Boxee is apparently having compile problems
# if HAVE_REALLOC is defined.  Sort this later.
#AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_SETVBUF_REVERSED
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_FUNC_STRCOLL
AC_FUNC_STRFTIME
AC_FUNC_STRTOD
AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([atexit dup2 fdatasync floor fs_stat_dev ftime ftruncate getcwd gethostbyaddr gethostbyname gethostname getpagesize getpass gettimeofday inet_ntoa lchown localeconv memchr memmove memset mkdir modf munmap pow rmdir select setenv setlocale socket sqrt strcasecmp strchr strcspn strdup strerror strncasecmp strpbrk strrchr strspn strstr strtol strtoul sysinfo tzset utime])

# Check for various sizes
AC_CHECK_SIZEOF([int])
AC_CHECK_SIZEOF([size_t])

# Add top source directory for all builds so we can use config.h
INCLUDES="$INCLUDES -I\$(abs_top_srcdir)"

# Check inotify availability
AC_CHECK_HEADER([sys/inotify.h], AC_DEFINE([HAVE_INOTIFY],[1],[Define if we have inotify]),)

# Checks for boost headers using CXX instead of CC
AC_LANG_PUSH([C++])
AC_CHECK_HEADER([boost/shared_ptr.hpp],, AC_MSG_ERROR($missing_library))
AC_LANG_POP([C++])

# Checks for platforms libraries.
if test "$use_gles" = "yes"; then
  use_gl="no"
  # GLES overwrites GL if both set to yes.
  if test "$host_vendor" = "apple" ; then
    AC_DEFINE([HAVE_LIBEGL],[1],["Define to 1 if you have the `EGL' library (-lEGL)."])
    AC_DEFINE([HAVE_LIBGLESV2],[1],["Define to 1 if you have the `GLESv2' library (-lGLESv2)."])
    AC_MSG_RESULT(== WARNING: OpenGLES support is assumed.)
  else
    AC_CHECK_LIB([EGL],   [main],, AC_MSG_ERROR($missing_library))
    AC_CHECK_LIB([GLESv2],[main],, AC_MSG_ERROR($missing_library))
  fi
else
  if test "$use_gl" = "yes"; then
    if test "$host_vendor" = "apple" ; then
      # linking to OpenGL.framework instead of libGL, libGLU so AC_CHECK_LIB will fail
      LIBS="$LIBS -framework OpenGL"
      AC_DEFINE([HAVE_LIBGL],[1],["Define to 1 if you have the `GL' library (-lGL)."])
      AC_MSG_RESULT(== WARNING: OpenGL support is assumed.)
      AC_DEFINE([HAVE_LIBGLU],[1],["Define to 1 if you have the `GLU' library (-lGLU)."])
      AC_MSG_RESULT(== WARNING: OpenGLU support is assumed.)
      AC_CHECK_LIB([GLEW],[main],, AC_MSG_ERROR($missing_library))
    else
      AC_CHECK_LIB([GL],  [main],, AC_MSG_ERROR($missing_library))
      AC_CHECK_LIB([GLEW],[main],, AC_MSG_ERROR($missing_library))
      AC_CHECK_LIB([GLU], [main],, AC_MSG_ERROR($missing_library))
    fi
  else
    AC_MSG_RESULT(== WARNING: OpenGL support is disabled. XBMC will run VERY slow. ==)
    AC_CHECK_LIB([SDL_gfx],[main])
  fi
fi

# platform common libraries
AC_CHECK_PROG(MYSQL_CONFIG, mysql_config, "yes", "no")
if test $MYSQL_CONFIG = "yes"; then
  INCLUDES="$INCLUDES `mysql_config --include`"
  MYSQL_LIBS=`mysql_config --libs`
  LIBS="$LIBS $MYSQL_LIBS"
  AC_SUBST(MYSQL_LIBS)
else
  AC_MSG_ERROR($missing_program)
fi
AC_CHECK_HEADER([ass/ass.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([mpeg2dec/mpeg2.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([mpeg2dec/mpeg2convert.h],, AC_MSG_ERROR($missing_library),
  AC_INCLUDES_DEFAULT()
  [#include <mpeg2dec/mpeg2.h>])
AC_CHECK_HEADER([mad.h],,            AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([jpeglib.h],,        AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([samplerate.h],,     AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([ogg/ogg.h],,        AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([vorbis/vorbisfile.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([vorbis/vorbisenc.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([libmodplug/modplug.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([curl/curl.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([FLAC/stream_decoder.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([bz2],         [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([jpeg],        [main],, AC_MSG_ERROR($missing_library)) # check for cximage
AC_CHECK_LIB([tiff],        [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([pthread],     [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([lzo2],        [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([z],           [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([ssl],         [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([crypto],      [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([mysqlclient], [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([ssh],         [sftp_tell64],, AC_MSG_RESULT([Could not find suitable version of libssh]))
AC_CHECK_LIB([smbclient],   [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([bluetooth],   [hci_devid],, AC_MSG_RESULT([Could not find suitable version of libbluetooth]))
AC_CHECK_LIB([yajl],        [main],, AC_MSG_ERROR($missing_library))
AC_LANG_PUSH([C++])
AC_DEFINE([USE_PTHREADS_THREADING], [1], [Whether to use pthreads as the threading implementation.])
AC_LANG_POP([C++])

PKG_CHECK_MODULES([FONTCONFIG], [fontconfig],
  [INCLUDES="$INCLUDES $FONTCONFIG_CFLAGS"; LIBS="$LIBS $FONTCONFIG_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([FRIBIDI],    [fribidi],
  [INCLUDES="$INCLUDES $FRIBIDI_CFLAGS"; LIBS="$LIBS $FRIBIDI_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([SQLITE3],    [sqlite3],
  [INCLUDES="$INCLUDES $SQLITE3_CFLAGS"; LIBS="$LIBS $SQLITE3_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([PNG],        [libpng],
  [INCLUDES="$INCLUDES $PNG_CFLAGS"; LIBS="$LIBS $PNG_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([PCRE],       [libpcre],
  [INCLUDES="$INCLUDES $PCRE_CFLAGS"; LIBS="$LIBS $PCRE_LIBS"]; \
  AC_DEFINE([HAVE_LIBPCRE],[1],["Define to 1 if libpcre is installed"]),
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([PCRECPP],    [libpcrecpp],
  [INCLUDES="$INCLUDES $PCRECPP_CFLAGS"; LIBS="$LIBS $PCRECPP_LIBS"]; \
  AC_DEFINE([HAVE_LIBPCRECPP],[1],["Define to 1 if libpcrecpp is installed"]),
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([CDIO],       [libcdio],
  [INCLUDES="$INCLUDES $CDIO_CFLAGS"; LIBS="$LIBS $CDIO_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([SAMPLERATE], [samplerate],
  [INCLUDES="$INCLUDES $SAMPLERATE_CFLAGS"; LIBS="$LIBS $SAMPLERATE_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([FREETYPE2],  [freetype2],
  [INCLUDES="$INCLUDES $FREETYPE2_CFLAGS"; LIBS="$LIBS $FREETYPE2_LIBS"],
  AC_MSG_ERROR($missing_library))

# check for libbluray
AS_CASE([x$use_libbluray],
  [xyes],[
    PKG_CHECK_MODULES([LIBBLURAY],[libbluray],[use_libbluray="yes"], AC_MSG_ERROR($missing_library))
  ],
  [xauto],[
    PKG_CHECK_MODULES([LIBBLURAY],[libbluray],[use_libbluray="yes"], [use_libbluray="no"])
  ])

AS_CASE([x$use_libbluray],
  [xyes],[
    INCLUDES="$INCLUDES $LIBBLURAY_CFLAGS";
    XB_FIND_SONAME([BLURAY], [bluray], [use_libbluray])
    AC_DEFINE([HAVE_LIBBLURAY], 1, [System has libbluray library])
    AC_SUBST([HAVE_LIBBLURAY], 1)
  ],[
#    AC_DEFINE([HAVE_LIBBLURAY], 0, [System has libbluray library])
    AC_SUBST([HAVE_LIBBLURAY], 0)
  ]
)

# platform dependent libraries
if test "$host_vendor" = "apple" ; then
  AC_CHECK_LIB([iconv],     [main],, AC_MSG_ERROR($missing_library))
  if test "$use_arch" != "arm"; then
    AC_CHECK_LIB([SDL_mixer],[main],, AC_MSG_ERROR($missing_library))
    AC_CHECK_LIB([SDL],      [main],, AC_MSG_ERROR($missing_library))
  fi
else
  AC_CHECK_LIB([SDL_mixer],  [main],, AC_MSG_ERROR($missing_library))
  AC_CHECK_LIB([dl],         [main],, AC_MSG_ERROR($missing_library))
  AC_CHECK_LIB([resolv],     [main],, AC_MSG_ERROR($missing_library))
  AC_CHECK_LIB([jasper],     [main],, AC_MSG_ERROR($missing_library)) # check for cximage
  AC_CHECK_LIB([rt],         [clock_gettime],, AC_MSG_ERROR($missing_library))
  AC_CHECK_LIB([SDL_image],  [main],, AC_MSG_ERROR($missing_library))

  PKG_CHECK_MODULES([ALSA],  [alsa],
    [INCLUDES="$INCLUDES $ALSA_CFLAGS"; LIBS="$LIBS $ALSA_LIBS"],
    AC_MSG_ERROR($missing_library))
  PKG_CHECK_MODULES([ENCA],  [enca],
    [INCLUDES="$INCLUDES $ENCA_CFLAGS"; LIBS="$LIBS $ENCA_LIBS"],
    AC_MSG_ERROR($missing_library))
  PKG_CHECK_MODULES([XT],    [xt],
    [INCLUDES="$INCLUDES $XT_CFLAGS"; LIBS="$LIBS $XT_LIBS"],
    AC_MSG_ERROR($missing_library))
  PKG_CHECK_MODULES([XEXT],  [xext],
    [INCLUDES="$INCLUDES $XEXT_CFLAGS"; LIBS="$LIBS $XEXT_LIBS"],
    AC_MSG_ERROR($missing_library))
  PKG_CHECK_MODULES([XMU],   [xmu],
    [INCLUDES="$INCLUDES $XMU_CFLAGS"; LIBS="$LIBS $XMU_LIBS"],
    AC_MSG_ERROR($missing_library))
  PKG_CHECK_MODULES([DBUS],  [dbus-1],
    [INCLUDES="$INCLUDES $DBUS_CFLAGS"; LIBS="$LIBS $DBUS_LIBS"],
    AC_MSG_ERROR($missing_library))
  PKG_CHECK_MODULES([SDL],   [sdl],
    [INCLUDES="$INCLUDES $SDL_CFLAGS"; LIBS="$LIBS $SDL_LIBS"],
    AC_MSG_ERROR($missing_library))
fi

XB_FIND_SONAME([MAD],         [mad])
XB_FIND_SONAME([OGG],         [ogg])
XB_FIND_SONAME([CURL],        [curl])
XB_FIND_SONAME([FLAC],        [FLAC])
XB_FIND_SONAME([VORBIS],      [vorbis])
XB_FIND_SONAME([VORBISENC],   [vorbisenc])
XB_FIND_SONAME([VORBISFILE],  [vorbisfile])
XB_FIND_SONAME([MODPLUG],     [modplug])
XB_FIND_SONAME([ASS],         [ass])
XB_FIND_SONAME([MPEG2],       [mpeg2])

# WebServer
if test "$use_webserver" = "yes"; then
  AC_CHECK_LIB([microhttpd],  [main],, AC_MSG_ERROR($missing_library))
fi

# Optical
if test "$use_optical_drive" = "yes"; then
  AC_DEFINE([HAS_DVD_DRIVE], [1], [Define to 1 to have optical drive support])
fi

# PulseAudio
if test "x$use_pulse" != "xno"; then
  if test "$host_vendor" = "apple" ; then
    if test "x$use_pulse" = "xyes"; then
      AC_MSG_ERROR($pulse_disabled)
    else
      use_pulse="no"
      AC_MSG_RESULT($pulse_disabled)
    fi
    USE_PULSE=0
  else
    AC_CHECK_LIB([pulse], [main],,
      [if test "x$use_pulse" = "xyes"; then
        AC_MSG_ERROR($pulse_not_found)
      else
        use_pulse=no
        USE_PULSE=0
        AC_MSG_RESULT($pulse_not_found)
      fi])
      USE_PULSE=1
  fi
else
  AC_MSG_RESULT($pulse_disabled)
  USE_PULSE=0
fi

# HAL
if test "$host_vendor" = "apple" ; then
  use_hal="no"
  AC_MSG_RESULT($hal_disabled)
else
  if test "$use_hal" = "yes"; then
    PKG_CHECK_MODULES([HAL], [hal],
      [INCLUDES="$INCLUDES $HAL_CFLAGS"; LIBS="$LIBS $HAL_LIBS"],
      use_hal=no;AC_MSG_RESULT($hal_not_found))
    PKG_CHECK_MODULES([HAL_STORAGE], [hal-storage],
      [INCLUDES="$INCLUDES $HAL_STORAGE_CFLAGS"; LIBS="$LIBS $HAL_STORAGE_LIBS"],
      use_hal=no;AC_MSG_RESULT($halstorage_not_found))
  else
    AC_MSG_RESULT($hal_disabled)
  fi
  if test "$use_hal" = "yes"; then
    AC_DEFINE([HAS_HAL], [1], [Define to 1 if you have HAL installed])
  fi
fi

# avahi
if test "$host_vendor" = "apple" ; then
  use_avahi="no"
  AC_MSG_RESULT($avahi_disabled)
else
  if test "$use_avahi" = "yes"; then
    AC_CHECK_LIB([avahi-common], [main],,
      use_avahi=no;AC_MSG_RESULT($avahi_not_found))
    if test "$use_avahi" = "yes"; then
      #either both libs or none
      AC_CHECK_LIB([avahi-client], [main],,
        use_avahi=no;AC_MSG_RESULT($avahi_not_found))
    fi
  else
    AC_MSG_RESULT($avahi_disabled)
  fi
fi

# XRandR
if test "$host_vendor" = "apple" ; then
  use_xrandr="no"
  AC_MSG_RESULT($xrandr_disabled)
else
  if test "$use_xrandr" = "yes" ; then
    AC_CHECK_LIB([Xrandr], [main],,
      use_xrandr="no";AC_MSG_RESULT($xrandr_not_found))
  else
    AC_MSG_RESULT($xrandr_disabled)
  fi
fi

# GOOM
if test "$host_vendor" = "apple" ; then
  AC_MSG_NOTICE($goom_disabled)
  DISABLE_GOOM=1
else
  if test "$use_goom" = "yes" && test "use_gl" == "yes"; then
    AC_MSG_NOTICE($goom_enabled)
    DISABLE_GOOM=0
  else
    AC_MSG_NOTICE($goom_disabled)
    DISABLE_GOOM=1
  fi
fi

# libRTMP
if test "$use_librtmp" != "no"; then
  AC_CHECK_HEADERS([librtmp/log.h librtmp/amf.h librtmp/rtmp.h],,
   [if test "$use_librtmp" = "yes"; then
      AC_MSG_ERROR($librtmp_not_found)
    elif test "$use_librtmp" != "no"; then
      AC_MSG_NOTICE($librtmp_not_found)
      use_librtmp="no"
    fi
   ])
  if test "$use_librtmp" != "no"; then
    XB_FIND_SONAME([RTMP], [rtmp], [use_librtmp])
  fi
  if test "$use_librtmp" != "no"; then
    AC_DEFINE([HAS_LIBRTMP], [1], [Whether to use libRTMP library.])
  fi
else
  AC_MSG_NOTICE($librtmp_disabled)
fi

# libnfs
if test "$use_libnfs" != "no"; then
  AC_CHECK_HEADERS([nfsc/libnfs.h],,
   [if test "$use_libnfs" = "yes"; then
      AC_MSG_ERROR($libnfs_not_found)
      USE_LIBNFS=0
    elif test "$use_libnfs" != "no"; then
      AC_MSG_NOTICE($libnfs_not_found)
      use_libnfs="no"
    fi
   ])
  if test "$use_libnfs" != "no"; then
    XB_FIND_SONAME([NFS], [nfs], [use_libnfs])
  fi
  if test "$use_libnfs" != "no"; then
    AC_DEFINE([HAVE_LIBNFS], [1], [Whether to use libnfs library.])
    USE_LIBNFS=1
  fi
else
  USE_LIBNFS=0
  AC_MSG_NOTICE($libnfs_disabled)
fi

### External libraries checks
# External FFmpeg
if test "$use_external_ffmpeg" = "yes"; then
  FFMPEG_LIBNAMES="libavcodec libavfilter libavformat libavutil libpostproc libswscale"

  # libavcore is optional
  PKG_CHECK_EXISTS([libavcore], FFMPEG_LIBNAMES="$FFMPEG_LIBNAMES libavcore")

  PKG_CHECK_MODULES([FFMPEG], [$FFMPEG_LIBNAMES],
                    [INCLUDES="$INCLUDES $FFMPEG_CFLAGS"; LIBS="$LIBS $FFMPEG_LIBS"],
                    AC_MSG_ERROR($missing_library))

  # Determine whether AVPacket and relevant functions are defined in libavformat
  # or libavcodec
  AC_CHECK_LIB([avcodec], [av_free_packet],
  [AC_MSG_NOTICE(== AVPacket and relevant functions defined in libavcodec. ==)],
  [AC_MSG_NOTICE(== AVPacket and relevant functions defined in libavformat. ==)
   AC_DEFINE([AVPACKET_IN_AVFORMAT], [1], [Whether AVPacket is in libavformat.])])

  # in case the headers are in a custom directory
  SAVE_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$CPPFLAGS $FFMPEG_CFLAGS"

  # Possible places the ffmpeg headers may be
  AC_CHECK_HEADERS([libavcodec/avcodec.h libavfilter/avfilter.h libavformat/avformat.h libavutil/avutil.h libpostproc/postprocess.h libswscale/swscale.h],,
  [AC_CHECK_HEADERS([ffmpeg/avcodec.h ffmpeg/avfilter.h ffmpeg/avformat.h ffmpeg/avutil.h postproc/postprocess.h ffmpeg/swscale.h],,
  [AC_MSG_ERROR($missing_headers)])])

  # optional
  AC_CHECK_HEADERS([libavcore/avcore.h libavcore/samplefmt.h libavutil/mem.h libavutil/samplefmt.h])

  # old FFmpeg have this in libavcodec/opt.h instead:
  AC_CHECK_HEADERS([libavutil/opt.h])

  # We'll support the use of rgb2rgb.h if it exists.
  AC_CHECK_HEADERS([libswscale/rgb2rgb.h],,)
  AC_CHECK_HEADERS([ffmpeg/rgb2rgb.h],,)

  # Check if AVFilterBufferRefVideoProps AVRational member is named
  # 'pixel_aspect' or 'sample_aspect_ratio'.
  AC_CHECK_MEMBER([AVFilterBufferRefVideoProps.sample_aspect_ratio],
    [AC_DEFINE([HAVE_AVFILTERBUFFERREFVIDEOPROPS_SAMPLE_ASPECT_RATIO],
    [1],
    [Define to 1 if AVFilterBufferRefVideoProps has member sample_aspect_ratio.])],
      [AC_CHECK_MEMBER([AVFilterBufferRefVideoProps.sample_aspect_ratio],
      [AC_DEFINE([HAVE_AVFILTERBUFFERREFVIDEOPROPS_SAMPLE_ASPECT_RATIO],
      [1],
      [Define to 1 if AVFilterBufferRefVideoProps has member sample_aspect_ratio.])],
      ,
      [[#include <ffmpeg/avfilter.h>]])],
    [[#include <libavfilter/avfilter.h>]])

  AC_MSG_NOTICE($external_ffmpeg_enabled)
  USE_EXTERNAL_FFMPEG=1
  AC_DEFINE([USE_EXTERNAL_FFMPEG], [1], [Whether to use external FFmpeg libraries.])

  # Disable vdpau support if external libavcodec doesn't have it
  AC_CHECK_LIB([avcodec], [ff_vdpau_vc1_decode_picture],,
    [if test "x$use_vdpau" = "xyes"; then
      AC_MSG_ERROR($ffmpeg_vdpau_not_supported)
    else
      use_vdpau=no
      AC_MSG_RESULT($ffmpeg_vdpau_not_supported)
    fi])

  # Check for 'PIX_FMT_VDPAU_MPEG4' from libavutil
  if test "x$use_vdpau" != "xno"; then
    AC_LANG_PUSH([C++])
    AC_LINK_IFELSE(
      [AC_LANG_SOURCE([ #include <libavutil/pixfmt.h>
        int main() { PixelFormat format = PIX_FMT_VDPAU_MPEG4; }])],
      [AC_DEFINE([PIX_FMT_VDPAU_MPEG4_IN_AVUTIL], [1],
      [Whether AVUtil defines PIX_FMT_VDPAU_MPEG4.])],)
    AC_LANG_POP([C++])
  fi
  CPPFLAGS="$SAVE_CPPFLAGS"
else
  AC_MSG_NOTICE($external_ffmpeg_disabled)
  USE_EXTERNAL_FFMPEG=0
  AC_DEFINE([PIX_FMT_VDPAU_MPEG4_IN_AVUTIL], [1], [Whether AVUtil defines PIX_FMT_VDPAU_MPEG4.])
fi

# Python
if test -z "$PYTHON_NOVERSIONCHECK"; then
  AX_PYTHON_DEVEL([>= 2.4])
  PYTHON_VERSION=$ac_python_version
fi

if test -z "$PYTHON_VERSION"; then
  AC_MSG_ERROR([Can't find a Python version.])
else
  AC_MSG_NOTICE([Using Python $PYTHON_VERSION])
fi

# VDPAU
if test "x$use_vdpau" != "xno"; then
  if test "$host_vendor" = "apple" ; then
    if test "x$use_vdpau" = "xyes"; then
      AC_MSG_ERROR([VDPAU not supported on this platform])
    else
      use_vdpau="no"
      AC_MSG_NOTICE($vdpau_disabled)
    fi
    USE_VDPAU=0
  else
    USE_VDPAU=1
    AC_CHECK_HEADER([vdpau/vdpau.h],AC_DEFINE([HAVE_LIBVDPAU], [],
      [Define to 1 if you have the 'vdpau' library (-lvdpau).]),
    [if test "x$use_vdpau" = "xyes"; then
      USE_VDPAU=0
      AC_MSG_ERROR([$vdpau_not_found])
    else
      use_vdpau="no"
      USE_VDPAU=0
      AC_MSG_RESULT($vdpau_not_found)
    fi])
  fi
else
  USE_VDPAU=0
  AC_MSG_NOTICE($vdpau_disabled)
fi

# VAAPI
if test "x$use_vaapi" != "xno"; then
  if test "$host_vendor" = "apple" ; then
    if test "x$use_vaapi" = "xyes"; then
      AC_MSG_ERROR([VAAPI not supported on this platform])
    else
      use_vaapi="no"
      AC_MSG_NOTICE($vaapi_disabled)
    fi
    USE_VAAPI=0
  else
    initial_val=$use_vaapi
    AC_CHECK_LIB([va], main, :, use_vaapi=no)
    if test "x$use_vaapi" != "xno"; then
      AC_CHECK_LIB([va-glx], main, LIBS="-lva -lva-glx $LIBS", use_vaapi=no, -lva)
    fi

    if test "x$use_vaapi" = "xno"; then
      if test "x$initial_val" = "xyes"; then
        AC_MSG_ERROR($vaapi_not_found)
      else
        AC_MSG_RESULT($vaapi_not_found)
      fi
      USE_VAAPI=0
    else
      AC_DEFINE([HAVE_LIBVA], [1], [Define to 1 if you have the 'vaapi' libraries (-lva AND -lva-glx)])
      USE_VAAPI=1
    fi
  fi
else
  AC_MSG_NOTICE($vaapi_disabled)
  USE_VAAPI=0
fi

# CrystalHD
if test "x$use_crystalhd" != "xno"; then
  SAVE_CFLAGS="$CFLAGS"
  CFLAGS="-D__LINUX_USER__"
  AC_CHECK_HEADER([libcrystalhd/libcrystalhd_if.h], [],
    [ if test "x$use_crystalhd" = "xyes"; then
        AC_MSG_ERROR($crystalhd_not_found)
      else
        use_crystalhd=no
        AC_MSG_RESULT($crystalhd_not_found)
      fi
      USE_CRYSTALHD=0
    ])
    CFLAGS="$SAVE_CFLAGS"
    if test "$host_vendor" != "apple"; then
      XB_FIND_SONAME([CRYSTALHD], [crystalhd], [use_crystalhd])
    fi
    if test "x$use_crystalhd" != "xno"; then
      SAVE_CFLAGS="$CFLAGS"
      CFLAGS="-D__LINUX_USER__ -llibcrystalhd"
      # check for new crystalhd lib
      AC_COMPILE_IFELSE(
        [AC_LANG_SOURCE([#include <libcrystalhd/bc_dts_types.h>
          #include <libcrystalhd/bc_dts_defs.h>
          PBC_INFO_CRYSTAL bCrystalInfo;])],
        [ AC_DEFINE([HAVE_LIBCRYSTALHD], [2], [Define to 2 if you have the 'New Broadcom Crystal HD' library.]) ], 
        [ AC_DEFINE([HAVE_LIBCRYSTALHD], [1], [Define to 1 if you have the 'Old Broadcom Crystal HD' library.]) ])
      CFLAGS="$SAVE_CFLAGS"
      USE_CRYSTALHD=1
    fi
else
  AC_MSG_NOTICE($crystalhd_disabled)
  USE_CRYSTALHD=0
fi

# VDADecoder
if test "x$use_vdadecoder" != "xno"; then
  if test "$host_vendor" = "apple" ; then
    HAVE_LIBVDADECODER=1
    AC_DEFINE([HAVE_LIBVDADECODER], [1], [Define to 1 if you have the 'VDADecoder' library.])
    AC_MSG_NOTICE($vdadecoder_enabled)
    USE_VDA=1
  else
    if test "x$use_vdadecoder" = "xyes"; then
      AC_MSG_ERROR([VDA Decoder not supported on this platform])
    else
      use_vdadecoder="no"
      AC_MSG_NOTICE($vdadecoder_disabled)
    fi
    USE_VDA=0
  fi
else
  AC_MSG_NOTICE($vdadecoder_disabled)
fi

# VTBDecoder
if test "x$use_vtbdecoder" != "xno"; then
  if test "$host_vendor" = "apple" ; then
    HAVE_VIDEOTOOLBOXDECODER=1
    AC_DEFINE([HAVE_VIDEOTOOLBOXDECODER], [1], [Define to 1 if you have the 'VTBDecoder' library.])
    AC_MSG_NOTICE($vtbdecoder_enabled)
  else
    if test "x$use_vtbdecoder" = "xyes"; then
      AC_MSG_ERROR([VTB Decoder not supported on this platform])
    else
      use_vtbdecoder="no"
      AC_MSG_NOTICE($vtbdecoder_disabled)
    fi
  fi
else
  AC_MSG_NOTICE($vtbdecoder_disabled)
fi

# OpenMax
if test "$host_vendor" = "apple" ; then
  use_openmax="no"
  USE_OPENMAX=0
  AC_MSG_NOTICE($openmax_disabled)
else
  if test "$use_gles" = "yes" && test "$use_openmax" = "auto"; then
    PKG_CHECK_MODULES([OPENMAX], [libomxil-bellagio],
                      USE_OPENMAX=1;[INCLUDES="$INCLUDES $OPENMAX_CFLAGS"; LIBS="$LIBS $OPENMAX_LIBS"],
                      use_openmax=no;USE_OPENMAX=0;AC_MSG_RESULT($openmax_not_found))
  elif test "$use_gles" = "yes" && test "$use_openmax" = "yes"; then
    PKG_CHECK_MODULES([OPENMAX], [libomxil-bellagio],
                      USE_OPENMAX=1;[INCLUDES="$INCLUDES $OPENMAX_CFLAGS"; LIBS="$LIBS $OPENMAX_LIBS"],
                      AC_MSG_ERROR($openmax_not_found))
  else
    AC_MSG_NOTICE($openmax_disabled)
    use_openmax=no
    USE_OPENMAX=0
  fi
fi

# yajl version check (yajl_version.h was added in yajl 2.0)
AC_CHECK_HEADERS([yajl/yajl_version.h], [], [
AC_DEFINE(YAJL_MAJOR, 1, [yajl version 1])
], [])

# platform specific bin utilities
if test "$host_vendor" != "apple" ; then
  AC_CHECK_PROG(HAVE_GAWK,gawk,"yes","no",)
  if test "$HAVE_GAWK" = "no" ; then
    AC_MSG_ERROR($missing_program)
  fi
fi

if test "$use_arch" != "arm" ; then
  AC_CHECK_PROG(HAVE_CMAKE,cmake,"yes","no",)
  if test "$HAVE_CMAKE" = "no" ; then
    AC_MSG_ERROR($missing_program)
  fi
fi

AC_CHECK_PROG(HAVE_GPERF,gperf,"yes","no",)
if test "$HAVE_GPERF" = "no" ; then
  AC_MSG_ERROR($missing_program)
fi

AC_CHECK_PROG(HAVE_UNZIP,unzip,"yes","no",)
if test "$HAVE_UNZIP" = "no" ; then
  AC_MSG_ERROR($missing_program)
fi

AC_CHECK_PROG(HAVE_ZIP,zip,"yes","no",)
if test "$HAVE_ZIP" = "no" ; then
  AC_MSG_ERROR($missing_program)
fi

if test "$ARCH" = "i486-linux" || test "$ARCH" = "x86-freebsd"; then
  AC_CHECK_PROG(HAVE_NASM,nasm,"yes","no",)
  if test "$HAVE_NASM" = "no" ; then
    AC_MSG_ERROR($missing_program)
  fi
fi

AC_CHECK_PROG(HAVE_GIT,git,"yes","no",)

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([arpa/inet.h fcntl.h float.h inttypes.h limits.h locale.h \
  malloc.h memory.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h \
  strings.h sys/file.h sys/ioctl.h sys/mount.h sys/param.h sys/socket.h \
  sys/time.h sys/timeb.h sys/vfs.h termios.h unistd.h utime.h wchar.h wctype.h])
AC_CHECK_HEADERS([cdio/iso9660.h],,AC_MSG_ERROR([$missing_headers]))

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STAT
AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_UID_T
AC_C_INLINE
AC_TYPE_INT8_T
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_C_RESTRICT
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_CHECK_MEMBERS([struct stat.st_rdev])
AC_HEADER_TIME
AC_STRUCT_TM
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_C_BIGENDIAN

if test "$cross_compiling" = "yes"; then
  final_message="$final_message\n  Crosscomp.:\tYes"
else
  final_message="$final_message\n  Crosscomp.:\tNo"
fi

final_message="$final_message\n  target ARCH:\t$use_arch"
final_message="$final_message\n  target CPU:\t$use_cpu"

if test "$use_gles" = "yes"; then
  final_message="$final_message\n  OpenGLES:\tYes"
  USE_OPENGLES=1
  USE_OPENGL=0
else
  USE_OPENGLES=0
  if test "$use_gl" = "yes"; then
    final_message="$final_message\n  OpenGL:\tYes"
    USE_OPENGL=1
  else
    final_message="$final_message\n  OpenGL:\tNo (Very Slow)"
    SDL_DEFINES="-DHAS_SDL_2D"
    USE_OPENGL=0
  fi
fi

if test "x$use_vdpau" != "xno"; then
  final_message="$final_message\n  VDPAU:\tYes"
else
  final_message="$final_message\n  VDPAU:\tNo"
fi

if test "x$use_vaapi" != "xno"; then
  final_message="$final_message\n  VAAPI:\tYes"
else
  final_message="$final_message\n  VAAPI:\tNo"
fi

if test "x$use_crystalhd" != "xno"; then
  final_message="$final_message\n  CrystalHD:\tYes"
else
  final_message="$final_message\n  CrystalHD:\tNo"
fi

if test "x$use_vdadecoder" != "xno"; then
  final_message="$final_message\n  VDADecoder:\tYes"
else
  final_message="$final_message\n  VDADecoder:\tNo"
fi

if test "x$use_vtbdecoder" != "xno"; then
  final_message="$final_message\n  VTBDecoder:\tYes"
else
  final_message="$final_message\n  VTBDecoder:\tNo"
fi

if test "$use_openmax" != "no"; then
  final_message="$final_message\n  OpenMax:\tYes"
else
  final_message="$final_message\n  OpenMax:\tNo"
fi

if test "$use_joystick" = "yes"; then
  final_message="$final_message\n  Joystick:\tYes"
  SDL_DEFINES="$SDL_DEFINES -DHAS_SDL_JOYSTICK"
else
  final_message="$final_message\n  Joystick:\tNo"
fi

if test "$use_xrandr" = "yes"; then
  final_message="$final_message\n  XRandR:\tYes"
  USE_XRANDR=1
else
  final_message="$final_message\n  XRandR:\tNo"
  USE_XRANDR=0
fi

if test "$use_goom" = "yes"; then
  final_message="$final_message\n  GOOM:\t\tYes"
else
  final_message="$final_message\n  GOOM:\t\tNo"
fi

if test "$use_libbluray" = "yes"; then
  final_message="$final_message\n  Bluray:\tYes"
else
  final_message="$final_message\n  Bluray:\tNo"
fi

USE_TEXTUREPACKER_NATIVE=0
if test "x$use_texturepacker" != "xno"; then
  final_message="$final_message\n  TexturePacker:Yes"
  USE_TEXTUREPACKER=1
  if test "x$use_texturepacker_native" = "xyes"; then
    USE_TEXTUREPACKER_NATIVE=1
    if [[ ! -d "$USE_TEXTUREPACKER_NATIVE_ROOT" ]]; then 
      USE_TEXTUREPACKER_NATIVE_ROOT= 
    fi
  fi
else
  final_message="$final_message\n  TexturePacker:No"
  USE_TEXTUREPACKER=0
fi

if test "$use_mid" = "yes"; then
  final_message="$final_message\n  MID Support:\tYes"
  SDL_DEFINES="$SDL_DEFINES -DMID"
else
  final_message="$final_message\n  MID Support:\tNo"
fi

if test "x$use_ccache" != "xno"; then
  AC_PATH_PROG(CCACHE,ccache,none)
  if test "$ac_cv_path_CCACHE" = "none"; then
    if test "x$use_ccache" = "xyes"; then
      AC_MSG_ERROR([ccache not found.]);
    else
      AC_MSG_NOTICE([ccache not found. Falling back to default CC])
      final_message="$final_message\n  ccache:\tNo"
    fi
  else
    CC="$ac_cv_path_CCACHE $CC"
    CXX="$ac_cv_path_CCACHE $CXX"
    AC_MSG_NOTICE(enabling ccache)
    final_message="$final_message\n  ccache:\tYes"
  fi
else
  final_message="$final_message\n  ccache:\tNo"
fi

if test "x$use_pulse" != "xno"; then
  XBMC_STANDALONE_SH_PULSE=tools/Linux/xbmc-standalone.sh.pulse
  final_message="$final_message\n  PulseAudio:\tYes"
else
  XBMC_STANDALONE_SH_PULSE=/dev/null
  final_message="$final_message\n  PulseAudio:\tNo"
fi

if test "$use_hal" = "yes"; then
  final_message="$final_message\n  HAL Support:\tYes"
else
  final_message="$final_message\n  HAL Support:\tNo"
fi

# DVDCSS
if test "$use_dvdcss" = "yes"; then
  AC_MSG_NOTICE($dvdcss_enabled)
  final_message="$final_message\n  DVDCSS:\tYes"
  BUILD_DVDCSS=1
  SKIP_CONFIG_DVDCSS=0
  DVDREAD_CFLAGS="-D_XBMC -DHAVE_DVDCSS_DVDCSS_H"
else
  AC_MSG_NOTICE($dvdcss_disabled)
  final_message="$final_message\n  DVDCSS:\tNo"
  BUILD_DVDCSS=0
  SKIP_CONFIG_DVDCSS=1
  DVDREAD_CFLAGS="-D_XBMC -UHAVE_DVDCSS_DVDCSS_H"
fi
if test "$host_vendor" = "apple"; then
 DVDREAD_CFLAGS="$DVDREAD_CFLAGS -D__DARWIN__"
fi

if test "$use_avahi" = "yes"; then
  final_message="$final_message\n  Avahi:\tYes"
else
  final_message="$final_message\n  Avahi:\tNo"
fi

if test "$HAVE_GIT" = "yes"; then
  GIT_REV=$(git --no-pager log --abbrev=7 -n 1 --pretty=format:"%h %ci" HEAD | awk '{gsub("-", "");print $2"-"$1}')
fi
if test "$GIT_REV" = ""; then
  GIT_REV="Unknown"
fi
if test "$host_vendor" = "apple"; then
  echo "#define GIT_REV \"$GIT_REV\"" > git_revision.h
else
  SDL_DEFINES="$SDL_DEFINES -D'GIT_REV=\"$GIT_REV\"'"
fi

if test "$use_nonfree" = "yes"; then
  final_message="$final_message\n  Non-free:\tYes"
  HAVE_XBMC_NONFREE=1
  AC_DEFINE([HAVE_XBMC_NONFREE], [1], [Define to 1 to enable non-free components.])
else
  HAVE_XBMC_NONFREE=0
  final_message="$final_message\n  Non-free:\tNo"
fi

if test "$use_asap" = "yes"; then
  AC_CHECK_PROG(HAVE_GDC,gdc,"yes","no")
  if test "$HAVE_GDC" = "no"; then
    AC_MSG_ERROR($missing_program);
  fi
  AC_CHECK_PROG(HAVE_FPC,fpc,"yes","no")
  if test "$HAVE_FPC" = "no"; then
    AC_MSG_ERROR($missing_program);
  fi
  USE_ASAP_CODEC=1
  AC_DEFINE([USE_ASAP_CODEC], [1], [Define to 1 to enable ASAP codec.])
  final_message="$final_message\n  ASAP Codec:\tYes"
else
  USE_ASAP_CODEC=0
  final_message="$final_message\n  ASAP Codec:\tNo"
fi

if test "$use_webserver" = "yes"; then
  final_message="$final_message\n  Webserver:\tYes"
else
  final_message="$final_message\n  Webserver:\tNo"
fi

if test "$use_librtmp" != "no"; then
  final_message="$final_message\n  libRTMP support:\tYes"
else
  final_message="$final_message\n  libRTMP support:\tNo"
fi

if test "$use_libnfs" != "no"; then
  final_message="$final_message\n  libnfs support:\tYes"
else
  final_message="$final_message\n  libnfs support:\tNo"
fi


if test "$use_optical_drive" = "yes"; then
  final_message="$final_message\n  Optical drive:\tYes"
else
  final_message="$final_message\n  Optical drive:\tNo"
fi

### External libraries messages
if test "$use_external_ffmpeg" = "yes"; then
  final_message="$final_message\n  External FFmpeg:\tYes"
else
  final_message="$final_message\n  External FFmpeg:\tNo"
fi

OUTPUT_FILES="Makefile \
    Makefile.include \
    addons/skin.confluence/media/Makefile \
    xbmc/Makefile \
    xbmc/cdrip/Makefile \
    xbmc/cores/Makefile \
    xbmc/cores/VideoRenderers/Makefile \
    xbmc/cores/dvdplayer/Makefile \
    lib/Makefile \
    lib/libdvd/Makefile \
    xbmc/cores/DllLoader/Makefile \
    xbmc/cores/dvdplayer/DVDCodecs/Makefile \
    xbmc/cores/dvdplayer/DVDCodecs/Audio/Makefile \
    xbmc/cores/dvdplayer/DVDCodecs/Overlay/Makefile \
    xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile \
    xbmc/cores/dvdplayer/DVDDemuxers/Makefile \
    xbmc/cores/dvdplayer/DVDSubtitles/Makefile \
    xbmc/cores/AudioRenderers/Makefile \
    xbmc/cores/paplayer/Makefile \
    lib/timidity/Makefile \
    lib/xbadpcm/Makefile \
    lib/asap/Makefile \
    lib/nosefart/Makefile \
    lib/libsidplay2/Makefile \
    lib/vgmstream/Makefile \
    lib/snesapu/SNES/SNESAPU/Makefile \
    lib/stsound/StSoundLibrary/Makefile \
    xbmc/cores/playercorefactory/Makefile \
    xbmc/music/karaoke/Makefile \
    xbmc/osx/Makefile \
    xbmc/guilib/Makefile \
    xbmc/interfaces/Makefile \
    xbmc/network/Makefile \
    lib/libRTV/Makefile \
    lib/libexif/Makefile \
    lib/libXDAAP/Makefile \
    lib/cmyth/Makefile \
    lib/libhdhomerun/Makefile \
    lib/libsquish/Makefile \
    lib/libid3tag/Makefile \
    lib/cximage-6.0/Makefile \
    lib/addons/script.module.pil/Makefile \
    xbmc/interfaces/python/Makefile \
    xbmc/interfaces/python/xbmcmodule/Makefile \
    lib/libUPnP/Makefile \
    xbmc/DllPaths_generated.h \
    xbmc/linux/Makefile \
    xbmc/filesystem/Makefile \
    xbmc/screensavers/rsxs-0.9/xbmc/Makefile \
    xbmc/visualizations/XBMCProjectM/Makefile \
    xbmc/visualizations/Goom/Makefile \
    xbmc/visualizations/OpenGLSpectrum/Makefile \
    xbmc/visualizations/WaveForm/Makefile \
    xbmc/visualizations/iTunes/Makefile \
    tools/Linux/xbmc.sh \
    tools/Linux/xbmc-standalone.sh \
    tools/TexturePacker/Makefile \
    tools/EventClients/Clients/OSXRemote/Makefile"

# Line below is used so we can use AM_INIT_AUTOMAKE. The corresponding
# .dummy.am does nothing.
AC_CONFIG_FILES([.dummy])

AC_CONFIG_FILES([${OUTPUT_FILES}])
OUTPUT_FILES="$OUTPUT_FILES \
  .dummy"
AC_SUBST(CFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(INCLUDES)
AC_SUBST(LDFLAGS)
AC_SUBST(SDL_DEFINES)
AC_SUBST(BUILD_DVDCSS)
AC_SUBST(DISABLE_GOOM)
AC_SUBST(USE_EXTERNAL_FFMPEG)
AC_SUBST(PYTHON_VERSION)
AC_SUBST(OUTPUT_FILES)
AC_SUBST(HAVE_XBMC_NONFREE)
AC_SUBST(USE_ASAP_CODEC)
AC_SUBST(LIBCURL_BASENAME)
AC_SUBST(LIBFLAC_BASENAME)
AC_SUBST(LIBVORBISFILE_BASENAME)
AC_SUBST(LIBMODPLUG_BASENAME)
AC_SUBST(LIBMAD_BASENAME)
AC_SUBST(LIBOGG_BASENAME)
AC_SUBST(LIBVORBISENC_BASENAME)
AC_SUBST(LIBVORBIS_BASENAME)
AC_SUBST(LIBASS_BASENAME)
AC_SUBST(LIBMEPG2_BASENAME)
AC_SUBST_FILE(XBMC_STANDALONE_SH_PULSE)
AC_SUBST(USE_OPENGL)
AC_SUBST(USE_OPENGLES)
AC_SUBST(USE_VDPAU)
AC_SUBST(USE_VAAPI)
AC_SUBST(USE_CRYSTALHD)
AC_SUBST(USE_LIBNFS)
AC_SUBST(USE_VDA)
AC_SUBST(USE_OPENMAX)
AC_SUBST(USE_PULSE)
AC_SUBST(USE_XRANDR)
AC_SUBST(USE_TEXTUREPACKER)
AC_SUBST(USE_TEXTUREPACKER_NATIVE)
AC_SUBST(USE_TEXTUREPACKER_NATIVE_ROOT)

# pushd and popd are not available in other shells besides bash, so implement
# our own pushd/popd functions
XB_DIRSTACK="$PWD"
xb_pushd()
{
  local dirname="$1"
  if [[ -d "$dirname" ]] && [[ -x "$dirname" ]]; then
    cd "$dirname"
    XB_DIRSTACK="$dirname ${XB_DIRSTACK:-$PWD}"
    return 0
  else
    AC_MSG_ERROR(xb_pushd: unable to change to $dirname)
  fi
}
xb_popd()
{
  if [[ -n "$XB_DIRSTACK" ]]; then
    XB_DIRSTACK="${XB_DIRSTACK#* }"
    cd "${XB_DIRSTACK%% *}"
    return 0
  else
    AC_MSG_ERROR(xb_popd: unable to go back to previous directory)
  fi
}

# Function to run the configure scripts in our submodules
# Consists of three paramaters, the path to the submodule, the configure command
# with appropriate arguments, and a third parameter set to 1 if we are to skip
# running the script, anything else if not.
AC_DEFUN([XB_CONFIG_MODULE],[
AC_CONFIG_COMMANDS_POST([
if [[ $3 != "1" ]]; then
    if [[ -d $1 ]]; then
      xb_pushd $1
      $2
      if [[ $? -ne 0 ]]; then
        xb_popd
        AC_MSG_ERROR([[Submodule $1 failed to configure]])
      else
        xb_popd
      fi
    else
      AC_MSG_ERROR([[Submodule $1 does not exist]])
    fi
else
    AC_MSG_NOTICE([[Skipping configuration of submodule $1.]])
fi
])
])

XB_CONFIG_MODULE([lib/ffmpeg], [
  if test "$host_vendor" = "apple" ; then
    ./configure \
      --extra-cflags="$CFLAGS $FFMPEG_EXTRACFLAGS -w -D_DARWIN_C_SOURCE -Dattribute_deprecated=" \
      `if test "$use_arch" != "no"; then echo --enable-cross-compile; fi` \
      `if test "$use_arch" != "no"; then echo --arch=$use_arch; fi`\
      `if test "$use_cpu" != "no"; then echo --cpu=$use_cpu; fi`\
      --target-os=$(tolower $(uname -s)) \
      --disable-amd3dnow \
      --disable-armv5te \
      --disable-armv6t2 \
      `if test "$use_arch" != "yes"; then echo --enable-neon; fi`\
      --disable-static \
      `if test "$use_debug" = "no"; then echo --disable-debug; fi` \
      --disable-muxers \
      --enable-muxer=spdif \
      --enable-muxer=adts \
      --disable-encoders \
      --enable-encoder=ac3 \
      --enable-encoder=aac \
      `if test "$use_ffmpeg_libvorbis" == "yes"; then echo --enable-libvorbis --enable-muxer=ogg --enable-encoder=libvorbis; else echo --disable-libvorbis; fi` \
      --disable-devices \
      --disable-ffprobe \
      --disable-ffplay \
      --disable-ffserver \
      --disable-ffmpeg \
      --enable-shared \
      --disable-doc \
      --disable-decoder=mpeg_xvmc \
      --enable-postproc \
      --enable-gpl \
      --enable-protocol=http \
      --enable-pthreads \
      --enable-runtime-cpudetect \
      --cc="$CC" &&
    sed -i "" -e "s#YASM=yasm#YASM=${prefix}/bin/yasm#" config.mak &&
    sed -i "" -e "s#YASMDEP=yasm#YASMDEP=${prefix}/bin/yasm#" config.mak &&
    sed -i "" -e "s# -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 # #" config.mak
    if test "$use_arch" = "ppc"; then
      sed -i "" -e "s/HAVE_GNU_AS 1/HAVE_GNU_AS 0/" config.h
      sed -i "" -e "s/^HAVE_GNU_AS=yes/!HAVE_GNU_AS=yes/" config.mak
    fi
  else
    CFLAGS="" \
    LDFLAGS="$(echo "$LDFLAGS" | sed "s/-Wl,-Bsymbolic-functions//g")" \
    ./configure \
      --extra-cflags="$PASSED_CFLAGS $FFMPEG_EXTRACFLAGS" \
      --disable-static \
      `if test "$use_debug" = "no"; then echo --disable-debug; fi` \
      `if test "$cross_compiling" = "yes"; then echo --enable-cross-compile; fi` \
      `if test "$use_arch" != "no"; then echo --arch=$use_arch; fi`\
      `if test "$use_cpu" != "no"; then echo --cpu=$use_cpu; fi`\
      --target-os=$(tolower $(uname -s)) \
      --disable-muxers \
      --enable-muxer=spdif \
      --enable-muxer=adts \
      --disable-encoders \
      --enable-encoder=ac3 \
      --enable-encoder=aac \
      `if test "$use_ffmpeg_libvorbis" == "yes"; then echo --enable-libvorbis --enable-muxer=ogg --enable-encoder=libvorbis; else echo --disable-libvorbis; fi` \
      --disable-decoder=mpeg_xvmc \
      --disable-devices \
      --disable-ffprobe \
      --disable-ffplay \
      --disable-ffserver \
      --disable-ffmpeg \
      --enable-shared \
      --disable-doc \
      --enable-postproc \
      --enable-gpl \
      `if test "x$use_vdpau" != "xno"; then echo --enable-vdpau; else echo --disable-vdpau; fi` \
      `if test "x$use_vaapi" != "xno"; then echo --enable-vaapi; else echo --disable-vaapi; fi` \
      --enable-protocol=http \
      --enable-pthreads \
      --enable-runtime-cpudetect \
      --custom-libname-with-major="\$(FULLNAME)-\$(LIBMAJOR)-${ARCH}\$(SLIBSUF)" \
      `case $host_cpu in i?86*) echo --disable-pic ;; *) echo --enable-pic ;; esac` \
      --cc="$CC" &&
      sed -i -e "s#define HAVE_SYMVER 1#define HAVE_SYMVER 0#" config.h &&
      sed -i -e "s#define HAVE_SYMVER_GNU_ASM 1#define HAVE_SYMVER_GNU_ASM 0#" config.h
  fi
], [$USE_EXTERNAL_FFMPEG])

XB_CONFIG_MODULE([lib/libdvd/libdvdcss], [
  ./configure \
    CC="$CC" \
    CXX="$CXX" \
    CFLAGS="$CFLAGS" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --disable-doc \
    --enable-static \
    --with-pic
], [$SKIP_CONFIG_DVDCSS])

XB_CONFIG_MODULE([lib/libdvd/libdvdread], [
  ./configure2 \
    --extra-cflags="$CFLAGS $DVDREAD_CFLAGS -I`pwd`/../libdvdcss/src" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --enable-static \
    --disable-shared \
    --disable-strip \
    --disable-opts \
    --cc="$CC" &&
  $MAKE dvdread-config &&
  mkdir -p `pwd`/../includes/dvdread
  cp `pwd`/../libdvdread/src/*.h `pwd`/../includes/dvdread
], [0])

XB_CONFIG_MODULE([lib/libdvd/libdvdnav], [
  ./configure2 \
    --extra-cflags="$CFLAGS $DVDREAD_CFLAGS -I`pwd`/../includes" \
    --extra-ldflags="-L`pwd`/../libdvdread/obj" \
    --with-dvdread-config="`pwd`/../libdvdread/obj/dvdread-config" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --enable-static \
    --disable-shared \
    --cc="$CC"
], [0])

XB_CONFIG_MODULE([lib/libid3tag/libid3tag],[
  ./configure \
    CC="$CC" \
    CXX="$CXX" \
    CFLAGS="$CFLAGS" \ 
    CXXFLAGS="$CXXFLAGS" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --disable-static \
    --with-pic
], [0])

XB_CONFIG_MODULE([xbmc/visualizations/XBMCProjectM/libprojectM],[
if test "$use_gl" = "no"; then :; else
set -x
    rm -f CMakeCache.txt && CC="$CC" CXX="$CXX" cmake    \
      -DCMAKE_BUILD_TYPE=None -DUSE_FTGL:BOOL=OFF        \
      -DCMAKE_C_FLAGS:STRING="${CPPFLAGS} ${CFLAGS}"     \
      -DCMAKE_CXX_FLAGS:STRING="${CPPFLAGS} ${CXXFLAGS}" \
      -DCMAKE_INSTALL_PREFIX="${prefix}"                 \
      -DCMAKE_INSTALL_LIBDIR:PATH="${libdir}"            \
      -DINCLUDE_INSTALL_DIR:PATH="${includedir}"         \
      -DLIB_INSTALL_DIR:PATH="${libdir}"                 \
      -DSYSCONF_INSTALL_DIR:PATH="${sysconfdir}"         \
      -DSHARE_INSTALL_PREFIX:PATH="${datadir}" . &&
    if test "$host_vendor" = "apple" ; then
      # cmake has hardcoded paths to macports which bork our darwin depends cross/ppc, remove them
      sed -i "" -e "s|-L/opt/local/lib| |" CMakeFiles/projectM.dir/link.txt
      sed -i "" -e "s|-L/opt/local/lib| |" CMakeFiles/projectM.dir/flags.make
      sed -i "" -e "s|-I/opt/local/include| |" CMakeFiles/projectM.dir/flags.make
    fi
set +x
fi
], [0])

XB_CONFIG_MODULE([xbmc/visualizations/Goom/goom2k4-0],[
  ./configure  \
    CFLAGS="$CFLAGS" \ 
    CXXFLAGS="$CXXFLAGS" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --disable-shared \
    --enable-static \
    --with-pic
], [$DISABLE_GOOM])

XB_CONFIG_MODULE([xbmc/screensavers/rsxs-0.9/], [
if test "$use_gl" = "no"; then :; else
  ./configure \
    CC="$CC" \
    CXX="$CXX" \
    CFLAGS="$CFLAGS" \ 
    CXXFLAGS="$CXXFLAGS" \
    `if test "$host_vendor" = "apple"; then echo --x-includes=/usr/X11/include --x-libraries=/usr/X11/lib; fi` \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --without-xscreensaver \
    --disable-sound \
    --disable-cyclone \
    --disable-fieldlines \
    --disable-flocks \
    --disable-flux \
    --disable-helios \
    --disable-hyperspace \
    --disable-lattice \
    --disable-skyrocket
fi
], [0])

XB_CONFIG_MODULE([lib/libapetag], [
  ./configure \
    `if test "$host_vendor" = "apple"; then echo --disable-shared; fi` \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias CFLAGS="$CFLAGS" CC="$CC" CXX="$CXX"
], [0])

XB_CONFIG_MODULE([lib/cpluff], [
  ./configure --disable-nls \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias CFLAGS="$CFLAGS" CC="$CC" CXX="$CXX"
    #LDFLAGS="$LDFLAGS -Wl,-read_only_relocs,suppress"    
], [0])

AC_OUTPUT

final_message="$final_message\n  prefix:\t$prefix\n$dashes"
echo -e "$final_message\n"