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

dnl AC_PREREQ(2.50)
dnl AC_REVISION($Revision: 1.127 $)

AM_INIT_AUTOMAKE(dia, 0.88.1)

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

dnl do this check now, to keep autogen quiet.
AC_PROG_CC 

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.
dnl AC_PROG_CC # already done 
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_ISC_POSIX

dnl stuff for xml-i18n-tools
AC_PROG_XML_I18N_TOOLS(0.9,UTF-8) 
dnl make that 0.10 as soon as the version number is bumped.
dnl XML_I18N_TOOLS_NEWER_THAN_0_9 || AC_MSG_ERROR(unsatisfied dependency)


dnl Checks for libraries.
dnl AM_PATH_GLIB(1.2.9) dnl (for g_critical)
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=""
bonobo_msg=no
have_gnome=false
have_bonobo=false
if test "$GNOME" = "yes"; then
  AC_DEFINE(GNOME)
  have_gnome=true
  components="gnomeui"
  hcomponents=""
  if test "$enable_gnome_print" = "yes"; then
    AC_DEFINE(GNOME_PRINT)
    components="$components print"
  fi
  if test "$enable_bonobo" = "yes"; then

    AC_MSG_CHECKING(for Bonobo >= 0.31)

    if gnome-config --libs bonobox_print > /dev/null 2>&1; then
      vers=`gnome-config --modversion bonobo | sed -e "s/bonobo-//" | \
  	awk 'BEGIN { FS = "."; } { printf "%d", $1 * 1000 + $2;}'`
      if test "$vers" -ge 31; then
        bonobo_ok=true
      else
        bonobo_ok=false
      fi
    else
      bonobo_ok=false
    fi
	
    if $bonobo_ok; then
      AC_MSG_RESULT([found ("$vers")])
      have_bonobo=true
      bonobo_msg=yes
    else
      AC_MSG_RESULT([not found])
    fi

    hcomponents="$hcomponents bonobox_print"
    BONOBO_LIBS=`gnome-config bonobox_print $components --libs`
  fi
  GNOME_CFLAGS=`gnome-config $hcomponents $components --cflags`
  GNOME_LIBS=`gnome-config $components --libs`
fi
AM_CONDITIONAL(HAVE_GNOME, $have_gnome)
AM_CONDITIONAL(HAVE_GNOME_PRINT,
	$have_gnome && test "$enable_gnome_print" = "yes")
AM_CONDITIONAL(HAVE_BONOBO, $have_bonobo)

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

dnl This is required to play character set games
AM_LANGINFO_CODESET
AM_ICONV

dnl check for libunicode 
AC_ARG_ENABLE(unicode, 
[  --enable-unicode    enable (LIMITED, EXPERIMENTAL) unicode support],,
        enable_unicode=yes)
UNICODE_CFLAGS=
UNICODE_LIBS=
have_unicode=false
yn_have_unicode=no

if test "$enable_unicode" = "yes"; then
  AC_MSG_CHECKING(for libunicode)
  if unicode-config --libs > /dev/null 2>&1; then
    vers=`unicode-config --version`
    have_unicode=true     
    yn_have_unicode=yes        
    UNICODE_CFLAGS=`unicode-config --cflags`
    UNICODE_LIBS=`unicode-config --libs`
    AC_DEFINE(HAVE_UNICODE,, Unicode support library available)
    AC_MSG_RESULT([found, version $vers])
  else
    AC_MSG_RESULT([not found])
  fi
else
  have_unicode=false
fi
AC_SUBST(UNICODE_CFLAGS)
AC_SUBST(UNICODE_LIBS)
AM_CONDITIONAL(HAVE_UNICODE,$have_unicode)

CPPFLAGS=$OLDCPPFLAGS

dnl check for libfreetype
AC_ARG_ENABLE(freetype, 
[  --enable-freetype    enable (LIMITED, EXPERIMENTAL) freetype support],,
        freetype=yes)
FREETYPE_CFLAGS=
FREETYPE_LIBS=
have_freetype=false
yn_have_freetype=no

