AC_PREREQ(2.54)

# Making releases:
#   libmate_micro_version += 1;
#   libmate_interface_age += 1;
# if any functions have been added, set libmate_interface_age to 0.
# if backwards compatibility has been broken,
# set LIBMATE_BINARY_AGE and LIBMATE_INTERFACE_AGE to 0.
#
m4_define([libmate_major_version], [1])
m4_define([libmate_minor_version], [2])
m4_define([libmate_micro_version], [0])
m4_define([libmate_interface_age], [0])
# If you need a modifier for the version number.
# Normally empty, but can be used to make "fixup" releases.
m4_define([libmate_extraversion], [])

dnl required versions of other tools.
m4_define([audiofile_required_version], [0.2.3])
m4_define([esound_required_version],    [0.2.26])
m4_define([mateconf_required_version],     [1.1.0])
m4_define([glib_required_version],      [2.8.0])
m4_define([mate_vfs_required_version], [1.1.0])
m4_define([libmatecomponent_required_version], [1.1.0])
m4_define([gobject_required_version], [2.0.0])
m4_define([gio_required_version],       [2.16.0])
m4_define([canberra_required_version], [0])

dnl libtool versioning from libmate
m4_define([libmate_current], [m4_eval(100 * libmate_minor_version + libmate_micro_version - libmate_interface_age)])
m4_define([libmate_binary_age], [m4_eval(100 * libmate_minor_version + libmate_micro_version)])
m4_define([libmate_revision], [libmate_interface_age])
m4_define([libmate_age], [m4_eval(libmate_binary_age - libmate_interface_age)])
m4_define([libmate_version], [libmate_major_version().libmate_minor_version().libmate_micro_version()libmate_extraversion()])

AC_INIT([libmate], [libmate_version], [https://github.com/perberos/mate-desktop-environment])
AC_CONFIG_SRCDIR([libmate/libmate.h])

LIBMATE_MAJOR_VERSION=libmate_major_version
LIBMATE_MINOR_VERSION=libmate_minor_version
LIBMATE_MICRO_VERSION=libmate_micro_version
LIBMATE_INTERFACE_AGE=libmate_interface_age

LIBMATE_CURRENT=libmate_current
LIBMATE_REVISION=libmate_revision
LIBMATE_AGE=libmate_age

AC_SUBST(LIBMATE_CURRENT)
AC_SUBST(LIBMATE_REVISION)
AC_SUBST(LIBMATE_AGE)

AM_INIT_AUTOMAKE([1.9 foreign no-dist-gzip dist-bzip2])

m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])

AC_CONFIG_HEADERS([config.h])

AM_MAINTAINER_MODE

dnl make aclocal calls respect $ACLOCAL_FLAGS
ACLOCAL_AMFLAGS="\${ACLOCAL_FLAGS}"
AC_SUBST(ACLOCAL_AMFLAGS)

IT_PROG_INTLTOOL([0.40.0])

AC_PROG_SED
AC_ISC_POSIX
AC_PROG_CC
AC_STDC_HEADERS
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL

AC_MSG_CHECKING([for Win32])
case "$host" in
  *-*-cygwin*)
    os_win32=no
    SOPREFIX=cyg
    ;;
  *-*-mingw*)
    os_win32=yes
    SOPREFIX=lib
    ;;
  *)
    os_win32=no
    SOPREFIX=lib
    ;;
esac
AC_MSG_RESULT([$os_win32])

AM_CONDITIONAL(OS_WIN32, [test $os_win32 = yes])
AC_SUBST(SOPREFIX)

AC_CHECK_FUNCS([setenv unsetenv clearenv setfsgid])
AC_CHECK_HEADERS(sys/fsuid.h)
AC_CHECK_FUNCS(bind_textdomain_codeset)

dnl Checks for Apple Darwin

AC_CHECK_FUNC(_NSGetEnviron, have_ns_getenviron=yes)
if test x$have_ns_getenviron = xyes; then
  AC_DEFINE(HAVE_NSGETENVIRON, 1, [whether we have _NSGetEnviron])
fi
AC_CHECK_HEADER(crt_externs.h, have_crt_externs=yes)
if test x$have_crt_externs = xyes; then
  AC_DEFINE(HAVE_CRT_EXTERNS_H, 1, [whether we have crt_externs.h])
fi

GETTEXT_PACKAGE=libmate
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [The gettext package])

AM_GLIB_GNU_GETTEXT

MATE_COMPILE_WARNINGS

