dnl	Configure.in script for DiaCanvas2
dnl
dnl dnl dnl dnl dnl dnl dnl dnl dnl dnl dnl

AC_INIT(diacanvas/diatypes.c)

dnl the diacanvas version number
m4_define(diacanvas_major_version, 0)
m4_define(diacanvas_minor_version, 13)
m4_define(diacanvas_micro_version, 0)
m4_define(diacanvas_version, diacanvas_major_version.diacanvas_minor_version.diacanvas_micro_version)

dnl required versions of other packages
m4_define(glib_required_version, 2.0.0)
m4_define(gobject_required_version, 2.0.0)
m4_define(libart_required_version, 2.0.0)
m4_define(libgnomecanvas_required_version, 2.0.0)
m4_define(pygtk_required_version, 2.0.0)
m4_define(libgnomeprint_required_version, 2.2.0)
dnl For the demo application:
m4_define(libgnomeprintui_required_version, 2.2.0)

AM_INIT_AUTOMAKE(diacanvas2, diacanvas_version)

AM_CONFIG_HEADER(config.h)

AC_DEFINE(DIACANVAS_MAJOR_VERSION, diacanvas_major_version, [DiaCanvas2 major version])
AC_DEFINE(DIACANVAS_MINOR_VERSION, diacanvas_minor_version, [DiaCanvas2 minor version])
AC_DEFINE(DIACANVAS_MICRO_VERSION, diacanvas_micro_version, [DiaCanvas2 micro version])

DIA_CANVAS_VERSION=diacanvas_version
AC_SUBST(DIA_CANVAS_VERSION)

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

AM_MAINTAINER_MODE

AC_PROG_LN_S


##########
# Libtool

AC_PROG_CC
AM_DISABLE_STATIC
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL


##########
# Gettext

GETTEXT_PACKAGE=diacanvas
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Gettext package name])
ALL_LINGUAS="nl"

AM_GLIB_GNU_GETTEXT


########
# Win32

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


##########################
# Check for libgnomeprint

AC_ARG_ENABLE(gnome-print, [  --enable-gnome-print=[no/yes]  enable GnomePrint support within DiaCanvas2 [default=auto]],, enable_gnome_print=yes)

# Pkg-config check for libgnomeprint
GNOME_PRINT_CHECK=""
# statement to be added to diacanvas.pc
GNOME_PRINT_PC=""
# Used for substitution in diacanvas/dia-features.h
FEATURE_GNOME_PRINT=0

if test "x$enable_gnome_print" = "xyes" ; then
    PKG_CHECK_MODULES_EXIST([libgnomeprint-2.2 >= libgnomeprint_required_version],
	[FEATURE_GNOME_PRINT=1
         GNOME_PRINT_CHECK="libgnomeprint-2.2 >= libgnomeprint_required_version"
	 GNOME_PRINT_PC="libgnomeprint-2.2"],
	[AC_MSG_RESULT(not found)
         enable_gnome_print="no"])
fi

AC_SUBST(GNOME_PRINT_PC)
AC_SUBST(FEATURE_GNOME_PRINT)


################
# Library flags

PKG_CHECK_MODULES(DIACANVAS2,
	     glib-2.0 >= glib_required_version
	     gobject-2.0 >= gobject_required_version
	     libart-2.0 >= libart_required_version
	     libgnomecanvas-2.0 >= libgnomecanvas_required_version
	     $GNOME_PRINT_CHECK)
AC_SUBST(DIACANVAS2_CFLAGS)
AC_SUBST(DIACANVAS2_LIBS)


#############################################
# Demo application, requires libgnomeprintui

have_gnome_print_ui="no"

if test "x$enable_gnome_print" = "xyes" ; then
    PKG_CHECK_MODULES_EXIST(libgnomeprintui-2.2 >= libgnomeprintui_required_version,
	have_gnome_print_ui="yes", )
fi

if test "x$have_gnome_print_ui" = "xyes" ; then
    PKG_CHECK_MODULES(DIACANVAS2_DEMO,
	     glib-2.0 >= glib_required_version
	     gobject-2.0 >= gobject_required_version
	     libart-2.0 >= libart_required_version
	     libgnomecanvas-2.0 >= libgnomecanvas_required_version
	     libgnomeprintui-2.2 >= libgnomeprintui_required_version)
    AC_DEFINE(HAVE_GNOME_PRINT_UI, 1, [We have found libgnomeprintui])
else
    DIACANVAS2_DEMO_CFLAGS="$DIACANVAS2_CFLAGS"
    DIACANVAS2_DEMO_LIBS="$DIACANVAS2_LIBS"
fi

AC_SUBST(DIACANVAS2_DEMO_CFLAGS)
AC_SUBST(DIACANVAS2_DEMO_LIBS)


