m4_define([cthulhu_version], [0.3])

m4_define(pygobject_required_version, 3.18)
m4_define(atspi_required_version, 2.48)
m4_define(atkbridge_required_version, 2.26)

AC_INIT([cthulhu],[cthulhu_version],[https://gitlab.gnome.org/GNOME/cthulhu/-/issues/],[cthulhu])

AC_CONFIG_MACRO_DIR([m4])

AM_INIT_AUTOMAKE([1.11 tar-ustar no-dist-gzip dist-xz])
AM_MAINTAINER_MODE([enable])

dnl Gettext stuff
# FIXME: Remove AM_GNU_GETTEXT_VERSION once autoreconf supports REQUIRE_VERSION
AM_GNU_GETTEXT_VERSION([0.19.8])
AM_GNU_GETTEXT_REQUIRE_VERSION([0.19.8])
AM_GNU_GETTEXT([external])

GETTEXT_PACKAGE=AC_PACKAGE_TARNAME
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [gettext package])

# User Documentation
YELP_HELP_INIT

PKG_CHECK_MODULES([PYGOBJECT], [pygobject-3.0 >= pygobject_required_version])
PKG_CHECK_MODULES([ATSPI2], [atspi-2 >= atspi_required_version])
PKG_CHECK_MODULES([ATKBRIDGE], [atk-bridge-2.0 >= atkbridge_required_version])
PKG_CHECK_MODULES([GSTREAMER], [gstreamer-1.0], [gstreamer="yes"], [gstreamer="no"])

dnl Needed programs
AC_PROG_INSTALL

dnl Check for python and python modules needed by Cthulhu
dnl TODO: check for incompatibilities between Cthulhu and liblouis
dnl per http://live.gnome.org/Cthulhu/Braille
AM_PATH_PYTHON(3.3)

# Don't require the DISPLAY to be set - the gtk checking will fail 
# if DISPLAY is not set, and we don't like that.

AM_CHECK_PYMOD(gi,,,[AC_MSG_ERROR(Could not find python module: gi)])
AM_CHECK_PYMOD(json,,,[AC_MSG_ERROR(Could not find python module: json)])
AM_CHECK_PYMOD(brlapi,,[brlapi_available="yes"],[brlapi_available="no"])
AM_CHECK_PYMOD(speechd,,[speechd_available="yes"],[speechd_available="no"])
AC_ARG_WITH([liblouis],
  AS_HELP_STRING([--without-liblouis], [Disable liblouis support]))

AS_IF([test "x$with_liblouis" != xno],
  [AM_CHECK_PYMOD(louis,,[louis_available="yes"],[louis_available="no"])],
  [louis_available=no])

if test "x$with_liblouis" = xyes -a "x$louis_available" = xno; then
  AC_MSG_ERROR([Liblouis was requested but could not be found])
fi

LOUIS_TABLE_DIR=""
if test x$louis_available = "xyes"; then
  LOUIS_TABLE_DIR=`pkg-config --variable=tablesdir liblouis`
fi
AC_SUBST(LOUIS_TABLE_DIR)

REVISION=`git rev-parse --short HEAD 2> /dev/null`
AC_SUBST(REVISION)

dnl Check for the OS. On *Solaris systems the PATH must be set
PLATFORM=`uname -a`
case "${PLATFORM}" in
    *SunOS*)
            PLATFORM_PATH=":/usr/ccs/bin:/usr/bin:/usr/sbin:/bin:/usr/sfw/bin:/usr/openwin/bin:/usr/X11R6/bin"
            ;;
    *Linux*)
            PLATFORM_PATH=":/usr/bin:/usr/sbin:/bin"
            ;;
esac
AC_SUBST(PLATFORM_PATH)

