# (C) 2003-2008 BMP developers, see AUTHORS

AC_PREREQ([2.60])
AC_INIT([BMPx], [0.40.14], [http://bmpx.backtrace.info])
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([1.8])
AC_CONFIG_HEADERS([config.h])

# stash the configure arguments in config.h
AC_DEFINE_UNQUOTED(CONFIGURE_ARGS, "$ac_configure_args", [configure arguments])

# Check for compilers 
AC_LANG([C])
AC_LANG([C++])
AC_ISC_POSIX

# Various checks
AC_PROG_CXX
AC_PROG_CXX_C_O
AC_PROG_AWK
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

AC_FUNC_ALLOCA
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([argz.h arpa/inet.h fcntl.h float.h inttypes.h langinfo.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdio_ext.h stdlib.h string.h strings.h sys/param.h sys/socket.h sys/time.h unistd.h wchar.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_UID_T
AC_C_INLINE
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_C_VOLATILE
AC_CHECK_TYPES([ptrdiff_t])

AC_FUNC_ERROR_AT_LINE
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STAT
AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([__argz_count __argz_next __argz_stringify dup2 fdatasync ftime ftruncate getcwd gethostbyname gettimeofday localtime_r mempcpy memset mkdir munmap nl_langinfo rmdir select setlocale socket stpcpy strcasecmp strchr strcspn strdup strerror strncasecmp strrchr strstr strtol strtoul memmem access])

AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long, 8)
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(long long, 8)

AC_SUBST(SIZEOF_INT, "$ac_cv_sizeof_int")
AC_SUBST(SIZEOF_LONG, "$ac_cv_sizeof_long")
AC_SUBST(SIZEOF_SHORT, "$ac_cv_sizeof_short")
AC_SUBST(SIZEOF_LONG_LONG, "$ac_cv_sizeof_long_long")

AM_CONDITIONAL([HAVE_MEMMEM], [test "$ac_cv_func_memmem" = "yes"])

AC_SEARCH_LIBS([connect], socket)
AC_SEARCH_LIBS([getrpcbyname], nsl)

# i18n
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$PACKAGE", [Package])
GETTEXT_PACKAGE="$PACKAGE"
AC_SUBST(GETTEXT_PACKAGE)

IT_PROG_INTLTOOL([0.35.0])
AM_GLIB_GNU_GETTEXT

# Next 2 lines is a hack to prevent libtool checking for F77
m4_undefine([AC_PROG_F77])
m4_defun([AC_PROG_F77],[])

# Libtool
AC_DISABLE_STATIC
AC_ENABLE_SHARED
AC_PROG_LIBTOOL

####################################
########## BUILDING FLAGS ##########
####################################

dnl Avoid unnecessary linking.

AC_MSG_CHECKING([whether $LD accepts --as-needed])
case `$LD --as-needed -v 2>&1 </dev/null` in
*GNU* | *'with BFD'*)
  LDFLAGS="$LDFLAGS -Wl,--as-needed"
  AC_MSG_RESULT([yes])
  ;;
*)
  AC_MSG_RESULT([no])
  ;;
esac

dnl Optimize linking.

AC_MSG_CHECKING([whether $LD accepts -O1])
case `$LD -O1 -v 2>&1 </dev/null` in
*GNU* | *'with BFD'*)
  LDFLAGS="$LDFLAGS -Wl,-O1"
  AC_MSG_RESULT([yes])
  ;;
*)
  AC_MSG_RESULT([no])
  ;;
esac

AC_ARG_ENABLE([ld-workaround],
    [AS_HELP_STRING([--enable-ld-workaround], [Enable Linker workaround for GCC 4.0.X to 4.2.1 series , possible other. (default=disabled)])],
    [ld_workaround="$enableval"],
    [ld_workaround="no"]
)

if test "$ld_workaround" = "yes"; then
    LDFLAGS="$LDFLAGS -Wl,--noinhibit-exec"
fi

