--- ext/gd/config.m4.orig	2007-07-03 12:25:43.000000000 -0500
+++ ext/gd/config.m4	2014-01-10 20:14:34.000000000 -0600
@@ -74,7 +74,7 @@
 AC_DEFUN([PHP_GD_JPEG],[
   if test "$PHP_JPEG_DIR" != "no"; then
 
-    for i in $PHP_JPEG_DIR /usr/local /usr; do
+    for i in $PHP_JPEG_DIR; do
       test -f $i/$PHP_LIBDIR/libjpeg.$SHLIB_SUFFIX_NAME || test -f $i/$PHP_LIBDIR/libjpeg.a && GD_JPEG_DIR=$i && break
     done
 
@@ -99,7 +99,7 @@
 AC_DEFUN([PHP_GD_PNG],[
   if test "$PHP_PNG_DIR" != "no"; then
 
-    for i in $PHP_PNG_DIR /usr/local /usr; do
+    for i in $PHP_PNG_DIR; do
       test -f $i/$PHP_LIBDIR/libpng.$SHLIB_SUFFIX_NAME || test -f $i/$PHP_LIBDIR/libpng.a && GD_PNG_DIR=$i && break
     done
 
@@ -134,7 +134,7 @@
 AC_DEFUN([PHP_GD_XPM],[
   if test "$PHP_XPM_DIR" != "no"; then
 
-    for i in $PHP_XPM_DIR /usr/local /usr/X11R6 /usr; do
+    for i in $PHP_XPM_DIR; do
       test -f $i/$PHP_LIBDIR/libXpm.$SHLIB_SUFFIX_NAME || test -f $i/$PHP_LIBDIR/libXpm.a && GD_XPM_DIR=$i && break
     done
 
@@ -203,30 +203,25 @@
 AC_DEFUN([PHP_GD_FREETYPE2],[
   if test "$PHP_FREETYPE_DIR" != "no"; then
 
-    for i in $PHP_FREETYPE_DIR /usr/local /usr; do
-      if test -f "$i/include/freetype2/freetype/freetype.h"; then
+    for i in $PHP_FREETYPE_DIR; do
+      if test -f "$i/bin/freetype-config"; then
         FREETYPE2_DIR=$i
-        FREETYPE2_INC_DIR=$i/include/freetype2
+        FREETYPE2_CONFIG="$i/bin/freetype-config"
         break
       fi
     done
 
     if test -z "$FREETYPE2_DIR"; then
-      AC_MSG_ERROR([freetype.h not found.])
+      AC_MSG_ERROR([freetype-config not found.])
     fi
 
-    PHP_CHECK_LIBRARY(freetype, FT_New_Face,
-    [
-      PHP_ADD_LIBRARY_WITH_PATH(freetype, $FREETYPE2_DIR/$PHP_LIBDIR, GD_SHARED_LIBADD)
-      PHP_ADD_INCLUDE($FREETYPE2_DIR/include)
-      PHP_ADD_INCLUDE($FREETYPE2_INC_DIR)
-      AC_DEFINE(USE_GD_IMGSTRTTF, 1, [ ])
-      AC_DEFINE(HAVE_LIBFREETYPE,1,[ ])
-    ],[
-      AC_MSG_ERROR([Problem with freetype.(a|so). Please check config.log for more information.])
-    ],[
-      -L$FREETYPE2_DIR/$PHP_LIBDIR
-    ])
+    FREETYPE2_CFLAGS=`$FREETYPE2_CONFIG --cflags`
+    FREETYPE2_LIBS=`$FREETYPE2_CONFIG --libs`
+
+    PHP_EVAL_INCLINE($FREETYPE2_CFLAGS)
+    PHP_EVAL_LIBLINE($FREETYPE2_LIBS, GD_SHARED_LIBADD)
+    AC_DEFINE(USE_GD_IMGSTRTTF, 1, [ ])
+    AC_DEFINE(HAVE_LIBFREETYPE,1,[ ])
   else
     AC_MSG_RESULT([If configure fails try --with-freetype-dir=<DIR>])
   fi
@@ -235,7 +230,7 @@
 AC_DEFUN([PHP_GD_T1LIB],[
   if test "$PHP_T1LIB" != "no"; then
 
-    for i in $PHP_T1LIB /usr/local /usr; do
+    for i in $PHP_T1LIB; do
       test -f "$i/include/t1lib.h" && GD_T1_DIR=$i && break
     done
 
