dnl Process this file with autoconf to produce a configure script.
AC_INIT(fib.c)
AC_CONFIG_HEADER(config.h)

dnl Checks for programs.
dnl AC_PROG_CC
dnl AC_PROG_CC shoves in -g by default, i *really* hate this so here goes...
dnl ill shove in the autoconf def of AC_PROG_CC verbatim and remove the -g 
dnl stuff
dnl autoconf stuff begins here

AC_DEFUN(AC_PROG_CC_NO_G,
[AC_BEFORE([$0], [AC_PROG_CPP])dnl
AC_CHECK_PROG(CC, gcc, gcc)
if test -z "$CC"; then
  AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
  test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
fi

AC_PROG_CC_WORKS
AC_PROG_CC_GNU

dnl exec suffix for DOSish OSes, autoconf-2.13 required.

if test $ac_cv_prog_gcc = yes; then
  GCC=yes
dnl Check whether -g works, even if CFLAGS is set, in case the package
dnl plays around with CFLAGS (such as to build both debugging and
dnl normal versions of a library), tasteless as that idea is.
  ac_test_CFLAGS="${CFLAGS+set}"
  ac_save_CFLAGS="$CFLAGS"
  CFLAGS=
dnl   C Begin
dnl AC_PROG_CC_G
dnl   C End
  if test "$ac_test_CFLAGS" = set; then
    CFLAGS="$ac_save_CFLAGS"
dnl   C Begin
dnl  elif test $ac_cv_prog_cc_g = yes; then
dnl    CFLAGS="-g -O2"
dnl   C End
  else
    CFLAGS="-O2"
  fi
else
  GCC=
  test "${CFLAGS+set}" = set 
dnl   C Begin
dnl || CFLAGS="-g"
dnl   C End
fi
])

dnl autoconf stuff ends here


AC_PROG_CC_NO_G
AC_PROG_MAKE_SET
AC_PROG_INSTALL

AC_PROG_RANLIB

# Tests for Windows
AC_CYGWIN
AC_EXEEXT
AC_OBJEXT
AC_MINGW32
# End Tests for Windows

# Configure libtool
#AM_ENABLE_SHARED(no)
#AM_ENABLE_STATIC(no)
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
#end libtool stuff


AC_HEADER_STDC
dnl AC_HEADER_SYS_WAIT
dnl AC_TYPE_SIGNAL
dnl AC_FUNC_WAIT3

AC_CHECK_HEADERS(fcntl.h sys/file.h sys/ioctl.h unistd.h)
CFLAGS="$CFLAGS $X_CFLAGS"


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

dnl LDFLAGS="$LDFLAGS -lm"

dnl test for X, and Xpm and ttf to get the flags needed to compile something to use libwmf

dnl finding X
AC_PATH_X
### Check for the pt library (for SCO, needed for X)
AC_CHECK_LIB(pt,ptsname,[X_EXTRA_LIBS="$X_EXTRA_LIBS -lpt"])

AC_PATH_XTRA

dnl CFLAGS="$CFLAGS $X_CFLAGS"

if test [ "$no_x" = yes ]; then
X11=""
else
X11="-lX11" 
fi

dnl LIBS="$X_LIBS $LIBS -lX11 $X_EXTRA_LIBS"


dnl system ZLIB support, originally nicked from mozilla source
dnl ========================================================
AC_ARG_WITH(zlib,
[  --with-zlib=\$dir        use libz in \$dir],
    ZLIB_DIR=$withval)

_SAVE_CFLAGS=$CFLAGS
_SAVE_LDFLAGS=$LDFLAGS
CFLAGS="-I${ZLIB_DIR}/include $CFLAGS"
LDFLAGS="-L${ZLIB_DIR}/lib $LDFLAGS"
if test "$ZLIB_DIR" = no; then
    SYSTEM_ZLIB=