# Clear C[XX]FLAGS option
AC_ARG_ENABLE([default-cflags],
    [AS_HELP_STRING([--enable-default-cflags], [Don't reset C{XX}FLAGS for the build (default=enabled)])],
    [default_cflags="$enableval"],
    [default_cflags="yes"]
)

if test "$default_cflags" != "yes"; then 
    CFLAGS=""
    CXXFLAGS=""
fi

# Debian C[XX]FLAGS option
AC_ARG_ENABLE([debian-cflags],
    [AS_HELP_STRING([--enable-debian-cflags], [Enable debian build flags])],
    [debian_cflags="$enableval"],
    [debian_cflags="no"]
)

if test "$debian_cflags" = "yes"; then 
    CFLAGS="-Wall -g -std=c99 -pedantic -fno-strict-aliasing -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -fPIC"
    CXXFLAGS="-g -fno-strict-aliasing -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -fPIC"
fi

# Profilling
AC_ARG_ENABLE([profile],
    [AS_HELP_STRING([--enable-profile], [Enable Profiling support ***THIS IS A DEVELOPER OPTION*** Don't enable this if you don't need it (and if you don't know whether you do or not, then you dont!) (default=disabled)])],
    [enable_profile="$enableval"],
    [enable_profile="no"]
)

if test "$enable_profile" = "yes"; then
    C_COMMON_FLAGS="$C_COMMON_FLAGS -pg -fno-inline"
fi


# Debugging
AC_ARG_ENABLE([debug],
    [AS_HELP_STRING([--enable-debug], [Enable Debugging support (default=disabled)])],
    [enable_debug="$enableval"],
    [enable_debug="no"]
)

if test "$enable_debug" = "yes"; then
    C_COMMON_FLAGS="$C_COMMON_FLAGS -ggdb3"
    CFLAGS="$CFLAGS -ggdb3"
    AC_DEFINE([WITH_DEBUG], [], [Building with debug information])
fi
AM_CONDITIONAL([WITH_DEBUG], [test "$enable_debug" = "yes"])

# CFLAGS/CXXFLAGS
if test "$GCC" = "yes"; then
    dnl NOTE: We cannot use -pedantic with g++ because GST headers ()@#!@#
    dnl adds extra commas after the last item in enums

    C_COMMON_FLAGS="$C_COMMON_FLAGS -fno-strict-aliasing -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2"
    CFLAGS="$CFLAGS -std=c99 -pedantic"
else
    C_COMMON_FLAGS="$C_COMMON_FLAGS -Wall -D_FORTIFY_SOURCE=2"
fi

###########################################
########## REQUIRED DEPENDENCIES ##########
###########################################

# X11
AC_PATH_XTRA

if test "$no_x" = "yes" ; then
    AC_MSG_ERROR([X11 headers/libraries were not found])
else
    XLIB_LIBS='$(X_LIBS) $(X_PRE_LIBS) -lX11 $(X_EXTRA_LIBS)'
    AC_SUBST([XLIB_LIBS])
fi

# Boost
AX_BOOST_BASE([1.33.1])
AX_BOOST_FILESYSTEM
AX_BOOST_REGEX
AX_BOOST_IOSTREAMS

# tr1
AC_ARG_WITH([tr1],
    [AS_HELP_STRING([--with-tr1], [Use C++ TR1 extensions])],
    [use_tr1="$withval"],
    [use_tr1="no"]
)

have_tr1=no
if test "$use_tr1" = "yes"; then
  BMP_CHECK_TR1
  if test "$have_tr1" = "yes"; then
    AC_MSG_RESULT([available])
    AC_DEFINE([HAVE_TR1], [], [Define when having C++ tr1 extensions])
  else
    AC_MSG_RESULT([not available])
  fi
fi
AM_CONDITIONAL([HAVE_TR1], [test "$have_tr1" = "yes"])

# pkg-config
PKG_PROG_PKG_CONFIG
AC_ARG_WITH([pkgconfig-dir],
    [AS_HELP_STRING([--with-pkgconfig-dir@<:@=PATH@:>@], [pkgconfig file destination dir])],
    [pkgconfigdir="$withval"],
    [pkgconfigdir='$(libdir)/pkgconfig']
)
AC_SUBST([pkgconfigdir])

# libsoup
PKG_CHECK_MODULES([SOUP], [libsoup-2.2 >= 2.2.100])
BMP_CHECK_SOUP_EXTERN_C

# sqlite
PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.4])

# glib/glibmm/sigc++
PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.12.0 gobject-2.0 gthread-2.0 gmodule-2.0])
PKG_CHECK_MODULES([GLIBMM], [glibmm-2.4 >= 2.8.3])
PKG_CHECK_MODULES([SIGC], [sigc++-2.0 >= 2.0.0])

# Gtk+
PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.12.0])

# RSVG
PKG_CHECK_MODULES([RSVG], [librsvg-2.0 >= 2.14.0])

# GTKmm
PKG_CHECK_MODULES([GTKMM], [gtkmm-2.4 >= 2.12.0])

# libglademm 
PKG_CHECK_MODULES([GLADEMM], [libglademm-2.4 >= 2.6.0])

# cairomm
PKG_CHECK_MODULES([CAIROMM], [cairomm-1.0 >= 0.6.0])

# Network Manager
AC_ARG_WITH([nm],
    [AS_HELP_STRING([--with-nm], [With GNOME NetworkManager])],
    [use_nm="$withval"],
    [use_nm="no"]
)

have_nm=no
if test "x$use_nm" = "xyes"; then 
    PKG_CHECK_MODULES([NM], [NetworkManager >= 0.6.0], [have_nm="yes"], [have_nm="no"])
fi
if test "x$have_nm" = "xyes"; then 
    AC_DEFINE([HAVE_NM], [], [Network Manager support])
fi
AM_CONDITIONAL([HAVE_NM], [test "x$have_nm" = "xyes"])

# sexymm
AC_ARG_WITH(sexymm-prefix,
    AC_HELP_STRING([--with-sexymm-prefix], [path to libsexymm [default=/usr]]),
    [sexymm_prefix="$withval"],
    [sexymm_prefix="/usr"]
)

PKG_CHECK_EXISTS([libsexymm >= 0.1.9],
                 [have_sexymm_pc="yes"], [have_sexymm_pc="no"])

have_sexymm=yes
if test "$have_sexymm_pc" = "yes"; then
    PKG_CHECK_MODULES([SEXYMM], [libsexymm >= 0.1.9])
else
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
    ac_cxxflags_save=$CXXFLAGS
    CXXFLAGS="$CXXFLAGS -I$sexymm_prefix/include"
    ac_ldflags_save=$LDFLAGS
    LDFLAGS="$LDFLAGS -L$sexymm_prefix/lib"

    ac_cppflags_save=$CPPFLAGS
    CPPFLAGS="$CPPFLAGS -I."
    AC_CHECK_LIB([sexymm], [_init], [have_sexymm=yes], [AC_MSG_ERROR([libsexymm not found])])

    if test "$have_sexymm" = "yes"; then
        AC_DEFINE([HAVE_SEXYMM], [1], [have sexymm])
        SEXYMM_CFLAGS="-I$sexymm_prefix/include"
        SEXYMM_LIBS="-L$sexymm_prefix/lib -lsexymm"
    else
        have_sexymm=no
    fi

    CPPFLAGS=$ac_cppflags_save
    CXXFLAGS=$ac_cxxflags_save
    LDFLAGS=$ac_ldflags_save
    AC_LANG_RESTORE

    AC_SUBST([SEXYMM_CFLAGS])
    AC_SUBST([SEXYMM_LIBS])
fi
AM_CONDITIONAL([HAVE_SEXYMM], [test "$have_sexymm" = "yes"])

# Libxml
PKG_CHECK_MODULES([XML], [libxml-2.0 >= 2.6.1])

# GStreamer
PKG_CHECK_MODULES([GST], [gstreamer-0.10 >= 0.10.14 gstreamer-base-0.10 >= 0.10.14])
PKG_CHECK_MODULES([GST_PLUGINS_BASE], [gstreamer-plugins-base-0.10 >= 0.10.9])

# D-BUS
PKG_CHECK_MODULES([DBUS], [dbus-1 >= 0.93 dbus-glib-1 >= 0.61])
DEFAULT_DBUS_PREFIX=`pkg-config --variable=prefix dbus-1` 

AC_ARG_WITH([dbus-services-dir],
    [AS_HELP_STRING([--with-dbus-services-dir@<:@=PATH@:>@], [D-BUS services file destination dir])],
    [DBUS_SERVICES_DIR="$withval"],
    [DBUS_SERVICES_DIR="$DEFAULT_DBUS_PREFIX/share/dbus-1/services"]
)

if test "$with_dbus_services_dir" = ""; then 
    if test "$DEFAULT_DBUS_PREFIX" = ""; then
        AC_MSG_ERROR([Unable to determine D-BUS installation prefix for automatic discovery of the serivices dir. Please use --with-dbus-services-dir!])
    fi
fi
AC_SUBST([DBUS_SERVICES_DIR])
AC_DEFINE_UNQUOTED([DBUS_SERVICES_DIR], ["$DBUS_SERVICES_DIR"], [Directory for D-BUS service files])

# HAL
AC_ARG_ENABLE([hal],
    [AS_HELP_STRING([--enable-hal], [Enable usage of HAL for managing storage (default=enabled)])],
    [enable_hal="$enableval"],
    [enable_hal="yes"]
)

if test "$enable_hal" = "yes"; then
PKG_CHECK_EXISTS([hal >= 0.5.7.1 hal-storage >= 0.5.7.1],
                 [enable_hal="yes"], [enable_hal="no"])
fi

if test "$enable_hal" = "yes"; then
  BMP_CHECK_HAL_NEWPSI
  have_hal_058=0
  PKG_CHECK_MODULES([HAL], [hal >= 0.5.7.1 hal-storage >= 0.5.7.1])
  AC_DEFINE([HAVE_HAL], [], [Define if building with HAL support])

  PKG_CHECK_EXISTS([hal >= 0.5.8.1 hal-storage >= 0.5.8.1],
                   [have_hal_058=1], [have_hal_058=0])
  if test "$have_hal_058" = "1"; then
    AC_DEFINE([HAVE_HAL_058], [], [Defined when building with HAL >= 0.5.8.1])
  fi

fi
AM_CONDITIONAL([HAVE_HAL], [test "$enable_hal" = "yes"])
AM_CONDITIONAL([HAVE_HAL_058], [test "$have_hal_058" = "1"])

# Taglib
PKG_CHECK_MODULES([TAGLIB], [taglib >= 1.4])

# libsidplay (v1.x)
AC_ARG_ENABLE([sid],
    [AC_HELP_STRING([--enable-sid],[build BMP with .sid/.psid taglib support])],
    [have_sid="$enableval"],
    [have_sid="no"]
)

AC_ARG_WITH([sid-prefix],
    [AC_HELP_STRING([--with-sid-prefix],[sidplay prefix [default=/usr]])],
    [sid_prefix="$withval"],
    [sid_prefix="/usr"]
)

if test "$have_sid" != "no"; then

    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS

    AC_CHECK_LIB([sidplay], [C64_clockSpeed], [have_sid=yes], [have_sid=no])

    if test "$have_sid" = "yes"; then
        AC_DEFINE([HAVE_SID], [1], [have sid])
        SID_INCLUDES="-I$sid_prefix/sidplay"
        SID_LIBS="-L$sid_prefix/lib -lsidplay"
    else
        AC_MSG_ERROR([libsidplay 1.x not found!])
    fi

    AC_LANG_RESTORE
fi
AC_SUBST([SID_INCLUDES])
AC_SUBST([SID_LIBS])
AM_CONDITIONAL([HAVE_SID], [test "$have_sid" != "no"])

# ModPlug check
AC_ARG_ENABLE([modplug],
    [AC_HELP_STRING([--enable-modplug],[build BMP with modplug taglib support])],
    [have_mod="$enableval"],
    [have_mod="no"]
)

if test "$have_mod" != "no"; then
  PKG_CHECK_MODULES([MOD], [libmodplug >= 0.7])
  AC_DEFINE([HAVE_MOD], [1], [have mod])
fi
AM_CONDITIONAL([HAVE_MOD], [test "$have_mod" != "no"])

# SMlib/ICE
AC_ARG_ENABLE([sm],
    [AS_HELP_STRING([--enable-sm], [Enable session management using SMlib (default=enabled)])],
    [enable_sm="$enableval"],
    [enable_sm="yes"]
)

if test "$enable_sm" = "yes" ; then
    BMP_CHECK_SMLIB([],
        [AC_MSG_ERROR([Cannot find SMlib])]
    )

    AC_DEFINE([HAVE_SM], [1], [Define if building with SMlib support])
fi
AM_CONDITIONAL([HAVE_SM], [test "$enable_sm" = "yes"])

# Startup Notification
AC_ARG_ENABLE([sn],
    [AS_HELP_STRING([--enable-sn], [Enable Startup Notification (default=enabled)])],
    [enable_sn="$enableval"],
    [enable_sn="yes"]
)

if test "$enable_sn" = "yes"; then
    PKG_CHECK_MODULES([STARTUP_NOTIFY], [libstartup-notification-1.0 >= 0.8])
    AC_DEFINE([HAVE_STARTUP_NOTIFICATION], [], [Define when building with libstartup-notification])
    ENABLE_SN_DESKTOP="true"
else
    ENABLE_SN_DESKTOP="false"
fi
AC_SUBST([ENABLE_SN_DESKTOP])
AM_CONDITIONAL([HAVE_STARTUP_NOTIFICATION], [test "$enable_sn" = "yes"])

# Zip
AC_CHECK_PROG(ZIP, zip, zip)
if test "x$ZIP" != "x"; then
  AC_DEFINE([HAVE_ZIP], [], [Define if having ZIP])
fi
AM_CONDITIONAL([HAVE_ZIP], [test "x$ZIP" != "x"])

# libofa
PKG_CHECK_MODULES([LIBOFA], [libofa >= 0.9.3])

# libcdio (or cdparanoia)
have_cdparanoia=no
have_cdio=no

AC_ARG_WITH([cdparanoia-prefix],
      [AC_HELP_STRING([--with-cdparanoia-prefix],[cdparanoia prefix [default=/usr]])],
      [cdparanoia_prefix="$withval"],
      [cdparanoia_prefix="/usr"]
)

PKG_CHECK_EXISTS([libcdio_cdda >= 0.77],
                 [have_libcdio_pc="yes"], [have_libcdio_pc="no"])

if test "$have_libcdio_pc" = "yes"; then
  PKG_CHECK_MODULES([CDIO], [libcdio_cdda >= 0.70])
  have_cdio=yes
  AC_DEFINE([HAVE_CDIO], [1], [have cdio])
else
  cdparanoia_cdda_h=no
  CFLAGS_SAVE="$CFLAGS"
  CFLAGS="$CFLAGS -I$cdparanoia_prefix/include"

  AC_CHECK_HEADER([cdda_interface.h], [], [AC_CHECK_HEADER([cdda/cdda_interface.h], [cdparanoia_cdda_h=yes], [AC_MSG_ERROR([cdparanoia headers not found])])])
  AC_CHECK_LIB([cdda_interface], [cdda_open], [have_cdparanoia=yes], [AC_MSG_ERROR([cdparanoia libraries not found])])

  if test "$have_cdparanoia" = "yes"; then
          AC_DEFINE([HAVE_CDPARANOIA], [1], [have cdparaonia])
          CDPARANOIA_INCLUDES=""
          if test "$cdparanoia_cdda_h" = "yes"; then
            CDPARANOIA_INCLUDES="-I$cdparanoia_prefix/include/cdda"
          else
            CDPARANOIA_INCLUDES="-I$cdparanoia_prefix/include"
          fi
          CDPARANOIA_LIBS="-L$cdparanoia_prefix/lib -lcdda_interface"
  else
          AC_MSG_ERROR([cdparanoia not found!])
  fi
  CFLAGS="$CFLAGS_SAVE"
  AC_SUBST([CDPARANOIA_INCLUDES])
  AC_SUBST([CDPARANOIA_LIBS])
fi

###########################################
######### PLATFORM SPECIFICITIES ##########
###########################################

# Architecture
arch=unknown
arch_ia32=false
arch_powerpc=false
arch_64bit=false
big_endian=false

case $build_cpu in
    i386 | i486 | i586 | i686)
        arch=ia32
        arch_ia32=true
        AC_DEFINE([ARCH_IA32], [], [Defined if using x86 ASM])
    ;;
    powerpc)
        arch=powerpc
        arch_powerpc=true
        big_endian=true
        AC_DEFINE([ARCH_POWERPC], [], [Defined if using PPC ASM])
        AC_DEFINE([ARCH_IS_BIG_ENDIAN], [], [Defined if arch is big endian])
    ;;
    x86_64 | ia64)
        C_COMMON_FLAGS="$C_COMMON_FLAGS -fPIC"
        AC_DEFINE([ARCH_64BIT], [], [Define if having a 64bit based architecture])
        arch_64bit=true
    ;;
    *)
    ;;
