# Check for libart
KDE_FIND_PATH(libart2-config, LIBART_CONFIG, [${prefix}/bin ${exec_prefix}/bin /usr/local/bin /opt/local/bin],)

if test -n "$LIBART_CONFIG"; then
  vers=`$LIBART_CONFIG --version 2>/dev/null | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
  if test -n "$vers" && test "$vers" -ge 2003008
  then
     LIBART_LIBS="`$LIBART_CONFIG --libs`"
     LIBART_RPATH=
     for args in $LIBART_LIBS; do
	  case $args in
	    -L*)
  	       LIBART_RPATH="$LIBART_RPATH $args"
 	       ;;
          esac
     done
     LIBART_RPATH=`echo $LIBART_RPATH | sed -e "s/-L/-R/g"`
     LIBART_CFLAGS="`$LIBART_CONFIG --cflags`"

     AC_DEFINE_UNQUOTED(HAVE_LIBART, 1, [Defines if your system has the libart library])
  fi
fi

AC_SUBST(LIBART_LIBS)
AC_SUBST(LIBART_CFLAGS)
AC_SUBST(LIBART_RPATH)

if test -z "$LIBART_LIBS"; then
	DO_NOT_COMPILE="$DO_NOT_COMPILE ksvg"
fi

# Check for fontconfig
KDE_FIND_PATH(fontconfig-config, FONTCONFIG_CONFIG, [${prefix}/bin ${exec_prefix}/bin /usr/local/bin /opt/local/bin], [
  KDE_FIND_PATH( pkg-config, PKG_CONFIG, [${prefix}/bin ${exec_prefix}/bin /usr/local/bin /opt/local/bin /usr/bin],)
  if test -n "$PKG_CONFIG"; then
	if ! $PKG_CONFIG --exists fontconfig; then
		unset PKG_CONFIG
	fi
  fi
])
if test -n "$FONTCONFIG_CONFIG" -o -n "$PKG_CONFIG"; then
	if test -n "$FONTCONFIG_CONFIG"; then
		fontconfigvers="`$FONTCONFIG_CONFIG --version 2>/dev/null | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`"
		fontconfiglibs="`$FONTCONFIG_CONFIG --libs`"
		fontconfigcflags="`$FONTCONFIG_CONFIG --cflags`"
	else
		fontconfigvers=`$PKG_CONFIG --modversion fontconfig 2>/dev/null | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3; }'`
		fontconfiglibs=`$PKG_CONFIG --libs fontconfig`
		fontconfigcflags="`$PKG_CONFIG --cflags fontconfig`"
	fi
	if test -n "$vers" && test "$vers" -ge 2002000
	then
		FONTCONFIG_LIBS=$fontconfiglibs
		FONTCONFIG_RPATH=
			for args in $FONTCONFIG_LIBS; do
				case $args in
					-L*)
						FONTCONFIG_RPATH="$FONTCONFIG_RPATH $args"
						;;
				esac
			done
		FONTCONFIG_RPATH=`echo $FONTCONFIG_RPATH | sed -e "s/-L/-R/g"`
		FONTCONFIG_CFLAGS=$fontconfigcflags

		AC_DEFINE_UNQUOTED(HAVE_FONTCONFIG, 1, [Defines if your system has the fontconfig library])
	fi
fi

AC_SUBST(FONTCONFIG_LIBS)
AC_SUBST(FONTCONFIG_CFLAGS)
AC_SUBST(FONTCONFIG_RPATH)

if test -z "$FONTCONFIG_LIBS"; then
	DO_NOT_COMPILE="$DO_NOT_COMPILE ksvg"
fi

# Check for freetype2
KDE_FIND_PATH(freetype-config, FREETYPE_CONFIG, [${prefix}/bin ${exec_prefix}/bin /usr/local/bin /opt/local/bin],)

if test -n "$FREETYPE_CONFIG"; then
  vers=`$FREETYPE_CONFIG --version 2>/dev/null | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
  if test -n "$vers" && test "$vers" -ge 8000002
  then
     FREETYPE_LIBS="`$FREETYPE_CONFIG --libs`"
     FREETYPE_RPATH=
     for args in $FREETYPE_LIBS; do
	  case $args in
	    -L*)
  	       FREETYPE_RPATH="$FREETYPE_RPATH $args"
 	       ;;
          esac
     done
     FREETYPE_RPATH=`echo $FREETYPE_RPATH | sed -e "s/-L/-R/g"`
     FREETYPE_CFLAGS="`$FREETYPE_CONFIG --cflags`"

     AC_DEFINE_UNQUOTED(HAVE_FREETYPE, 1, [Defines if your system has the freetype library])

     ftvers=`$FREETYPE_CONFIG --ftversion 2>/dev/null | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
     if test -n "$ftvers" && test "$ftvers" -ge 2002000
     then
        AC_DEFINE_UNQUOTED(HAVE_FREETYPE_2_2_x, 1, [Defines if your system has the 2.2.x freetype library])
     fi
  fi
