dnl ***************************************************************************
dnl *** configure.in for MATE-APPLETS                                      ***
dnl ***************************************************************************
AC_INIT(mate-applets, 1.5.1)
AC_PREREQ(2.59)

AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE([1.9 tar-ustar])
AC_CONFIG_MACRO_DIR(m4)

dnl ***************************************************************************
dnl *** Minimum library versions for MATE-APPLETS                          ***
dnl ***************************************************************************
GTK_REQUIRED=2.20.0
GLIB_REQUIRED=2.22.0
GIO_REQUIRED=2.15.3
LIBPANEL4_REQUIRED=1.5.2
LIBGTOP_REQUIRED=2.11.92
LIBXKLAVIER_REQUIRED=4.0
LIBMATEWNCK_REQUIRED=1.3.0
LIBMATE_DESKTOP_REQUIRED=1.1.0
LIBMATENOTIFY_REQUIRED=1.1.0
HAL_REQUIRED=0.5.3
UPOWER_REQUIRED=0.9.4
DBUS_REQUIRED=1.1.2
DBUS_GLIB_REQUIRED=0.74
PYGTK_REQUIRED=2.6
PYGOBJECT_REQUIRED=2.6
MATE_ICON_THEME_REQUIRED=1.1.0
LIBXML_REQUIRED=2.5.0
GUCHARMAP2_REQUIRED=2.23.0
GUCHARMAP_REQUIRED=1.4.0
POLKIT_REQUIRED=0.92
NETWORKMANAGER_REQUIRED=0.7
dnl ***************************************************************************

AM_MAINTAINER_MODE

IT_PROG_INTLTOOL([0.35.0])
PKG_PROG_PKG_CONFIG([0.19])

AC_PROG_CC
AC_ISC_POSIX
AC_STDC_HEADERS
AM_PROG_LIBTOOL
AC_PATH_XTRA
AM_PATH_PYTHON(2.4)
AM_CHECK_PYTHON_HEADERS(HAVE_PYHDRS="yes", HAVE_PYHDRS="no")

X_LIBS="$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS"
AC_SUBST(X_LIBS)

MATE_COMPILE_WARNINGS

dnl Check for non-portable headers
AC_CHECK_HEADERS([pty.h values.h])

dnl ***************************************************************************
dnl *** --enable-more-warnings turns on more compiler warnings              ***
dnl ***************************************************************************
AC_ARG_ENABLE(more-warnings,
[  --enable-more-warnings  Maximum compiler warnings],
set_more_warnings="$enableval",[
    set_more_warnings=no
])
AC_MSG_CHECKING(for more warnings, including -Werror)
if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
    AC_MSG_RESULT(yes)
    CFLAGS="\
    -Wall \
    -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes \
    -Wnested-externs -Wpointer-arith \
    -Wcast-align -Wsign-compare \
    -std=gnu89 \
    $CFLAGS"

    for option in -Wno-strict-aliasing -Wno-sign-compare; do
        SAVE_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS $option"
        AC_MSG_CHECKING([whether gcc understands $option])
        AC_TRY_COMPILE([], [],
            has_option=yes,
            has_option=no,)
        if test $has_option = no; then
            CFLAGS="$SAVE_CFLAGS"
        fi
        AC_MSG_RESULT($has_option)
        unset has_option
        unset SAVE_CFLAGS
    done
    unset option
else
    AC_MSG_RESULT(no)
fi
dnl ***************************************************************************

dnl ***************************************************************************
dnl *** Use pkg-config to check for dependancies                            ***
dnl ***************************************************************************

dnl -- Check for mate-icon-theme (required) ----------------------------------
PKG_CHECK_MODULES(GIT, mate-icon-theme >= $MATE_ICON_THEME_REQUIRED)

dnl -- check for gio (required) ------------------------------------------
PKG_CHECK_MODULES(GIO, gio-2.0 >= $GIO_REQUIRED gio-unix-2.0)
AC_SUBST(GIO_CFLAGS)
AC_SUBST(GIO_LIBS)