esac
AM_CONDITIONAL([ARCH_POWERPC], [test "$arch" = "powerpc"])
AM_CONDITIONAL([ARCH_IA32], [test "$arch" = "ia32"])
AM_CONDITIONAL([ARCH_64BIT], [test "$arch_64bit" = "true"])
AM_CONDITIONAL([ARCH_IS_BIG_ENDIAN], [test "$big_endian" = "true"])

#########################
### Operating System ####
#########################

system=unknown
have_alsa=false
default_sink="autoaudiosink"
default_device="/dev/dsp"

case $host in
    *linux*)
      system=linux
      default_sink="alsasink"
      default_device="default"
      PKG_CHECK_MODULES([ALSA], [alsa >= 1.0.9])
      AC_DEFINE([HAVE_ALSA], [], [Define if ALSA is present])
      AC_DEFINE([HAVE_LINUX], [], [Define if building on FreeBSD])
      have_alsa=true
      ;;
    *freebsd*)
      system=freebsd
      default_sink="osssink"
      default_device="/dev/dsp"
      AC_DEFINE([HAVE_FREEBSD], [], [Define if building on FreeBSD])
      ;;
    *netbsd*)
      system=netbsd
      default_sink="osssink"
      default_device="/dev/dsp"
      AC_DEFINE([HAVE_NETBSD], [], [Define if building on NetBSD])
      ;;
    *dragonfly*)
      system=dragonflybsd
      default_sink="osssink"
      default_device="/dev/dsp"
      AC_DEFINE([HAVE_DRAGONFLYBSD], [], [Define if building on DragonFlyBSD])
      ;;
    *-*-solaris* | *-*-sunos*)
      system=solaris
      default_sink="sunaudiosink"
      default_device="/dev/audio"
      AC_DEFINE([HAVE_SUN], [], [Define if building on Solaris/SunOS])
      ;;
    *)
      ;;