else
    AC_MSG_CHECKING("for zlib.h")
    AC_TRY_COMPILE([#include "zlib.h"], [],
    [result="yes" SYSTEM_ZLIB=1],
    [result="no" SYSTEM_ZLIB=])
    AC_MSG_RESULT("$result") 
fi  

if [ test "$SYSTEM_ZLIB" = 1 ]; then

dnl there is often a crap libz hiding in the X11 lib dir
dnl redhat 4.2 and SuSE have been known to do this, something to do with the 
dnl libgr package and imake
dnl so for this reason i stick -L/usr/lib before the X11 options here first

	_SAVE_LD=$LDFLAGS
	LDFLAGS="-L/usr/lib $LDFLAGS"
	
    AC_CHECK_LIB(z, gzread, [SYSTEM_ZLIB=1 ZLIB_LIBS="-lz"],
    [SYSTEM_ZLIB= ZLIB_CFLAGS= ZLIB_LIBS=])

dnl if there wasn't a usable libz, then look for libgz ala SuSE

	if [ test "$SYSTEM_ZLIB" = "" ]; then
    AC_CHECK_LIB(gz, gzread, [SYSTEM_ZLIB=1 ZLIB_LIBS="-lgz"],
    [SYSTEM_ZLIB= ZLIB_CFLAGS= ZLIB_LIBS=])
	fi
fi

if [ test -n "${ZLIB_DIR}" && test -d "${ZLIB_DIR}" && test "$SYSTEM_ZLIB" = 1 ]; then
    ZLIB_CFLAGS="-I${ZLIB_DIR}/include"
    ZLIB_LIBS="-L${ZLIB_DIR}/lib ${ZLIB_LIBS}"
fi

if [ test "$SYSTEM_ZLIB" = "" ]; then
	CFLAGS="-I${ZLIB_DIR} $CFLAGS"
	LDFLAGS="-L${ZLIB_DIR} $LDFLAGS"
	if test "$ZLIB_DIR" = no; then
		SYSTEM_ZLIB=
	else
		AC_MSG_CHECKING("for zlib.h")
		AC_TRY_COMPILE([#include "zlib.h"], [],
		[result="yes" SYSTEM_ZLIB=1],
		[result="no" SYSTEM_ZLIB=])
		AC_MSG_RESULT("$result") 
	fi  

	if [ test "$SYSTEM_ZLIB" = 1 ]; then

	dnl there is often a crap libz hiding in the X11 lib dir
	dnl redhat 4.2 and SuSE have been known to do this, something to do with the libgr 
	dnl package and imake
	dnl so for this reason i stick -L/usr/lib before the X11 options here first

		LDFLAGS=$_SAVE_LD
		LDFLAGS="-L/usr/lib $LDFLAGS"
		
		AC_CHECK_LIB(z, gzread, [SYSTEM_ZLIB=1 ZLIB_LIBS="-lz"],
		[SYSTEM_ZLIB= ZLIB_CFLAGS= ZLIB_LIBS=])

	dnl if there wasn't a usable libz, then look for libgz ala SuSE

		if [ test "$SYSTEM_ZLIB" = "" ]; then
		AC_CHECK_LIB(gz, gzread, [SYSTEM_ZLIB=1 ZLIB_LIBS="-lgz"],
		[SYSTEM_ZLIB= ZLIB_CFLAGS= ZLIB_LIBS=])
		fi
	fi


if [ test -n "${ZLIB_DIR}" && test -d "${ZLIB_DIR}" && test "$SYSTEM_ZLIB" = 1 ]; then
    ZLIB_CFLAGS="-I${ZLIB_DIR}"
    ZLIB_LIBS="-L${ZLIB_DIR} ${ZLIB_LIBS}"
fi

fi

CFLAGS=$_SAVE_CFLAGS
LDFLAGS=$_SAVE_LDFLAGS

dnl ========================================================
dnl end of zlib

dnl system xpm support, done after X, as its usually in the same place
dnl ========================================================
AC_ARG_WITH(xpm,
[  --with-xpm=\$dir	  use xpm in \$dir],
    XPM_DIR=$withval)

_SAVE_CFLAGS=$CFLAGS
_SAVE_LDFLAGS=$LDFLAGS
_SAVE_LIBS=$LIBS

CFLAGS="$CFLAGS $X_CFLAGS"

dnl LIBS="$LIBS $X_LIBS $X_EXTRA_LIBS"

if test "$XPM_DIR" != "" ; then
CFLAGS="-I${XPM_DIR}/include $CFLAGS"
LDFLAGS="-L${XPM_DIR}/lib $LDFLAGS"
fi


if test "$XPM_DIR" = no; then
    SYSTEM_XPM=0
else
    AC_MSG_CHECKING("for xpm.h")
    AC_TRY_COMPILE([#include <X11/xpm.h>], [],
    [result="yes" SYSTEM_XPM=1],
    [result="no" SYSTEM_XPM=0])
    if [test "$SYSTEM_XPM" = 0]; then
        AC_TRY_COMPILE([#include <xpm.h>], [],
        [result="yes" SYSTEM_XPM=1],
        [result="no" SYSTEM_XPM=0])
        XPMINCLUDE="<xpm.h>"
    else
        XPMINCLUDE="<X11/xpm.h>"
    fi
    AC_MSG_RESULT("$result")
fi
if [ test "$SYSTEM_XPM" = 1 ]; then
    AC_CHECK_LIB(Xpm, main, [XPM_LIBS="-lXpm"],no_Xpm=yes,$X_LIBS -lX11 $X_EXTRA_LIBS)
else
    no_Xpm=yes
fi

if [ test -n "${XPM_DIR}" && test -d "${XPM_DIR}" && test "$SYSTEM_XPM" = 1 ]; then
    XPM_CFLAGS="-I${XPM_DIR}/include"
    XPM_LIBS="-L${XPM_DIR}/lib ${XPM_LIBS}"
fi

if test "x$no_Xpm" = "xyes"; then
	if test "$XPM_DIR" != "" ; then
	CFLAGS="-I${XPM_DIR}/include $CFLAGS"
	LDFLAGS="-L${XPM_DIR}/lib $LDFLAGS"
	fi


	if test "$XPM_DIR" = no; then
		SYSTEM_XPM=0
	else
		AC_MSG_CHECKING("for xpm.h")
		AC_TRY_COMPILE([#include <X11/xpm.h>], [],
		[result="yes" SYSTEM_XPM=1],
		[result="no" SYSTEM_XPM=0])
		if [test "$SYSTEM_XPM" = 0]; then
			AC_TRY_COMPILE([#include <xpm.h>], [],
			[result="yes" SYSTEM_XPM=1],
			[result="no" SYSTEM_XPM=0])
			XPMINCLUDE="<xpm.h>"
		else
			XPMINCLUDE="<X11/xpm.h>"
		fi
		AC_MSG_RESULT("$result")
	fi
	if [ test "$SYSTEM_XPM" = 1 ]; then
		AC_CHECK_LIB(Xpm, main, [XPM_LIBS="-lXpm"],no_Xpm=yes,$X_LIBS -lX11 $X_EXTRA_LIBS)
	else
		no_Xpm=yes
	fi


if [ test -n "${XPM_DIR}" && test -d "${XPM_DIR}" && test "$SYSTEM_XPM" = 1 ]; then
    XPM_CFLAGS="-I${XPM_DIR}"
    XPM_LIBS="-L${XPM_DIR} ${XPM_LIBS}"
fi

fi

CFLAGS=$_SAVE_CFLAGS
LDFLAGS=$_SAVE_LDFLAGS
LIBS=$_SAVE_LIBS



dnl system ttf support
dnl ========================================================
AC_ARG_WITH(ttf,
[  --with-ttf=\$dir	  use ttf in \$dir],
    TTF_DIR=$withval)

_SAVE_CFLAGS=$CFLAGS
_SAVE_LDFLAGS=$LDFLAGS

if test "$TTF_DIR" != "" ; then
CFLAGS="-I${TTF_DIR}/include $CFLAGS"
LDFLAGS="-L${TTF_DIR}/lib $LDFLAGS"
fi

if test "$TTF_DIR" = no; then
    SYSTEM_TTF=0
else
    AC_MSG_CHECKING("for freetype.h")
    AC_TRY_COMPILE([#include "freetype.h"], [],
    [result="yes" SYSTEM_TTF=1],
    [])
    AC_MSG_RESULT("$result")
fi
if [ test "$SYSTEM_TTF" = 1 ]; then
    AC_CHECK_LIB(ttf, TT_Init_FreeType, [TTF_LIBS="-lttf"],no_ttf=yes,-lm)
else
    no_ttf=yes
fi

if [ test -n "${TTF_DIR}" && test -d "${TTF_DIR}" && test "$SYSTEM_TTF" = 1 ]; then
    TTF_CFLAGS="-I${TTF_DIR}/include"
    TTF_LIBS="-L${TTF_DIR}/lib ${TTF_LIBS}"
fi

if test "x$no_ttf" = xyes; then
	if test "$TTF_DIR" != "" ; then
	CFLAGS="-I${TTF_DIR} $CFLAGS"
	LDFLAGS="-L${TTF_DIR} $LDFLAGS"
	fi

	if test "$TTF_DIR" = no; then
		SYSTEM_TTF=0
	else
		AC_MSG_CHECKING("for freetype.h")
		AC_TRY_COMPILE([#include "freetype.h"], [],
		[result="yes" SYSTEM_TTF=1],
		[result="no" SYSTEM_TTF=0])
		AC_MSG_RESULT("$result")
	fi
	if [ test "$SYSTEM_TTF" = 1 ]; then
		AC_CHECK_LIB(ttf, TT_Init_FreeType, [TTF_LIBS="-lttf"],no_ttf=yes,-lm)
	else
		no_ttf=yes
	fi


if [ test -n "${TTF_DIR}" && test -d "${TTF_DIR}" && test "$SYSTEM_TTF" = 1 ]; then
    TTF_CFLAGS="-I${TTF_DIR}"
    TTF_LIBS="-L${TTF_DIR} ${TTF_LIBS}"
fi

fi

 CFLAGS=$_SAVE_CFLAGS
 LDFLAGS=$_SAVE_LDFLAGS



dnl system libwmf support
dnl ========================================================
AC_ARG_WITH(wmf,
[  --with-wmf=\$dir	  use wmf libraries in \$dir],
    WMF_DIR=$withval)

_SAVE_CFLAGS=$CFLAGS
_SAVE_LDFLAGS=$LDFLAGS
_SAVE_LIBS=$LIBS

if test "$WMF_DIR" != "" ; then
CFLAGS="-I${WMF_DIR}/include $CFLAGS"
LDFLAGS="-L${WMF_DIR}/lib $LDFLAGS"
fi

dnl LIBS="$LIBS $TTF_LIBS $XPM_LIBS"

if test "$WMF_DIR" = no; then
    SYSTEM_WMF=0
else
    AC_MSG_CHECKING("for gdwmfapi.h")
    AC_TRY_COMPILE([#include "gdwmfapi.h"], [],
    [result="yes" SYSTEM_WMF=1],
    [result="no" SYSTEM_WMF=0])
    AC_MSG_RESULT("$result") 
fi  
if [ test "$SYSTEM_WMF" = 1 ]; then
    AC_CHECK_LIB(gdwmf, gd_draw_rectangle, [WMF_LIBS="-lgdwmf -lwmf -lxgd -ldib -lpng"],
	no_wmf=yes,-lwmf -lxgd -ldib -lpng $TTF_LIBS $XPM_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS -lm)
else
    no_wmf=yes
fi

if [ test -n "${WMF_DIR}" && test -d "${WMF_DIR}" && test "$SYSTEM_WMF" = 1 ]; then
    WMF_CFLAGS="-I${WMF_DIR}/include"
    WMF_LIBS="-L${WMF_DIR}/lib ${WMF_LIBS}"
fi

if test "x$no_wmf" = xyes; then
	if test "$WMF_DIR" != "" ; then
	CFLAGS="-I${WMF_DIR}/include $CFLAGS"
	LDFLAGS="-L${WMF_DIR}/lib $LDFLAGS"
	fi

	LDFLAGS="$LDFLAGS $TTF_LIBS $XPM_LIBS"

	if test "$WMF_DIR" = no; then
		SYSTEM_WMF=0
	else
		AC_MSG_CHECKING("for gdwmfapi.h")
		AC_TRY_COMPILE([#include "gdwmfapi.h"], [],
		[result="yes" SYSTEM_WMF=1],
		[result="no"  SYSTEM_WMF=0])
		AC_MSG_RESULT("$result") 
	fi  
	if [ test "$SYSTEM_WMF" = 1 ]; then
		AC_CHECK_LIB(gdwmf, gd_draw_rectangle, [WMF_LIBS="-lgdwmf -lwmf -lxgd -ldib -lpng"],
		no_wmf=yes,-lwmf -lxgd -ldib -lpng $TTF_LIBS $XPM_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS -lm)
	else
		no_wmf=yes
	fi


if [ test -n "${WMF_DIR}" && test -d "${WMF_DIR}" && test "$SYSTEM_WMF" = 1 ]; then
    WMF_CFLAGS="-I${WMF_DIR}"
    WMF_LIBS="-L${WMF_DIR} ${WMF_LIBS}"
fi

fi

CFLAGS=$_SAVE_CFLAGS
LDFLAGS=$_SAVE_LDFLAGS
LIBS=$_SAVE_LIBS

dnl ========================================================
dnl end of libwmf


dnl ========================================================
dnl test for iconv


AC_DEFUN(AC_SYS_ICONV_WIN_CP_SUPPORT,
[
AC_MSG_CHECKING([for existance of $1 to $2 iconv support])
dnl AC_CACHE_VAL(have_codepages,
dnl [
AC_TRY_RUN([
	#include <iconv.h>
	#include <stdio.h>
	#include <errno.h>
	#include <string.h>
	#include <stdlib.h>

	int main(int argc, char *argv[])
	{
		char f_code[33];              /* From CCSID                           */
		char t_code[33];              /* To CCSID                             */
		iconv_t iconv_handle;         /* Conversion Descriptor returned       */
									/* from iconv_open() function           */
		const char *ibuf = "ABCxyz012#&";   /* Buffer of characters to be converted */
		char *obuf;                   /* Buffer for converted characters      */
		size_t ibuflen;               /* Length of input buffer               */
		size_t obuflen;               /* Length of output buffer              */
		const char *isav;             /* Saved pointer to input buffer        */
		char *osav;                   /* Saved pointer to output buffer       */

	/* All reserved positions of from code (last 12 characters) and to code   */
	/* (last 19 characters) must be set to hexadecimal zeros.                 */

		memset(f_code,'\0',33);
		memset(t_code,'\0',33);

		strcpy(f_code,"$1");
		strcpy(t_code,"$2");

		iconv_handle = iconv_open(t_code,f_code);
		if (iconv_handle == (iconv_t)-1)
		{
			perror("ERROR");
			fprintf(stderr,"iconv_open fail: cannot handle %s to %s\n","$1","$2");
			exit(-1);
		}
		else
			{
			fprintf(stderr,"success!, can handle %s to %s\n","$1","$2");
			iconv_close(iconv_handle);
			}
		return(0);
	}
], have_codepages=yes, have_codepages=no, have_codepages=no)
dnl])
AC_MSG_RESULT($have_codepages)
if test $have_codepages = no; then
AC_DEFINE(MUST_USE_INTERNAL_ICONV_TABLE)
ICONVOBJS="\$(RICONVOBJS)"
ICONV="ICONV"
fi
])

AC_CHECK_FUNC(iconv, [
AC_DEFINE(USE_ICONV)
have_iconv=yes], 
ICONVOBJS="\$(RICONVOBJS)"
ICONV="ICONV"
have_iconv=no)

if [ test "$have_iconv" = yes ]; then
	AC_SYS_ICONV_WIN_CP_SUPPORT(CP874,UCS-2)
dnl	AC_SYS_ICONV_WIN_CP_SUPPORT(CP936,UCS-2)
dnl	AC_SYS_ICONV_WIN_CP_SUPPORT(CP932,UCS-2)
dnl	AC_SYS_ICONV_WIN_CP_SUPPORT(CP949,UCS-2)
dnl	AC_SYS_ICONV_WIN_CP_SUPPORT(CP950,UCS-2)
	AC_SYS_ICONV_WIN_CP_SUPPORT(CP1250,UCS-2)
	AC_SYS_ICONV_WIN_CP_SUPPORT(CP1251,UCS-2)
	AC_SYS_ICONV_WIN_CP_SUPPORT(CP1252,UCS-2)
	AC_SYS_ICONV_WIN_CP_SUPPORT(CP1253,UCS-2)
	AC_SYS_ICONV_WIN_CP_SUPPORT(CP1254,UCS-2)
	AC_SYS_ICONV_WIN_CP_SUPPORT(CP1255,UCS-2)
	AC_SYS_ICONV_WIN_CP_SUPPORT(CP1256,UCS-2)
	AC_SYS_ICONV_WIN_CP_SUPPORT(CP1257,UCS-2)

	AC_SYS_ICONV_WIN_CP_SUPPORT(UCS-2,UCS-2)
	AC_SYS_ICONV_WIN_CP_SUPPORT(UCS-2,UTF-8)
	AC_SYS_ICONV_WIN_CP_SUPPORT(UCS-2,koi8-r)
	AC_SYS_ICONV_WIN_CP_SUPPORT(UCS-2,tis-620)
	AC_SYS_ICONV_WIN_CP_SUPPORT(UCS-2,iso-8859-15)
fi

dnl end of iconv
dnl ========================================================

dnl ========================================================
dnl test for imagemagick
dnl test for the existance of the MagickConfig program,
dnl if its not there then we dont have imagemagick, if it
dnl is there then we still have to do a big dance to get
dnl something to link against it as it does not provide all
dnl the information that we need to compile against it
dnl first try it raw, maybe the author will have fixed it
dnl by now, then try it with the prefix attached, and then
dnl try it with the X varient of that, and then try it with
dnl both.

AC_ARG_WITH(Magick,
[  --with-Magick=\$dir	  use Magick in \$dir],
MAGICK_DIR=$withval)

if test "$MAGICK_DIR" = no; then
	result="no"
else
	AC_CHECK_PROG(havemagick,Magick-config,"yes","no")
	if test "x$havemagick" = xyes; then
dnl cflags test begins 

		_SAVE_CFLAGS=$CFLAGS

		mflags=`Magick-config --cflags`

		CFLAGS="$mflags $CFLAGS"

		AC_MSG_CHECKING("for magick.h")
		AC_TRY_COMPILE([#include "magick.h"], [],
		[result="yes"],
		[result="no" CFLAGS=$_SAVE_CFLAGS])
		AC_MSG_RESULT("$result") 

		if test "x$result" = xno; then
			_SAVE_CFLAGS=$CFLAGS

			mflags=`Magick-config --cflags`
			CFLAGS="$mflags $CFLAGS"
			mflags=`Magick-config --prefix`
			CFLAGS="-I$mflags/include/magick/ $CFLAGS"

			AC_MSG_CHECKING("for magick.h in location 2")
			AC_TRY_COMPILE([#include "magick.h"], [],
			[result="yes"],
			[result="no" CFLAGS=$_SAVE_CFLAGS])
			AC_MSG_RESULT("$result")
			
			if test "x$result" = xno; then
				_SAVE_CFLAGS=$CFLAGS

				mflags=`Magick-config --cflags`
				CFLAGS="$mflags $CFLAGS"
				mflags=`Magick-config --prefix`
				CFLAGS="-I$mflags/include/X11/magick/ $CFLAGS $X_CFLAGS/X11"

				AC_MSG_CHECKING("for magick.h in location 3")
				AC_TRY_COMPILE([#include "magick.h"], [],
				[result="yes"],
				[result="no" CFLAGS=$_SAVE_CFLAGS])
				AC_MSG_RESULT("$result")
			fi
dnl cflags test ends
		fi

dnl lib test begins 
		if test "x$result" = xyes; then
			_SAVE_CFLAGS=$CFLAGS
			_SAVE_LDFLAGS=$LDFLAGS

			mflags=`Magick-config --libs`

			LDFLAGS="$mflags $LDFLAGS"
			CFLAGS="$CFLAGS $X_CFLAGS"
			
			AC_CHECK_LIB(Magick, GetImageInfo, 
			[result="yes" MAGICK_LIBS="$mflags"],
			[result="no" LDFLAGS=$_SAVE_LDFLAGS])

			if test "x$result" = xno; then
				_SAVE_LDFLAGS=$LDFLAGS
				mflags=`Magick-config --libs`
				LDFLAGS="$mflags $LDFLAGS"
				AC_CHECK_LIB(Magick, WritePNGImage, 
				[result="yes" MAGICK_LIBS="$mflags $X_LIBS -lX11 $X_EXTRA_LIBS"],
				[result="no" LDFLAGS=$_SAVE_LDFLAGS],
				$X_LIBS -lX11 $X_EXTRA_LIBS
				)
			fi
		LDFLAGS=$_SAVE_LDFLAGS
		CFLAGS=$_SAVE_CFLAGS
		fi
dnl lib test ends
	else
		result="no";
	fi
fi

if test "x$result" != xyes; then
	MAGICK="MAGICK"
	MAGICKOBJS="\$(RMAGICKOBJS)"

dnl if we have to use our own then we need libpng
#
# Check for PNG
#
AC_ARG_WITH(png,
[  --with-png=\$dir	  use png in \$dir],
    PNG_DIR=$withval)
_SAVE_CFLAGS=$CFLAGS
_SAVE_LDFLAGS=$LDFLAGS
	have_png='no'
	LIB_PNG=''
	if test "$with_png" != 'no'; then

		AC_CHECKING(for PNG support ...)
		failed=0;
		passed=0;
		AC_CHECK_HEADER(png.h,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
		AC_CHECK_HEADER(pngconf.h,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
		AC_CHECK_LIB(png,png_info_init,passed=`expr $passed + 1`,failed=`expr $failed + 1`,$ZLIB_LIBS -lm)
		AC_MSG_CHECKING(if PNG package is complete)
		if test $passed -gt 0; then
			if test $failed -gt 0; then
				AC_MSG_RESULT(no -- some components failed test)
				have_png='no (failed tests)'
			else
				LIB_PNG='-lpng'
				AC_DEFINE(HasPNG)
				AC_MSG_RESULT(yes)
				have_png='yes'
			fi
		else
			AC_MSG_RESULT(no)
		fi
	fi
fi
CFLAGS=$_SAVE_CFLAGS
LDFLAGS=$_SAVE_LDFLAGS


dnl end of imagemagick
dnl ========================================================



AC_SUBST(TTF_LIBS)
AC_SUBST(TTF_CFLAGS)
AC_SUBST(XPM_LIBS)
AC_SUBST(WMF_LIBS)
AC_SUBST(WMF_CFLAGS)

if [ test "$XPM_LIBS" != "" ]; then
AC_DEFINE(USE_X)
AC_SUBST(X11)
AC_SUBST(X_LIBS)
AC_SUBST(X_EXTRA_LIBS)
fi

dnl ========================================================
dnl begin of possible optimization tests
dnl read notes/optimization

AC_CHECK_SIZEOF(char,1)
AC_CHECK_SIZEOF(short,2)
AC_CHECK_SIZEOF(int,4)
AC_CHECK_SIZEOF(long,4)

if [test "$SIZEOF_CHAR" != "1" ]; then
    if [test "$SIZEOF_SHORT" != "2" ]; then
        if [test "$SIZEOF_INT" != "4" ]; then
            AC_DEFINE(MATCHED_TYPE)
        fi
    fi
fi

if [ test "$cross_compiling" != "yes" ]; then
    AC_C_BIGENDIAN
dnl	here we will know the endianness
	if [ test "$ac_cv_c_bigendian" = "no" ]; then
	    AC_DEFINE(XML_BYTE_ORDER,12)
	else 
		if [ test "$ac_cv_c_bigendian" = "yes" ]; then
			AC_DEFINE(XML_BYTE_ORDER,21)
		fi
	fi
else
dnl	here we will not know the endianness, so we will
dnl go with the mechanism that works everywhere
    AC_DEFINE(WORDS_BIGENDIAN)
fi

dnl given matched types and little endian we can read types larger
dnl than a byte with fread and avoid byteswapping

dnl at some later stage we will have a test to see if the compiler can
dnl get rid of holes, for the moment we will assume only that we can
dnl do it if we have __GNUC__ defined

dnl end of possible optimization tests


dnl check for getopt
AC_CHECK_FUNC(getopt_long, , [LIBOBJS="$LIBOBJS getopt1.o getopt.o"])
dnl check for strerror
AC_CHECK_FUNC(strerror, , [LIBOBJS="$LIBOBJS strerror.o"])
dnl check for strcasecmp
AC_CHECK_FUNC(strcasecmp, , [LIBOBJS="$LIBOBJS strcasecmp.o"])
dnl check for memcpy, if not there we'll use bcopy
AC_CHECK_FUNCS(memcpy)
dnl check for mmap
AC_FUNC_MMAP

AC_SUBST(LIBOBJS)
AC_SUBST(ICONV)
AC_SUBST(ICONVOBJS)
AC_SUBST(MAGICK)
AC_SUBST(MAGICKOBJS)
AC_SUBST(MAGICK_LIBS)
AC_SUBST(ZLIB_CFLAGS)
AC_SUBST(ZLIB_LIBS)
AC_SUBST(LIB_PNG)



if test "x$no_wmf" != xyes; then
	AC_DEFINE(HAVE_WMF)
fi

if test "x$no_ttf" != xyes; then
	AC_DEFINE(HAVE_TTF)
fi

if test "x$no_Xpm" != xyes; then
	AC_DEFINE(HAVE_XPM)
fi

if [ test "$SYSTEM_ZLIB" != "" ]; then
	AC_DEFINE(SYSTEM_ZLIB)
fi


AC_OUTPUT(
Makefile 
oledecod/Makefile 
libole2/Makefile 
glib-wv/Makefile 
expat/Makefile 
expat/xmltok/Makefile 
expat/xmlparse/Makefile
iconv/Makefile
magick/Makefile
)

if test "x$no_wmf" = xyes; then
	AC_MSG_WARN(Could not find gdwmf library or some of its components: libwv *will* build but will not have wmf to png support: see README)
fi

if test "x$no_ttf" = xyes; then
	AC_MSG_WARN(Could not find ttf library or some of its components: libwv *will* build but will not have text in its wmf to png support: see README)
fi

if test "x$no_Xpm" = xyes; then
	AC_MSG_WARN(Could not find xpm library or some of its components: libwv *will* build but will not have full wmf to png support: see README)
fi

if [ test "$SYSTEM_ZLIB" = "" ]; then
	AC_MSG_WARN(Could not find zlib library or some of its components: libwv *will* build but will not be able to decompress most wmf files: see README)
fi
