dnl Process this file with autoconf to produce a configure script.

dnl initialization
AC_INIT([DVDStyler], [1.8.3], [www.dvdstyler.org])
AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE

dnl options
AM_OPTIONS_WXCONFIG
AC_ARG_ENABLE(debug, [  --enable-debug          Enable debugging information], USE_DEBUG="$enableval", USE_DEBUG="no")

AC_MSG_CHECKING(for install location)
case "$prefix" in
NONE)	AC_CACHE_VAL(m_cv_prefix,m_cv_prefix=$ac_default_prefix);;
*)	m_cv_prefix=$prefix ;;
esac
AC_MSG_RESULT($m_cv_prefix)
case "$m_cv_prefix" in /*) ;; *)
	AC_MSG_WARN([--prefix=$prefix must be an absolute path name, using $ac_default_prefix])
	m_cv_prefix=$ac_default_prefix
esac
prefix=$m_cv_prefix


dnl Checks for programs.
AC_LANG_CPLUSPLUS
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_RANLIB
AC_PROG_CC
AC_PROG_CXX
AC_PROG_CXXCPP
AC_PROG_LEX
AC_PROG_YACC
PKG_PROG_PKG_CONFIG()

dnl debug flags
case "$USE_DEBUG" in
yes)
  DEBUG_FLAGS="-g -Wall -DDEBUG"
  ;;    
*)
  DEBUG_FLAGS=""
  ;;
esac
CXXFLAGS="$CXXFLAGS $DEBUG_FLAGS -fno-strict-aliasing "

dnl check wxWidgets >= 2.8.7
AM_PATH_WXCONFIG([2.8.7], [WXFOUND=1], [WXFOUND=0], [html,core,net,adv,media])
if test "$WXFOUND" != 1; then
    AC_MSG_ERROR([
        Please check that wx-config is in path, the directory
        where wxWidgets libraries are installed (returned by
        'wx-config --libs' command) is in LD_LIBRARY_PATH or
        equivalent variable and wxWidgets is version 2.8.7 or above.
    ])
fi
CXXFLAGS="$CXXFLAGS $WX_CXXFLAGS "
CPPFLAGS="$CPPFLAGS $WX_CPPFLAGS "
LIBS="$LIBS $WX_LIBS "

dnl check for wxSVG
PKG_CHECK_MODULES(wxSVG, [libwxsvg >= 1.0.8], [LIBS="$LIBS $wxSVG_LIBS"], [AC_MSG_ERROR([*** missing wxSVG library >= 1.0.8 ***])])
AC_MSG_CHECKING([for wxSVG library with FFMPEG support])
WXSVGFFMPEG=no
AC_TRY_LINK(
    [#include <wxSVG/mediadec_ffmpeg.h>],
    [wxFfmpegMediaDecoder *a = new wxFfmpegMediaDecoder;],
    [WXSVGFFMPEG=yes], [WXSVGFFMPEG=no])
AC_MSG_RESULT([$WXSVGFFMPEG])
if test "x$WXSVGFFMPEG" = x"no"; then
  AC_MSG_ERROR([
    DVDStyler requires the wxSVG library with FFMPEG support.
])
fi

dnl check gnomeui-2.0
CHECK_WX_BUILT_WITH_GTK2()
if test x"$GTK_USEDVERSION" = x"2" ; then
  PKG_CHECK_MODULES(GNOMEUI2, libgnomeui-2.0, GNOME2="-DGNOME2",
    AC_MSG_WARN([libgnomeui will not be used for rendering of thumbnails]))
fi
CXXFLAGS="$CXXFLAGS $GNOME2"
LIBS="$LIBS $GNOMEUI2_LIBS "

dnl check libexif
PKG_CHECK_MODULES(LIBEXIF, libexif, [LIBS="$LIBS $LIBEXIF_LIBS"], [AC_MSG_ERROR([*** missing libexif ***])])

dnl check ffmpeg
PKG_CHECK_MODULES(FFMPEG, [libavformat >= 52.21.0 libavcodec >= 51.69.0 libavutil >= 49.10.0 libswscale])
dnl check path for old ffmpeg
AC_CHECK_HEADERS([ffmpeg/avutil.h])
CXXFLAGS="$CXXFLAGS $FFMPEG_CFLAGS"
LIBS="$LIBS $FFMPEG_LIBS"

PKG_CHECK_MODULES(FONTCONFIG, fontconfig)
CXXFLAGS="$CXXFLAGS $FONTCONFIG_CFLAGS"
LIBS="$LIBS $FONTCONFIG_LIBS"

PKG_CHECK_MODULES(LIBUDEV, libudev, [CXXFLAGS="$CXXFLAGS $LIBUDEV_CFLAGS -DHAVE_LIBUDEV";LIBS="$LIBS $LIBUDEV_LIBS"],
  AC_MSG_WARN([libudev will not be used to get list of devices]))

CXXFLAGS="$CXXFLAGS -DDATADIR=\\\"$datadir/$PACKAGE\\\""

dnl vars
AC_SUBST(LDFLAGS)
AC_SUBST(CFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(WX_CONFIG_NAME)

dnl check msgfmt
AC_PATH_PROG(MSGFMT_PATH, msgfmt)
if test "x$MSGFMT_PATH" = x; then
  AC_MSG_ERROR([
    DVDStyler requires gettext-tools.
    Please check that msgfmt is in path.
])
fi

dnl check xmlto
AC_PATH_PROG(XMLTO, xmlto)
if test "x$XMLTO" = x; then
  AC_MSG_ERROR([
    DVDStyler requires xmlto to build DocBook documentation.
    Please check that xmlto is in path.
])
fi

dnl check zip
AC_PATH_PROG(ZIP, zip)
if test "x$ZIP" = x; then
  AC_MSG_ERROR([
    DVDStyler requires zip to build html help file.
    Please check that zip is in path.
])
fi

dnl check dvdauthor
AC_PATH_PROG(DVDAUTHOR_PATH, dvdauthor)
if test "x$DVDAUTHOR_PATH" = x; then
  AC_MSG_ERROR([
    DVDStyler requires dvdauthor >= 0.6.10.
    Please check that dvdauthor is in path.
])
fi
AC_PATH_PROG(MKISOFS_PATH, mkisofs)
if test "x$MKISOFS_PATH" = x; then
  AC_MSG_ERROR([
    DVDStyler requires mkisofs (cdrtools).
    Please check that mkisofs is in path.
])
fi
AC_PATH_PROG(GROWISOFS_PATH, growisofs)
if test "x$GROWISOFS_PATH" = x; then
  AC_MSG_ERROR([
    DVDStyler requires growisofs (dvd+rw-tools).
    Please check that growisofs is in path.
])
fi

dnl create Makefiles
AC_OUTPUT([
  Makefile
  src/Makefile
  src/rc/Makefile
  wxVillaLib/Makefile
  locale/Makefile
  backgrounds/Makefile
  buttons/Makefile
  docs/Makefile
  objects/Makefile
  data/Makefile
  templates/Makefile
  src/Version.h
  Info.plist
])