esac

AM_CONDITIONAL([HAVE_NM], [test x$HAVE_NM = xyes])
AM_CONDITIONAL([HAVE_CDPARANOIA], [test "$have_cdparanoia" != "no"])
AM_CONDITIONAL([HAVE_CDIO], [test "$have_cdio" != "no"])

AM_CONDITIONAL([HAVE_SUN], [test "$system" = "solaris"])
AM_CONDITIONAL([HAVE_FREEBSD], [test "$system" = "freebsd"])
AM_CONDITIONAL([HAVE_NETBSD], [test "$system" = "netbsd"])
AM_CONDITIONAL([HAVE_DRAGONFLYBSD], [test "$system" = "dragonflybsd"])
AM_CONDITIONAL([HAVE_LINUX], [test "$system" = "linux"])

AC_DEFINE_UNQUOTED(DEFAULT_SINK, "$default_sink", [default sink])
AC_DEFINE_UNQUOTED(DEFAULT_DEVICE_OSS, "/dev/dsp0", [default oss device])
AC_DEFINE_UNQUOTED(DEFAULT_DEVICE_ALSA, "default", [default alsa device])
AC_DEFINE_UNQUOTED(DEFAULT_DEVICE_SUN, "/dev/audio", [default sun device])
AC_DEFINE_UNQUOTED(DEFAULT_DEVICE_ESD, "localhost", [default esd device])

