dnl
dnl Configure script for the Gnome library
dnl

AC_INIT(gnome.h)
AM_CONFIG_HEADER(config.h)

AC_CANONICAL_SYSTEM

AM_INIT_AUTOMAKE(gnome-libs, 1.0.12)

AM_ACLOCAL_INCLUDE(macros)

AC_ISC_POSIX
AC_PROG_CC
AC_STDC_HEADERS
AC_ARG_PROGRAM

AM_PROG_LIBTOOL

AM_MAINTAINER_MODE

dnl
dnl let applications configure for gnome
dnl
gnome_cv_use_gnome=yes

GNOME_COMPILE_WARNINGS

GNOME_X_CHECKS

GNOME_SUPPORT_CHECKS


dnl Evil stuff to extract GLIB stuff from gtk-config output
dnl (we want to make sure it matches with the gtk we're using)

changequote(,)dnl
GLIB_CFLAGS=`echo $GTK_CFLAGS | sed 's/^.*\(-I[^ ]*glib[^ ]*  *-I[^ ]*\).*$/\1/'`
GLIB_LDFLAGS=`echo $GTK_LIBS | sed -e 's/^.*-lgdk[^ ]* *\(-L[^ ]*\).*$/\1/' -e 's/^.* -lgdk[^ ]* .*$//'`
if test -z "$GLIB_LDFLAGS" ; then
  GLIB_LDFLAGS=`echo $GTK_LIBS | sed -e 's/\(-L[^ ]*\) .*$/\1/' -e 's/^.*\(-L[^ ]*\)$/\1/'`
fi 
GLIB_LIBS="$GLIB_LDFLAGS `echo $GTK_LIBS | sed 's/^.*\(-lglib[^ ]*\).*$/\1/'`"
changequote([,])dnl

AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

# define a MAINT-like variable REBUILD which is set if Perl
# and awk are found, so autogenerated sources can be rebuilt

AC_PROG_AWK
AC_CHECK_PROGS(PERL, perl5 perl)

AC_CHECK_PROG(GTKDOC, gtkdoc-mkdb, true, false)
AM_CONDITIONAL(HAVE_GTK_DOC, $GTKDOC)
AC_SUBST(HAVE_GTK_DOC)

dnl Let people disable the gtk-doc stuff.
AC_ARG_ENABLE(gtk-doc, [  --enable-gtk-doc  Use gtk-doc to build documentation [default=auto]], enable_gtk_doc="$enableval", enable_gtk_doc=auto)

if test x$enable_gtkdoc = xauto ; then
  if test x$GTKDOC = xtrue ; then
    enable_gtkdoc=yes
  else
    enable_gtkdoc=no
  fi
fi

dnl NOTE: We need to use a separate automake conditional for this
dnl       to make this work with the tarballs.
AM_CONDITIONAL(ENABLE_GTK_DOC, test x$enable_gtkdoc = xyes)
    

# We would like indent, but don't require it.
AC_CHECK_PROG(INDENT, indent, indent)

REBUILD=\#
if test -n "$PERL" && $PERL -v | grep 'version 5.' > /dev/null ; then
  if test -n "$AWK" ; then 
    REBUILD=
  fi
fi
AC_SUBST(REBUILD)

dnl Utility conditional
AM_CONDITIONAL(FALSE, test x = y)

AC_ARG_ENABLE(debug, [  --enable-debug turn on debugging [default=no]], enable_debug="$enableval", enable_debug=no)

if test x$enable_debug = xyes ; then
  AC_DEFINE(GNOME_ENABLE_DEBUG)
fi

ALL_LINGUAS="ca cs da de el en_GB es eu fi fr ga hr hu it ja ko nl no pl pt ru sk sv wa zh_TW.Big5"
	
AM_GNOME_GETTEXT
# AM_GNOME_GETTEXT above substs $DATADIRNAME
# this is the directory where the *.{mo,gmo} files are installed
gnomelocaledir='${prefix}/${DATADIRNAME}/locale'
AC_SUBST(gnomelocaledir)

AC_CHECK_LIB(m, main)

AC_CHECK_HEADERS(dlfcn.h dl.h)

DL_LIB=
AC_CHECK_FUNCS(dlopen,,[
AC_CHECK_LIB(dl, dlopen, DL_LIB="-ldl",[
AC_CHECK_LIB(dld, shl_load, DL_LIB="-ldld",[
AC_CHECK_FUNCS(dlopen, DL_LIB="",
AC_MSG_ERROR(Dynamic linking is not available on this platform.  Some apps,
like panel, will not run properly.))
])])])
oLIBS="$LIBS"
LIBS="$LIBS $DL_LIB"
AC_CHECK_FUNCS(dlerror,,)
LIBS="$oLIBS"
AC_SUBST(DL_LIB)

AC_CHECK_FUNCS(strerror gethostbyname setfsgid setenv putenv strdup)
oLIBS="$LIBS"
LIBS="-lm"
AC_CHECK_FUNCS(hypot)
LIBS="$oLIBS"

NSL_LIBS=""
if test $ac_cv_func_gethostbyname = no; then
  AC_CHECK_LIB(nsl,gethostbyname,NSL_LIBS=-lnsl)
fi
AC_SUBST(NSL_LIBS)
AC_CHECK_FUNC(inet_aton,,[AC_CHECK_LIB(resolv,inet_aton)])

dnl libgtkxmhtml enables a workaround if this isn't present
xLIBS="$LIBS"
LIBS="$GTK_LIBS $X_LIBS $x_libs $LIBS"
AC_CHECK_FUNCS(gtk_signal_handler_pending)
LIBS="$xLIBS"

dnl
dnl zvt checks
dnl
AC_CHECK_HEADERS(sys/select.h sys/time.h sys/un.h paths.h sys/syslimits.h sys/fsuid.h)

dnl
dnl gnome-pty-support checks
dnl

AC_MSG_CHECKING([for Unix98 sendmsg])
AC_TRY_LINK([
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
],[
struct msghdr hdr;
hdr.msg_control = NULL;
hdr.msg_controllen = 0;
sendmsg (0, &hdr, 0);
],[
AC_DEFINE(HAVE_SENDMSG)
AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])

AC_CHECK_UTMP

AC_CHECK_HEADERS(pty.h util.h libutil.h ttyent.h)

AC_CHECK_LIB(util, openpty,
    [
    AC_CHECK_LIB(util, login_tty, [AC_DEFINE(HAVE_LOGIN_TTY)])
    AC_DEFINE(HAVE_OPENPTY)
    AC_DEFINE(HAVE_LIBUTIL)
    UTIL_LIBS="-lutil"
    AC_SUBST(UTIL_LIBS)
    ])

AC_CHECK_FUNCS(grantpt utmpxname utmpname getutmpx getutent getttyent)
AC_CHECK_FUNCS(updwtmpx updwtmp fcntl flock strrchr seteuid)

AC_CHECK_HEADER(stropts.h, AC_DEFINE(HAVE_STROPTS_H))
AC_CHECK_HEADER(dlfcn.h, AC_DEFINE(HAVE_DLFCN_H))

dnl And workaround for a Autoconf 2.4 bug:
if test x$ac_cv_func_grantpt = xyes; then
    :
else
    AC_CHECK_LIB(pt, grantpt)
fi

dnl
dnl Image handling libraries
dnl
Z_LIBS= JPEG_LIBS= PNG_LIBS= TIFF_LIBS= GIF_LIBS= GDK_IMLIB_LIBS=

dnl Test for libz
AC_CHECK_LIB(z, inflate,
  AC_CHECK_HEADER(zlib.h,
    Z_LIBS="-lz";  AC_DEFINE(HAVE_LIBZ)))
AC_CHECK_LIB(z, compress, , 
   AC_MSG_ERROR([[
*** Incorrect libz version found.  Please make sure you do not have
*** an outdated libz.a or libz.so hiding in your X11 distribution or
*** elsewhere on your system.  Versions of libz with the "compress" and
*** "uncompress" symbols are sufficiently recent to build GNOME.]]))

dnl Test for libjpeg
AC_CHECK_LIB(jpeg, jpeg_destroy_decompress,
  jpeg_ok=yes,
  jpeg_ok=no)
if test "$jpeg_ok" = yes; then
  AC_MSG_CHECKING([for jpeglib.h])
  AC_TRY_CPP(
[#include <stdio.h>
#undef PACKAGE
#undef VERSION
/* AAARGH!!! jpeglib.h defines HAVE_STDLIB_H.  */
#undef HAVE_STDDEF_H
#undef HAVE_STDLIB_H
#include <jpeglib.h>],
    jpeg_ok=yes,
    jpeg_ok=no)
  AC_MSG_RESULT($jpeg_ok)
  if test "$jpeg_ok" = yes; then
    JPEG_LIBS="-ljpeg"; AC_DEFINE(HAVE_LIBJPEG)
  fi
fi

dnl Test for libtiff
AC_CHECK_LIB(tiff, TIFFReadScanline,
  AC_CHECK_HEADER(tiffio.h,
    TIFF_LIBS="-ltiff"; AC_DEFINE(HAVE_LIBTIFF)),
  AC_CHECK_LIB(tiff, TIFFWriteScanline,
    AC_CHECK_HEADER(tiffio.h,
      TIFF_LIBS="-ltiff $JPEG_LIBS $Z_LIBS"; AC_DEFINE(HAVE_LIBTIFF)),
    AC_CHECK_LIB(tiff34, TIFFFlushData,
      AC_CHECK_HEADER(tiffio.h,
        TIFF_LIBS="-ltiff34 $JPEG_LIBS $Z_LIBS"; AC_DEFINE(HAVE_LIBTIFF)),,
$JPEG_LIBS $Z_LIBS -lm), $JPEG_LIBS $Z_LIBS -lm), -lm)

dnl Test for libgif
AC_CHECK_LIB(gif, DGifOpenFileName,
  AC_CHECK_HEADER(gif_lib.h,
    GIF_LIBS="-lgif"; AC_DEFINE(HAVE_LIBGIF)),,$GTK_LIBS)

dnl Test for libungif
AC_CHECK_LIB(ungif, DGifOpenFileName,
  AC_CHECK_HEADER(gif_lib.h,
    GIF_LIBS="-lungif"; AC_DEFINE(HAVE_LIBGIF)),,$GTK_LIBS)

dnl Test for libpng
AC_CHECK_LIB(png, png_read_info,
  AC_CHECK_HEADER(png.h,
    png_ok=yes,
    png_ok=no),,$Z_LIBS -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 $Z_LIBS"; AC_DEFINE(HAVE_LIBPNG)
  fi
fi

dnl Tests to support libvfs.
AC_CHECK_FUNCS(strdup)
AC_CHECK_HEADERS(utime.h)
AC_FUNC_MMAP
AC_CHECK_TYPE(umode_t, int)

dnl
dnl Check for db stuff (gnome-metadata)
dnl
DB_LIB=
AC_CHECK_FUNC(dbopen,,[
  AC_CHECK_LIB(db, dbopen, DB_LIB="-ldb",[
    AC_CHECK_LIB(db, db_open, [
      AC_MSG_ERROR([Your db library is missing db 1.85 compatibility mode])], [
      AC_MSG_ERROR([Berkeley db library required for Gnome])])])])

dnl the SleepyCat db2 library has a compatibility header for db 1.85.
AC_CHECK_HEADERS(db_185.h db.h)

if test x$ac_cv_header_db_185_h = xno && test x$ac_cv_header_db_h = xno; then
  AC_MSG_ERROR([Berkeley db library required for Gnome])
fi

dnl
dnl This is needed for the gnome-moz-remote program.  It doesn't use GDK,
dnl since some of the code in it was written before GDK existed.
dnl
AC_PATH_X
AC_PATH_XTRA

AM_PATH_GDK_IMLIB(1.9, [define_imlib_1_9=true],[
    AM_PATH_GDK_IMLIB(1.8,[
	    LIBGNOMEUI_LIBS="$LIBGNOMEUI_LIBS $PNG_LIBS"
	],[AC_MSG_ERROR([*** IMLIB 1.8 not installed - please install first ***])])])


if test x$define_imlib_1_9 = xtrue; then
    AC_DEFINE(HAVE_IMLIB_1_9)
fi

dnl
dnl Check for esound library
dnl
AM_PATH_ESD(0.2.5, AC_DEFINE(HAVE_ESD))

dnl
dnl Check for audiofile library
dnl
AM_PATH_AUDIOFILE(0.1.5,AC_DEFINE(HAVE_LIBAUDIOFILE))

dnl
dnl These are for building the appropriate lib*
dnl
LIBGNOME_LIBS="$ESD_LIBS $AUDIOFILE_LIBS $DB_LIB $GLIB_LIBS $DL_LIB"
LIBGNOMEUI_LIBS="$LIBGNOME_LIBS $GDK_IMLIB_LIBS $GTK_LIBS"
LIBGTKXMHTML_LIBS="$XPM_LIBS $JPEG_LIBS $PNG_LIBS $Z_LIBS $GTK_LIBS"
LIBSUPPORT='$(top_builddir)/support/libgnomesupport.la'
SUPPORTINCS='-DNEED_GNOMESUPPORT_H -I$(top_builddir)/support -I$(top_srcdir)/support'

dnl These are for using lib*
ART_LIBS="-lart_lgpl"
GNOME_LIBS="-lgnome -lgnomesupport $LIBGNOME_LIBS"
GNOMEUI_LIBS="-lgnomeui $ART_LIBS $GDK_IMLIB_LIBS $GTK_LIBS $GNOME_LIBS"
GTKXMHTML_LIBS="-lgtkxmhtml $LIBGTKXMHTML_LIBS"
ZVT_LIBS="-lzvt $UTIL_LIBS $GTK_LIBS"

dnl These definitions are expanded in make and gnome-config
GNOME_LIBDIR='-L${libdir}'
GNOME_INCLUDEDIR='-I${includedir} -DNEED_GNOMESUPPORT_H -I${pkglibdir}/include'
GNOME_IDLDIR='-I${datadir}/idl'

dnl
dnl ORBit checks
dnl
GNOME_ORBIT_CHECK

dnl
dnl Gnome-Hello
dnl
AC_ARG_ENABLE(gnome-hello, [  --enable-gnome-hello    compile the gnome-hello examples [default=yes]],[compile_gnome_hello="$enableval"],[compile_gnome_hello=yes])
AM_CONDITIONAL(COMPILE_GNOME_HELLO, test x$compile_gnome_hello = xyes)

AC_ARG_ENABLE(test-gnome, [  --enable-test-gnome     compile the test-gnome examples [default=yes]],[compile_test_gnome="$enableval"],[compile_test_gnome=yes])
AM_CONDITIONAL(COMPILE_TEST_GNOME, test x$compile_test_gnome = xyes)

dnl AC_CONFIG_SUBDIRS(libgtktty)

dnl
dnl LibART_LGPL
dnl
AC_CONFIG_SUBDIRS(libart_lgpl)

dnl
dnl GNOME libs Documentation
dnl 
GNOME_LIBS_DIR=`(cd $srcdir; pwd)`
AC_SUBST(GNOME_LIBS_DIR)

AM_CONDITIONAL(INSIDE_GNOME_DOCU, false)

dnl
dnl Substitutions
dnl

AC_SUBST(ESD_LIBS)
AC_SUBST(GTK_LIBS)
AC_SUBST(GNOME_LIBS)
AC_SUBST(GNOMEUI_LIBS)
AC_SUBST(ZVT_LIBS)
AC_SUBST(GTKXMHTML_LIBS)
AC_SUBST(GNOME_LIBDIR)
AC_SUBST(GNOME_INCLUDEDIR)
AC_SUBST(GNOME_IDLDIR)
AC_SUBST(LIBSUPPORT)
AC_SUBST(SUPPORTINCS)

AC_SUBST(LIBGNOME_LIBS)
AC_SUBST(LIBGNOMEUI_LIBS)
AC_SUBST(LIBGTKXMHTML_LIBS)

dnl
dnl List of files to create
dnl
AC_OUTPUT([
gnome-bug
gnome-config
gnome-libs.spec
Makefile
po/Makefile.in
intl/Makefile
images/Makefile
gtk-xmhtml/Makefile
idl/Makefile
libgnome/Makefile
libgnomeui/Makefile
libgnomeui/pixmaps/Makefile
libgnorba/Makefile
libvfs/Makefile
zvt/Makefile
test-suite/Makefile
test-suite/tests/Makefile
gnome-data/Makefile
gnome-hello/Makefile
test-gnome/Makefile
gnome-faq/Makefile
devel-docs/Makefile
devel-docs/gnome/Makefile
devel-docs/gnomeui/Makefile
devel-docs/gnorba/Makefile
devel-docs/templates/Makefile
devel-docs/ui-guide/Makefile
man/Makefile
devel-docs/zvt/Makefile
support/Makefile
tools/Makefile
tools/convertrgb/Makefile
tools/gnome-doc/Makefile
macros/Makefile])
