AC_INIT(_gtkmodule.c)

dnl get information for generating Makefile.
PY_INIT

AC_ARG_WITH(imlib,
[  --without-imlib         do not compile imlib extension, even if gdk_imlib
                          library is found],
[if test "x$with_imlib" != xno; then
  NO_IMLIB=""
else
  NO_IMLIB="#"
fi],
[NO_IMLIB=""])

AC_ARG_WITH(gtk-config,
[  --with-gtk-config=CFG   name of the gtk-config executable],
[if test -x "$with_gtk_config"; then
  GTK_CONFIG="$with_gtk_config"
else
  GTK_CONFIG="no"
fi],
[GTK_CONFIG="no"])

if test "x$GTK_CONFIG" = xno; then
  AC_PATH_PROG(GTK_CONFIG, gtk-config, no)
fi
if test "x$GTK_CONFIG" = xno; then
  AC_MSG_ERROR([Can't find gtk-config.  Try giving configure an argument like
--with-gtk-config=/subdir/gtk-config])
fi

AC_MSG_CHECKING([for GTK cflags])
GTK_CFLAGS=`$GTK_CONFIG --cflags`
AC_MSG_RESULT($GTK_CFLAGS)
AC_MSG_CHECKING([for GTK libs])
GTK_LIBS=`$GTK_CONFIG --libs`
dnl we are compiling a shared module anyway, so -rdynamic isn't needed.
dnl (also it confuses the python Setup file parser)
GTK_LIBS=`echo "$GTK_LIBS" | sed 's/-rdynamic//'`
AC_MSG_RESULT($GTK_LIBS)
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)

IMAGE_LIBS=""
AC_CHECK_LIB(z, main,[IMAGE_LIBS="-lz $IMAGE_LIBS"])
AC_CHECK_LIB(tiff, main,[IMAGE_LIBS="-ltiff $IMAGE_LIBS"],,$IMAGE_LIBS)
AC_CHECK_LIB(gif, main,[IMAGE_LIBS="-lgif $IMAGE_LIBS"],,$IMAGE_LIBS)
AC_CHECK_LIB(jpeg, main,[IMAGE_LIBS="-ljpeg $IMAGE_LIBS"],,$IMAGE_LIBS)
AC_CHECK_LIB(png, png_get_valid,[IMAGE_LIBS="-lpng -lm $IMAGE_LIBS"],,-lm $IMAGE_LIBS)
AC_SUBST(IMAGE_LIBS)

AC_CHECK_LIB(gdk_imlib, gdk_imlib_init,[:],[NO_IMLIB="#"],
[$IMAGE_LIBS $GTK_LIBS])
AC_SUBST(NO_IMLIB)

PY_OUTPUT(Makefile, Setup)