dnl -- Check for GTK+ 2.0 (required) ------------------------------------------
PKG_CHECK_MODULES(GTK, gtk+-2.0 >= $GTK_REQUIRED)
AC_SUBST(GTK_FLAGS)
AC_SUBST(GTK_LIBS)

dnl -- check for libmatepanelapplet4 (required) ------------------------------------
PKG_CHECK_MODULES(MATE_APPLETS4, libmatepanelapplet-4.0 >= $LIBPANEL4_REQUIRED)
AC_SUBST(MATE_APPLETS4_CFLAGS)
AC_SUBST(MATE_APPLETS4_LIBS)

dnl -- check for mate-desktop (required) -------------------------------------
PKG_CHECK_MODULES(MATEDESKTOP, mate-desktop-2.0 >= $LIBMATE_DESKTOP_REQUIRED)
AC_SUBST(MATEDESKTOP_CFLAGS)
AC_SUBST(MATEDESKTOP_LIBS)

dnl -- check for libgtop (optional) -------------------------------------------
build_gtop_applets=false
PKG_CHECK_MODULES(GTOP_APPLETS,
                 [libgtop-2.0 >= $LIBGTOP_REQUIRED],
                 build_gtop_applets=true,
		 AC_MSG_WARN([libgtop not found. Not building gtop applets.]))
AC_SUBST(GTOP_APPLETS_CFLAGS)
AC_SUBST(GTOP_APPLETS_LIBS)
AM_CONDITIONAL(BUILD_GTOP_APPLETS, $build_gtop_applets)

dnl -- check for mate-settings-daemon (optional) -----------------------------
PKG_CHECK_MODULES(MATE_SETTINGS_DAEMON, mate-settings-daemon,
	HAVE_MATE_SETTINGS_DAEMON=yes, HAVE_MATE_SETTINGS_DAEMON=no)

if test "x$HAVE_MATE_SETTINGS_DAEMON" = "xno"; then
	AC_MSG_WARN([mate-settings-daemon DBUS API is required to build modem-applet.])
fi

AC_SUBST(MATE_SETTINGS_DAEMON_CFLAGS)
AC_SUBST(MATE_SETTINGS_DAEMON_LIBS)

dnl -- check for libmatewnck (required) -------------------------------------------
PKG_CHECK_MODULES(LIBMATEWNCK, libmatewnck >= $LIBMATEWNCK_REQUIRED,,
	AC_MSG_ERROR([libmatewnck is required to build mate-applets.], 1))

AC_SUBST(LIBMATEWNCK_CFLAGS)
AC_SUBST(LIBMATEWNCK_LIBS)

dnl -- check for libmatenotify (optional) -----------------------------------------
LIBMATENOTIFY_CFLAGS=
LIBMATENOTIFY_LIBS=
PKG_CHECK_MODULES(LIBMATENOTIFY, libmatenotify >= $LIBMATENOTIFY_REQUIRED,
		  HAVE_LIBMATENOTIFY="yes", HAVE_LIBMATENOTIFY="no")

if test "x$HAVE_LIBMATENOTIFY" = "xyes"; then
	AC_DEFINE(HAVE_LIBMATENOTIFY, 1, [libmatenotify available])
fi

AC_SUBST(LIBMATENOTIFY_CFLAGS)
AC_SUBST(LIBMATENOTIFY_LIBS)

dnl -- check for glib/gobject (required) --------------------------------------
PKG_CHECK_MODULES(CPUFREQ_SELECTOR, glib-2.0 >= $GLIB_REQUIRED gobject-2.0 >= $GLIB_REQUIRED)
AC_SUBST(CPUFREQ_SELECTOR_CFLAGS)
AC_SUBST(CPUFREQ_SELECTOR_LIBS)

dnl -- check for dbus (required for cpufreq-selector)
PKG_CHECK_MODULES(DBUS, dbus-1 >= $DBUS_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED, HAVE_DBUS=yes, HAVE_DBUS=no)

AC_SUBST(DBUS_CFLAGS)
AC_SUBST(DBUS_LIBS)

