dnl Process this file with autoconf to produce a configure script.
AC_INIT(app/diagram.c)

AM_INIT_AUTOMAKE(dia, 0.86)

dnl Specify a header configuration file
AM_CONFIG_HEADER(config.h)

dnl Initialize maintainer mode
AM_MAINTAINER_MODE

dnl Initialize libtool
AC_DISABLE_STATIC
AC_PROG_LIBTOOL

dnl Build time sanity check
AM_SANITY_CHECK

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_ISC_POSIX

dnl Checks for libraries.
AM_PATH_GTK(1.2.0)

dnl XIM support (on by default)
AC_ARG_ENABLE(xim,
[  --disable-xim           enable gnome code],,enable_xim=yes)
AC_MSG_CHECKING([whether to enable XIM support])
if test "x$enable_xim" != xno; then
  AC_DEFINE(USE_XIM)
fi
AC_MSG_RESULT($enable_xim)

APP_LIBS=""
AC_SUBST(APP_LIBS)

dnl
dnl GNOME
dnl

AC_MSG_CHECKING([whether GNOME specific code should be used])
AC_ARG_ENABLE(gnome,
[  --enable-gnome          enable gnome code],
    GNOME=$enableval,
    GNOME=no)
AC_ARG_ENABLE(gnome-print,
[  --enable-gnome-print    enable gnome-print support],,enable_gnome_print=no)
AC_ARG_ENABLE(bonobo,
[  --enable-bonobo         enable bonobo support],,enable_bonobo=no)
AC_MSG_RESULT($GNOME)
GNOME_CFLAGS=""
GNOME_LIBS=""
BONOBO_LIBS=""
if test "$GNOME" = "yes"; then
  AC_DEFINE(GNOME)
  components="gnomeui"
  hcomponents=""
  if test "$enable_gnome_print" = "yes"; then
    AC_DEFINE(GNOME_PRINT)
    components="$components print"
  fi
  if test "$enable_bonobo" = "yes"; then
    hcomponents="$hcomponents bonobo"
    BONOBO_LIBS=`gnome-config bonobo $components --libs`

    AC_MSG_CHECKING(if bonobo uses oaf)
    using_oaf="no"
    if ( gnome-config --libs bonobo | grep oaf ) > /dev/null 2>&1 ; then
      using_oaf="yes"
      AC_DEFINE(USE_OAF)
    fi
    AC_MSG_RESULT($using_oaf)
    AM_CONDITIONAL(USING_OAF, test x"$using_oaf" = xyes)
  fi
  GNOME_CFLAGS=`gnome-config $hcomponents $components --cflags`
  GNOME_LIBS=`gnome-config $components --libs`
fi
AM_CONDITIONAL(HAVE_GNOME_PRINT,
	test "$GNOME" = "yes" && test "$enable_gnome_print" = "yes")
AM_CONDITIONAL(HAVE_BONOBO, 
	test "$GNOME" = "yes" && test "$enable_bonobo" = "yes")
AC_SUBST(GNOME_CFLAGS)
AC_SUBST(GNOME_LIBS)
AC_SUBST(BONOBO_LIBS)

dnl Check if this Gnome has Bonobo
OLDCPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS `glib-config --cflags`"


CPPFLAGS=$OLDCPPFLAGS

dnl
dnl Popt
dnl

AC_CHECK_LIB(popt, poptSetOtherOptionHelp, [AC_DEFINE(HAVE_LIBPOPT)
		   APP_LIBS="$APP_LIBS -lpopt"])
AC_CHECK_HEADERS(popt.h)

dnl
dnl libart_lgpl
dnl

AM_PATH_LIBART(2.1.0,dnl
 [have_libart=yes
  AC_DEFINE(HAVE_LIBART)],
 [have_libart=no])

dnl
dnl gdk_pixbuf or imlib
dnl

AM_PATH_GDK_PIXBUF(0.7.0,dnl
  [have_gdkpixbuf=yes
   AC_DEFINE(HAVE_GDK_PIXBUF) ],
  [have_gdkbuf=no
   AM_PATH_GDK_IMLIB(1.8.0,,dnl
    AC_MSG_ERROR(you need either gdk-pixbuf or imlib installed)) ])

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 Debugging
dnl