if test "$enable_freetype" = "yes"; then
  AC_MSG_CHECKING(for libfreetype)
  if freetype-config --libs > /dev/null 2>&1; then
    vers=`freetype-config --version`
    have_freetype=true     
    yn_have_freetype=yes        
    FREETYPE_CFLAGS=`freetype-config --cflags`
    FREETYPE_LIBS=`freetype-config --libs`
    AC_DEFINE(HAVE_FREETYPE,, Freetype support library available)
    AC_MSG_RESULT([found, version $vers])
  else
    AC_MSG_RESULT([not found])
  fi
else
  have_freetype=false
fi
AC_SUBST(FREETYPE_CFLAGS)
AC_SUBST(FREETYPE_LIBS)
AM_CONDITIONAL(HAVE_FREETYPE,$have_freetype)

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
dnl

AM_PATH_GDK_PIXBUF(0.7.0,,AC_MSG_ERROR([gdk-pixbuf >= 0.7.0 is required]))

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="az ca da de el en_GB es fi fr ga hu it ja ko nl nn no pl pt pt_BR ru sl sv tr uk zh_CN.GB2312 zh_TW.Big5"

AM_GNU_GETTEXT

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

dnl	
dnl Locate the gnome-xml library
dnl

AC_CHECK_PROG(XML2_CONFIG, xml2-config, xml2-config)
if test "$XML2_CONFIG" != ""
then
  AC_MSG_CHECKING(for libxml >= 2.3.9)
  vers=`$XML2_CONFIG --version | sed -e "s/libxml //" | awk 'BEGIN {FS=".";} { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
  if test "$vers" -ge 2003009; then
    AC_MSG_RESULT(found)
    XML_LIBS="`$XML2_CONFIG --libs`"
    XML_CFLAGS="`$XML2_CONFIG --cflags`"

    if test "$enable_gnome_print" = "yes"
    then
        gnome-config --cflags print | \
        grep gnome-xml 2>&1 >/dev/null && \
        AC_MSG_ERROR(libxml2 found but gnome-print uses libxml1 ; this is a conflict.\nPlease do either provide libxml1 or disable gnome-print.)
    fi
    echo $GNOME_CFLAGS | \
    grep gnome-xml 2>&1 >/dev/null && \
    AC_MSG_ERROR(libxml2 found but one GNOME component uses libxml1 ; this is a conflict.\nPlease do either provide libxml1 or disable the offending GNOME component.)
        
  else
    AC_MSG_RESULT(not found)
  fi
fi
if test "$XML_CONFIG" = ""
then
  AC_CHECK_PROG(XML_CONFIG, xml-config, xml-config)
  if test "$XML_CONFIG" != "" 
  then
    AC_MSG_CHECKING(for libxml >= 1.8.14)
    vers=`$XML_CONFIG --version | sed -e "s/libxml //" | awk 'BEGIN {FS=".";} { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
    if test "$vers" -ge 1008014; then
      dnl 1.18.14 is required for xmlUseNewParser()    
      AC_MSG_RESULT(found)
    else
      AC_MSG_ERROR(you need libxml >= 1.8.14 for this version of dia)
    fi
    XML_LIBS="`$XML_CONFIG --libs`"
    XML_CFLAGS="`$XML_CONFIG --cflags`"
  else 
    AC_MSG_RESULT(not found)
  fi
fi

if test "$XML_CONFIG" != "" -a "$XML2_CONFIG" != ""
then
    AC_MSG_ERROR(Both libxml1 and libxml2 found. You need to choose one or face crashes.\nWe advise you use only libxml1 for the moment.)
fi

if test "$XML_CONFIG" = "" -a "$XML2_CONFIG" = ""
then
    AC_MSG_ERROR(Neither libxml1 or libxml2 found. You must install one (libxml1, preferably))
fi

AC_SUBST(XML_LIBS)
AC_SUBST(XML_CFLAGS)

CFLAGS="$XML_CFLAGS $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 Set some variables we'll need for the UTF-8 transition.
gtk_advancement=initial