dnl -- check for PolicyKit and PolicyKit-mate (optional) -----------------------------------------
POLKIT_CFLAGS=
POLKIT_LIBS=
AC_ARG_ENABLE([polkit],
    AC_HELP_STRING([--enable-polkit], [Enable PolicyKit support @<:@default auto@:>@]),
    enable_polkit=$enableval,
    enable_polkit=auto)
if test "x$enable_polkit" != "xno"; then
    PKG_CHECK_MODULES(POLKIT, polkit-gobject-1 >= $POLKIT_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED, HAVE_POLKIT=yes, HAVE_POLKIT=no)
    if test "x$enable_polkit" = "xyes" -a "x$HAVE_POLKIT" = "xno"; then
        AC_MSG_ERROR([PolicyKit support explicitly requested but dependencies not found])
    fi
fi
dnl - This is only so the printout at the end of configure is correct -
if test "x$enable_polkit" = "xno"; then
   HAVE_POLKIT=no
fi
if test "x$HAVE_POLKIT" = "xyes"; then
    AC_DEFINE(HAVE_POLKIT, [1], [PolicyKit available])
fi
AM_CONDITIONAL(HAVE_POLKIT, test "x$HAVE_POLKIT" = "xyes")
AC_SUBST(POLKIT_CFLAGS)
AC_SUBST(POLKIT_LIBS)


dnl -- check for libhal (optional) --------------------------------------------
HAL_CFLAGS=
HAL_LIBS=
AC_ARG_WITH(hal,[  --without-hal           build without hal support])

if test "x$with_hal" != xno; then
	PKG_CHECK_MODULES(HAL, hal >= $HAL_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED,
		  HAVE_HAL="yes",
		  HAVE_HAL="no")

	if test "x$HAVE_HAL" = "xyes"; then
		AC_DEFINE(HAVE_HAL, 1, [HAL available])
	fi
else
	AC_MSG_WARN(["Hal support disabled"])
fi

AC_SUBST(HAL_CFLAGS)
AC_SUBST(HAL_LIBS)

dnl -- checkf or libupower-glib (optional) ------------------------------------
UPOWER_CFLAGS=
UPOWER_LIBS=
AC_ARG_WITH(upower, [   --without-upower           build without upower support])

if test "x$with_upower" != xno; then
   PKG_CHECK_MODULES(UPOWER, upower-glib >= $UPOWER_REQUIRED,
         HAVE_UPOWER="yes",
         HAVE_UPOWER="no")
         
   if test "x$HAVE_UPOWER" = "xyes"; then
       AC_DEFINE(HAVE_UPOWER, 1, [UPOWER available])
   fi
else
   AC_MSG_WARN(["upower support disabled"])
fi

AC_SUBST(UPOWER_CFLAGS)
AC_SUBST(UPOWER_LIBS)

dnl -- check for gucharmap (optional) -----------------------------------------

PKG_CHECK_EXISTS([gucharmap-2 >= $GUCHARMAP2_REQUIRED],
                 [have_gucharmap=yes have_gucharmap_2=yes],[have_gucharmap_2=no])
if test "$have_gucharmap_2" = "yes"; then
      PKG_CHECK_MODULES([GUCHARMAP],[gucharmap-2 >= $GUCHARMAP2_REQUIRED])
else
      PKG_CHECK_MODULES([GUCHARMAP], [gucharmap >= $GUCHARMAP_REQUIRED],
                        [have_gucharmap=yes],[have_gucharmap=no])
fi

if test "$have_gucharmap_2" = "yes"; then
        AC_DEFINE([HAVE_GUCHARMAP_2],[1],[Define if gucharmap API is version 2])
fi
if test "$have_gucharmap" = "yes"; then
	AC_DEFINE([HAVE_GUCHARMAP],[1],[Gucharmap Available])
else
  AC_MSG_WARN([*** 'charpick' applet will not be built with gucharmap support ***])
fi
AC_SUBST(GUCHARMAP_CFLAGS)
AC_SUBST(GUCHARMAP_LIBS)

dnl -- check for Python modules (optional) ------------------------------
PYGTK_CFLAGS=
PYGTK_LIBS=
PKG_CHECK_MODULES(PYGTK,
	pygtk-2.0	>= $PYGTK_REQUIRED
	pygobject-2.0	>= $PYGOBJECT_REQUIRED,
	HAVE_PYGTK="yes", HAVE_PYGTK="no")
