# Process this file with autoconf to produce a configure script.
AC_INIT(gdk-pixbuf/gdk-pixbuf.c)

# Save this value here, since automake will set cflags later
cflags_set=${CFLAGS+set}

AM_CONFIG_HEADER(config.h)

GDK_PIXBUF_MAJOR=0
GDK_PIXBUF_MINOR=18
GDK_PIXBUF_MICRO=0
GDK_PIXBUF_VERSION="${GDK_PIXBUF_MAJOR}.${GDK_PIXBUF_MINOR}.${GDK_PIXBUF_MICRO}"
AM_INIT_AUTOMAKE(gdk-pixbuf, ${GDK_PIXBUF_VERSION})

AC_SUBST(GDK_PIXBUF_MAJOR)
AC_SUBST(GDK_PIXBUF_MINOR)
AC_SUBST(GDK_PIXBUF_MICRO)
AC_SUBST(GDK_PIXBUF_VERSION)
AM_PROG_LIBTOOL

AC_PROG_CC
AC_ISC_POSIX
AM_PROG_CC_STDC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_CPP
AC_PATH_XTRA

dnl  Initialize maintainer mode
AM_MAINTAINER_MODE

AM_PATH_GLIB(1.2.0,,,gmodule)
AM_PATH_GTK(1.2.0)

AC_MSG_CHECKING(whether make is GNU Make)
STRIP_BEGIN=
STRIP_END=
if $ac_make --version 2>/dev/null | grep '^GNU Make ' >/dev/null ; then
	STRIP_BEGIN='$(strip $(STRIP_DUMMY)'
	STRIP_END=')'
	AC_MSG_RESULT(yes)
else
	AC_MSG_RESULT(no)
fi
STRIP_DUMMY=
AC_SUBST(STRIP_DUMMY)
AC_SUBST(STRIP_BEGIN)
AC_SUBST(STRIP_END)

AC_PATH_PROG(GNOME_CONFIG,gnome-config,no)
if test x$GNOME_CONFIG != xno; then
	echo "Building the GnomeCanvasPixbuf library"
	GNOME_LIBS=`$GNOME_CONFIG --libs gnomeui`
	GNOME_CFLAGS=`$GNOME_CONFIG --cflags gnomeui`
	BUILD_CANVAS=yes
else
	echo "Not building GnomeCanvasPixbuf library"
	BUILD_CANVAS=no
fi       

AM_CONDITIONAL(BUILD_CANVAS_ITEM, test $BUILD_CANVAS = yes)

AC_SUBST(GNOME_LIBS)
AC_SUBST(GNOME_CFLAGS)

AC_MSG_CHECKING(whether to build gmodulized gdk-pixbuf)

AC_ARG_ENABLE(modules, [  --disable-modules       Disables dynamic module loading],[
	if test x$withval = xyes; then 
	    with_modules=yes
        else
            with_modules=no
	fi
])

dynworks=false
deps=
if test x$with_modules = xno; then
    AC_MSG_RESULT(no)
else
    AC_MSG_RESULT(yes)
    AC_MSG_CHECKING(whether dynamic modules work)
    oLIBS="$LIBS"
    oCFLAGS="$CFLAGS"
    CFLAGS="$GLIB_CFLAGS"
    LIBS="$GLIB_LIBS"
    AC_TRY_RUN([
    #include <glib.h>
    #include <gmodule.h>
    main ()
    {
    	if (g_module_supported ())
    	    exit (0);
    	else
    	    exit (1);
    }
    ], dynworks=true)
    LIBS="$oLIBS"
    CFLAGS="$oCFLAGS"
fi
    
dnl Now we check to see if our libtool supports shared lib deps
dnl (in a rather ugly way even)
if $dynworks; then
   pixbuf_libtool_config="${CONFIG_SHELL-/bin/sh} libtool --config"
   pixbuf_deplibs_check=`$pixbuf_libtool_config | \
      grep '^[[a-z_]]*check[[a-z_]]*_method=[['\''"]]' | \
      sed 's/.*[['\''"]]\(.*\)[['\''"]]$/\1/'`
   if test "x$pixbuf_deplibs_check" = "xnone" || \
      test "x$pixbuf_deplibs_check" = "xunknown" || \
      test "x$pixbuf_deplibs_check" = "x"; then
      dynworks=false
   fi
fi

if $dynworks; then
   AC_DEFINE(USE_GMODULE)
   GMODULE_LIBS="`glib-config --libs gmodule`"
   GMODULE_FLAGS="`glib-config --cflags gmodule`"
   AC_SUBST(GMODULE_LIBS)
   AC_SUBST(GMODULE_FLAGS)
   AC_MSG_RESULT(yes)
else
   AC_MSG_RESULT(no)
fi

dnl Check for location of rgb.txt file (works without, but better with)
AC_MSG_CHECKING([for location of rgb.txt database])