AC_CONFIG_FILES([
Makefile
docs/Makefile
docs/man/Makefile
po/Makefile.in
help/Makefile
icons/Makefile
src/Makefile
src/cthulhu/Makefile
src/cthulhu/scripts/Makefile
src/cthulhu/scripts/apps/Makefile
src/cthulhu/scripts/apps/Banshee/Makefile
src/cthulhu/scripts/apps/Eclipse/Makefile
src/cthulhu/scripts/apps/epiphany/Makefile
src/cthulhu/scripts/apps/evince/Makefile
src/cthulhu/scripts/apps/evolution/Makefile
src/cthulhu/scripts/apps/gajim/Makefile
src/cthulhu/scripts/apps/gcalctool/Makefile
src/cthulhu/scripts/apps/gedit/Makefile
src/cthulhu/scripts/apps/gnome-documents/Makefile
src/cthulhu/scripts/apps/gnome-shell/Makefile
src/cthulhu/scripts/apps/kwin/Makefile
src/cthulhu/scripts/apps/notification-daemon/Makefile
src/cthulhu/scripts/apps/notify-osd/Makefile
src/cthulhu/scripts/apps/pidgin/Makefile
src/cthulhu/scripts/apps/soffice/Makefile
src/cthulhu/scripts/apps/SeaMonkey/Makefile
src/cthulhu/scripts/apps/smuxi-frontend-gnome/Makefile
src/cthulhu/scripts/apps/Thunderbird/Makefile
src/cthulhu/scripts/apps/xfwm4/Makefile
src/cthulhu/scripts/switcher/Makefile
src/cthulhu/scripts/terminal/Makefile
src/cthulhu/scripts/web/Makefile
src/cthulhu/scripts/toolkits/Makefile
src/cthulhu/scripts/toolkits/Chromium/Makefile
src/cthulhu/scripts/toolkits/Gecko/Makefile
src/cthulhu/scripts/toolkits/J2SE-access-bridge/Makefile
src/cthulhu/scripts/toolkits/clutter/Makefile
src/cthulhu/scripts/toolkits/GAIL/Makefile
src/cthulhu/scripts/toolkits/Qt/Makefile
src/cthulhu/scripts/toolkits/WebKitGtk/Makefile
src/cthulhu/scripts/toolkits/gtk/Makefile
src/cthulhu/plugins/Makefile
src/cthulhu/plugins/ByeCthulhu/Makefile
src/cthulhu/plugins/HelloCthulhu/Makefile
src/cthulhu/plugins/PluginManager/Makefile
src/cthulhu/plugins/Clipboard/Makefile
src/cthulhu/plugins/HelloWorld/Makefile
src/cthulhu/plugins/CapsLockHack/Makefile
src/cthulhu/plugins/SelfVoice/Makefile
src/cthulhu/plugins/Date/Makefile
src/cthulhu/plugins/Time/Makefile
src/cthulhu/plugins/MouseReview/Makefile
src/cthulhu/plugins/ClassicPreferences/Makefile
src/cthulhu/backends/Makefile
src/cthulhu/cthulhu_bin.py
src/cthulhu/cthulhu_i18n.py
src/cthulhu/cthulhu_platform.py
])
AC_CONFIG_COMMANDS([default],[cp src/cthulhu/cthulhu_bin.py src/cthulhu/cthulhu],[])
AC_OUTPUT

if test "x$brlapi_available" = "xno" ; then
echo
echo "NOTE: Braille support requires BrlTTY >= 3.9 and BrlAPI >= 0.5.1."
fi
if test "x$wnck_available" = "xno" ; then
echo
echo "NOTE: Mouse review requires wnck, which was not found."
fi

if test "x$speechd_available" = "xno" ; then
echo
echo "NOTE: Speech support requires speech-dispatcher >= 0.8."
fi

if test "x$gstreamer" = "xno" ; then
echo
echo "NOTE: Sound support requires gstreamer-1.0."
fi

echo
echo Use speech-dispatcher: $speechd_available
echo Use brltty: $brlapi_available
echo Use liblouis: $louis_available
echo Use gstreamer: $gstreamer
echo
