dnl Process this file with autoconf to produce a configure script.

AC_INIT(configure.in)
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE(terraform, 0.9.0)
AM_CONFIG_HEADER(config.h)

dnl extra configure arguments
AC_ARG_ENABLE(sgmltools, [ --disable-sgmltools      don't use sgmltools [default=no]],
                have_sgmltools="no", have_sgmltools="yes")


dnl Pick up the Gnome macros.
AM_ACLOCAL_INCLUDE(macros)

GNOME_INIT
AC_ISC_POSIX
AC_PROG_CC
AM_PROG_CC_STDC
AC_HEADER_STDC

GNOME_COMPILE_WARNINGS
GNOME_X_CHECKS
GNOME_XML_CHECK
GNOME_PRINT_CHECK

AM_PATH_GDK_PIXBUF(0.10.1,AC_DEFINE(HAVE_GDKPIXBUF))

dnl Add the languages which your application supports here.
ALL_LINGUAS="fr nl"
AM_GNU_GETTEXT

dnl OS/X (darwin) defines xxscanf() via a macro so the check incorrectly
dnl deduces that these functions are missing while they actually exist.
do_scanf_check="yes"
case "$target" in
  darwin*) do_scanf_check="no";;
esac

dnl Not all systems have these (IRIX, for example, doesn't)
if test "$do_scanf_check" = "yes"; then
  AC_CHECK_FUNC(vfscanf, HAVE_VFSCANF="yes", HAVE_VFSCANF="no")
  AC_CHECK_FUNC(vsscanf, HAVE_VSSCANF="yes", HAVE_VSSCANF="no")
  if test "$HAVE_VFSCANF" = "no"; then
    NEED_EXTERNAL_SCANF="yes";
  fi;
  if test "$HAVE_VSSCANF" = "no"; then
    NEED_EXTERNAL_SCANF="yes";
  fi;
fi

dnl Missing xxscanf and xxprintf functions can be supplied by libtrio
if test "$NEED_EXTERNAL_SCANF" = "yes"; then
  AC_CHECK_LIB(trio, trio_printf, HAVE_LIB_TRIO="yes", HAVE_LIB_TRIO="no")
  if test "$HAVE_LIB_TRIO" = "yes"; then
    AC_DEFINE (HAVE_LIB_TRIO)
  else
    echo "You don't have libtrio to provide missing libc xxscanf methods."
    echo "Please get it from http://sourceforge.net/projects/ctrio/"
    exit;
  fi;
fi;

dnl Set PACKAGE_LOCALE_DIR in config.h.
if test "x${prefix}" = "xNONE"; then
  AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${ac_default_prefix}/${DATADIRNAME}/locale")
else
  AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${prefix}/${DATADIRNAME}/locale")
fi

dnl
dnl libpng
dnl

png_ok="no"
AC_CHECK_LIB(png, png_read_info,
  AC_CHECK_HEADER(png.h, png_ok="yes", png_ok="no"),png_ok="no", -lz -lm)
if test "$png_ok" = "yes"; then
  AC_MSG_CHECKING([for png_structp in png.h])
  AC_TRY_COMPILE([#include <png.h>],
                 [png_structp pp; png_infop info; png_colorp cmap; png_create_read_struct;],
                 png_ok="yes",
                 png_ok="no")
  AC_MSG_RESULT($png_ok)
  if test "$png_ok" = "yes"; then
    PNG_LIBS='-lpng -lz -lm'
    AC_DEFINE(HAVE_LIBPNG)
  fi
fi
AC_SUBST(PNG_LIBS)

dnl
dnl Test for sgmltools
dnl
if test "x$have_sgmltools" = "xyes" ; then
        AC_CHECK_PROG(SGMLTOOLS, sgmltools, "yes", "no")
        if test "$SGMLTOOLS" = "no"; then
                have_sgmltools="no"
        fi
fi

if test "$SGMLTOOLS" = "yes" ; then
        AC_DEFINE(HAVE_SGMLTOOLS)
fi

AM_CONDITIONAL(HAVE_SGMLTOOLS, test "x$have_sgmltools" = "xyes")

dnl Subst PACKAGE_PIXMAPS_DIR.
PACKAGE_PIXMAPS_DIR="`gnome-config --datadir`/pixmaps/${PACKAGE}"
AC_SUBST(PACKAGE_PIXMAPS_DIR)

dnl Subst GNOME_DATADIR.
GNOME_DATADIR="`gnome-config --datadir`"
AC_SUBST(GNOME_DATADIR)

dnl extra conditionals
AM_CONDITIONAL(HAVE_LIB_TRIO, test "$HAVE_LIB_TRIO" = "yes")

AC_OUTPUT([
Makefile
terraform.spec
macros/Makefile
docs/Makefile
data/Makefile
data/image_maps/Makefile
data/include/Makefile
data/include/atmospheres/Makefile
data/include/earth_textures/Makefile
data/include/skies/Makefile
data/include/skies/include/Makefile
data/include/water/Makefile
data/include/water/Makefile
data/objects/Makefile
desktop-links/Makefile
help/Makefile
help/C/Makefile
help/fr/Makefile
src/Makefile
intl/Makefile
po/Makefile.in
])