DEFAULT_SINK=$default_sink
DEFAULT_DEVICE=$default_device

AC_SUBST(DEFAULT_SINK)
AC_SUBST(DEFAULT_DEVICE)

# Multimedia keys
PKG_CHECK_MODULES([XPROTO], [xproto >= 7.0.10])

# BMP 
AC_SUBST([abs_top_srcdir])
AC_SUBST([abs_top_builddir])

PREFIX=${prefix}
PLUGIN_DIR=${libdir}/${PACKAGE}/plugins
LOCALE_DIR=${localedir}
DATA_DIR=${pkgdatadir}
AC_SUBST([PREFIX])
AC_SUBST([PLUGIN_DIR])
AC_SUBST([LOCALE_DIR])
AC_SUBST([DATA_DIR])

AX_DEFINE_UNQUOTED([PREFIX], [${prefix}], [The installation prefix])
AX_DEFINE_UNQUOTED([PLUGIN_DIR], [${libdir}/${PACKAGE}/plugins], [Plugins path])
AX_DEFINE_UNQUOTED([LOCALE_DIR], [${localedir}], [The locale directory])
AX_DEFINE_UNQUOTED([DATA_DIR], [${prefix}/share/${PACKAGE}], [Data directory])

BMP_DBUS_SERVICE_="\"org.mpris.bmp\""