AC_SUBST(PYGTK_LIBS)
AC_SUBST(PYGTK_CFLAGS)

dnl -- check for libxml2 (required) ------------------------------------------
PKG_CHECK_MODULES(XML2, libxml-2.0 >= $LIBXML_REQUIRED)
AC_SUBST(XML2_CFLAGS)
AC_SUBST(XML2_LIBS)

 dnl -- check for libmateweather (required for mateweather applet) ------------------
build_libmateweather_applets=false
PKG_CHECK_MODULES(LIBMATEWEATHER, mateweather >= 1.5.0,
	          build_libmateweather_applets=true,
		  AC_MSG_WARN([libmateweather not found. Not building the weather applet.]))
AC_SUBST(LIBMATEWEATHER_CFLAGS)
AC_SUBST(LIBMATEWEATHER_LIBS)
AM_CONDITIONAL(BUILD_LIBMATEWEATHER_APPLETS, $build_libmateweather_applets)

dnl -- check for NetworkManager -----------------------------------------------
AC_ARG_ENABLE([networkmanager],
	AC_HELP_STRING([--enable-networkmanager],
	[Enable NetworkManager support @<:@default=yes@:>@]),
	ENABLE_NETWORKMANAGER=$enableval, ENABLE_NETWORKMANAGER=yes)

HAVE_NETWORKMANAGER=no
NETWORKMANAGER_VERSION=unknown
AC_SUBST(NETWORKMANAGER_VERSION)
if test "x$ENABLE_NETWORKMANAGER" = "xyes"; then
   PKG_CHECK_MODULES(NETWORKMANAGER, NetworkManager >= $NETWORKMANAGER_REQUIRED,
   		HAVE_NETWORKMANAGER=yes, HAVE_NETWORKMANAGER=no)

   if test "x$HAVE_NETWORKMANAGER" = "xyes"; then
      AC_DEFINE(HAVE_NETWORKMANAGER, 1, [NetworkManager available])
      NETWORKMANAGER_VERSION=`$PKG_CONFIG --modversion NetworkManager`
      AC_SUBST(NETWORKMANAGER_CFLAGS)
      AC_SUBST(NETWORKMANAGER_LIBS)
      AC_SUBST(NETWORKMANAGER_VERSION)
   fi
fi

dnl ***************************************************************************
dnl *** find paths to installed binaries                                    ***
dnl ***************************************************************************

dnl -- gdk-pixbuf-csource -----------------------------------------------------
AC_PATH_PROG(GDK_PIXBUF_CSOURCE, gdk-pixbuf-csource, no)

if test x"$GDK_PIXBUF_CSOURCE" = xno; then
  AC_MSG_ERROR([gdk-pixbuf-csource executable not found in your path - should be installed with GTK])
fi
AC_SUBST(GDK_PIXBUF_CSOURCE)

dnl -- glib-genmarshal --------------------------------------------------------
AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)

dnl -- xsltproc ---------------------------------------------------------------
AC_PATH_PROG(XSLTPROC, xsltproc, no)
if test x"$XSLTPROC" = xno; then
  AC_MSG_ERROR([xsltproc executable not found in your path - should be installed with libxslt])
fi

dnl -- jw ---------------------------------------------------------------------
AC_PATH_PROG(JW, jw, no)
if test x$JW = xno; then
  HAVE_JW="no"
else
  HAVE_JW="yes"
fi
AM_CONDITIONAL(HAVE_JW, test "x$HAVE_JW" = "xyes")
AC_SUBST(HAVE_JW)

dnl ***************************************************************************
dnl *** GSettings                                                               ***
dnl ***************************************************************************
GLIB_GSETTINGS

dnl ***************************************************************************
dnl *** Set up gettext                                                      ***
dnl ***************************************************************************

GETTEXT_PACKAGE=mate-applets
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Gettext Package])
AC_DEFINE_DIR(MATELOCALEDIR, "${datadir}/locale", [locale directory])
AM_GLIB_GNU_GETTEXT

