dnl $Id$

dnl Process this file with autoconf to produce a configure script.
dnl May need to run automake && aclocal first

AC_PREREQ(2.57)
AC_INIT(gramps, 2.1.0, [gramps-bugs@lists.sourceforge.net])
AC_CONFIG_SRCDIR(configure.in)
AM_INIT_AUTOMAKE(1.6.3)

RELEASE=0.SVN$(svnversion -n .)
dnl RELEASE=1

VERSIONSTRING=$VERSION
if test x"$RELEASE" != "x"
then
  VERSIONSTRING="$VERSION-$RELEASE"
fi

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

AC_PROG_INTLTOOL

dnl Checking for gconftool-2
AC_PATH_PROG(GCONFTOOL, gconftool-2, no)
if test "x$GCONFTOOL" = xno; then
  AC_MSG_ERROR([gconftool-2 executable not found in your path - should be installed with GConf])
fi

AM_GCONF2_REPLACEMENT
AM_SHARED_MIME
AM_PACKAGER
AC_SUBST(RELEASE)
AC_SUBST(VERSIONSTRING)

AC_PATH_PROG(MSGFMT, msgfmt,no)
if test x$MSGFMT = xno; then
  AC_MSG_ERROR(Couldn't find msgfmt program. Please install the GNU gettext package.)
fi
AC_PATH_PROG(MSGCONV, msgconv,no)
if test x$MSGCONV = xno; then
  AC_MSG_ERROR(Couldn't find msgconv program. Please install the GNU gettext package.)
fi
AC_PATH_PROG(ICONV, iconv,no)
if test x$ICONV = xno; then
  AC_MSG_ERROR(Couldn't find iconv program.)
fi

dnl Add the languages which your application supports here.
ALL_LINGUAS="hu zh_CN cs da de es fr it nb nl no pl pt_BR ro ru sv eo fi lt sk"
GETTEXT_PACKAGE=gramps
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Define to the Gettext package name.])
AM_GLIB_GNU_GETTEXT

dnl Checks for programs.  
dnl We first only check for python >= 2.3

AM_PATH_PYTHON(2.3)
AC_PATH_PROG(BINSH, sh)

pygtk_require="
try:
    import pygtk
    pygtk.require('2.0')
except ImportError:
    pass

def out(str):
    f = open('conftest.out', 'w')
    f.write(str)
    f.close()
"

AC_MSG_CHECKING(Python bindings for gtk2.4 (pygtk2>=2.3.4))
cat > conftest.py <<EOF
$pygtk_require
try:
    import gobject
    version = gobject.pygtk_version
    if version >= (2,3,4):
        out("YES")
    else:
        out("No")
except ImportError:
    out("No")
except AttributeError:
    out("No")
EOF
$PYTHON conftest.py
has_pygtk=`cat conftest.out`
rm -f conftest.out conftest.py
if test YES != "$has_pygtk"
then
   AC_MSG_ERROR([

**** The python bindings for gtk 2.4 (pygtk2>=2.3.4) could not be found.])
fi
AC_MSG_RESULT(ok)

AC_MSG_CHECKING(Python bindings for gnome)
cat > conftest.py <<EOF
$pygtk_require
try:
    import gnome
    # Do not import gnome.ui, this can kill python if the
    # display cannot be opened.  Just search it.
    import imp
    imp.find_module('gnome/ui')
    out("YES")
except ImportError:
    out("NO")
EOF
$PYTHON conftest.py
has_pygnome=`cat conftest.out`
rm -f conftest.out conftest.py
if test YES != "$has_pygnome"
then
   AC_MSG_ERROR([
**** The python bindings for gnome 2.0 (gnome-python2) could not be found.])
fi
AC_MSG_RESULT(ok)

AC_MSG_CHECKING(Python bindings for gconf)
cat > conftest.py <<EOF
$pygtk_require
try:
    import gconf
    out("YES")
except ImportError:
    import gnome.gconf
    out("YES")
except ImportError:
    out("NO")
EOF
$PYTHON conftest.py
has_gconf=`cat conftest.out`
rm -f conftest.out conftest.py
if test YES != "$has_gconf"
then
   AC_MSG_ERROR([
**** The python bindings for gconf (gnome-python2-gconf) could not be found.])
fi
AC_MSG_RESULT(ok)

AC_MSG_CHECKING(Python bindings for gnome vfs)
cat > conftest.py <<EOF
$pygtk_require
try:
    # Do not import gnome.canvas, this can raise a RuntimeError if the
    # display cannot be opened.  Just search it.
    import imp
    imp.find_module('gnome/vfs')
    out("YES")
except ImportError:
    out("NO")
EOF
$PYTHON conftest.py
has_vfs=`cat conftest.out`
rm -f conftest.out conftest.py
if test YES != "$has_vfs"
then
   AC_MSG_ERROR([
**** The python bindings for GNOME VFS (gnome-python2-vfs) could not be found.])
fi
AC_MSG_RESULT(ok)

AC_MSG_CHECKING(Python bindings for glade)
cat > conftest.py <<EOF
$pygtk_require
try:
    # Do not import gtk.glade, this can raise a RuntimeError if the
    # display cannot be opened.  Just search it.
    import imp
    imp.find_module('gtk/glade')
    out("YES")
except ImportError:
    out("NO")
EOF
$PYTHON conftest.py
has_pygtk=`cat conftest.out`
rm -f conftest.out conftest.py
if test YES != "$has_pygtk"
then
   AC_MSG_ERROR([

**** The python bindings for glade (pygtk2-libglade) could not be found.])
fi
AC_MSG_RESULT(ok)

dnl Checks for libraries.

dnl Checks for header files.

dnl ====================================
dnl = Begin tests for scrollkeeper
dnl ====================================
AC_PATH_PROG(SK_CONFIG,scrollkeeper-config,no)
if test x$SK_CONFIG = xno; then
  AC_MSG_ERROR(Couldn't find scrollkeeper-config. Please install the scrollkeeper package: http://scrollkeeper.sourceforge.net)
fi
dnl ====================================
dnl = End tests for scrollkeeper
dnl ====================================

dnl ===================================
dnl Set localstatedir to /var/lib -- this is apparently not used 
dnl     by anything besides scrollkeeper in our setup
dnl ==================================
localstatedir=/var/lib

if test ${prefix} = "NONE" ; then
   GPREFIX="/usr/local"
else
   GPREFIX="${prefix}"
fi

dnl ======================================================
dnl == end of modern doc tests
dnl ======================================================
SCROLLKEEPER_BUILD_REQUIRED=0.3.5
AC_SUBST(SCROLLKEEPER_BUILD_REQUIRED)

AC_SUBST(GNOMEHELP)
AC_SUBST(GPREFIX)

AC_CONFIG_FILES([
po/Makefile.in
Makefile 
src/Makefile
src/RelLib/Makefile
src/Config/Makefile
src/Mime/Makefile
src/ObjectSelector/Makefile
src/GrampsLogger/Makefile
src/TreeViews/Makefile
src/GrampsDb/Makefile
src/docgen/Makefile
src/Models/Makefile
src/Editors/Makefile
src/DataViews/Makefile
src/PluginUtils/Makefile
src/plugins/Makefile
src/DateHandler/Makefile
src/data/Makefile
src/glade/Makefile
src/images/Makefile
src/data/templates/Makefile
doc/Makefile
doc/man/Makefile
doc/man/fr/Makefile
doc/gramps-manual/Makefile
doc/gramps-manual/C/Makefile	
doc/gramps-manual/fr/Makefile	
example/Makefile
example/gramps/Makefile
])

AC_OUTPUT([
src/const.py
gramps.spec
gramps.sh
])