BMP_DBUS_INTERFACE__MPRIS_="\"org.freedesktop.MediaPlayer\""
BMP_DBUS_PATH__MPRIS_ROOT_="\"/\""
BMP_DBUS_PATH__MPRIS_PLAYER_="\"/Player\""
BMP_DBUS_PATH__MPRIS_TRACKLIST_="\"/TrackList\""

BMP_DBUS_INTERFACE__BMP_="\"org.beepmediaplayer.bmp\""
BMP_DBUS_PATH__BMP_="\"/BMP\""

AC_SUBST(BMP_DBUS_PATH__MPRIS_ROOT_)
AC_SUBST(BMP_DBUS_PATH__MPRIS_PLAYER_)
AC_SUBST(BMP_DBUS_PATH__MPRIS_TRACKLIST_)
AC_SUBST(BMP_DBUS_PATH__BMP_)
AC_SUBST(BMP_DBUS_INTERFACE__MPRIS_)
AC_SUBST(BMP_DBUS_INTERFACE__BMP_)
AC_SUBST(BMP_DBUS_SERVICE_)

AC_DEFINE([PLUGIN_VERSION], [6], [Plugin Version])

# MCS stubs
AC_DEFINE([HAVE_BMP], [1], [Defined when having BMP])
AC_DEFINE([HAVE_XML], [1], [Defined when having libxml2])
AC_DEFINE([HAVE_GTK], [1], [Defined when having GTK2])
AM_CONDITIONAL([HAVE_BMP], [test "$PACKAGE" = "bmpx"])
AM_CONDITIONAL([HAVE_XML], [test "1" = "1"]) 
AM_CONDITIONAL([HAVE_GTK], [test "1" = "1"])