# this is the directory where the *.{mo,gmo} files are installed
matelocaledir='${prefix}/${DATADIRNAME}/locale'
AC_SUBST(matelocaledir)

dnl ***************************************************************************
dnl *** mate-doc-utils                                                     ***
dnl ***************************************************************************
MATE_DOC_INIT

dnl ***************************************************************************
dnl *** battstat specific checks                                            ***
dnl ***************************************************************************

dnl --disable-battstat=(yes|no)
AC_ARG_ENABLE(battstat,
	      [  --disable-battstat=[@<:@no/yes@:>@]
                          dont build battery monitor applet [@<:@default: no@:>@]],,
	      disable_battstat=no)

HAVE_LIBAPM=no
NEED_LIBAPM=no
ACPIINC=
build_battstat_applet=no

if test x$disable_battstat = xno; then
   build_battstat_applet=yes
   AC_CHECK_HEADERS([err.h sys/sysctl.h])
   case "${host}" in
       powerpc-*-linux*)
           NEED_LIBAPM=yes
           AC_CHECK_LIB(apm,apm_read,[HAVE_LIBAPM=yes],[HAVE_LIBAPM=no])
	   ;;
       # list of supported OS cores that use libapm
       *-*-linux*)
	   NEED_LIBAPM=yes
	   AC_CHECK_LIB(apm,apm_read,[HAVE_LIBAPM=yes],[HAVE_LIBAPM=no])
	   ;;
       # list of supported OS cores that do not use libapm
       i386-*-freebsd*|*-*-netbsd*|*-*-openbsd*|*-*kfreebsd*-gnu)
          if [ -n "${OS_SYS}" ]; then
	       ACPIINC="-I${OS_SYS}"
	   else
	       ACPIINC="-I/usr/src/sys"
	   fi

	   savecppflags=$CPPFLAGS
	   CPPFLAGS="$CPPFLAGS $ACPIINC"
	   AC_CHECK_HEADER(dev/acpica/acpiio.h, have_acpiio=true, have_acpiio=false)
	   if test $have_acpiio = true; then
	     AC_DEFINE(HAVE_ACPIIO, 1, [Define if acpiio.h exists on the system])
	   fi

	   ;;
       *)
	   echo "warning: ${host} is not supported by battstat_applet, not building" >&2
	   build_battstat_applet=no
	   ;;
    esac
fi

AC_SUBST(HAVE_LIBAPM)
AC_SUBST(NEED_LIBAPM)
AC_SUBST(ACPIINC)
AM_CONDITIONAL(HAVE_LIBAPM, test "x$HAVE_LIBAPM" = "xyes")
AM_CONDITIONAL(NEED_LIBAPM, test "x$NEED_LIBAPM" = "xyes")
AM_CONDITIONAL(BUILD_BATTSTAT_APPLET, test x$build_battstat_applet = xyes)

dnl ***************************************************************************
dnl *** Stickynotes specific checks                                         ***
dnl ***************************************************************************
# AC_ARG_ENABLE(stickynotes, [  --enable-stickynotes build stickynotes
#                           [@<:@default: no, transparent upgrade to Tomboy@:>@]], enable_stickynotes="yes", enable_stickynotes="no")
enable_stickynotes="yes"
AM_CONDITIONAL(BUILD_STICKYNOTES_APPLET, test "x$enable_stickynotes" = "xyes")

dnl ***************************************************************************
dnl *** Timer applet specific checks                                        ***
dnl ***************************************************************************
AC_ARG_ENABLE([timer-applet],
    AC_HELP_STRING([--enable-timer-applet], [Enable the timer applet.]),
    enable_timerapplet=$enableval,
    enable_timerapplet=no)
AM_CONDITIONAL(BUILD_TIMER_APPLET, test "x$enable_timerapplet" = "xyes")

dnl ***************************************************************************
dnl *** keyboard accessibility status applet check                          ***
dnl ***************************************************************************

savecppflags=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $X_CFLAGS"
AC_CHECK_HEADER(X11/extensions/XKB.h, HAVE_XKB=true, HAVE_XKB=false)
AC_SUBST(HAVE_XKB)