if $gtk_advancement = initial ; then
   AC_DEFINE(GTK_DOESNT_SPEAK_UTF8_NEITHER_DO_WE,,
          We haven't begun the transition yet)
elif $gtk_advancement=dia_talks_utf8 ; then
   AC_DEFINE(UNICODE_WORK_IN_PROGRESS,,Cyrille's work towards UTF-8)
   AC_DEFINE(GTK_DOESNT_TALK_UTF8_WE_DO,,...)
   AC_DEFINE(GTK_CHARSET_MISMATCH,,     
             Mismatch between the charset dia uses and the charset GTK uses)
elif $gtk_advancement = dia_under_win32 ; then
   dnl please check this with Hans. I believe this is true -- CC
   AC_DEFINE(GTK_TALKS_UTF8,,...)
   AC_DEFINE(GTK_TALKS_UTF8_WE_DONT,,...)
   AC_DEFINE(GTK_CHARSET_MISMATCH,,     
             Mismatch between the charset dia uses and the charset GTK uses)
elif $gtk_advancement = gtk2 ; then
   AC_DEFINE(GTK_TALKS_UTF8,,...)
   AC_DEFINE(UNICODE_WORK_IN_PROGRESS,,Cyrille's work towards UTF-8)
   dnl the latter shouldn't appear anymore by then (manually compiled)
fi

dnl Solaris provides isinf() in -lsunmath and defines finite() in math.h
  AC_CHECK_HEADERS(ieeefp.h sunmath.h)
  AC_CHECK_LIB(sunmath,isinf)

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.
dnl case "$host" in 
dnl  i?86-pc-*)
dnl    DIA_CHECK_CFLAG(-fomit-frame-pointer)
dnl    ;;
dnl esac
dnl (it looks like gdb is very confused by this now even on x86. We might be
dnl getting poor stack traces with bug-buddy because of this)

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

dnl Do we have the db2html script to build the documentation?
AC_PATH_PROG(DB2HTML, db2html, no)
AM_CONDITIONAL(HAVE_DB2HTML, test "x$DB2HTML" != xno)

dnl Handling for Python
AC_ARG_WITH(python,
[  --with-python           compile python plug-in],,with_python=no)

#hello
if test "x$with_python" != xno; then
  AM_PATH_PYTHON(1.5.2)
  AM_CHECK_PYMOD(gtk,,,[AC_MSG_ERROR(could not find pygtk module)])
  AM_CHECK_PYTHON_HEADERS
  AM_CHECK_PYTHON_LIB

  if test -z "$PYTHON_INCLUDES" || test -z "$PYTHON_LIBS"; then
    AC_MSG_ERROR([could not find files required to build python plugin])
  fi
fi
AM_CONDITIONAL(WITH_PYTHON, test "x$with_python" != "xno")

AC_OUTPUT(
Makefile
lib/Makefile
 po/Makefile.in intl/Makefile
objects/Makefile
objects/standard/Makefile
objects/network/Makefile
objects/UML/Makefile
objects/EML/Makefile
objects/ER/Makefile
objects/FS/Makefile
dnl 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
shapes/jigsaw/Makefile
shapes/MSE/Makefile
shapes/SDL/Makefile
shapes/Logic/Makefile
shapes/sybase/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
plug-ins/shape/Makefile
plug-ins/xfig/Makefile
plug-ins/python/Makefile
doc/Makefile
doc/en/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):	${bonobo_msg}
        Gnome-print support (not recommended):  ${enable_gnome_print}

	Python support:				${with_python}
        (LIMITED) Unicode support:              ${yn_have_unicode}
        (LIMITED) Freetype support:             ${yn_have_freetype}
"
if test "$yn_have_unicode" != "yes" ; then
  echo "WARNING: Unicode support disabled or support libraries missing.
We contemplate making these mandatory in the future; if this upsets you, please
speak up *NOW* (summer 2001), in the dia mailing list 
<dia-list@lists.gnome.org>. Thank you very much.
"
fi

echo "Now type make to build dia."

