-*- mode: m4 -*-
AC_PREREQ(2.52)

dnl the pygtk version number
m4_define(pygtk_major_version, 2)
m4_define(pygtk_minor_version, 6)
m4_define(pygtk_micro_version, 1)
m4_define(pygtk_version, pygtk_major_version.pygtk_minor_version.pygtk_micro_version)

dnl versions of packages we require ...
m4_define(glib_required_version,     2.6.0)
m4_define(pango_required_version,    1.8.0)
m4_define(atk_required_version,      1.8.0)
m4_define(gtk_required_version,      2.6.0)
m4_define(libglade_required_version, 2.4.0)

AC_INIT(pygtk, pygtk_version,
        [http://bugzilla.gnome.org/enter_bug.cgi?product=pygtk])
AC_SUBST(ACLOCAL_AMFLAGS, "-I m4 -I .")

AC_DEFINE(PYGTK_MAJOR_VERSION, pygtk_major_version, [PyGtk major version])
AC_SUBST(PYGTK_MAJOR_VERSION, pygtk_major_version)
AC_DEFINE(PYGTK_MINOR_VERSION, pygtk_minor_version, [PyGtk minor version])
AC_SUBST(PYGTK_MINOR_VERSION, pygtk_minor_version)
AC_DEFINE(PYGTK_MICRO_VERSION, pygtk_micro_version, [PyGtk micro version])
AC_SUBST(PYGTK_MICRO_VERSION, pygtk_micro_version)

AC_CONFIG_SRCDIR([gtk/gtkmodule.c])
AM_CONFIG_HEADER(config.h)

AM_INIT_AUTOMAKE
AC_CHECK_FUNCS(bind_textdomain_codeset)

dnl put the ACLOCAL flags in the makefile
ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"

AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_MSG_CHECKING([for some Win32 platform])
case "$host" in
  *-*-mingw*|*-*-cygwin*)
    platform_win32=yes
    ;;
  *)
    platform_win32=no
    ;;
esac
AC_MSG_RESULT([$platform_win32])
AM_CONDITIONAL(PLATFORM_WIN32, test "$platform_win32" = "yes")

AC_MSG_CHECKING([for native Win32])
case "$host" in
  *-*-mingw*)
    os_win32=yes
    ;;
  *)
    os_win32=no
    ;;
esac
AC_MSG_RESULT([$os_win32])
AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")

AC_DISABLE_STATIC
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL

AM_PATH_PYTHON(2.3)

AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])

AC_ARG_ENABLE(thread,
  AC_HELP_STRING([--disable-thread], [Disable pygtk threading support]),,
  enable_thread=yes)

AM_CHECK_PYMOD(thread,,,enable_thread=no)

AC_MSG_CHECKING(whether to enable threading in pygtk)
if test "x$enable_thread" != xno; then
  extra_mods=gthread
  THREADING_CFLAGS=
  AC_MSG_RESULT(yes)
else
  extra_mods=
  THREADING_CFLAGS="-DDISABLE_THREADING"
  AC_MSG_RESULT(no)
fi
AC_SUBST(THREADING_CFLAGS)
CPPFLAGS="${CPPFLAGS} $THREADING_CFLAGS"

dnl get rid of the -export-dynamic stuff from the configure flags ...
export_dynamic=`(./libtool --config; echo eval echo \\$export_dynamic_flag_spec) | sh`

dnl glib
AM_PATH_GLIB_2_0(glib_required_version,,[AC_MSG_ERROR(maybe you want the pygtk-2-4 branch?)],gobject $extra_mods)
if test -n "$export_dynamic"; then
  GLIB_LIBS=`echo $GLIB_LIBS | sed -e "s/$export_dynamic//"`
fi

dnl atk
PKG_CHECK_MODULES(ATK, atk >= atk_required_version,
	build_atk=true, build_atk=false)
AC_SUBST(ATK_CFLAGS)
AC_SUBST(ATK_LIBS)
AM_CONDITIONAL(BUILD_ATK, $build_atk)
if test -n "$export_dynamic"; then
  ATK_LIBS=`echo $ATK_LIBS | sed -e "s/$export_dynamic//"`
fi

dnl pango
PKG_CHECK_MODULES(PANGO, pango >= pango_required_version,
	build_pango=true, build_pango=false)
AC_SUBST(PANGO_CFLAGS)
AC_SUBST(PANGO_LIBS)
AM_CONDITIONAL(BUILD_PANGO, $build_pango)
if test -n "$export_dynamic"; then
  PANGO_LIBS=`echo $PANGO_LIBS | sed -e "s/$export_dynamic//"`
fi

dnl gtk+
AM_PATH_GTK_2_0(gtk_required_version,
	         build_gtk=true, build_gtk=false)
AM_CONDITIONAL(BUILD_GTK, $build_gtk)
if test -n "$export_dynamic"; then
  GTK_LIBS=`echo $GTK_LIBS | sed -e "s/$export_dynamic//"`
fi

dnl Check for newer gtk+ versions, for conditional compiling of new features
PYGTK_CODEGEN_DEFINES=""
AC_SUBST(PYGTK_CODEGEN_DEFINES)

AC_MSG_CHECKING([for GTK+ 2.4])
if version=$(pkg-config --modversion "gtk+-2.0 >= 2.3.4" 2> /dev/null); then
	PYGTK_CODEGEN_DEFINES="-DHAVE_GTK24";
	AC_MSG_RESULT([found (version $version)])
else
	AC_MSG_RESULT([not found])
fi

dnl libglade
PKG_CHECK_MODULES(LIBGLADE, libglade-2.0 >= libglade_required_version,
	build_libglade=true, build_libglade=false)
AC_SUBST(LIBGLADE_CFLAGS)
AC_SUBST(LIBGLADE_LIBS)
AM_CONDITIONAL(BUILD_LIBGLADE, $build_libglade)
if test -n "$export_dynamic"; then
  LIBGLADE_LIBS=`echo $LIBGLADE_LIBS | sed -e "s/$export_dynamic//"`
fi

AC_ARG_ENABLE(numpy,
  AC_HELP_STRING([--disable-numpy], [Disable numeric python features]),,
  enable_numpy=yes)

dnl checks to see if Numeric Python is installed.
if test "x$enable_numpy" != xno; then
  save_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
  AC_CHECK_HEADER([Numeric/arrayobject.h],
    [AC_DEFINE(HAVE_NUMPY,,[whether to include numeric python support])],,
    [#include <Python.h>])
  CPPFLAGS="$save_CPPFLAGS"
fi

dnl add required cflags ...
JH_ADD_CFLAG([-Wall])
JH_ADD_CFLAG([-std=c9x])
JH_ADD_CFLAG([-fno-strict-aliasing])

AC_CONFIG_FILES(
  Makefile
  pygobject-2.0.pc
  pygtk-2.0.pc
  codegen/Makefile
  gobject/Makefile
  gtk/Makefile
  docs/Makefile
  examples/Makefile
  tests/Makefile
  codegen/pygtk-codegen-2.0
  pygtk.spec
  PKG-INFO)
AC_OUTPUT


echo
echo "The following modules will be built:"
echo
true                     && echo     gobject
$build_atk               && echo     atk
$build_pango             && echo     pango
$build_gtk               && echo     gtk
$build_libglade          && echo     gtk.glade
echo

if test ! $build_atk || ! $build_pango || \
        ! $build_gtk || ! $build_libglade; then
  echo "The following modules will NOT be built:"
  echo
  $build_atk               || echo     atk
  $build_pango             || echo     pango
  $build_gtk               || echo     gtk
  $build_libglade          || echo     gtk.glade
fi