AC_ARG_ENABLE(debug, 
[  --enable-debug=[no/minimum/yes] turn on debugging [default=minimum]],
  ,
  enable_debug=minimum)

if test "x$enable_debug" = "xyes"; then
  DEBUG_FLAGS="-g -DENABLE_DEBUG"
else
  if test "x$enable_debug" = "xno"; then
    DEBUG_FLAGS=""
  else
    DEBUG_FLAGS=""
  fi
fi
AC_SUBST(DEBUG_FLAGS)

dnl
dnl i18n
dnl

ALL_LINGUAS="ca da de el en_GB fi fr ga hu it ja ko no pl pt ru sl sv tr uk zh_TW.Big5"

AM_GNU_GETTEXT
localedir='${prefix}/${DATADIRNAME}/locale'
AC_SUBST(localedir)

dnl	
dnl Locate the gnome-xml library
dnl
AC_CHECK_PROG(XML_CONFIG, xml-config, xml-config)
if test "$XML_CONFIG" != "" 
then
  AC_MSG_CHECKING(for libxml >= 1.8.5)
  vers=`$XML_CONFIG --version | sed -e "s/libxml //" | awk 'BEGIN {FS=".";} { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
  if test "$vers" -ge 1008005; then
    AC_MSG_RESULT(found)
  else
    AC_MSG_ERROR(you need libxml >= 1.8.5 for this version of dia)
  fi
  XML_LIBS="`$XML_CONFIG --libs`"
  XML_CFLAGS="`$XML_CONFIG --cflags`"
else
  AC_MSG_ERROR(Can't find libxml library.)
fi
AC_SUBST(XML_LIBS)
AC_SUBST(XML_CFLAGS)

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(stddef.h fcntl.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

dnl Checks for library functions.
AC_CHECK_FUNCS(select strcspn strdup strtol snprintf)

dnl Alpha needs -mieee or we get a segfault
dnl This shouldn't be needed but is here until a real solution is found
case "$host" in
  alpha*-*-linux*)
    CFLAGS="$CFLAGS -mieee"
    ;;
esac

DIA_CHECK_CFLAG(-Wall)
DIA_CHECK_CFLAG(-Wunused)
DIA_CHECK_CFLAG(-Winline)
DIA_CHECK_CFLAG(-Wmissing-prototypes)
DIA_CHECK_CFLAG(-Wmissing-declarations)

dnl Relieve register pressure on i386. Other architectures may become unable
dnl to debug, and usually have more registers anyway.
case "$host" in 
  i?86-pc-*)
    DIA_CHECK_CFLAG(-fomit-frame-pointer)
    ;;
esac

DIA_CHECK_CFLAG(-finline-functions)
DIA_CHECK_CFLAG(-fstrict-aliasing)

AC_OUTPUT(
Makefile
lib/Makefile
intl/Makefile
po/Makefile.in
objects/Makefile
objects/standard/Makefile
objects/network/Makefile
objects/UML/Makefile
objects/ER/Makefile
objects/FS/Makefile
objects/sybase/Makefile
objects/flowchart/Makefile
objects/custom/Makefile
objects/GRAFCET/Makefile
objects/chronogram/Makefile
objects/SADT/Makefile
shapes/Makefile
shapes/Circuit/Makefile
shapes/flowchart/Makefile
shapes/Contact/Makefile
shapes/network/Makefile
shapes/Pneumatic/Makefile
shapes/Electric/Makefile
shapes/Civil/Makefile
app/Makefile
samples/Makefile
sheets/Makefile
sheets/UML/Makefile
sheets/ER/Makefile
sheets/GRAFCET/Makefile
plug-ins/Makefile
plug-ins/cgm/Makefile
plug-ins/pstricks/Makefile
plug-ins/dxf/Makefile
plug-ins/hpgl/Makefile
plug-ins/wpg/Makefile
plug-ins/svg/Makefile
)

echo "

Configuration:
	Source code location:	${srcdir}
	Compiler:		${CC}

	Use gdk-pixbuf:				${have_gdkpixbuf}
	Libart (AA rendering, png export):	${have_libart}

	Gnome support:				${GNOME}
	Build bonobo component (not supported):	${enable_bonobo}
        Gnome-print support (not recommended):  ${enable_gnome_print}

Now type make to build dia."