AM_CONDITIONAL(APPLET_ACCESSX, $HAVE_XKB)
if test "x$APPLET_ACCESSX" = "xtrue"; then
  AC_MSG_WARN([*** keyboard accessibility status applet will not be built ***])
fi
CPPFLAGS=$savecppflags

dnl ***************************************************************************
dnl *** modemlights applet check                                            ***
dnl ***************************************************************************

SU_TOOL=
HAVE_LIBUTIL=

AC_PATH_PROG(SU_TOOL, su)
AC_CHECK_LIB(util, forkpty, HAVE_LIBUTIL=true, HAVE_LIBUTIL=false)

dnl ***
dnl *** Modem lights does not currently compile. It needs to be ported to a
dnl *** modern mate-system-tools backend.
dnl ***
dnl if test "x$HAVE_LIBUTIL" = "xtrue" -a "x$HAVE_MATE_SETTINGS_DAEMON" = "xyes"; then
dnl   MODEMLIGHTS_LIBS=" -lutil"
dnl   AC_SUBST(MODEMLIGHTS_LIBS)
dnl   AC_DEFINE_UNQUOTED(STB_SCRIPTS_DIR, "$STB_SCRIPTS_DIR", [System tools backends])
dnl   AC_DEFINE_UNQUOTED(SU_PATH, "${SU_TOOL}", [su executable path])
dnl   BUILD_MODEM_LIGHTS=yes
dnl else
  AC_MSG_WARN([*** modemlights applet will not be built ***])
  BUILD_MODEM_LIGHTS=no
dnl fi

AM_CONDITIONAL(APPLET_MODEMLIGHTS, test "x$BUILD_MODEM_LIGHTS" = "xyes")

dnl ***************************************************************************
dnl *** cpufreq applet check                                                ***
dnl ***************************************************************************

dnl --disable-cpufreq=(yes|no)
AC_ARG_ENABLE(cpufreq,
	      [  --disable-cpufreq[@<:@=no/yes@:>@]
                          dont build cpu frequency scaling monitor applet
			  [@<:@default: no@:>@]],,
	      disable_cpufreq=no)

dnl --enable-frequency-selector=(yes/no)
AC_ARG_ENABLE(frequency-selector,
	      [  --enable-frequency-selector[@<:@=yes/no@:>@]
	                  build frequency selector [@<:@default: yes@:>@]], ,
	      enable_selector=yes)

dnl --enable-suid=(yes/no)
AC_ARG_ENABLE(suid,
       [  --enable-suid[@:<@=yes/no@:>@]  suid root the frequency selector executable
                   [@<:@default: yes@:>@]], ,
       suid=yes)

if test "x$HAVE_POLKIT" = "xyes"; then
   suid=no
fi

AC_CHECK_HEADER(cpufreq.h, have_libcpufreq=yes, have_libcpufreq=no)
LIBCPUFREQ_LIBS=
if test "x$have_libcpufreq" = "xyes"; then
   AC_DEFINE([HAVE_LIBCPUFREQ], [1], [Have libcpufreq.])
   LIBCPUFREQ_LIBS=-lcpufreq
fi
AM_CONDITIONAL(HAVE_LIBCPUFREQ, test x$have_libcpufreq = xyes)
AC_SUBST(LIBCPUFREQ_LIBS)

build_cpufreq_applet=no

if test x$disable_cpufreq = xno; then
   case "${host}" in
      *linux*)
         build_cpufreq_applet=yes
	 ;;
      *)
         AC_MSG_WARN([${host} is not supported by cpufreq applet, not building])
	 build_cpufreq_applet=no
	 ;;
   esac
fi

AM_CONDITIONAL(BUILD_CPUFREQ_APPLET, test x$build_cpufreq_applet = xyes)
AM_CONDITIONAL(BUILD_CPUFREQ_SELECTOR, test x$enable_selector = xyes)
AM_CONDITIONAL(CPUFREQ_SELECTOR_SUID, test x$suid = xyes)

dnl ***************************************************************************
dnl *** invest-applet specific checks                                       ***
dnl ***************************************************************************