dnl Define MATE_ENABLE_DEBUG if the --enable-debug switch was given.
MATE_DEBUG_CHECK

dnl Do not use AC_PROG_AWK since we need the full pathname.
AC_PATH_PROGS(AWK, mawk gawk nawk awk, )
AC_PATH_PROGS(PERL, perl5 perl)

# define a MAINT-like variable REBUILD which is set if Perl
# and awk are found, so autogenerated sources can be rebuilt
AC_ARG_ENABLE(rebuilds,
              AC_HELP_STRING([--disable-rebuilds],
                             [disable all source autogeneration rules]),,
              [enable_rebuilds=yes])
REBUILD=\#
if test "x$enable_rebuilds" = "xyes" && \
     test -n "$PERL" && \
     $PERL -e 'exit !($] >= 5.002)' > /dev/null 2>&1 && \
     test -n "$AWK" ; then
  REBUILD=
fi
AC_SUBST(REBUILD)

dnl
dnl Start of pkg-config checks
dnl

PKG_PROG_PKG_CONFIG()

dnl We first check for esound and audiofile (which has conditional
dnl support built in)
dnl

AC_MSG_CHECKING([whether ESounD support is requested])
AC_ARG_ENABLE([esd],
    AS_HELP_STRING([--enable-esd],[Enable ESounD (default=no)]),
    [enable_esd=$enableval],
    [enable_esd=no])
AC_MSG_RESULT([$enable_esd])

ESD_DEPS=""
SOUND_MODULES=""
if test x$enable_esd = xyes; then
	SOUND_MODULES="esound >= esound_required_version dnl
		audiofile >= audiofile_required_version"
	ESD_DEPS="esound"
fi

AC_MSG_CHECKING([whether to use libcanberra])
AC_ARG_ENABLE([canberra],
    AS_HELP_STRING([--enable-canberra],[Enable canberra (default=yes)]),
    [],[enable_canberra=yes])
AC_MSG_RESULT([$enable_canberra])

if test "$enable_canberra" = "yes"; then
  SOUND_MODULES="$SOUND_MODULES libcanberra >= canberra_required_version"
  ESD_DEPS="$ESD_DEPS libcanberra >= canberra_required_version"

  AC_DEFINE([HAVE_CANBERRA],[1],[Define if canberra is enabled])
fi

AC_SUBST(ESD_DEPS)

PKG_CHECK_MODULES(LIBMATE, dnl
 [glib-2.0 >= glib_required_version dnl
  gobject-2.0 >= gobject_required_version dnl
  gmodule-2.0 >= glib_required_version dnl
  gobject-2.0 >= glib_required_version dnl
  mate-vfs-2.0 >= mate_vfs_required_version dnl
  libmatecomponent-2.0 >= libmatecomponent_required_version dnl
  mateconf-2.0 >= mateconf_required_version dnl
  $SOUND_MODULES])

# for mate-open
PKG_CHECK_MODULES([GIO],[gio-2.0 >= gio_required_version])

dnl
dnl Check for gtk-doc
dnl
GTK_DOC_CHECK([1.0])

dnl ==============================================
dnl Special MateConf section
dnl ==============================================

AC_PATH_PROG(MATECONFTOOL, mateconftool-2, no)

if test x"$MATECONFTOOL" = xno; then
	AC_MSG_ERROR([mateconftool-2 executable not found in your path - should be installed with MateConf])
fi

AM_MATECONF_SOURCE_2

dnl
dnl Substitute these
dnl
MATE_VFS_VERSION=`$PKG_CONFIG --modversion mate-vfs-2.0`
AC_SUBST(MATE_VFS_VERSION)

AC_CHECK_LIB(popt, poptStrippedArgv,, AC_MSG_ERROR([popt 1.5 or newer is required to build
libmate. You can download the latest version from ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.0.x/]))

LIBMATE_MINOR_VERSION=libmate_minor_version
if test $(( $(echo $LIBMATE_MINOR_VERSION) %2)) = "1"; then
	A11Y_ENABLED=true
else
	A11Y_ENABLED=false
fi

AC_SUBST(A11Y_ENABLED)

AC_CONFIG_FILES([
Makefile
libmate-zip
po/Makefile.in
libmate/Makefile
monikers/Makefile
schemas/Makefile
schemas/desktop_mate_interface.schemas.in
mate-data/Makefile
libmate/libmate-2.0.pc
libmate/libmate-2.0-uninstalled.pc
doc/Makefile
doc/reference/Makefile
doc/reference/version.xml
])

AC_OUTPUT
