AC_PREREQ(2.54)

# Making releases:
#   LIBMATEUI_MICRO_VERSION += 1;
#   LIBMATEUI_INTERFACE_AGE += 1;
#   LIBMATEUI_BINARY_AGE += 1;
# if any functions have been added, set LIBMATEUI_INTERFACE_AGE to 0.
# if backwards compatibility has been broken,
# set LIBMATEUI_BINARY_AGE and LIBMATEUI_INTERFACE_AGE to 0.
#
m4_define([libmateui_major_version], [1])
m4_define([libmateui_minor_version], [2])
m4_define([libmateui_micro_version], [0])
m4_define([libmateui_interface_age], [4])
# If you need a modifier for the version number.
# Normally empty, but can be used to make "fixup" releases.
m4_define([libmateui_extraversion], [])

dnl Required versions of other packages
m4_define([libxml_required_version],         [2.4.20])
m4_define([libmate_required_version],       [1.1.0])
m4_define([libmatecanvas_required_version], [1.1.0])
m4_define([libmatecomponentui_required_version],    [1.1.0])
m4_define([mateconf_required_version],          [1.1.0])
m4_define([pango_required_version],          [1.1.2])
m4_define([glib_required_version],           [2.16.0])
m4_define([gio_required_version],            [2.16.0])
m4_define([gtk_required_version],            [2.12.0])
m4_define([matevfs_required_version],       [1.1.0])
m4_define([libglade_required_version],       [2.0.0])
m4_define([mate_keyring_required_version],  [1.1.0])

dnl libtool versioning from libmate

m4_define([libmateui_current], [m4_eval(100 * libmateui_minor_version + libmateui_micro_version - libmateui_interface_age)])
m4_define([libmateui_binary_age], [m4_eval(100 * libmateui_minor_version + libmateui_micro_version)])
m4_define([libmateui_revision], [libmateui_interface_age])
m4_define([libmateui_age], [m4_eval(libmateui_binary_age - libmateui_interface_age)])
m4_define([libmateui_version], [libmateui_major_version().libmateui_minor_version().libmateui_micro_version()libmateui_extraversion()])

AC_INIT([libmateui], [libmateui_version], [https://github.com/perberos/mate-desktop-environment])

AC_CONFIG_SRCDIR([libmateui/libmateui.h])
AC_CONFIG_HEADERS([config.h])

LIBMATEUI_MAJOR_VERSION=libmateui_major_version
LIBMATEUI_MINOR_VERSION=libmateui_minor_version
LIBMATEUI_MICRO_VERSION=libmateui_micro_version
LIBMATEUI_INTERFACE_AGE=libmateui_interface_age

dnl libtool versioning from libmate

LIBMATEUI_CURRENT=libmateui_current
LIBMATEUI_REVISION=libmateui_revision
LIBMATEUI_AGE=libmateui_age

AC_SUBST(LIBMATEUI_CURRENT)
AC_SUBST(LIBMATEUI_REVISION)
AC_SUBST(LIBMATEUI_AGE)

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

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

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_ISC_POSIX
AC_PROG_CC
AC_STDC_HEADERS
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL

dnl check for libm, for floor()
LT_LIB_M
AC_SUBST(LIBM)

dnl
dnl Check for -lX11 (for XUngrabServer in mate-ui-init.c) and set
dnl X11_CFLAGS and X11_LIBS
dnl

MATE_HAVE_X11=yes
PKG_CHECK_MODULES(X11, x11, :, [
# pkg-config modules not found (only present since X11R7); use old-style
# detection
AC_PATH_XTRA
# X found
if test x$no_x != xyes ; then
    libmateui_save_cflags="$CFLAGS"
    libmateui_save_libs="$LIBS"
    CFLAGS="$X_CFLAGS"
    LIBS="$X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS"
    AC_CHECK_LIB(X11,
                 XUngrabServer,
                 [X11_CFLAGS="$X_CFLAGS"
                  X11_LIBS="$X_PRE_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"],
                 MATE_HAVE_X11=no)
    CFLAGS="$libmateui_save_cflags"
    LIBS="$libmateui_save_libs"
else
    MATE_HAVE_X11=no
fi
])



case "$host" in
  *-*-mingw*)
    os_win32=yes
    mate_keyring_requirement=""
    MATE_KEYRING=""
    ;;
  *)
    os_win32=no
    mate_keyring_requirement="mate-keyring-1 >= mate_keyring_required_version"
    MATE_KEYRING="mate-keyring-1"

    if test x$MATE_HAVE_X11 != xyes ; then
        AC_MSG_ERROR([libX11 not found])
    fi
    ;;
esac
AM_CONDITIONAL(OS_WIN32, [test "$os_win32" = "yes"])
AC_SUBST(MATE_KEYRING)

GETTEXT_PACKAGE=libmateui
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",
                   [Name of gettext translation domain for library])

AM_GLIB_GNU_GETTEXT

MATE_COMPILE_WARNINGS

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

dnl
dnl Check for -lSM (for mate-client)
dnl