# BMP User Manual Pages
AC_ARG_WITH([xsl-prefix],
    [AC_HELP_STRING([--with-xsl-prefix],[docbook xsl prefix])],
    [xsl_prefix="$withval"],
    [xsl_prefix=""]
)

AC_ARG_ENABLE([doc],
    [AS_HELP_STRING([--enable-doc], [Generate documentation (default=enabled)])],
    [enable_doc="$enableval"],
    [enable_doc="yes"]
)

generate_documentation="no"
if test "$enable_doc" = "yes"; then
    AC_CHECK_PROG(XSLTPROC, xsltproc, xsltproc)
    if test "x$XSLTPROC" != "x"; then
      AC_DEFINE([GENERATE_DOC], [], [Define if having xsltproc])
      # Look in common places for xsl stylesheets
      for i in /usr/share/xml/docbook/stylesheet/nwalsh \
           /usr/share/sgml/docbook/stylesheet/xsl/nwalsh \
           /usr/share/sgml/docbook/xsl-stylesheets \
           /usr/local/share/xsl/docbook \
           $xsl_prefix;
      do
        if test -f "$i/xhtml/chunk.xsl"; then
          DOCBOOK_ROOT="$i"
          generate_documentation="yes"
        fi
      done
    fi
fi
AM_CONDITIONAL([GENERATE_DOC], [test "$generate_documentation" = "yes"])
AC_SUBST(XSLTPROC)
AC_SUBST(DOCBOOK_ROOT)

CFLAGS="$CFLAGS $C_COMMON_FLAGS"
CXXFLAGS="$CXXFLAGS $C_COMMON_FLAGS"