########
# Debug

AC_ARG_ENABLE(debug, [  --enable-debug=[no/yes] turn on debugging [default=no]])
if test "x$enable_debug" == "xyes"; then
    AC_DEFINE(ENABLE_DEBUG, 1, [Enable debug output for DiaCanvas2])
fi


#########################
# Generated header files

AC_ARG_ENABLE(rebuilds, [  --disable-rebuilds      disable all source autogeneration rules],,enable_rebuilds=yes)

# define a MAINT-like variable REBUILD which is set if Perl
# and awk are found, so autogenerated sources can be rebuilt
AC_PROG_AWK
AC_CHECK_PROGS(PERL, perl5 perl)
# We would like indent, but don't require it.
AC_CHECK_PROG(INDENT, indent, indent)
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)


####################
# Check for gtk-doc

AC_ARG_WITH(html-dir, [  --with-html-dir=PATH path to installed docs ])

if test "x$with_html_dir" = "x" ; then
    HTML_DIR='${datadir}/gtk-doc/html'
else
    HTML_DIR=$with_html_dir
fi

AC_SUBST(HTML_DIR)

AC_CHECK_PROG(GTKDOC, gtkdoc-mkdb, true, false)

gtk_doc_min_version=1.0
if $GTKDOC ; then 
    gtk_doc_version=`gtkdoc-mkdb --version`
    AC_MSG_CHECKING([gtk-doc version ($gtk_doc_version) >= $gtk_doc_min_version])
    if perl <<EOF ; then
        exit (("$gtk_doc_version" =~ /^[[0-9]]+\.[[0-9]]+$/) &&
              ("$gtk_doc_version" >= "$gtk_doc_min_version") ? 0 : 1);
EOF
        AC_MSG_RESULT(yes)
    else
        AC_MSG_RESULT(no)
        GTKDOC=false
    fi
fi

dnl Let people disable the gtk-doc stuff.
AC_ARG_ENABLE(gtk-doc, [  --enable-gtk-doc  Use gtk-doc to build documentation [default=auto]], enable_gtk_doc="$enableval", enable_gtk_doc=auto)

if test x$enable_gtk_doc = xauto ; then
    if test x$GTKDOC = xtrue ; then
        enable_gtk_doc=yes
    else
        enable_gtk_doc=no 
    fi
fi

AM_CONDITIONAL(ENABLE_GTK_DOC, test x$enable_gtk_doc = xyes)


#################
# Python wrapper

AC_ARG_ENABLE(python, [  --enable-python=[no/yes]  create a Python bindings (needs Python 2.2) [default=auto]],, enable_python=yes)

if test "x$enable_python" = "xyes" ; then

AM_PATH_PYTHON
if test "x$PYTHON" = "x" ; then
    enable_python=no
fi

AM_CHECK_PYTHON_HEADERS(,[AC_MSG_RESULT(could not find Python headers)
enable_python=no])

dnl check for pygtk
PKG_CHECK_MODULES(PYGTK, pygtk-2.0 >= pygtk_required_version, \
		AC_MSG_RESULT(yes), [ \
		AC_MSG_RESULT(no)
		enable_python=no])
AC_SUBST(PYGTK_CFLAGS)

AC_PATH_PROG(PYGTK_CODEGEN, pygtk-codegen-2.0, no)
if test "x$PYGTK_CODEGEN" = xno; then
    dnl AC_MSG_RESULT(could not find pygtk-codegen-2.0 script)
    enable_python=no
fi

AC_MSG_CHECKING(for pygtk defs)
PYGTK_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0`
AC_SUBST(PYGTK_DEFSDIR)
AC_MSG_RESULT($PYGTK_DEFSDIR)

AC_MSG_CHECKING(for gnome-python (for GnomeCanvas))
prog="
import sys
import imp
try:
	import pygtk
	pygtk.require('2.0')
	#imp.find_module('gnome/canvas')
	import gnome.canvas
except ImportError:
	sys.exit(1)
sys.exit(0)"
if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC; then
    AC_MSG_RESULT(yes)
else
    AC_MSG_RESULT(no)
    enable_python=no
fi

fi # enable_python

AM_CONDITIONAL(ENABLE_PYTHON, test "x$enable_python" = "xyes")

###############
# Output files

AC_OUTPUT([
./Makefile
./diacanvas2.pc
./diacanvas2.spec
./po/Makefile.in
./diacanvas/Makefile
./diacanvas/dia-features.h
./python/Makefile
./demos/Makefile
./unit_tests/Makefile
./doc/Makefile
./doc/ref/Makefile
])

echo "
DiaCanvas2 is configured:

	Source code location:	$srcdir
	Compiler:		$CC

	GnomePrint support:	$enable_gnome_print
	Python wrapper:		$enable_python
"