AM_CONDITIONAL(BUILD_INVEST_APPLET, test "x$HAVE_PYGTK" = "xyes")

dnl ***************************************************************************
dnl *** Check if IPv6 is available                                          ***
dnl ***************************************************************************
AC_MSG_CHECKING([whether to enable ipv6])
AC_ARG_ENABLE(ipv6, [  --enable-ipv6 enable IPv6 extensions], ,enable_ipv6=yes)
if test $enable_ipv6 = yes; then

  dnl Code for checking presence of AF_INET6 on the system.
  AC_TRY_COMPILE([
    #include <sys/types.h>
    #include <sys/socket.h>], [
    socket(AF_INET6, SOCK_STREAM, 0)
    ],
    have_ipv6=yes,
    have_ipv6=no
  )
  AC_MSG_RESULT($have_ipv6)
  if test $have_ipv6 = yes; then
      AC_DEFINE(ENABLE_IPV6, 1, [Define if system is IPv6 enabled])
  fi
fi

dnl ***************************************************************************
dnl *** Check for getaddrinfo                                               ***
dnl ***************************************************************************
have_getaddrinfo=no
AC_CHECK_FUNC(getaddrinfo, have_getaddrinfo=yes)
if test $have_getaddrinfo != yes; then
  # getaddrinfo is not in the default libraries.  See if it's in some other.
  for lib in bsd socket inet; do
    AC_CHECK_LIB($lib, getaddrinfo, [LIBS="$LIBS -l$lib";have_getaddrinfo=yes; break])
  done
fi
if test $have_getaddrinfo = yes; then
  AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo() exists on the system])
fi

dnl ***************************************************************************
dnl *** Check for presence of tm.tm_gmtoff on the system                    ***
dnl ***************************************************************************
AC_CHECK_MEMBER([struct tm.tm_gmtoff],[struct_tm_tm_gmtoff=true],[struct_tm_tm_gmtoff=false],[#include <time.h>])
case $struct_tm_tm_gmtoff in
        true)
                AC_DEFINE_UNQUOTED(HAVE_TM_TM_GMOFF, 1, Have the tm.tm_gmtoff member.)
                ;;
        *)
                AC_CHECK_DECL(timezone,AC_DEFINE(HAVE_TIMEZONE,1,Have timezone),,
[
#include <time.h>
])
                ;;
esac

dnl ***************************************************************************
dnl *** _NL_MEASUREMENT_MEASUREMENT is an enum and not a define             ***
dnl ***************************************************************************
AC_MSG_CHECKING([for _NL_MEASUREMENT_MEASUREMENT])
AC_TRY_LINK([#include <langinfo.h>], [
char c;
c = *((unsigned char *)  nl_langinfo(_NL_MEASUREMENT_MEASUREMENT));
], gtk_ok=yes, gtk_ok=no)
AC_MSG_RESULT($gtk_ok)
if test "$gtk_ok" = "yes"; then
  AC_DEFINE([HAVE__NL_MEASUREMENT_MEASUREMENT], [1],
            [Define if _NL_MEASUREMENT_MEASUREMENT is available])
fi

dnl ***************************************************************************
dnl *** Honour aclocal flags                                                ***
dnl ***************************************************************************
ACLOCAL_AMFLAGS="\${ACLOCAL_FLAGS}"
AC_SUBST(ACLOCAL_AMFLAGS)

dnl ***************************************************************************
dnl *** Set install directories                                             ***
dnl ***************************************************************************
iconsdir="${datadir}/icons"
AC_SUBST(iconsdir)
pixmapsdir="${datadir}/pixmaps"
AC_SUBST(pixmapsdir)
pkgdatadir="${datadir}/mate-applets"
AC_SUBST(pkgdatadir)
builderdir="${pkgdatadir}/builder"
AC_SUBST(builderdir)