dnl default to this..
path_rgb_txt=/usr/lib/X11/rgb.txt

if test -r ${x_libraries}/X11/rgb.txt; then
  path_rgb_txt="${x_libraries}/X11/rgb.txt"
else
  for d in /usr/lib/X11 /usr/local/lib/X11 /usr/openwin/lib; do
    if test -r $d/rgb.txt; then
      path_rgb_txt="$d/rgb.txt"
      break
    fi
  done
fi
AC_MSG_RESULT([$path_rgb_txt])
AC_DEFINE_UNQUOTED(PATH_RGB_TXT,"$path_rgb_txt")

dnl Test for libtiff
  if test -z "$LIBTIFF"; then
    AC_CHECK_LIB(tiff, TIFFReadScanline,
      AC_CHECK_HEADER(tiffio.h,
        TIFF='tiff'; LIBTIFF='-ltiff',
        AC_MSG_WARN(*** TIFF loader will not be built (TIFF header files not found) ***)),
      AC_CHECK_LIB(tiff, TIFFWriteScanline,
        AC_CHECK_HEADER(tiffio.h,
          TIFF='tiff'; LIBTIFF='-ltiff -ljpeg -lz',
          AC_MSG_WARN(*** TIFF loader will not be built (TIFF header files not found) ***)),
        AC_CHECK_LIB(tiff34, TIFFFlushData,
          AC_CHECK_HEADER(tiffio.h,
            TIFF='tiff'; LIBTIFF='-ltiff34 -ljpeg -lz',
            AC_MSG_WARN(*** TIFF loader will not be built (TIFF header files not found) ***)),
        AC_MSG_WARN(*** TIFF plug-in will not be built (TIFF library not found) ***), -ljpeg -lz -lm), -ljpeg -lz -lm), -lm)
  fi

