FOUND_FREETYPE=0

KDE_FIND_PATH(freetype-config, FREETYPE_CONFIG, [${prefix}/bin ${exec_prefix}/bin /usr/bin /usr/local/bin /opt/local/bin], [
  AC_MSG_WARN([Could not find libfreetype anywhere, check http://www.freetype.org/])
])

if test -n "$FREETYPE_CONFIG"; then
  vers=`$FREETYPE_CONFIG --version 2>/dev/null | sed -e 's/libfreetype //' | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
  if test -n "$vers" && test "$vers" -ge 6001000
  then
     LIBFREETYPE_LIBS="`$FREETYPE_CONFIG --libs`"
     LIBFREETYPE_RPATH=
     for args in $LIBFREETYPE_LIBS; do
          case $args in
            -L*)
               LIBFREETYPE_RPATH="$LIBFREETYPE_RPATH $args"
               ;;
          esac
     done
     LIBFREETYPE_RPATH=`echo $LIBFREETYPE_RPATH | sed -e "s/-L/-R/g"`
     LIBFREETYPE_CFLAGS="`$FREETYPE_CONFIG --cflags`"
     FOUND_FREETYPE=1
  else
     AC_MSG_WARN([You need at least FreeType 2.0.2])
  fi
fi

if test $FOUND_FREETYPE -eq 1; then
    AC_SUBST(LIBFREETYPE_LIBS)
    AC_SUBST(LIBFREETYPE_CFLAGS)
    AC_SUBST(LIBFREETYPE_RPATH)
    FONTINST_SUBDIR="kfontinst"
else
    AC_MSG_WARN([Missing FreeType2 - disabling kfontinst!])
    FONTINST_SUBDIR=""
fi

AM_CONDITIONAL(include_kcontrol_kfontinst, test -n "$FONTINST_SUBDIR")

FONTINST_TN=""
if test $FOUND_FREETYPE -eq 1; then
    KDE_CHECK_LIB(freetype, FTC_Manager_New, FONTINST_TN="thumbnail",,
    -lm -L/usr/X11R6/lib $X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS)
fi

AM_CONDITIONAL(include_fontinst_tn, test -n "$FONTINST_TN")