fi

AC_SUBST(FREETYPE_LIBS)
AC_SUBST(FREETYPE_CFLAGS)
AC_SUBST(FREETYPE_RPATH)

if test -z "$FREETYPE_LIBS"; then
	DO_NOT_COMPILE="$DO_NOT_COMPILE ksvg"
fi

# Check for lcms
have_lcms_header='no'
KDE_CHECK_HEADER(lcms2.h,have_lcms2_header='yes',,)
if test "$have_lcms2_header" = 'yes'; then
    AC_DEFINE(LCMS_HEADER, <lcms2.h>, [LCMS header])
else
    KDE_CHECK_HEADER(lcms.h,have_lcms_header='yes',,)
    if test "$have_lcms_header" = 'yes'; then
        AC_DEFINE(LCMS_HEADER, <lcms.h>, [LCMS header])                                            else                                                                                               KDE_CHECK_HEADER(lcms/lcms.h,have_lcms_header='yes',,)
        if test "$have_lcms_header" = 'yes'; then
            AC_DEFINE(LCMS_HEADER, <lcms/lcms.h>, [LCMS header])
        fi
    fi
fi

LCMS_LIBS=''
have_lcms='no'
saved_libs=$LIBS
saved_cflags="$CFLAGS"
saved_ldflags="$LDFLAGS"
CFLAGS="$CFLAGS $all_includes -I/usr/include/tqt"
LDFLAGS="$LDFLAGS $all_libraries"
if test "$have_lcms2_header" = 'yes'; then
    LIBS="$LIBS -llcms2"
    AC_TRY_LINK([
#define inline __inline /* gcc is in ansi mode */
#include LCMS_HEADER
#if LCMS_VERSION < 112
choke!
#endif
], [
cmsOpenProfileFromFile("foo", "r");
],
        [LCMS_LIBS='-llcms2'; have_lcms='yes'])
else
    if test "$have_lcms_header" = 'yes'; then
        LIBS="$LIBS -llcms"
        AC_TRY_LINK([
#define inline __inline /* gcc is in ansi mode */
#include LCMS_HEADER
#if LCMS_VERSION < 112
choke!
#endif
], [
cmsOpenProfileFromFile("foo", "r");
],
        [LCMS_LIBS='-llcms'; have_lcms='yes'])
    fi
fi
LIBS=$saved_libs
CFLAGS=$saved_cflags
LDFLAGS=$saved_ldflags

if test -z "$LCMS_LIBS"; then
	DO_NOT_COMPILE="$DO_NOT_COMPILE ksvg"
fi

AC_SUBST(LCMS_LIBS)

# Check for fribidi
KDE_FIND_PATH(fribidi-config, FRIBIDI_CONFIG, [${prefix}/bin ${exec_prefix}/bin /usr/local/bin /opt/local/bin],)

if test -n "$FRIBIDI_CONFIG"; then
  vers=`$FRIBIDI_CONFIG --version 2>/dev/null | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
  if test -n "$vers" && test "$vers" -ge 10004
  then
     FRIBIDI_LIBS="`$FRIBIDI_CONFIG --libs`"
     FRIBIDI_RPATH=
     for args in $FIBIDI_LIBS; do
	  case $args in
	    -L*)
  	       FRIBIDI_RPATH="$FRIBIDI_CONFIG $args"
 	       ;;
          esac
     done
     FRIBIDI_RPATH=`echo $FRIBIDI_RPATH | sed -e "s/-L/-R/g"`
     FRIBIDI_CFLAGS="`$FRIBIDI_CONFIG --cflags`"

     AC_DEFINE_UNQUOTED(HAVE_FRIBIDI, 1, [Defines if your system has the fribidi library])
  fi
else
  FRIBIDI_LIBS=`$PKG_CONFIG --libs fribidi`
  FRIBIDI_CFLAGS="`$PKG_CONFIG --cflags fribidi`"
fi

AC_SUBST(FRIBIDI_LIBS)
AC_SUBST(FRIBIDI_CFLAGS)
AC_SUBST(FRIBIDI_RPATH)

if test -z "$FRIBIDI_LIBS"; then
	DO_NOT_COMPILE="$DO_NOT_COMPILE ksvg"
fi

AC_LANG_SAVE
AC_LANG_CPLUSPLUS
KDE_CHECK_HEADERS(sstream)
AC_LANG_RESTORE