MATE_HAVE_SM=true
PKG_CHECK_MODULES(SM, sm ice, :, [
# pkg-config modules not found (only present since X11R7); use old-style
# detection
AC_PATH_XTRA
# X found
if test x$no_x != xyes ; then
    libmateui_save_cflags="$CFLAGS"
    libmateui_save_libs="$LIBS"
    CFLAGS="$X_CFLAGS"
    LIBS="$X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS"
    AC_CHECK_LIB(SM,
                 SmcSaveYourselfDone,
                 [SM_CFLAGS="$X_CFLAGS"
                  SM_LIBS="$X_PRE_LIBS $X_LIBS -lSM -lICE $X_EXTRA_LIBS"],
                 MATE_HAVE_SM=false,
                 $X_LIBS -lICE)
    AC_CHECK_HEADERS(X11/SM/SMlib.h, :, MATE_HAVE_SM=false)
    CFLAGS="$libmateui_save_cflags"
    LIBS="$libmateui_save_libs"
else
    MATE_HAVE_SM=false
fi
])

if test "$MATE_HAVE_SM" = true; then
	AC_DEFINE(HAVE_LIBSM, 1, [Define to 1 if you have libSM installed])
fi


dnl ----------------------------------------------------------------------------
dnl GTK library version
dnl ----------------------------------------------------------------------------
GTK_API_VERSION=2.0
GTK_REQUIRED=2.12.0

AC_MSG_CHECKING([which gtk+ version to compile against])
AC_ARG_WITH([gtk],
  [AS_HELP_STRING([--with-gtk=2.0|3.0],[which gtk+ version to compile against (default: 2.0)])],
  [case "$with_gtk" in
     2.0|3.0) ;;
     *) AC_MSG_ERROR([invalid gtk version specified]) ;;
   esac],
  [with_gtk=2.0])
AC_MSG_RESULT([$with_gtk])

case "$with_gtk" in
  2.0) GTK_API_VERSION=2.0
       GTK_REQUIRED=2.12.0
       ;;
  3.0) GTK_API_VERSION=3.0
       GTK_REQUIRED=3.0.0
       ;;
esac

dnl ----------------------------------------------------------------------------
dnl Start of pkg-config checks
dnl ----------------------------------------------------------------------------

MATEUI_MODULES="dnl
  libxml-2.0 >= libxml_required_version dnl
  libmate-2.0 >= libmate_required_version dnl
  libmatecanvas-2.0 >= libmatecanvas_required_version dnl
  libmatecomponentui-2.0 >= libmatecomponentui_required_version dnl
  mateconf-2.0 >= mateconf_required_version dnl
  pango >= pango_required_version dnl
  glib-2.0 >= glib_required_version
  gio-2.0 >= gio_required_version
  mate-vfs-2.0 >= matevfs_required_version dnl
  $mate_keyring_requirement"
PKG_CHECK_MODULES(LIBMATEUI, [$MATEUI_MODULES])
LIBMATEUI_CFLAGS="$X_CFLAGS $LIBMATEUI_CFLAGS"
LIBMATEUI_LIBS="$LIBMATEUI_LIBS $LIBJPEG"

MATE_TEST_MODULES="dnl
  gdk-pixbuf-2.0 >= gtk_required_version"
PKG_CHECK_MODULES(MATE_TEST, [$MATE_TEST_MODULES])
MATE_TEST_LIBS="$LIBMATEUI_LIBS $MATE_TEST_LIBS"

PKG_CHECK_MODULES(LIBMATEUI_COMPONENTS, [$MATEUI_MODULES])
PKG_CHECK_MODULES(LIBMATEUI_DEMOS, [$MATEUI_MODULES])
PKG_CHECK_MODULES(LIBMATEUI_GLADE, [$MATEUI_MODULES dnl
  libglade-2.0 >= libglade_required_version])

dnl
dnl Check for gtk-doc
dnl
GTK_DOC_CHECK([1.0],[--flavour no-tmpl])


dnl AC_SUBST GTK+ version
GTK_VERSION=`$PKG_CONFIG --modversion gtk+-$GTK_REQUIRED`
AC_SUBST(GTK_VERSION)

AC_MSG_CHECKING([for gtk+ multihead support])
if $PKG_CONFIG --atleast-version 2.1.0 gtk+-$GTK_API_VERSION; then
   AC_DEFINE(HAVE_GTK_MULTIHEAD,,[gtk+ with multihead support found])
   AC_MSG_RESULT(yes)
else
   AC_MSG_RESULT(no)
fi

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

AC_CHECK_HEADERS(locale.h unistd.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

dnl This is installed from GTK+ 2.0's gdk-pixbuf
AC_PATH_PROG(GDK_PIXBUF_CSOURCE, gdk-pixbuf-csource)
test -z "$GDK_PIXBUF_CSOURCE" && AC_MSG_ERROR([
*** You need the gdk-pixbuf-csource tool which is installed
*** from GTK+ 2.0's gdk-pixbuf.
***
*** Either the location where you installed your GTK+ 2.0 is
*** not in your PATH or something is screwed up with your
*** GTK+ 2.0 installation
])

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

AC_PATH_PROG(MATECONFTOOL, mateconftool-2)

# 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)

AC_CONFIG_FILES([
	Makefile
	libmateui-zip
	po/Makefile.in
	libmateui/Makefile
	libmateui/libmateui-2.0.pc
	libmateui/pixmaps/Makefile
	glade/Makefile
	images/Makefile
	demos/Makefile
	test-mate/Makefile
	doc/Makefile
	doc/reference/Makefile
	doc/reference/version.xml
])

AC_OUTPUT
echo "
configuration:

	Gtk+ version:    ${GTK_API_VERSION}
	doc build:       ${enable_gtk_doc}
"
