KDE_FIND_PATH(fontconfig-config, FONTCONFIG_CONFIG, [${prefix}/bin ${exec_prefix}/bin /usr/bin /usr/local/bin /opt/local/bin], [
        KDE_FIND_PATH(pkg-config, PKGCONFIG, [${prefix}/bin ${exec_prefix}/bin /usr/bin /usr/local/bin /opt/local/bin], [
            AC_MSG_WARN([Could not find neither pkg-config nor fontconfig-config, check http://www.fontconfig.org/ ])
        ])
])

if test -n "$PKGCONFIG"; then
  vers=`$PKGCONFIG fontconfig --modversion 2>/dev/null | sed -e 's/libfontconfig //' | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
  if test -n "$vers" && test "$vers" -ge 1000000
  then
     LIBFONTCONFIG_LIBS="`$PKGCONFIG fontconfig --libs`"
     LIBFONTCONFIG_RPATH=
     for args in $LIBFONTCONFIG_LIBS; do
          case $args in
            -L*)
               LIBFONTCONFIG_RPATH="$LIBFONTCONFIG_RPATH $args"
               ;;
          esac
     done
     LIBFONTCONFIG_RPATH=`echo $LIBFONTCONFIG_RPATH | sed -e "s/-L/-R/g"`
     LIBFONTCONFIG_CFLAGS="`$PKGCONFIG fontconfig --cflags`"

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

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

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

AC_SUBST(LIBFONTCONFIG_LIBS)
AC_SUBST(LIBFONTCONFIG_CFLAGS)
AC_SUBST(LIBFONTCONFIG_RPATH)

if pkg-config --exists freetype2 2>/dev/null; then
    FREETYPE2_CFLAGS=`pkg-config --cflags freetype2`
    FREETYPE2_LDFLAGS=`pkg-config --libs freetype2`
    AC_DEFINE(HAVE_FREETYPE2, 1, [Define if you have FreeType2 library])
fi
AC_SUBST(FREETYPE2_CFLAGS)
AC_SUBST(FREETYPE2_LDFLAGS)