dnl Test for libjpeg
  if test -z "$LIBJPEG"; then
    AC_CHECK_LIB(jpeg, jpeg_destroy_decompress,
      jpeg_ok=yes,
      jpeg_ok=no
      AC_MSG_WARN(*** JPEG loader will not be built (JPEG library not found) ***))
    if test "$jpeg_ok" = yes; then
      AC_MSG_CHECKING([for jpeglib.h])
      AC_TRY_CPP(
[#include <stdio.h>
#undef PACKAGE
#undef VERSION
#include <jpeglib.h>],
        jpeg_ok=yes,
        jpeg_ok=no)
      AC_MSG_RESULT($jpeg_ok)
      if test "$jpeg_ok" = yes; then
        LIBJPEG='-ljpeg'
        AC_CHECK_LIB(jpeg, jpeg_simple_progression,     
          AC_DEFINE(HAVE_PROGRESSIVE_JPEG),
          AC_MSG_WARN(JPEG library does not support progressive saving.))
      else
          AC_MSG_WARN(*** JPEG loader will not be built (JPEG header file not found) ***)
      fi
    fi
  fi

dnl Test for libpng
  if test -z "$LIBPNG"; then
    AC_CHECK_LIB(png, png_read_info,
      AC_CHECK_HEADER(png.h,
        png_ok=yes,
        png_ok=no),
      AC_MSG_WARN(*** PNG loader will not be built (PNG library not found) ***), -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='png'; LIBPNG='-lpng -lz'
      else
        AC_MSG_WARN(*** PNG loader will not be built (PNG library is too old) ***)
      fi
    else
     AC_MSG_WARN(*** PNG loader will not be built (PNG header file not found) ***)
    fi
  fi

deps="$LIBTIFF $LIBJPEG $LIBPNG"

AC_SUBST(LIBTIFF)
AC_SUBST(LIBJPEG)
AC_SUBST(LIBPNG)

AM_CONDITIONAL(BUILD_DYNAMIC_MODULES, $dynworks)

AC_HEADER_STDC
AC_HEADER_DIRENT
AC_HEADER_SYS_WAIT

AC_TYPE_SIGNAL

AM_CONDITIONAL(HAVE_TIFF, test "x$LIBTIFF" != x)
AM_CONDITIONAL(HAVE_PNG, test "x$LIBPNG" != x)
AM_CONDITIONAL(HAVE_JPEG, test "x$LIBJPEG" != x)

GDK_PIXBUF_LIBDIR='-L${libdir}'
GDK_PIXBUF_INCLUDEDIR="-I${includedir}/gdk-pixbuf-1.0 $GTK_CFLAGS"
GDK_PIXBUF_LIBS="$GLIB_LIBS -lgdk_pixbuf $GTK_LIBS"
AC_SUBST(STATIC_LIB_DEPS)
STATIC_LIB_DEPS="$deps"

GDK_PIXBUF_XLIB_LIBDIR=$GDK_PIXBUF_LIBDIR
GDK_PIXBUF_XLIB_INCLUDEDIR=$GDK_PIXBUF_INCLUDEDIR
GDK_PIXBUF_XLIB_LIBS="$GLIB_LIBS -lgdk_pixbuf_xlib $X11_LIBS"

GNOMECANVASPIXBUF_LIBDIR=$GDK_PIXBUF_LIBDIR
GNOMECANVASPIXBUF_INCLUDEDIR=$GDK_PIXBUF_INCLUDEDIR
GNOMECANVASPIXBUF_LIBS="$GDK_PIXBUF_LIBS -lgnomecanvaspixbuf"

AC_SUBST(GDK_PIXBUF_LIBDIR)
AC_SUBST(GDK_PIXBUF_INCLUDEDIR)
AC_SUBST(GDK_PIXBUF_LIBS)

AC_SUBST(GDK_PIXBUF_XLIB_LIBDIR)
AC_SUBST(GDK_PIXBUF_XLIB_INCLUDEDIR)
AC_SUBST(GDK_PIXBUF_XLIB_LIBS)

AC_SUBST(GNOMECANVASPIXBUF_LIBDIR)
AC_SUBST(GNOMECANVASPIXBUF_INCLUDEDIR)
AC_SUBST(GNOMECANVASPIXBUF_LIBS)

##################################################
# Checks for gtk-doc and docbook-tools
##################################################

AC_ARG_WITH(html-dir, [  --with-html-dir=PATH path to installed docs ])

if test "x$with_html_dir" = "x" ; then
  HTML_DIR='${datadir}/gnome/html'
else
  HTML_DIR=$with_html_dir
fi

AC_SUBST(HTML_DIR)

AC_CHECK_PROG(GTKDOC, gtkdoc-mkdb, true, false)

gtk_doc_min_version=0.6
if $GTKDOC ; then 
    gtk_doc_version=`gtkdoc-mkdb --version`
    AC_MSG_CHECKING([gtk-doc version ($gtk_doc_version) >= $gtk_doc_min_version])
    if perl <<EOF ; then
      exit (("$gtk_doc_version" =~ /^[[0-9]]+\.[[0-9]]+$/) &&
            ("$gtk_doc_version" >= "$gtk_doc_min_version") ? 0 : 1);
EOF
      AC_MSG_RESULT(yes)
   else
      AC_MSG_RESULT(no)
      GTKDOC=false
   fi
fi

AM_CONDITIONAL(HAVE_GTK_DOC, $GTKDOC)
AC_SUBST(HAVE_GTK_DOC)

AC_CHECK_PROG(DB2HTML, db2html, true, false)
AM_CONDITIONAL(HAVE_DOCBOOK, $DB2HTML)

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_gtk_doc = xauto ; then
  if test x$GTKDOC = xtrue ; then
    enable_gtk_doc=yes
  else
    enable_gtk_doc=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_gtk_doc = xyes)

#
# Checks to see if we should compile in MMX support (there will be
# a runtime test when the code is actually run to see if it should
# be used - this just checks if we can compile it.)
#
# This code is partially taken from Mesa
#
dnl Let people disable the MMX optimization
AC_ARG_ENABLE(mmx, [  --disable-mmx     Don't use MMX optimization [default=auto]], enable_mmx="$enableval", enable_mmx=auto)

AC_MSG_CHECKING(for x86 platform)
  case $host_cpu in
    i386|i486|i586|i686|i786|k6|k7)
	use_x86_asm=yes
	;;
    *)
  	use_x86_asm=no
  esac
AC_MSG_RESULT($use_x86_asm)

dnl Are we going to use MMX extensions
use_mmx_asm=no

AC_MSG_CHECKING(compiler support for MMX)

if test x$enable_mmx = xauto ; then
  if test $use_x86_asm = yes; then
    save_ac_ext=$ac_ext
    ac_ext=S
    
    cp $srcdir/gdk-pixbuf/pixops/scale_line_22_33_mmx.S conftest.S
    if AC_TRY_EVAL(ac_compile); then
        use_mmx_asm=yes
    fi
    dnl rm -f conftest.[oS]

    ac_ext=$save_ac_ext
  fi

dnl Enforce usage of MMX extensions
elif test x$enable_mmx = xyes ; then
    use_mmx_asm=yes
else
    use_mmx_asm=no
fi

if test $use_mmx_asm = yes; then
  AC_DEFINE(USE_MMX)
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi

AM_CONDITIONAL(USE_MMX, test x$use_mmx_asm = xyes)

# Output files

AC_OUTPUT([
Makefile
gdk-pixbuf.spec
gdk-pixbuf/Makefile
gdk-pixbuf/gdk-pixbuf-features.h
gdk-pixbuf/pixops/Makefile
gdk-pixbuf-config
demo/Makefile
doc/Makefile
])