AC_DEFINE_DIR(MATE_ICONDIR, "${iconsdir}", [Mate Icon Directory])
AC_DEFINE_DIR(MATE_PIXMAPSDIR, "${pixmapsdir}", [Mate Pixmaps Directory])
AC_DEFINE_DIR(PKGDATADIR, "${pkgdatadir}", [Mate Applets Directory])
AC_DEFINE_DIR(GTK_BUILDERDIR, "${builderdir}", [GtkBuilder Resources Directory])
AC_DEFINE_DIR(DATADIR, "${datadir}", [datadir])
AC_DEFINE_DIR(SYSCONFDIR, "${sysconfdir}", [sysconfdir])
AC_DEFINE_DIR(LIBDIR, "${libdir}", [libdir])
AC_DEFINE_DIR(PREFIX, "$prefix", [install prefix])

AS_AC_EXPAND(DATADIR, "${datadir}")
AS_AC_EXPAND(PYTHONDIR, $pythondir)
AS_AC_EXPAND(BUILDERDIR, $builderdir)

AC_SUBST(VERSION)
AC_SUBST(PACKAGE)
AC_SUBST(DATADIR)
AC_SUBST(LIBDIR)
AC_SUBST(PYTHONDIR)
AC_SUBST(PKGDATADIR)
AC_SUBST(BUILDERDIR)

dnl ***************************************************************************
dnl *** Output Makefiles et al                                              ***
dnl ***************************************************************************
AC_OUTPUT([
mate-applets.spec
Makefile
po/Makefile.in
accessx-status/Makefile
accessx-status/docs/Makefile
accessx-status/pixmaps/Makefile
drivemount/Makefile
drivemount/help/Makefile
modemlights/Makefile
multiload/Makefile
multiload/docs/Makefile
charpick/Makefile
charpick/help/Makefile
invest-applet/Makefile
invest-applet/docs/Makefile
invest-applet/invest/Makefile
invest-applet/invest/defs.py
invest-applet/data/Makefile
invest-applet/data/art/Makefile
mateweather/Makefile
mateweather/docs/Makefile
geyes/Makefile
geyes/themes/Makefile
geyes/docs/Makefile
battstat/Makefile
battstat/apmlib/Makefile
battstat/sounds/Makefile
battstat/docs/Makefile
man/Makefile
stickynotes/Makefile
stickynotes/pixmaps/Makefile
stickynotes/docs/Makefile
stickynotes/data/Makefile
trashapplet/Makefile
trashapplet/src/Makefile
trashapplet/docs/Makefile
cpufreq/Makefile
cpufreq/src/Makefile
cpufreq/src/cpufreq-selector/Makefile
cpufreq/pixmaps/Makefile
cpufreq/help/Makefile
timer-applet/Makefile
timer-applet/data/Makefile
timer-applet/images/Makefile
timer-applet/src/Makefile
timer-applet/src/timerapplet/Makefile
timer-applet/src/timerapplet/controllers/Makefile
timer-applet/src/timerapplet/core/Makefile
timer-applet/src/timerapplet/ui/Makefile
null_applet/Makefile
])

dnl ***************************************************************************
dnl *** Display Summary                                                     ***
dnl ***************************************************************************
echo "
mate-applets-$VERSION configure summary:

    Prefix:                        ${prefix}
    Source code location:          ${srcdir}
    Compiler:                      ${CC}

    Building:
        - accessx-status           $HAVE_XKB
        - battstat                 $build_battstat_applet
        - charpick                 always
            - gucharmap support    $have_gucharmap
            - gucharmap-2 support  $have_gucharmap_2
        - cpufreq                  $build_cpufreq_applet
            - building selector    $enable_selector
            - using PolicyKit      $HAVE_POLKIT
            - enabling suid bit    $suid
        - drivemount               always
        - geyes                    always
        - mateweather              $build_libmateweather_applets
        - invest-applet            $BUILD_INVEST_APPLET
        - modemlights              $BUILD_MODEM_LIGHTS
        - multiload                $build_gtop_applets
        - stickynotes              $enable_stickynotes
        - trashapplet              always
        - timer-applet             $enable_timerapplet

    Using DBUS:                    $HAVE_DBUS
    Using NetworkManager:          $HAVE_NETWORKMANAGER
    Using HAL:                     $HAVE_HAL
    Using UPOWER:                  $HAVE_UPOWER
    Enabling IPv6:                 $have_ipv6
" >&2