AC_OUTPUT([

    Makefile

    scripts/Makefile

    include/Makefile

    include/bmp/Makefile
    include/bmp/types/Makefile
    include/bmp/dbus.hh

    remote/Makefile
    sentinel/Makefile
    widgets/Makefile
    libhal++/Makefile
    mcs/Makefile
    jnetlib/Makefile
    json/Makefile

    src/Makefile
    src/parser/Makefile
    src/musicbrainz/Makefile
    src/audio/Makefile
    src/dbus-obj-BMP.xml
    src/dbus-obj-root.xml
    src/dbus-obj-player.xml
    src/dbus-obj-tracklist.xml

    plugins/Makefile
    plugins/vfs/Makefile
    plugins/vfs/container/Makefile
    plugins/vfs/transport/Makefile

    plugins/taglib/Makefile
    plugins/taglib/id3v2/Makefile
    plugins/taglib/xiph/Makefile
    plugins/taglib/common/Makefile
    plugins/taglib/mp4/Makefile
    plugins/taglib/asf/Makefile
    plugins/taglib/sid/Makefile
    plugins/taglib/mod/Makefile
    plugins/taglib/ogg/Makefile
    plugins/taglib/flac/Makefile
    plugins/taglib/mp3/Makefile
    plugins/taglib/mpc/Makefile

    data/Makefile

    data/glade/Makefile

    data/icons/Makefile
    data/icons/tray-icons/Makefile
    data/icons/themes/Makefile
    data/icons/themes/plastic/Makefile
    data/icons/themes/display/Makefile
    data/icons/themes/red/Makefile
    data/icons/themes/tango/Makefile
    data/icons/themes/darksphere/Makefile

    data/images/Makefile
    data/images/cdda/Makefile
    data/images/lastfm/Makefile
    data/images/main/Makefile
    data/images/podcast/Makefile
    data/images/svg/Makefile
    data/images/rating/Makefile
    data/images/sources/Makefile
    data/images/stock/Makefile

    data/desktop/Makefile
    data/desktop/bmp-2.0.desktop
    data/desktop/bmp-2.0-offline.desktop
    data/desktop/bmp-play-2.0.desktop

    xpi/Makefile
    xpi/chrome/content/bmp/BMPOverlay.js
    xpi/chrome/Makefile
    xpi/chrome/skin/Makefile
    xpi/chrome/skin/classic/Makefile
    xpi/chrome/skin/classic/bmp/Makefile
    xpi/chrome/content/Makefile
    xpi/chrome/content/bmp/Makefile

    po/Makefile.in

    docs/Makefile
    docs/images/Makefile
    docs/chapters/Makefile
    docs/xsl/Makefile
    docs/xsl/bump.xsl

    bmp-2.0.pc
    beep-media-player-2.1
    bmpx.spec
])


echo
echo "BMPx Build Configuration"
echo "========================"
echo
echo "    C compiler flags.............: $CFLAGS"
echo "    C++ compiler flags...........: $CXXFLAGS"
echo "    Linker flags.................: $LDFLAGS"
if test "$ld_workaround" = "no"; then
echo "      ** Linker workarounds are disabled. Do *NOT* report *ANY* linking errors"
echo "      ** when building with gcc 4.0.X - 4.2.1 and binutils >=2.17.X."
echo
fi
echo "    Documentation generation.....: $generate_documentation"
echo
echo "    Audio: Default Sink..........: $default_sink (device $default_device)"
echo
echo "    X Session Management.........: $enable_sm"
echo "    Startup-notification Support.: $enable_sn"
echo "    HAL Storage Management.......: $enable_hal" 
echo -n "    Optional taglib plugins......:" 
if test "$have_sid" = "yes"; then
echo -n " SID/PSID "
taglib_warning=yes
fi
if test "$have_mod" = "yes"; then
echo -n " MOD/S3M/XM/IT "
taglib_warning=yes
fi
if test "$taglib_warning" = "yes"; then
echo
echo "      ** You will need to install the corresponding GStreamer plugins to be" 
echo "      ** able to play these formats; the support indicated is just for metadata"
echo "      ** reading" 
fi
echo
