diff --git a/MagickCore/magick-baseconfig.h b/MagickCore/magick-baseconfig.h
index 507e73e..d542af0 100644
--- a/MagickCore/magick-baseconfig.h
+++ b/MagickCore/magick-baseconfig.h
@@ -371,20 +371,6 @@
 #define MAGICKCORE_HAVE_J1 1
 #endif
 
-/* Define if you have the <lcms2.h> header file. */
-#ifndef MAGICKCORE_HAVE_LCMS2_H
-#define MAGICKCORE_HAVE_LCMS2_H 1
-#endif
-
-/* Define if you have the <lcms2/lcms2.h> header file. */
-/* #undef HAVE_LCMS2_LCMS2_H */
-
-/* Define if you have the <lcms.h> header file. */
-/* #undef HAVE_LCMS_H */
-
-/* Define if you have the <lcms/lcms.h> header file. */
-/* #undef HAVE_LCMS_LCMS_H */
-
 /* Define to 1 if you have the `gcov' library (-lgcov). */
 /* #undef HAVE_LIBGCOV */
 
@@ -1127,7 +1113,7 @@
 #define MAGICKCORE_JPEG_DELEGATE 1
 #endif
 
-/* Define if you have LCMS (v1.11 or later) library */
+/* Define if you have LCMS library */
 #ifndef MAGICKCORE_LCMS_DELEGATE
 #define MAGICKCORE_LCMS_DELEGATE 1
 #endif
@@ -1464,10 +1450,7 @@
 /* Define if using the dmalloc debugging malloc package */
 /* #undef WITH_DMALLOC */
 
-/* Define if you have wmflite library */
-/* #undef WMFLITE_DELEGATE */
-
-/* Define if you have wmf library */
+/* Define if you have WMF library */
 /* #undef WMF_DELEGATE */
 
 /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
@@ -1503,7 +1486,7 @@
 /* Build self-contained, embeddable, zero-configuration ImageMagick */
 /* #undef ZERO_CONFIGURATION_SUPPORT */
 
-/* Define if you have zlib compression library */
+/* Define if you have ZLIB library */
 #ifndef MAGICKCORE_ZLIB_DELEGATE
 #define MAGICKCORE_ZLIB_DELEGATE 1
 #endif
diff --git a/MagickCore/version.h b/MagickCore/version.h
index 42dedd7..7444c88 100644
--- a/MagickCore/version.h
+++ b/MagickCore/version.h
@@ -27,7 +27,7 @@
 */
 #define MagickPackageName "ImageMagick"
 #define MagickCopyright  "Copyright (C) 1999-2015 ImageMagick Studio LLC"
-#define MagickSVNRevision  "18723M"
+#define MagickSVNRevision  "18729M"
 #define MagickLibVersion  0x700
 #define MagickLibVersionText  "7.0.0"
 #define MagickLibVersionNumber  0,0,0
@@ -48,7 +48,7 @@
 #define MagickppLibAddendum  "-0"
 #define MagickppLibInterface  0
 #define MagickppLibMinInterface  0
-#define MagickReleaseDate  "2015-06-04"
+#define MagickReleaseDate  "2015-06-05"
 #define MagickChangeDate   "20120427"
 #define MagickAuthoritativeLicense  \
   "http://www.imagemagick.org/script/license.php"
diff --git a/Makefile.in b/Makefile.in
index 35fed5a..a6898d2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1703,8 +1703,7 @@
 @WEBP_DELEGATE_TRUE@@WITH_MODULES_TRUE@am_coders_webp_la_rpath =  \
 @WEBP_DELEGATE_TRUE@@WITH_MODULES_TRUE@	-rpath $(codersdir)
 coders_wmf_la_DEPENDENCIES = $(MAGICKCORE_LIBS) $(MAGICKWAND_LIBS) \
-	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-	$(am__DEPENDENCIES_1)
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am_coders_wmf_la_OBJECTS = coders/coders_wmf_la-wmf.lo
 coders_wmf_la_OBJECTS = $(am_coders_wmf_la_OBJECTS)
 coders_wmf_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
@@ -2614,6 +2613,7 @@
 DEPDIR = @DEPDIR@
 DIRSEP = @DIRSEP@
 DISTCHECK_CONFIG_FLAGS = @DISTCHECK_CONFIG_FLAGS@
+DJVU_CFLAGS = @DJVU_CFLAGS@
 DJVU_LIBS = @DJVU_LIBS@
 DLLTOOL = @DLLTOOL@
 DNGDecodeDelegate = @DNGDecodeDelegate@
@@ -2634,6 +2634,7 @@
 EXEEXT = @EXEEXT@
 EchoDelegate = @EchoDelegate@
 EditorDelegate = @EditorDelegate@
+FFTW_CFLAGS = @FFTW_CFLAGS@
 FFTW_LIBS = @FFTW_LIBS@
 FGREP = @FGREP@
 FILTER_DIRNAME = @FILTER_DIRNAME@
@@ -2684,6 +2685,7 @@
 JPEG_LIBS = @JPEG_LIBS@
 JXRDecodeDelegate = @JXRDecodeDelegate@
 JXREncodeDelegate = @JXREncodeDelegate@
+LCMS_CFLAGS = @LCMS_CFLAGS@
 LCMS_LIBS = @LCMS_LIBS@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
@@ -2819,6 +2821,7 @@
 PKG_CONFIG = @PKG_CONFIG@
 PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
 PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+PNG_CFLAGS = @PNG_CFLAGS@
 PNG_LIBS = @PNG_LIBS@
 POVDelegate = @POVDelegate@
 POW_LIB = @POW_LIB@
@@ -2872,8 +2875,8 @@
 VERSION = @VERSION@
 WEBP_LIBS = @WEBP_LIBS@
 WMFDecodeDelegate = @WMFDecodeDelegate@
+WMF_CFLAGS = @WMF_CFLAGS@
 WMF_LIBS = @WMF_LIBS@
-WMF_LIBS_DEPS = @WMF_LIBS_DEPS@
 WWWDecodeDelegate = @WWWDecodeDelegate@
 WebPDecodeDelegate = @WebPDecodeDelegate@
 WebPEncodeDelegate = @WebPEncodeDelegate@
@@ -2881,6 +2884,7 @@
 X11_LIBS = @X11_LIBS@
 XEXT_LIBS = @XEXT_LIBS@
 XMKMF = @XMKMF@
+XML_CFLAGS = @XML_CFLAGS@
 XML_LIBS = @XML_LIBS@
 XPSCMYKDevice = @XPSCMYKDevice@
 XPSColorDevice = @XPSColorDevice@
@@ -2892,6 +2896,7 @@
 X_LIBS = @X_LIBS@
 X_PRE_LIBS = @X_PRE_LIBS@
 ZIP = @ZIP@
+ZLIB_CFLAGS = @ZLIB_CFLAGS@
 ZLIB_LIBS = @ZLIB_LIBS@
 ZipDelegate = @ZipDelegate@
 abs_builddir = @abs_builddir@
@@ -2918,12 +2923,16 @@
 builddir = @builddir@
 datadir = @datadir@
 datarootdir = @datarootdir@
+ddjvuapi_CFLAGS = @ddjvuapi_CFLAGS@
+ddjvuapi_LIBS = @ddjvuapi_LIBS@
 dejavu_font_dir = @dejavu_font_dir@
 
 # Architecture independent data files installed in the package's data directory
 docdir = $(DOCUMENTATION_PATH)
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+fftw3_CFLAGS = @fftw3_CFLAGS@
+fftw3_LIBS = @fftw3_LIBS@
 ghostscript_font_dir = @ghostscript_font_dir@
 host = @host@
 host_alias = @host_alias@
@@ -2962,7 +2971,6 @@
 top_srcdir = @top_srcdir@
 type_include_files = @type_include_files@
 windows_font_dir = @windows_font_dir@
-xml2_config = @xml2_config@
 topincludedir = @includedir@/MagickCore
 AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir)
 ACLOCAL_AMFLAGS = -I m4
@@ -4110,7 +4118,7 @@
 coders_wmf_la_SOURCES = coders/wmf.c
 coders_wmf_la_CPPFLAGS = $(MAGICK_CODER_CPPFLAGS)
 coders_wmf_la_LDFLAGS = $(MODULECOMMONFLAGS)
-coders_wmf_la_LIBADD = $(MAGICKCORE_LIBS) $(MAGICKWAND_LIBS) $(WMF_LIBS) $(WMF_LIBS_DEPS) $(MATH_LIBS)
+coders_wmf_la_LIBADD = $(MAGICKCORE_LIBS) $(MAGICKWAND_LIBS) $(WMF_LIBS) $(MATH_LIBS)
 
 # WPG coder module
 coders_wpg_la_SOURCES = coders/wpg.c
diff --git a/PerlMagick/Makefile.PL b/PerlMagick/Makefile.PL
index e0d5ea4..6f091d9 100644
--- a/PerlMagick/Makefile.PL
+++ b/PerlMagick/Makefile.PL
@@ -161,9 +161,9 @@
 }
 
 # defaults for LIBS & INC & CCFLAGS params that we later pass to Writemakefile
-my $INC_magick = '-I../ -I.. -pthread -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libdrm -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/libxml2 -I"' . $Config{'usrinc'} . '/ImageMagick"';
+my $INC_magick = '-I../ -I.. -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I"' . $Config{'usrinc'} . '/ImageMagick"';
 my $LIBS_magick = '-L../MagickCore/.libs -lMagickCore-7.Q16HDRI -lperl -lm';
-my $CCFLAGS_magick = "$Config{'ccflags'} -pthread -I/usr/include/OpenEXR -I/usr/include/libdrm -I/usr/include/freetype2 -I/usr/include/libpng16 -fopenmp -g -O2 -Wall -mtune=sandybridge -fexceptions -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16";
+my $CCFLAGS_magick = "$Config{'ccflags'} -I/usr/include/libxml2 -I/usr/include/libpng16 -pthread -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/OpenEXR -fopenmp -g -O2 -Wall -mtune=sandybridge -fexceptions -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16";
 my $LDFLAGS_magick   = "-L../MagickCore/.libs -lMagickCore-7.Q16HDRI $Config{'ldflags'} ";
 my $LDDLFLAGS_magick = "-L../MagickCore/.libs -lMagickCore-7.Q16HDRI $Config{'lddlflags'} ";
 
@@ -209,7 +209,7 @@
    #'CC' => 'gcc',
 
    # C pre-processor flags (e.g. -I & -D options)
-   # 'CPPFLAGS' => "$Config{'cppflags'} -pthread -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libdrm -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/libxml2",
+   # 'CPPFLAGS' => "$Config{'cppflags'} -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16",
 
    # C compiler flags (e.g. -O -g)
    'CCFLAGS' => $CCFLAGS_magick,
diff --git a/coders/Makefile.am b/coders/Makefile.am
index 1ab8312..8a26eff 100644
--- a/coders/Makefile.am
+++ b/coders/Makefile.am
@@ -1030,7 +1030,7 @@
 coders_wmf_la_SOURCES      = coders/wmf.c
 coders_wmf_la_CPPFLAGS     = $(MAGICK_CODER_CPPFLAGS)
 coders_wmf_la_LDFLAGS      = $(MODULECOMMONFLAGS)
-coders_wmf_la_LIBADD       = $(MAGICKCORE_LIBS) $(MAGICKWAND_LIBS) $(WMF_LIBS) $(WMF_LIBS_DEPS) $(MATH_LIBS)
+coders_wmf_la_LIBADD       = $(MAGICKCORE_LIBS) $(MAGICKWAND_LIBS) $(WMF_LIBS) $(MATH_LIBS)
 
 # WPG coder module
 coders_wpg_la_SOURCES      = coders/wpg.c
diff --git a/coders/wmf.c b/coders/wmf.c
index c52d1d4..22430d2 100644
--- a/coders/wmf.c
+++ b/coders/wmf.c
@@ -64,10 +64,10 @@
 #include "MagickWand/MagickWand.h"
 
 #if defined(__CYGWIN__)
-#undef MAGICKCORE_WMF_DELEGATE 
+#undef MAGICKCORE_SANS_DELEGATE 
 #endif
 
-#if defined(MAGICKCORE_WMF_DELEGATE)
+#if defined(MAGICKCORE_SANS_DELEGATE)
 #include "libwmf/api.h"
 #include "libwmf/eps.h"
 
@@ -235,7 +235,7 @@
   (void) RelinquishUniqueFileResource(filename);
   return(GetFirstImageInList(image));
 }
-#elif defined(MAGICKCORE_WMFLITE_DELEGATE)
+#elif defined(MAGICKCORE_WMF_DELEGATE)
 
 #define ERR(API)  ((API)->err != wmf_E_None)
 #define XC(x) ((double) x)
@@ -300,7 +300,7 @@
 #define CENTIMETERS_PER_INCH  2.54
 #define POINTS_PER_INCH       72
 
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_WMF_DELEGATE)
 # define wmf_api_create(api,flags,options) wmf_lite_create(api,flags,options)
 # define wmf_api_destroy(api) wmf_lite_destroy(api)
 # undef WMF_FONT_PSNAME
@@ -394,7 +394,7 @@
 }
 magick_arc_t;
 
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_WMF_DELEGATE)
 static void  lite_font_init (wmfAPI* API, wmfAPI_Options* options);
 static void  lite_font_map(wmfAPI* API,wmfFont* font);
 static float lite_font_stringwidth(wmfAPI* API, wmfFont* font, char* str);
@@ -420,7 +420,7 @@
 static void         ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc);
 static void         ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel);
 static void         ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * poly_line);
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_WMF_DELEGATE)
 static void         ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon);
 #endif
 static void         ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect);
@@ -439,7 +439,7 @@
 static void         ipa_udata_set(wmfAPI * API, wmfUserData_t * userdata);
 static int          magick_progress_callback(void* wand,float quantum);
 static void         util_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc,magick_arc_t finish);
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_WMF_DELEGATE)
 /*static int          util_font_weight( const char* font );*/
 #endif
 static double       util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height, ExceptionInfo *);
@@ -1203,7 +1203,7 @@
 }
 
 /* Draw a polypolygon.  A polypolygon is a list of polygons */
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_WMF_DELEGATE)
 static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon)
 {
   if (TO_FILL(polypolygon) || TO_DRAW(polypolygon))
@@ -1396,7 +1396,7 @@
   FR->draw_line = ipa_draw_line;
   FR->poly_line = ipa_poly_line;
   FR->draw_polygon = ipa_draw_polygon;
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_WMF_DELEGATE)
   FR->draw_polypolygon = ipa_draw_polypolygon;
 #endif
   FR->draw_rectangle = ipa_draw_rectangle;
@@ -1539,7 +1539,7 @@
               double
                 text_width = metrics.width * (ddata->scale_y / ddata->scale_x);
 
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_WMF_DELEGATE)
               point.x -= text_width / 2;
 #else
               point.x += bbox_width / 2 - text_width / 2;
@@ -2203,7 +2203,7 @@
   return floor(pointsize);
 }
 
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_WMF_DELEGATE)
 /* Estimate weight based on font name */
 /*
 static int util_font_weight( const char* font )
@@ -2523,7 +2523,7 @@
   ((wmf_magick_font_t*)font_data->user_data)->pointsize = 0;
 }
 
-#endif /* MAGICKCORE_WMFLITE_DELEGATE */
+#endif /* MAGICKCORE_WMF_DELEGATE */
 
 /* BLOB read byte */
 static int ipa_blob_read(void* wand)
@@ -2639,7 +2639,7 @@
   ddata->draw_info->text=(char *)
     RelinquishMagickMemory(ddata->draw_info->text);
 
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_WMF_DELEGATE)
   /* Must initialize font subystem for WMFlite interface */
   lite_font_init (API,&wmf_api_options); /* similar to wmf_ipa_font_init in src/font.c */
   /* wmf_arg_fontdirs (API,options); */ /* similar to wmf_arg_fontdirs in src/wmf.c */
@@ -2830,7 +2830,7 @@
     printf("dc->Window.height = %d\n", dc->Window.height);
     printf("dc->pixel_width   = %g\n", dc->pixel_width);
     printf("dc->pixel_height  = %g\n", dc->pixel_height);
-#if defined(MAGICKCORE_WMFLITE_DELEGATE)  /* Only in libwmf 0.3 */
+#if defined(MAGICKCORE_WMF_DELEGATE)  /* Only in libwmf 0.3 */
     printf("dc->Ox            = %.d\n", dc->Ox);
     printf("dc->Oy            = %.d\n", dc->Oy);
     printf("dc->width         = %.d\n", dc->width);
@@ -2949,13 +2949,13 @@
     *entry;
 
   entry = AcquireMagickInfo("WMF","WMZ","Compressed Windows Meta File");
-#if defined(MAGICKCORE_WMF_DELEGATE) || defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_SANS_DELEGATE) || defined(MAGICKCORE_WMF_DELEGATE)
   entry->decoder=ReadWMFImage;
 #endif
   entry->flags|=CoderSeekableStreamFlag;
   (void) RegisterMagickInfo(entry);
   entry=AcquireMagickInfo("WMF","WMF","Windows Meta File");
-#if defined(MAGICKCORE_WMF_DELEGATE) || defined(MAGICKCORE_WMFLITE_DELEGATE)
+#if defined(MAGICKCORE_SANS_DELEGATE) || defined(MAGICKCORE_WMF_DELEGATE)
   entry->decoder=ReadWMFImage;
 #endif
   (void) RegisterMagickInfo(entry);
diff --git a/config/config.h.in b/config/config.h.in
index c43f91b..c8f9d50 100644
--- a/config/config.h.in
+++ b/config/config.h.in
@@ -242,18 +242,6 @@
 /* Define to 1 if you have the `j1' function. */
 #undef HAVE_J1
 
-/* Define if you have the <lcms2.h> header file. */
-#undef HAVE_LCMS2_H
-
-/* Define if you have the <lcms2/lcms2.h> header file. */
-#undef HAVE_LCMS2_LCMS2_H
-
-/* Define if you have the <lcms.h> header file. */
-#undef HAVE_LCMS_H
-
-/* Define if you have the <lcms/lcms.h> header file. */
-#undef HAVE_LCMS_LCMS_H
-
 /* Define to 1 if you have the `gcov' library (-lgcov). */
 #undef HAVE_LIBGCOV
 
@@ -736,7 +724,7 @@
 /* Define if you have JPEG library */
 #undef JPEG_DELEGATE
 
-/* Define if you have LCMS (v1.11 or later) library */
+/* Define if you have LCMS library */
 #undef LCMS_DELEGATE
 
 /* Define if you have OPENJP2 library */
@@ -967,10 +955,7 @@
 /* Define if using the dmalloc debugging malloc package */
 #undef WITH_DMALLOC
 
-/* Define if you have wmflite library */
-#undef WMFLITE_DELEGATE
-
-/* Define if you have wmf library */
+/* Define if you have WMF library */
 #undef WMF_DELEGATE
 
 /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
@@ -1000,7 +985,7 @@
 /* Build self-contained, embeddable, zero-configuration ImageMagick */
 #undef ZERO_CONFIGURATION_SUPPORT
 
-/* Define if you have zlib compression library */
+/* Define if you have ZLIB library */
 #undef ZLIB_DELEGATE
 
 /* Enable large inode numbers on Mac OS X 10.5.  */
diff --git a/configure b/configure
index a88c1b0..23d2dda 100755
--- a/configure
+++ b/configure
@@ -763,14 +763,14 @@
 INCLUDEARCH_PATH
 INCLUDE_PATH
 PERLMAINCC
-XML_LIBS
 XML_DELEGATE_FALSE
 XML_DELEGATE_TRUE
-xml2_config
-WMF_LIBS_DEPS
-WMF_LIBS
+XML_LIBS
+XML_CFLAGS
 WMF_DELEGATE_FALSE
 WMF_DELEGATE_TRUE
+WMF_LIBS
+WMF_CFLAGS
 WEBP_LIBS
 WEBP_DELEGATE_FALSE
 WEBP_DELEGATE_TRUE
@@ -785,9 +785,10 @@
 CAIRO_SVG_CFLAGS
 RSVG_LIBS
 RSVG_CFLAGS
-PNG_LIBS
 PNG_DELEGATE_FALSE
 PNG_DELEGATE_TRUE
+PNG_LIBS
+PNG_CFLAGS
 PANGOCAIRO_DELEGATE_FALSE
 PANGOCAIRO_DELEGATE_TRUE
 PANGO_DELEGATE_FALSE
@@ -810,9 +811,10 @@
 LIBOPENJP2_DELEGATE_TRUE
 LIBOPENJP2_LIBS
 LIBOPENJP2_CFLAGS
-LCMS_LIBS
 LCMS_DELEGATE_FALSE
 LCMS_DELEGATE_TRUE
+LCMS_LIBS
+LCMS_CFLAGS
 JPEG_LIBS
 JPEG_DELEGATE_FALSE
 JPEG_DELEGATE_TRUE
@@ -835,14 +837,20 @@
 FONTCONFIG_LIBS
 FONTCONFIG_CFLAGS
 DJVU_LIBS
+DJVU_CFLAGS
 DJVU_DELEGATE_FALSE
 DJVU_DELEGATE_TRUE
+ddjvuapi_LIBS
+ddjvuapi_CFLAGS
 FPX_LIBS
 FPX_DELEGATE_FALSE
 FPX_DELEGATE_TRUE
 FFTW_LIBS
+FFTW_CFLAGS
 FFTW_DELEGATE_FALSE
 FFTW_DELEGATE_TRUE
+fftw3_LIBS
+fftw3_CFLAGS
 DPS_LIBS
 DPS_DELEGATE_FALSE
 DPS_DELEGATE_TRUE
@@ -853,9 +861,10 @@
 LIB_DL
 WITH_LTDL_FALSE
 WITH_LTDL_TRUE
-ZLIB_LIBS
 ZLIB_DELEGATE_FALSE
 ZLIB_DELEGATE_TRUE
+ZLIB_LIBS
+ZLIB_CFLAGS
 XEXT_LIBS
 X11_LIBS
 X11_DELEGATE_FALSE
@@ -1193,7 +1202,6 @@
 with_jbig
 with_jpeg
 with_lcms
-with_lcms2
 with_openjp2
 with_lqr
 with_lzma
@@ -1225,14 +1233,22 @@
 PKG_CONFIG_LIBDIR
 CXXCPP
 XMKMF
+ZLIB_CFLAGS
+ZLIB_LIBS
 AUTOTRACE_CFLAGS
 AUTOTRACE_LIBS
+fftw3_CFLAGS
+fftw3_LIBS
+ddjvuapi_CFLAGS
+ddjvuapi_LIBS
 FONTCONFIG_CFLAGS
 FONTCONFIG_LIBS
 FREETYPE_CFLAGS
 FREETYPE_LIBS
 GVC_CFLAGS
 GVC_LIBS
+LCMS_CFLAGS
+LCMS_LIBS
 LIBOPENJP2_CFLAGS
 LIBOPENJP2_LIBS
 LQR_CFLAGS
@@ -1243,10 +1259,16 @@
 OPENEXR_LIBS
 PANGO_CFLAGS
 PANGO_LIBS
+PNG_CFLAGS
+PNG_LIBS
 RSVG_CFLAGS
 RSVG_LIBS
 CAIRO_SVG_CFLAGS
-CAIRO_SVG_LIBS'
+CAIRO_SVG_LIBS
+WMF_CFLAGS
+WMF_LIBS
+XML_CFLAGS
+XML_LIBS'
 
 
 # Initialize some variables set by options.
@@ -1972,7 +1994,6 @@
   --without-jbig          disable JBIG support
   --without-jpeg          disable JPEG support
   --without-lcms          disable lcms (v1.1X) support
-  --without-lcms2         disable lcms (v2.X) support
   --without-openjp2       disable OpenJP2 support
   --without-lqr           disable Liquid Rescale support
   --without-lzma          disable LZMA support
@@ -2005,10 +2026,19 @@
               path overriding pkg-config's built-in search path
   CXXCPP      C++ preprocessor
   XMKMF       Path to xmkmf, Makefile generator for X Window System
+  ZLIB_CFLAGS C compiler flags for ZLIB, overriding pkg-config
+  ZLIB_LIBS   linker flags for ZLIB, overriding pkg-config
   AUTOTRACE_CFLAGS
               C compiler flags for AUTOTRACE, overriding pkg-config
   AUTOTRACE_LIBS
               linker flags for AUTOTRACE, overriding pkg-config
+  fftw3_CFLAGS
+              C compiler flags for fftw3, overriding pkg-config
+  fftw3_LIBS  linker flags for fftw3, overriding pkg-config
+  ddjvuapi_CFLAGS
+              C compiler flags for ddjvuapi, overriding pkg-config
+  ddjvuapi_LIBS
+              linker flags for ddjvuapi, overriding pkg-config
   FONTCONFIG_CFLAGS
               C compiler flags for FONTCONFIG, overriding pkg-config
   FONTCONFIG_LIBS
@@ -2019,6 +2049,8 @@
               linker flags for FREETYPE, overriding pkg-config
   GVC_CFLAGS  C compiler flags for GVC, overriding pkg-config
   GVC_LIBS    linker flags for GVC, overriding pkg-config
+  LCMS_CFLAGS C compiler flags for LCMS, overriding pkg-config
+  LCMS_LIBS   linker flags for LCMS, overriding pkg-config
   LIBOPENJP2_CFLAGS
               C compiler flags for LIBOPENJP2, overriding pkg-config
   LIBOPENJP2_LIBS
@@ -2034,12 +2066,18 @@
   PANGO_CFLAGS
               C compiler flags for PANGO, overriding pkg-config
   PANGO_LIBS  linker flags for PANGO, overriding pkg-config
+  PNG_CFLAGS  C compiler flags for PNG, overriding pkg-config
+  PNG_LIBS    linker flags for PNG, overriding pkg-config
   RSVG_CFLAGS C compiler flags for RSVG, overriding pkg-config
   RSVG_LIBS   linker flags for RSVG, overriding pkg-config
   CAIRO_SVG_CFLAGS
               C compiler flags for CAIRO_SVG, overriding pkg-config
   CAIRO_SVG_LIBS
               linker flags for CAIRO_SVG, overriding pkg-config
+  WMF_CFLAGS  C compiler flags for WMF, overriding pkg-config
+  WMF_LIBS    linker flags for WMF, overriding pkg-config
+  XML_CFLAGS  C compiler flags for XML, overriding pkg-config
+  XML_LIBS    linker flags for XML, overriding pkg-config
 
 Use these variables to override the choices made by `configure' or to help
 it to find libraries and programs with nonstandard names/locations.
@@ -4342,7 +4380,7 @@
 
 MAGICK_VERSION=7.0.0-0
 
-MAGICK_SVN_REVISION=18723M
+MAGICK_SVN_REVISION=18729M
 
 
 # Substitute library versioning
@@ -28349,307 +28387,94 @@
 fi
 
 have_zlib='no'
-ZLIB_LIBS=''
-if test "$with_zlib" != 'no' || test "$with_png" != 'no'; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+ZLIB_CFLAGS=""
+ZLIB_LIBS=""
+ZLIB_PKG=""
+if test "x$with_zlib" = "xyes"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ZLIB" >&5
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ZLIB" >&5
 $as_echo_n "checking for ZLIB... " >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
-$as_echo "" >&6; }
-    ZLIB_LIBS=''
-    failed=0
-    passed=0
-    ac_fn_c_check_header_mongrel "$LINENO" "zconf.h" "ac_cv_header_zconf_h" "$ac_includes_default"
-if test "x$ac_cv_header_zconf_h" = xyes; then :
-  passed=`expr $passed + 1`
+
+if test -n "$ZLIB_CFLAGS"; then
+    pkg_cv_ZLIB_CFLAGS="$ZLIB_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"zlib >= 1.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "zlib >= 1.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_ZLIB_CFLAGS=`$PKG_CONFIG --cflags "zlib >= 1.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
 else
-  failed=`expr $failed + 1`
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$ZLIB_LIBS"; then
+    pkg_cv_ZLIB_LIBS="$ZLIB_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"zlib >= 1.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "zlib >= 1.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_ZLIB_LIBS=`$PKG_CONFIG --libs "zlib >= 1.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
 fi
 
 
-    ac_fn_c_check_header_mongrel "$LINENO" "zlib.h" "ac_cv_header_zlib_h" "$ac_includes_default"
-if test "x$ac_cv_header_zlib_h" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
 
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for compress in -lz" >&5
-$as_echo_n "checking for compress in -lz... " >&6; }
-if ${ac_cv_lib_z_compress+:} false; then :
-  $as_echo_n "(cached) " >&6
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
 else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char compress ();
-int
-main ()
-{
-return compress ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_z_compress=yes
-else
-  ac_cv_lib_z_compress=no
+        _pkg_short_errors_supported=no
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_compress" >&5
-$as_echo "$ac_cv_lib_z_compress" >&6; }
-if test "x$ac_cv_lib_z_compress" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for uncompress in -lz" >&5
-$as_echo_n "checking for uncompress in -lz... " >&6; }
-if ${ac_cv_lib_z_uncompress+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char uncompress ();
-int
-main ()
-{
-return uncompress ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_z_uncompress=yes
-else
-  ac_cv_lib_z_uncompress=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_uncompress" >&5
-$as_echo "$ac_cv_lib_z_uncompress" >&6; }
-if test "x$ac_cv_lib_z_uncompress" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for deflate in -lz" >&5
-$as_echo_n "checking for deflate in -lz... " >&6; }
-if ${ac_cv_lib_z_deflate+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char deflate ();
-int
-main ()
-{
-return deflate ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_z_deflate=yes
-else
-  ac_cv_lib_z_deflate=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_deflate" >&5
-$as_echo "$ac_cv_lib_z_deflate" >&6; }
-if test "x$ac_cv_lib_z_deflate" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inflate in -lz" >&5
-$as_echo_n "checking for inflate in -lz... " >&6; }
-if ${ac_cv_lib_z_inflate+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char inflate ();
-int
-main ()
-{
-return inflate ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_z_inflate=yes
-else
-  ac_cv_lib_z_inflate=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_inflate" >&5
-$as_echo "$ac_cv_lib_z_inflate" >&6; }
-if test "x$ac_cv_lib_z_inflate" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gzseek in -lz" >&5
-$as_echo_n "checking for gzseek in -lz... " >&6; }
-if ${ac_cv_lib_z_gzseek+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char gzseek ();
-int
-main ()
-{
-return gzseek ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_z_gzseek=yes
-else
-  ac_cv_lib_z_gzseek=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_gzseek" >&5
-$as_echo "$ac_cv_lib_z_gzseek" >&6; }
-if test "x$ac_cv_lib_z_gzseek" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gztell in -lz" >&5
-$as_echo_n "checking for gztell in -lz... " >&6; }
-if ${ac_cv_lib_z_gztell+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lz  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char gztell ();
-int
-main ()
-{
-return gztell ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_z_gztell=yes
-else
-  ac_cv_lib_z_gztell=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_gztell" >&5
-$as_echo "$ac_cv_lib_z_gztell" >&6; }
-if test "x$ac_cv_lib_z_gztell" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ZLIB package is complete" >&5
-$as_echo_n "checking if ZLIB package is complete... " >&6; }
-    if test $passed -gt 0; then
-        if test $failed -gt 0; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: result: no -- some components failed test" >&5
-$as_echo "no -- some components failed test" >&6; }
-            have_zlib='no (failed tests)'
+        if test $_pkg_short_errors_supported = yes; then
+	        ZLIB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "zlib >= 1.0.0" 2>&1`
         else
-            ZLIB_LIBS='-lz'
-            LIBS="$ZLIB_LIBS $LIBS"
+	        ZLIB_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "zlib >= 1.0.0" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$ZLIB_PKG_ERRORS" >&5
+
+	have_zlib=no
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	have_zlib=no
+else
+	ZLIB_CFLAGS=$pkg_cv_ZLIB_CFLAGS
+	ZLIB_LIBS=$pkg_cv_ZLIB_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	have_zlib=yes
+fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+$as_echo "" >&6; }
+fi
+
+if test "$have_zlib" = 'yes'; then
 
 $as_echo "#define ZLIB_DELEGATE 1" >>confdefs.h
 
-            { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-            have_zlib='yes'
-        fi
-    else
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-    fi
+  CFLAGS="$ZLIB_CFLAGS $CFLAGS"
 fi
+
  if test "$have_zlib" = 'yes'; then
   ZLIB_DELEGATE_TRUE=
   ZLIB_DELEGATE_FALSE='#'
@@ -28660,6 +28485,8 @@
 
 
 
+
+
 # whether modules are built or not.
 with_ltdl='yes'
 have_ltdl='no'
@@ -28848,7 +28675,7 @@
 AUTOTRACE_LIBS=""
 AUTOTRACE_PKG=""
 if test "x$with_autotrace" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -28921,18 +28748,15 @@
 $as_echo "yes" >&6; }
 	have_autotrace=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
 if test "$have_autotrace" = 'yes'; then
-    failed=0
 
 $as_echo "#define AUTOTRACE_DELEGATE 1" >>confdefs.h
 
-    if test "$build_modules" = 'no'; then
-      CPPFLAGS="$AUTOTRACE_CFLAGS $CPPFLAGS"
-    fi
+  CFLAGS="$AUTOTRACE_CFLAGS $CFLAGS"
 fi
 
  if test "$have_autotrace" = 'yes'; then
@@ -29198,88 +29022,94 @@
 fi
 
 have_fftw='no'
-FFTW_LIBS=''
-if test "$with_fftw" != 'no'; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+FFTW_CFLAGS=""
+FFTW_LIBS=""
+FFTW_PKG=""
+if test "x$with_fftw" = "xyes"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for FFTW" >&5
-$as_echo_n "checking for FFTW... " >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
-$as_echo "" >&6; }
-    failed=0
-    passed=0
-    ac_fn_c_check_header_mongrel "$LINENO" "fftw3.h" "ac_cv_header_fftw3_h" "$ac_includes_default"
-if test "x$ac_cv_header_fftw3_h" = xyes; then :
-  passed=`expr $passed + 1`
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fftw3" >&5
+$as_echo_n "checking for fftw3... " >&6; }
+
+if test -n "$fftw3_CFLAGS"; then
+    pkg_cv_fftw3_CFLAGS="$fftw3_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"fftw3 >= 3.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "fftw3 >= 3.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_fftw3_CFLAGS=`$PKG_CONFIG --cflags "fftw3 >= 3.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
 else
-  failed=`expr $failed + 1`
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$fftw3_LIBS"; then
+    pkg_cv_fftw3_LIBS="$fftw3_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"fftw3 >= 3.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "fftw3 >= 3.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_fftw3_LIBS=`$PKG_CONFIG --libs "fftw3 >= 3.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
 fi
 
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fftw_execute in -lfftw3" >&5
-$as_echo_n "checking for fftw_execute in -lfftw3... " >&6; }
-if ${ac_cv_lib_fftw3_fftw_execute+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lfftw3  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
 
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char fftw_execute ();
-int
-main ()
-{
-return fftw_execute ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_fftw3_fftw_execute=yes
-else
-  ac_cv_lib_fftw3_fftw_execute=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_fftw3_fftw_execute" >&5
-$as_echo "$ac_cv_lib_fftw3_fftw_execute" >&6; }
-if test "x$ac_cv_lib_fftw3_fftw_execute" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if FFTW package is complete" >&5
-$as_echo_n "checking if FFTW package is complete... " >&6; }
-    if test $passed -gt 0; then
-        if test $failed -gt 0; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: result: no -- some components failed test" >&5
-$as_echo "no -- some components failed test" >&6; }
-            have_fftw='no (failed tests)'
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        fftw3_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "fftw3 >= 3.0.0" 2>&1`
         else
-            FFTW_LIBS='-lfftw3'
-            LIBS="$FFTW_LIBS $LIBS"
+	        fftw3_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "fftw3 >= 3.0.0" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$fftw3_PKG_ERRORS" >&5
+
+	have_fftw=no
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	have_fftw=no
+else
+	fftw3_CFLAGS=$pkg_cv_fftw3_CFLAGS
+	fftw3_LIBS=$pkg_cv_fftw3_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	have_fftw=yes
+fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+$as_echo "" >&6; }
+fi
+
+if test "$have_fftw" = 'yes'; then
 
 $as_echo "#define FFTW_DELEGATE 1" >>confdefs.h
 
-            { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-            have_fftw='yes'
-        fi
-    else
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-    fi
+  CFLAGS="$fftw3_CFLAGS $CFLAGS"
 fi
+
  if test "$have_fftw" = 'yes'; then
   FFTW_DELEGATE_TRUE=
   FFTW_DELEGATE_FALSE='#'
@@ -29291,6 +29121,7 @@
 
 
 
+
 #
 # Check for FlashPIX delegate library.
 #
@@ -29431,88 +29262,94 @@
 fi
 
 have_djvu='no'
-DJVU_LIBS=''
-if test "$with_djvu" != 'no'; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+DJVU_CFLAGS=""
+DJVU_LIBS=""
+DJVU_PKG=""
+if test "x$with_djvu" = "xyes"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for DJVU" >&5
-$as_echo_n "checking for DJVU... " >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
-$as_echo "" >&6; }
-    failed=0
-    passed=0
-    ac_fn_c_check_header_mongrel "$LINENO" "libdjvu/ddjvuapi.h" "ac_cv_header_libdjvu_ddjvuapi_h" "$ac_includes_default"
-if test "x$ac_cv_header_libdjvu_ddjvuapi_h" = xyes; then :
-  passed=`expr $passed + 1`
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ddjvuapi" >&5
+$as_echo_n "checking for ddjvuapi... " >&6; }
+
+if test -n "$ddjvuapi_CFLAGS"; then
+    pkg_cv_ddjvuapi_CFLAGS="$ddjvuapi_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"ddjvuapi >= 3.5.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "ddjvuapi >= 3.5.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_ddjvuapi_CFLAGS=`$PKG_CONFIG --cflags "ddjvuapi >= 3.5.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
 else
-  failed=`expr $failed + 1`
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$ddjvuapi_LIBS"; then
+    pkg_cv_ddjvuapi_LIBS="$ddjvuapi_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"ddjvuapi >= 3.5.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "ddjvuapi >= 3.5.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_ddjvuapi_LIBS=`$PKG_CONFIG --libs "ddjvuapi >= 3.5.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
 fi
 
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ddjvu_context_create in -ldjvulibre" >&5
-$as_echo_n "checking for ddjvu_context_create in -ldjvulibre... " >&6; }
-if ${ac_cv_lib_djvulibre_ddjvu_context_create+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-ldjvulibre  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
 
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char ddjvu_context_create ();
-int
-main ()
-{
-return ddjvu_context_create ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_djvulibre_ddjvu_context_create=yes
-else
-  ac_cv_lib_djvulibre_ddjvu_context_create=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_djvulibre_ddjvu_context_create" >&5
-$as_echo "$ac_cv_lib_djvulibre_ddjvu_context_create" >&6; }
-if test "x$ac_cv_lib_djvulibre_ddjvu_context_create" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if DJVU package is complete" >&5
-$as_echo_n "checking if DJVU package is complete... " >&6; }
-    if test $passed -gt 0; then
-        if test $failed -gt 0; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: result: no -- some components failed test" >&5
-$as_echo "no -- some components failed test" >&6; }
-            have_djvu='no (failed tests)'
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        ddjvuapi_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "ddjvuapi >= 3.5.0" 2>&1`
         else
-            DJVU_LIBS='-ldjvulibre'
-            LIBS="$DJVU_LIBS $LIBS"
+	        ddjvuapi_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "ddjvuapi >= 3.5.0" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$ddjvuapi_PKG_ERRORS" >&5
+
+	have_djvu=no
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	have_djvu=no
+else
+	ddjvuapi_CFLAGS=$pkg_cv_ddjvuapi_CFLAGS
+	ddjvuapi_LIBS=$pkg_cv_ddjvuapi_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	have_djvu=yes
+fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+$as_echo "" >&6; }
+fi
+
+if test "$have_djvu" = 'yes'; then
 
 $as_echo "#define DJVU_DELEGATE 1" >>confdefs.h
 
-            { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-            have_djvu='yes'
-        fi
-    else
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-    fi
+  CFLAGS="$DDJVUAPI_CFLAGS $CFLAGS"
 fi
+
  if test "$have_djvu" = 'yes'; then
   DJVU_DELEGATE_TRUE=
   DJVU_DELEGATE_FALSE='#'
@@ -29524,6 +29361,7 @@
 
 
 
+
 #
 # Check for fontconfig delegate library.
 #
@@ -29545,7 +29383,7 @@
 FONTCONFIG_LIBS=""
 FONTCONFIG_PKG=""
 if test "x$with_fontconfig" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -29618,7 +29456,7 @@
 $as_echo "yes" >&6; }
 	have_fontconfig=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
@@ -29626,9 +29464,7 @@
 
 $as_echo "#define FONTCONFIG_DELEGATE 1" >>confdefs.h
 
-  if test "$build_modules" = 'no'; then
-    CPPFLAGS="$FONTCONFIG_CFLAGS $CPPFLAGS"
-  fi
+  CFLAGS="$FONTCONFIG_CFLAGS $CFLAGS"
 fi
 
  if test "$have_fontconfig" = 'yes'; then
@@ -29664,7 +29500,7 @@
 FREETYPE_LIBS=""
 FREETYPE_PKG=""
 if test "x$with_freetype" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -29737,7 +29573,7 @@
 $as_echo "yes" >&6; }
 	have_freetype=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
@@ -29745,7 +29581,7 @@
 
 $as_echo "#define FREETYPE_DELEGATE 1" >>confdefs.h
 
-    CFLAGS="$FREETYPE_CFLAGS $CFLAGS"
+  CFLAGS="$FREETYPE_CFLAGS $CFLAGS"
 fi
 
  if test "$have_freetype" = 'yes'; then
@@ -29985,7 +29821,7 @@
 
 GVC_PKG=""
 if test "x$with_gvc" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -30058,7 +29894,7 @@
 $as_echo "yes" >&6; }
 	have_gvc=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
@@ -30066,9 +29902,7 @@
 
 $as_echo "#define GVC_DELEGATE 1" >>confdefs.h
 
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$GVC_CFLAGS $CPPFLAGS"
-    fi
+  CFLAGS="$GVC_CFLAGS $CFLAGS"
 fi
 
  if test "$have_gvc" = 'yes'; then
@@ -30364,7 +30198,6 @@
 #
 # Check for LCMS delegate library.
 #
-# Disable LCMS.
 
 # Check whether --with-lcms was given.
 if test "${with_lcms+set}" = set; then :
@@ -30377,248 +30210,96 @@
     DISTCHECK_CONFIG_FLAGS="${DISTCHECK_CONFIG_FLAGS} --with-lcms=$with_lcms "
 fi
 
-# Disable LCMS2.
-
-# Check whether --with-lcms2 was given.
-if test "${with_lcms2+set}" = set; then :
-  withval=$with_lcms2; with_lcms2=$withval
-else
-  with_lcms2='yes'
-fi
-
-if test "$with_lcms2" != 'yes' ; then
-    DISTCHECK_CONFIG_FLAGS="${DISTCHECK_CONFIG_FLAGS} --with-lcms2=$with_lcms2 "
-fi
-
-have_lcms2='no'
-LCMS_LIBS=''
-if test "$with_lcms2" != 'no'; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
-$as_echo "-------------------------------------------------------------" >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LCMS v2" >&5
-$as_echo_n "checking for LCMS v2... " >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
-$as_echo "" >&6; }
-    failed=0
-    passed=0
-    have_lcms_header='no'
-
-    # Check for <lcms2.h>
-    ac_fn_c_check_header_mongrel "$LINENO" "lcms2.h" "ac_cv_header_lcms2_h" "$ac_includes_default"
-if test "x$ac_cv_header_lcms2_h" = xyes; then :
-  have_lcms_header='yes'
-fi
-
-
-    if test "$have_lcms_header" = 'yes'; then
-
-$as_echo "#define HAVE_LCMS2_H 1" >>confdefs.h
-
-       passed=`expr $passed + 1`
-    fi
-
-    # Check for <lcms2/lcms2.h)
-    if test "$have_lcms_header" != 'yes'; then
-      ac_fn_c_check_header_mongrel "$LINENO" "lcms2/lcms2.h" "ac_cv_header_lcms2_lcms2_h" "$ac_includes_default"
-if test "x$ac_cv_header_lcms2_lcms2_h" = xyes; then :
-  have_lcms_header='yes'
-fi
-
-
-      if test "$have_lcms_header" = 'yes'; then
-        passed=`expr $passed + 1`
-
-$as_echo "#define HAVE_LCMS2_LCMS2_H 1" >>confdefs.h
-
-      fi
-    fi
-
-    # Failed to find lcms header?
-    if test "$have_lcms_header" != 'yes'; then
-      failed=`expr $failed + 1`
-    fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cmsSetLogErrorHandler in -llcms2" >&5
-$as_echo_n "checking for cmsSetLogErrorHandler in -llcms2... " >&6; }
-if ${ac_cv_lib_lcms2_cmsSetLogErrorHandler+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-llcms2  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char cmsSetLogErrorHandler ();
-int
-main ()
-{
-return cmsSetLogErrorHandler ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_lcms2_cmsSetLogErrorHandler=yes
-else
-  ac_cv_lib_lcms2_cmsSetLogErrorHandler=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lcms2_cmsSetLogErrorHandler" >&5
-$as_echo "$ac_cv_lib_lcms2_cmsSetLogErrorHandler" >&6; }
-if test "x$ac_cv_lib_lcms2_cmsSetLogErrorHandler" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if LCMS v2 package is complete" >&5
-$as_echo_n "checking if LCMS v2 package is complete... " >&6; }
-    if test $passed -gt 0; then
-      if test $failed -gt 0; then
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no -- some components failed test" >&5
-$as_echo "no -- some components failed test" >&6; }
-        have_lcms2='no (failed tests)'
-      else
-        LCMS_LIBS='-llcms2'
-        LIBS="$LCMS_LIBS $LIBS"
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-        have_lcms2='yes'
-      fi
-    else
-      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-    fi
-fi
-
-#
-# Check for LCMS v1 (1.11 or later)
-#
-if test $have_lcms2 = 'yes'; then
-  with_lcms='no'
-fi
-
 have_lcms='no'
-if test "$with_lcms" != 'no'; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+LCMS_CFLAGS=""
+LCMS_LIBS=""
+LCMS_PKG=""
+if test "x$with_lcms" = "xyes"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LCMS v1.1X" >&5
-$as_echo_n "checking for LCMS v1.1X... " >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
-$as_echo "" >&6; }
-    failed=0
-    passed=0
-    have_lcms_header='no'
 
-    # Check for <lcms.h>
-    if test "$have_lcms_header" != 'yes'; then
-      ac_fn_c_check_header_mongrel "$LINENO" "lcms.h" "ac_cv_header_lcms_h" "$ac_includes_default"
-if test "x$ac_cv_header_lcms_h" = xyes; then :
-  have_lcms_header='yes'
-fi
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LCMS" >&5
+$as_echo_n "checking for LCMS... " >&6; }
 
-
-      if test "$have_lcms_header" = 'yes'; then
-        passed=`expr $passed + 1`
-
-$as_echo "#define HAVE_LCMS_H 1" >>confdefs.h
-
-      fi
-    fi
-
-    # Check for <lcms/lcms.h>
-    if test "$have_lcms_header" != 'yes'; then
-      ac_fn_c_check_header_mongrel "$LINENO" "lcms/lcms.h" "ac_cv_header_lcms_lcms_h" "$ac_includes_default"
-if test "x$ac_cv_header_lcms_lcms_h" = xyes; then :
-  have_lcms_header='yes'
-fi
-
-
-      if test "$have_lcms_header" = 'yes'; then
-        passed=`expr $passed + 1`
-
-$as_echo "#define HAVE_LCMS_LCMS_H 1" >>confdefs.h
-
-      fi
-    fi
-
-    # Failed to find lcms header?
-    if test "$have_lcms_header" != 'yes'; then
-      failed=`expr $failed + 1`
-    fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cmsSetErrorHandler in -llcms" >&5
-$as_echo_n "checking for cmsSetErrorHandler in -llcms... " >&6; }
-if ${ac_cv_lib_lcms_cmsSetErrorHandler+:} false; then :
-  $as_echo_n "(cached) " >&6
+if test -n "$LCMS_CFLAGS"; then
+    pkg_cv_LCMS_CFLAGS="$LCMS_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lcms >= 1.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "lcms >= 1.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LCMS_CFLAGS=`$PKG_CONFIG --cflags "lcms >= 1.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
 else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-llcms  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char cmsSetErrorHandler ();
-int
-main ()
-{
-return cmsSetErrorHandler ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_lcms_cmsSetErrorHandler=yes
-else
-  ac_cv_lib_lcms_cmsSetErrorHandler=no
+  pkg_failed=yes
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
+ else
+    pkg_failed=untried
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lcms_cmsSetErrorHandler" >&5
-$as_echo "$ac_cv_lib_lcms_cmsSetErrorHandler" >&6; }
-if test "x$ac_cv_lib_lcms_cmsSetErrorHandler" = xyes; then :
-  passed=`expr $passed + 1`
+if test -n "$LCMS_LIBS"; then
+    pkg_cv_LCMS_LIBS="$LCMS_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lcms >= 1.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "lcms >= 1.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LCMS_LIBS=`$PKG_CONFIG --libs "lcms >= 1.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
 else
-  failed=`expr $failed + 1`
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
 fi
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if LCMS package is complete" >&5
-$as_echo_n "checking if LCMS package is complete... " >&6; }
-    if test $passed -gt 0; then
-      if test $failed -gt 0; then
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no -- some components failed test" >&5
-$as_echo "no -- some components failed test" >&6; }
-        have_lcms='no (failed tests)'
-      else
-        LCMS_LIBS='-llcms'
-        LIBS="$LCMS_LIBS $LIBS"
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        LCMS_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lcms >= 1.0.0" 2>&1`
+        else
+	        LCMS_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lcms >= 1.0.0" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$LCMS_PKG_ERRORS" >&5
+
+	have_lcms=no
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	have_lcms=no
+else
+	LCMS_CFLAGS=$pkg_cv_LCMS_CFLAGS
+	LCMS_LIBS=$pkg_cv_LCMS_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
-        have_lcms='yes'
-      fi
-    else
-      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-    fi
+	have_lcms=yes
+fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+$as_echo "" >&6; }
 fi
 
- if test "$have_lcms2" = 'yes' -o "$have_lcms" = 'yes'; then
+if test "$have_lcms" = 'yes'; then
+
+$as_echo "#define LCMS_DELEGATE 1" >>confdefs.h
+
+  CFLAGS="$LCMS_CFLAGS $CFLAGS"
+fi
+
+ if test "$have_lcms" = 'yes'; then
   LCMS_DELEGATE_TRUE=
   LCMS_DELEGATE_FALSE='#'
 else
@@ -30626,11 +30307,6 @@
   LCMS_DELEGATE_FALSE=
 fi
 
-if test "$have_lcms2" = 'yes' -o "$have_lcms" = 'yes'; then
-
-$as_echo "#define LCMS_DELEGATE 1" >>confdefs.h
-
-fi
 
 
 
@@ -30656,7 +30332,7 @@
 LIBOPENJP2_LIBS=""
 LIBOPENJP2_PKG=""
 if test "x$with_openjp2" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -30729,7 +30405,7 @@
 $as_echo "yes" >&6; }
 	have_openjp2=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
@@ -30737,9 +30413,7 @@
 
 $as_echo "#define LIBOPENJP2_DELEGATE 1" >>confdefs.h
 
-    if test "$build_modules" = 'no'; then
-        CFLAGS="$LIBOPENJP2_CFLAGS $CFLAGS"
-    fi
+  CFLAGS="$LIBOPENJP2_CFLAGS $CFLAGS"
 fi
 
  if test "$have_openjp2" = 'yes'; then
@@ -30776,7 +30450,7 @@
 LQR_LIBS=""
 LQR_PKG=""
 if test "x$with_lqr" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -30849,7 +30523,7 @@
 $as_echo "yes" >&6; }
 	have_lqr=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
@@ -30857,7 +30531,7 @@
 
 $as_echo "#define LQR_DELEGATE 1" >>confdefs.h
 
-    CFLAGS="$LQR_CFLAGS $CFLAGS"
+  CFLAGS="$LQR_CFLAGS $CFLAGS"
 fi
 
  if test "$have_lqr" = 'yes'; then
@@ -30887,7 +30561,7 @@
 
 LZMA_PKG=""
 if test "x$with_lzma" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -30960,7 +30634,7 @@
 $as_echo "yes" >&6; }
 	have_lzma=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
@@ -30968,9 +30642,7 @@
 
 $as_echo "#define LZMA_DELEGATE 1" >>confdefs.h
 
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$LZMA_CFLAGS $CPPFLAGS"
-    fi
+  CFLAGS="$LZMA_CFLAGS $CFLAGS"
 fi
 
  if test "$have_lzma" = 'yes'; then
@@ -31006,7 +30678,7 @@
 OPENEXR_LIBS=""
 OPENEXR_PKG=""
 if test "x$with_openexr" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -31079,7 +30751,7 @@
 $as_echo "yes" >&6; }
 	have_openexr=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
@@ -31087,9 +30759,7 @@
 
 $as_echo "#define OPENEXR_DELEGATE 1" >>confdefs.h
 
-    if test "$build_modules" = 'no'; then
-        CFLAGS="$OPENEXR_CFLAGS $CFLAGS"
-    fi
+  CFLAGS="$OPENEXR_CFLAGS $CFLAGS"
 fi
 
  if test "$have_openexr" = 'yes'; then
@@ -31126,7 +30796,7 @@
 PANGO_LIBS=""
 PANGO_PKG=""
 if test "x$with_pango" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -31199,7 +30869,7 @@
 $as_echo "yes" >&6; }
 	have_pangocairo=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 
 pkg_failed=no
@@ -31272,7 +30942,7 @@
 $as_echo "yes" >&6; }
 	have_pango=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
@@ -31280,18 +30950,14 @@
 
 $as_echo "#define PANGO_DELEGATE 1" >>confdefs.h
 
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$PANGO_CFLAGS $CPPFLAGS"
-    fi
+  CFLAGS="$PANGO_CFLAGS $CFLAGS"
 fi
 
 if test "$have_pangocairo" = 'yes'; then
 
 $as_echo "#define PANGOCAIRO_DELEGATE 1" >>confdefs.h
 
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$PANGOCAIRO_CFLAGS $CPPFLAGS"
-    fi
+  CFLAGS="$PANGOCAIRO_CFLAGS $CFLAGS"
 fi
 
  if test "$have_pango" = 'yes'; then
@@ -31331,541 +30997,92 @@
 fi
 
 have_png='no'
-PNG_LIBS=''
-
-if test "$with_png" != 'no' -a  "$have_zlib" != 'no' ; then
+PNG_CFLAGS=""
+PNG_LIBS=""
+PNG_PKG=""
+if test "x$with_png" = "xyes"; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for PNG support " >&5
-$as_echo_n "checking for PNG support ... " >&6; }
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for PNG" >&5
+$as_echo_n "checking for PNG... " >&6; }
+
+if test -n "$PNG_CFLAGS"; then
+    pkg_cv_PNG_CFLAGS="$PNG_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpng >= 1.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libpng >= 1.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_PNG_CFLAGS=`$PKG_CONFIG --cflags "libpng >= 1.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$PNG_LIBS"; then
+    pkg_cv_PNG_LIBS="$PNG_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpng >= 1.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libpng >= 1.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_PNG_LIBS=`$PKG_CONFIG --libs "libpng >= 1.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        PNG_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libpng >= 1.0.0" 2>&1`
+        else
+	        PNG_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libpng >= 1.0.0" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$PNG_PKG_ERRORS" >&5
+
+	have_png=no
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	have_png=no
+else
+	PNG_CFLAGS=$pkg_cv_PNG_CFLAGS
+	PNG_LIBS=$pkg_cv_PNG_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	have_png=yes
+fi
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
-  failed=0
-  passed=0
-  ac_fn_c_check_header_mongrel "$LINENO" "png.h" "ac_cv_header_png_h" "$ac_includes_default"
-if test "x$ac_cv_header_png_h" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
 fi
 
-
-
-  if test $passed -gt 0; then
-    for var in 7 6 5 4 2 '' ; do
-      if test "$have_png" = 'no' ; then
-        if test "x${var}" = 'x' ; then
-          pnglib='png'
-        else
-          pnglib="png1${var}"
-        fi
-
-#       Test for compatible LIBPNG library
-        failed=0
-        passed=0
-        if test "$with_png" = 'yes' -o "$with_png" = "libpng1${var}" ; then
-          if test "${pnglib}" != 'png' ; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBPNG1${var} support " >&5
-$as_echo_n "checking for LIBPNG1${var} support ... " >&6; }
-            cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <stdio.h>
-#include <stdlib.h>
-#include <png.h>
-
-int
-main ()
-{
-
-#if PNG_LIBPNG_VER_MINOR != ${var}
-#error LIBPNG library must be version 1${var}!
-Kaboom, Kaboom
-#endif
-return 0;
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-              ac_cv_libpng_ok='yes'
-else
-  ac_cv_libpng_ok='no'
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-            if test "$ac_cv_libpng_ok" = 'yes' ; then
-              passed=`expr $passed + 1`
-              { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-            else
-              failed=`expr $failed + 1`
-              { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-            fi
-          else
-            passed=`expr $passed + 1`
-            { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-          fi
-        fi
-
-        if test $passed -gt 0 -a $failed -le 0; then
-          if test "1${var}" = '17' ; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_get_io_ptr in -lpng17" >&5
-$as_echo_n "checking for png_get_io_ptr in -lpng17... " >&6; }
-if ${ac_cv_lib_png17_png_get_io_ptr+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng17  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_get_io_ptr ();
-int
-main ()
-{
-return png_get_io_ptr ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png17_png_get_io_ptr=yes
-else
-  ac_cv_lib_png17_png_get_io_ptr=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png17_png_get_io_ptr" >&5
-$as_echo "$ac_cv_lib_png17_png_get_io_ptr" >&6; }
-if test "x$ac_cv_lib_png17_png_get_io_ptr" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_longjmp in -lpng17" >&5
-$as_echo_n "checking for png_longjmp in -lpng17... " >&6; }
-if ${ac_cv_lib_png17_png_longjmp+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng17  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_longjmp ();
-int
-main ()
-{
-return png_longjmp ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png17_png_longjmp=yes
-else
-  ac_cv_lib_png17_png_longjmp=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png17_png_longjmp" >&5
-$as_echo "$ac_cv_lib_png17_png_longjmp" >&6; }
-if test "x$ac_cv_lib_png17_png_longjmp" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-          fi
-          if test "1${var}" = '16' ; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_get_io_ptr in -lpng16" >&5
-$as_echo_n "checking for png_get_io_ptr in -lpng16... " >&6; }
-if ${ac_cv_lib_png16_png_get_io_ptr+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng16  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_get_io_ptr ();
-int
-main ()
-{
-return png_get_io_ptr ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png16_png_get_io_ptr=yes
-else
-  ac_cv_lib_png16_png_get_io_ptr=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png16_png_get_io_ptr" >&5
-$as_echo "$ac_cv_lib_png16_png_get_io_ptr" >&6; }
-if test "x$ac_cv_lib_png16_png_get_io_ptr" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_longjmp in -lpng16" >&5
-$as_echo_n "checking for png_longjmp in -lpng16... " >&6; }
-if ${ac_cv_lib_png16_png_longjmp+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng16  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_longjmp ();
-int
-main ()
-{
-return png_longjmp ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png16_png_longjmp=yes
-else
-  ac_cv_lib_png16_png_longjmp=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png16_png_longjmp" >&5
-$as_echo "$ac_cv_lib_png16_png_longjmp" >&6; }
-if test "x$ac_cv_lib_png16_png_longjmp" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-          fi
-          if test "1${var}" = '15' ; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_get_io_ptr in -lpng15" >&5
-$as_echo_n "checking for png_get_io_ptr in -lpng15... " >&6; }
-if ${ac_cv_lib_png15_png_get_io_ptr+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng15  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_get_io_ptr ();
-int
-main ()
-{
-return png_get_io_ptr ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png15_png_get_io_ptr=yes
-else
-  ac_cv_lib_png15_png_get_io_ptr=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png15_png_get_io_ptr" >&5
-$as_echo "$ac_cv_lib_png15_png_get_io_ptr" >&6; }
-if test "x$ac_cv_lib_png15_png_get_io_ptr" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_longjmp in -lpng15" >&5
-$as_echo_n "checking for png_longjmp in -lpng15... " >&6; }
-if ${ac_cv_lib_png15_png_longjmp+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng15  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_longjmp ();
-int
-main ()
-{
-return png_longjmp ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png15_png_longjmp=yes
-else
-  ac_cv_lib_png15_png_longjmp=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png15_png_longjmp" >&5
-$as_echo "$ac_cv_lib_png15_png_longjmp" >&6; }
-if test "x$ac_cv_lib_png15_png_longjmp" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-          fi
-          if test "1${var}" = '14' ; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_get_io_ptr in -lpng14" >&5
-$as_echo_n "checking for png_get_io_ptr in -lpng14... " >&6; }
-if ${ac_cv_lib_png14_png_get_io_ptr+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng14  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_get_io_ptr ();
-int
-main ()
-{
-return png_get_io_ptr ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png14_png_get_io_ptr=yes
-else
-  ac_cv_lib_png14_png_get_io_ptr=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png14_png_get_io_ptr" >&5
-$as_echo "$ac_cv_lib_png14_png_get_io_ptr" >&6; }
-if test "x$ac_cv_lib_png14_png_get_io_ptr" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_get_io_state in -lpng14" >&5
-$as_echo_n "checking for png_get_io_state in -lpng14... " >&6; }
-if ${ac_cv_lib_png14_png_get_io_state+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng14  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_get_io_state ();
-int
-main ()
-{
-return png_get_io_state ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png14_png_get_io_state=yes
-else
-  ac_cv_lib_png14_png_get_io_state=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png14_png_get_io_state" >&5
-$as_echo "$ac_cv_lib_png14_png_get_io_state" >&6; }
-if test "x$ac_cv_lib_png14_png_get_io_state" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-          fi
-          if test "1${var}" = '12' ; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_get_io_ptr in -lpng12" >&5
-$as_echo_n "checking for png_get_io_ptr in -lpng12... " >&6; }
-if ${ac_cv_lib_png12_png_get_io_ptr+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng12  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_get_io_ptr ();
-int
-main ()
-{
-return png_get_io_ptr ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png12_png_get_io_ptr=yes
-else
-  ac_cv_lib_png12_png_get_io_ptr=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png12_png_get_io_ptr" >&5
-$as_echo "$ac_cv_lib_png12_png_get_io_ptr" >&6; }
-if test "x$ac_cv_lib_png12_png_get_io_ptr" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-          fi
-          if test "1${var}" = '1' ; then
-              { $as_echo "$as_me:${as_lineno-$LINENO}: checking for png_get_io_ptr in -lpng" >&5
-$as_echo_n "checking for png_get_io_ptr in -lpng... " >&6; }
-if ${ac_cv_lib_png_png_get_io_ptr+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpng  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char png_get_io_ptr ();
-int
-main ()
-{
-return png_get_io_ptr ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_png_png_get_io_ptr=yes
-else
-  ac_cv_lib_png_png_get_io_ptr=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_png_png_get_io_ptr" >&5
-$as_echo "$ac_cv_lib_png_png_get_io_ptr" >&6; }
-if test "x$ac_cv_lib_png_png_get_io_ptr" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-          fi
-          if test $passed -gt 0 -a $failed -le 0 ; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ${pnglib} package is complete" >&5
-$as_echo_n "checking if ${pnglib} package is complete... " >&6; }
-            if test $passed -gt 0 ; then
-              if test $failed -gt 0 ; then
-                  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no -- some components failed test" >&5
-$as_echo "no -- some components failed test" >&6; }
-                  have_png='no (failed tests)'
-              else
-                  PNG_LIBS="-l${pnglib}"
-                  LIBS="$PNG_LIBS $LIBS"
+if test "$have_png" = 'yes'; then
 
 $as_echo "#define PNG_DELEGATE 1" >>confdefs.h
 
-                  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-                  have_png='yes'
-              fi
-            fi
-          fi
-        fi
-      fi
-    done
-  fi
+  CFLAGS="$PNG_CFLAGS $CFLAGS"
 fi
 
  if test "$have_png" = 'yes'; then
@@ -31902,7 +31119,7 @@
 RSVG_LIBS=""
 RSVG_PKG=""
 if test "x$with_rsvg" = "xyes"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
 
 pkg_failed=no
@@ -31975,7 +31192,7 @@
 $as_echo "yes" >&6; }
 	have_rsvg=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 
 pkg_failed=no
@@ -32048,7 +31265,7 @@
 $as_echo "yes" >&6; }
 	have_cairo=yes
 fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 fi
 
@@ -32056,18 +31273,14 @@
 
 $as_echo "#define RSVG_DELEGATE 1" >>confdefs.h
 
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$RSVG_CFLAGS $CPPFLAGS"
-    fi
+  CFLAGS="$RSVG_CFLAGS $CFLAGS"
 fi
 
 if test "$have_cairo" = 'yes'; then
 
 $as_echo "#define CAIRO_DELEGATE 1" >>confdefs.h
 
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$CAIRO_SVG_CFLAGS $CPPFLAGS"
-    fi
+  CFLAGS="$CAIRO_SVG_CFLAGS $CFLAGS"
 fi
 
  if test "$have_rsvg" = 'yes'; then
@@ -32538,7 +31751,7 @@
 if test "${with_wmf+set}" = set; then :
   withval=$with_wmf; with_wmf=$withval
 else
-  with_wmf='no'
+  with_wmf='yes'
 fi
 
 
@@ -32547,149 +31760,94 @@
 fi
 
 have_wmf='no'
-WMF_LIBS=''
-WMF_LIBS_DEPS=''
-OLIBS="$LIBS"
-if test "$with_wmf" != 'no'; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+WMF_CFLAGS=""
+WMF_LIBS=""
+WMF_PKG=""
+if test "x$with_wmf" = "xyes"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for WMF" >&5
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for WMF" >&5
 $as_echo_n "checking for WMF... " >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
-$as_echo "" >&6; }
-    have_libwmf='no'
-    have_libwmflite='no'
-    have_libwmf_ipa_h='no'
 
-    ac_fn_c_check_header_compile "$LINENO" "libwmf/ipa.h" "ac_cv_header_libwmf_ipa_h" "$FT2BUILD_H
-"
-if test "x$ac_cv_header_libwmf_ipa_h" = xyes; then :
-  have_libwmf_ipa_h='yes'
-fi
-
-
-    if test "$have_libwmf_ipa_h" = 'yes'; then
-        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wmf_lite_create in -lwmflite" >&5
-$as_echo_n "checking for wmf_lite_create in -lwmflite... " >&6; }
-if ${ac_cv_lib_wmflite_wmf_lite_create+:} false; then :
-  $as_echo_n "(cached) " >&6
+if test -n "$WMF_CFLAGS"; then
+    pkg_cv_WMF_CFLAGS="$WMF_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"wmf >= 0.2.8\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "wmf >= 0.2.8") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_WMF_CFLAGS=`$PKG_CONFIG --cflags "wmf >= 0.2.8" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
 else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lwmflite  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char wmf_lite_create ();
-int
-main ()
-{
-return wmf_lite_create ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_wmflite_wmf_lite_create=yes
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$WMF_LIBS"; then
+    pkg_cv_WMF_LIBS="$WMF_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"wmf >= 0.2.8\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "wmf >= 0.2.8") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_WMF_LIBS=`$PKG_CONFIG --libs "wmf >= 0.2.8" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
 else
-  ac_cv_lib_wmflite_wmf_lite_create=no
+  pkg_failed=yes
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_wmflite_wmf_lite_create" >&5
-$as_echo "$ac_cv_lib_wmflite_wmf_lite_create" >&6; }
-if test "x$ac_cv_lib_wmflite_wmf_lite_create" = xyes; then :
-  have_libwmflite='yes'
+ else
+    pkg_failed=untried
 fi
 
-        if test "$have_libwmflite" = 'yes'; then
 
-$as_echo "#define WMFLITE_DELEGATE 1" >>confdefs.h
 
-            WMF_LIBS='-lwmflite'
-            LIBS="$WMF_LIBS $LIBS"
-            have_wmf='yes'
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        WMF_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "wmf >= 0.2.8" 2>&1`
         else
-            WMF_LIBS_DEPS=''
-            WMF_CONFIG_LIBS=`libwmf-config --libs`
-            for lib in xml2 expat freetype jpeg png z; do
-                testlib="-l${lib}"
-                echo "$WMF_CONFIG_LIBS" | grep -- "$testlib" > /dev/null && WMF_LIBS_DEPS="$WMF_LIBS_DEPS $testlib"
-            done
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wmf_api_create in -lwmf" >&5
-$as_echo_n "checking for wmf_api_create in -lwmf... " >&6; }
-if ${ac_cv_lib_wmf_wmf_api_create+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lwmf $WMF_LIBS_DEPS $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
+	        WMF_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "wmf >= 0.2.8" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$WMF_PKG_ERRORS" >&5
 
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char wmf_api_create ();
-int
-main ()
-{
-return wmf_api_create ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_wmf_wmf_api_create=yes
+	have_wmf=no
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	have_wmf=no
 else
-  ac_cv_lib_wmf_wmf_api_create=no
+	WMF_CFLAGS=$pkg_cv_WMF_CFLAGS
+	WMF_LIBS=$pkg_cv_WMF_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	have_wmf=yes
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_wmf_wmf_api_create" >&5
-$as_echo "$ac_cv_lib_wmf_wmf_api_create" >&6; }
-if test "x$ac_cv_lib_wmf_wmf_api_create" = xyes; then :
-  have_libwmf='yes'
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+$as_echo "" >&6; }
 fi
 
-            if test "$have_libwmf" = 'yes'; then
+if test "$have_wmf" = 'yes'; then
 
 $as_echo "#define WMF_DELEGATE 1" >>confdefs.h
 
-                WMF_LIBS='-lwmf'
-                LIBS="$WMF_LIBS $LIBS"
-                have_wmf='yes'
-            else
-                { $as_echo "$as_me:${as_lineno-$LINENO}: result: no -- some components failed test" >&5
-$as_echo "no -- some components failed test" >&6; }
-                have_wmf='no (failed tests)'
-                have_wmflite='no (failed tests)'
-                LIBS="$OLIBS"
-                WMF_LIBS=''
-            fi
-        fi
-    fi
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if WMF package is complete" >&5
-$as_echo_n "checking if WMF package is complete... " >&6; }
-    if test "$have_wmf" = 'yes'; then
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-    else
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-    fi
+  CFLAGS="$WMF_CFLAGS $CFLAGS"
 fi
+
  if test "$have_wmf" = 'yes'; then
   WMF_DELEGATE_TRUE=
   WMF_DELEGATE_FALSE='#'
@@ -32702,7 +31860,6 @@
 
 
 
-
 #
 # Check for XML delegate library.
 #
@@ -32720,228 +31877,94 @@
 fi
 
 have_xml='no'
-XML_LIBS=''
-if test "$with_xml" != 'no'; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
+XML_CFLAGS=""
+XML_LIBS=""
+XML_PKG=""
+if test "x$with_xml" = "xyes"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5
 $as_echo "-------------------------------------------------------------" >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XML" >&5
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XML" >&5
 $as_echo_n "checking for XML... " >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
-$as_echo "" >&6; }
-    PERSIST_LDFLAGS=$LDFLAGS
-    PERSIST_CPPFLAGS=$CPPFLAGS
-    xml2_config=''
-    # Extract the first word of "xml2-config", so it can be a program name with args.
-set dummy xml2-config; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_xml2_config+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  case $xml2_config in
-  [\\/]* | ?:[\\/]*)
-  ac_cv_path_xml2_config="$xml2_config" # Let the user override the test with a path.
-  ;;
-  *)
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_path_xml2_config="$as_dir/$ac_word$ac_exec_ext"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
 
-  ;;
-esac
-fi
-xml2_config=$ac_cv_path_xml2_config
-if test -n "$xml2_config"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $xml2_config" >&5
-$as_echo "$xml2_config" >&6; }
+if test -n "$XML_CFLAGS"; then
+    pkg_cv_XML_CFLAGS="$XML_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libxml-2.0 >= 2.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libxml-2.0 >= 2.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_XML_CFLAGS=`$PKG_CONFIG --cflags "libxml-2.0 >= 2.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$XML_LIBS"; then
+    pkg_cv_XML_LIBS="$XML_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libxml-2.0 >= 2.0.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libxml-2.0 >= 2.0.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_XML_LIBS=`$PKG_CONFIG --libs "libxml-2.0 >= 2.0.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-fi
 
-    if test -n "$xml2_config"; then
-        # Debian installs libxml headers under /usr/include/libxml2/libxml with
-        # the shared library installed under /usr/lib, whereas the package
-        # installs itself under $prefix/libxml and $prefix/lib.
-        xml2_prefix=`${xml2_config} --prefix`
-        if test -d "${xml2_prefix}/include/libxml2"; then
-            CPPFLAGS="$CPPFLAGS -I${xml2_prefix}/include/libxml2"
-        fi
-        if test "${xml2_prefix}" != '/usr'; then
-            LDFLAGS="$LDFLAGS -L${xml2_prefix}/lib"
-        fi
-    fi
-    failed=0
-    passed=0
-    ac_fn_c_check_header_mongrel "$LINENO" "libxml/parser.h" "ac_cv_header_libxml_parser_h" "$ac_includes_default"
-if test "x$ac_cv_header_libxml_parser_h" = xyes; then :
-  passed=`expr $passed + 1`
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
 else
-  failed=`expr $failed + 1`
+        _pkg_short_errors_supported=no
 fi
-
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for xmlSAXVersion in -lxml2" >&5
-$as_echo_n "checking for xmlSAXVersion in -lxml2... " >&6; }
-if ${ac_cv_lib_xml2_xmlSAXVersion+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lxml2  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char xmlSAXVersion ();
-int
-main ()
-{
-return xmlSAXVersion ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_xml2_xmlSAXVersion=yes
-else
-  ac_cv_lib_xml2_xmlSAXVersion=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_xml2_xmlSAXVersion" >&5
-$as_echo "$ac_cv_lib_xml2_xmlSAXVersion" >&6; }
-if test "x$ac_cv_lib_xml2_xmlSAXVersion" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for xmlParseChunk in -lxml2" >&5
-$as_echo_n "checking for xmlParseChunk in -lxml2... " >&6; }
-if ${ac_cv_lib_xml2_xmlParseChunk+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lxml2  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char xmlParseChunk ();
-int
-main ()
-{
-return xmlParseChunk ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_xml2_xmlParseChunk=yes
-else
-  ac_cv_lib_xml2_xmlParseChunk=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_xml2_xmlParseChunk" >&5
-$as_echo "$ac_cv_lib_xml2_xmlParseChunk" >&6; }
-if test "x$ac_cv_lib_xml2_xmlParseChunk" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for xmlCreatePushParserCtxt in -lxml2" >&5
-$as_echo_n "checking for xmlCreatePushParserCtxt in -lxml2... " >&6; }
-if ${ac_cv_lib_xml2_xmlCreatePushParserCtxt+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lxml2  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char xmlCreatePushParserCtxt ();
-int
-main ()
-{
-return xmlCreatePushParserCtxt ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_xml2_xmlCreatePushParserCtxt=yes
-else
-  ac_cv_lib_xml2_xmlCreatePushParserCtxt=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_xml2_xmlCreatePushParserCtxt" >&5
-$as_echo "$ac_cv_lib_xml2_xmlCreatePushParserCtxt" >&6; }
-if test "x$ac_cv_lib_xml2_xmlCreatePushParserCtxt" = xyes; then :
-  passed=`expr $passed + 1`
-else
-  failed=`expr $failed + 1`
-fi
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if XML package is complete" >&5
-$as_echo_n "checking if XML package is complete... " >&6; }
-    if test $passed -gt 0; then
-        if test $failed -gt 0; then
-            { $as_echo "$as_me:${as_lineno-$LINENO}: result: no -- some components failed test" >&5
-$as_echo "no -- some components failed test" >&6; }
-            have_xml='no (failed tests)'
-            LDFLAGS="$PERSIST_LDFLAGS"
-            CPPFLAGS="$PERSIST_CPPFLAGS"
+        if test $_pkg_short_errors_supported = yes; then
+	        XML_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libxml-2.0 >= 2.0.0" 2>&1`
         else
-            XML_LIBS='-lxml2'
-            LIBS="$XML_LIBS $LIBS"
+	        XML_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libxml-2.0 >= 2.0.0" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$XML_PKG_ERRORS" >&5
+
+	have_xml=no
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	have_xml=no
+else
+	XML_CFLAGS=$pkg_cv_XML_CFLAGS
+	XML_LIBS=$pkg_cv_XML_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	have_xml=yes
+fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
+$as_echo "" >&6; }
+fi
+
+if test "$have_xml" = 'yes'; then
 
 $as_echo "#define XML_DELEGATE 1" >>confdefs.h
 
-            { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-            have_xml='yes'
-        fi
-    else
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-    fi
+  CFLAGS="$XML_CFLAGS $CFLAGS"
 fi
+
  if test "$have_xml" = 'yes'; then
   XML_DELEGATE_TRUE=
   XML_DELEGATE_FALSE='#'
@@ -32953,6 +31976,7 @@
 
 
 
+
 # Substitute compiler name to build/link PerlMagick
 #
 
@@ -36536,16 +35560,16 @@
 #
 
 if test "$build_modules" != 'no'; then
-    MAGICK_DEP_LIBS="$USER_LIBS $LCMS_LIBS $FREETYPE_LIBS $LQR_LIBS $FFTW_LIBS $FONTCONFIG_LIBS $XEXT_LIBS $IPC_LIBS $X11_LIBS $XT_LIBS $LZMA_LIBS $BZLIB_LIBS $ZLIB_LIBS $LTDL_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $JEMALLOC_LIBS $THREAD_LIBS"
+    MAGICK_DEP_LIBS="$USER_LIBS $LCMS_LIBS $FREETYPE_LIBS $LQR_LIBS $fftw3_LIBS $FONTCONFIG_LIBS $XEXT_LIBS $IPC_LIBS $X11_LIBS $XT_LIBS $LZMA_LIBS $BZLIB_LIBS $ZLIB_LIBS $LTDL_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $JEMALLOC_LIBS $THREAD_LIBS"
 else
-    MAGICK_DEP_LIBS="$USER_LIBS $JBIG_LIBS $LCMS_LIBS $TIFF_LIBS $FREETYPE_LIBS $JPEG_LIBS $GS_LIBS $LQR_LIBS $PNG_LIBS $AUTOTRACE_LIBS $DJVU_LIBS $FFTW_LIBS $FPX_LIBS $FONTCONFIG_LIBS $WEBP_LIBS $WMF_LIBS $DPS_LIBS $XEXT_LIBS $XT_LIBS $IPC_LIBS $X11_LIBS $LZMA_LIBS $BZLIB_LIBS $OPENEXR_LIBS $LIBOPENJP2_LIBS $PANGO_LIBS $RSVG_LIBS $XML_LIBS $GVC_LIBS $ZLIB_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $JEMALLOC_LIBS $THREAD_LIBS"
+    MAGICK_DEP_LIBS="$USER_LIBS $JBIG_LIBS $LCMS_LIBS $TIFF_LIBS $FREETYPE_LIBS $JPEG_LIBS $GS_LIBS $LQR_LIBS $PNG_LIBS $AUTOTRACE_LIBS $DDJVUAP_LIBS $fftw3_LIBS $FPX_LIBS $FONTCONFIG_LIBS $WEBP_LIBS $WMF_LIBS $DPS_LIBS $XEXT_LIBS $XT_LIBS $IPC_LIBS $X11_LIBS $LZMA_LIBS $BZLIB_LIBS $OPENEXR_LIBS $LIBOPENJP2_LIBS $PANGO_LIBS $RSVG_LIBS $XML_LIBS $GVC_LIBS $ZLIB_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $JEMALLOC_LIBS $THREAD_LIBS"
 fi
 
 
 #
 # Sanitize output variables (asthetic).
 #
-for variable in CC CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MAGICK_DEP_LIBS TESTED_LIBS X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS; do
+for variable in CFLAGS CPPFLAGS CXXFLAGS LDFLAGS PCFLAGS X_CFLAGS; do
   sanitize=''
   eval value=$`echo $variable`
   for component in $value
diff --git a/configure.ac b/configure.ac
index c6ef5cc..1d262f1 100755
--- a/configure.ac
+++ b/configure.ac
@@ -1635,42 +1635,26 @@
 fi
 
 have_zlib='no'
-ZLIB_LIBS=''
-dnl PNG requires zlib so enable zlib check if PNG is requested
-if test "$with_zlib" != 'no' || test "$with_png" != 'no'; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    AC_MSG_CHECKING([for ZLIB])
-    AC_MSG_RESULT([])
-    ZLIB_LIBS=''
-    failed=0
-    passed=0
-    AC_CHECK_HEADER(zconf.h,passed=`expr $passed + 1`,failed=`expr $failed + 1`)
-    AC_CHECK_HEADER(zlib.h,passed=`expr $passed + 1`,failed=`expr $failed + 1`)
-    AC_CHECK_LIB(z,compress,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_CHECK_LIB(z,uncompress,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_CHECK_LIB(z,deflate,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_CHECK_LIB(z,inflate,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_CHECK_LIB(z,gzseek,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_CHECK_LIB(z,gztell,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_MSG_CHECKING([if ZLIB package is complete])
-    if test $passed -gt 0; then
-        if test $failed -gt 0; then
-            AC_MSG_RESULT([no -- some components failed test])
-            have_zlib='no (failed tests)'
-        else
-            ZLIB_LIBS='-lz'
-            LIBS="$ZLIB_LIBS $LIBS"
-            AC_DEFINE(ZLIB_DELEGATE,1,Define if you have zlib compression library)
-            AC_MSG_RESULT([yes])
-            have_zlib='yes'
-        fi
-    else
-        AC_MSG_RESULT([no])
-    fi
+ZLIB_CFLAGS=""
+ZLIB_LIBS=""
+ZLIB_PKG=""
+if test "x$with_zlib" = "xyes"; then
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(ZLIB,[zlib >= 1.0.0], have_zlib=yes, have_zlib=no)
+  AC_MSG_RESULT([])
 fi
+
+if test "$have_zlib" = 'yes'; then
+  AC_DEFINE(ZLIB_DELEGATE,1,Define if you have ZLIB library)
+  CFLAGS="$ZLIB_CFLAGS $CFLAGS"
+fi
+
 AM_CONDITIONAL(ZLIB_DELEGATE, test "$have_zlib" = 'yes')
+AC_SUBST(ZLIB_CFLAGS)
 AC_SUBST(ZLIB_LIBS)
 
+dnl ===========================================================================
+
 # whether modules are built or not.
 with_ltdl='yes'
 have_ltdl='no'
@@ -1749,17 +1733,14 @@
 AUTOTRACE_LIBS=""
 AUTOTRACE_PKG=""
 if test "x$with_autotrace" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(AUTOTRACE,[autotrace >= 0.31.1], have_autotrace=yes, have_autotrace=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(AUTOTRACE,[autotrace >= 0.31.1], have_autotrace=yes, have_autotrace=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_autotrace" = 'yes'; then
-    failed=0
-    AC_DEFINE(AUTOTRACE_DELEGATE,1,Define if you have AUTOTRACE library)
-    if test "$build_modules" = 'no'; then
-      CPPFLAGS="$AUTOTRACE_CFLAGS $CPPFLAGS"
-    fi
+  AC_DEFINE(AUTOTRACE_DELEGATE,1,Define if you have AUTOTRACE library)
+  CFLAGS="$AUTOTRACE_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(AUTOTRACE_DELEGATE,test "$have_autotrace" = 'yes')
@@ -1866,32 +1847,22 @@
 fi
 
 have_fftw='no'
-FFTW_LIBS=''
-if test "$with_fftw" != 'no'; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    AC_MSG_CHECKING([for FFTW])
-    AC_MSG_RESULT([])
-    failed=0
-    passed=0
-    AC_CHECK_HEADER(fftw3.h,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_CHECK_LIB(fftw3,fftw_execute,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_MSG_CHECKING([if FFTW package is complete])
-    if test $passed -gt 0; then
-        if test $failed -gt 0; then
-            AC_MSG_RESULT([no -- some components failed test])
-            have_fftw='no (failed tests)'
-        else
-            FFTW_LIBS='-lfftw3'
-            LIBS="$FFTW_LIBS $LIBS"
-            AC_DEFINE(FFTW_DELEGATE,1,Define if you have FFTW library)
-            AC_MSG_RESULT([yes])
-            have_fftw='yes'
-        fi
-    else
-        AC_MSG_RESULT([no])
-    fi
+FFTW_CFLAGS=""
+FFTW_LIBS=""
+FFTW_PKG=""
+if test "x$with_fftw" = "xyes"; then
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(fftw3,[fftw3 >= 3.0.0], have_fftw=yes, have_fftw=no)
+  AC_MSG_RESULT([])
 fi
+
+if test "$have_fftw" = 'yes'; then
+  AC_DEFINE(FFTW_DELEGATE,1,Define if you have FFTW library)
+  CFLAGS="$fftw3_CFLAGS $CFLAGS"
+fi
+
 AM_CONDITIONAL(FFTW_DELEGATE, test "$have_fftw" = 'yes')
+AC_SUBST(FFTW_CFLAGS)
 AC_SUBST(FFTW_LIBS)
 
 dnl ===========================================================================
@@ -1956,32 +1927,22 @@
 fi
 
 have_djvu='no'
-DJVU_LIBS=''
-if test "$with_djvu" != 'no'; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    AC_MSG_CHECKING([for DJVU])
-    AC_MSG_RESULT([])
-    failed=0
-    passed=0
-    AC_CHECK_HEADER(libdjvu/ddjvuapi.h,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_CHECK_LIB(djvulibre,ddjvu_context_create,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_MSG_CHECKING([if DJVU package is complete])
-    if test $passed -gt 0; then
-        if test $failed -gt 0; then
-            AC_MSG_RESULT([no -- some components failed test])
-            have_djvu='no (failed tests)'
-        else
-            DJVU_LIBS='-ldjvulibre'
-            LIBS="$DJVU_LIBS $LIBS"
-            AC_DEFINE(DJVU_DELEGATE,1,Define if you have DJVU library)
-            AC_MSG_RESULT([yes])
-            have_djvu='yes'
-        fi
-    else
-        AC_MSG_RESULT([no])
-    fi
+DJVU_CFLAGS=""
+DJVU_LIBS=""
+DJVU_PKG=""
+if test "x$with_djvu" = "xyes"; then
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(ddjvuapi,[ddjvuapi >= 3.5.0], have_djvu=yes, have_djvu=no)
+  AC_MSG_RESULT([])
 fi
+
+if test "$have_djvu" = 'yes'; then
+  AC_DEFINE(DJVU_DELEGATE,1,Define if you have DJVU library)
+  CFLAGS="$DDJVUAPI_CFLAGS $CFLAGS"
+fi
+
 AM_CONDITIONAL(DJVU_DELEGATE, test "$have_djvu" = 'yes')
+AC_SUBST(DJVU_CFLAGS)
 AC_SUBST(DJVU_LIBS)
 
 dnl ===========================================================================
@@ -2004,16 +1965,14 @@
 FONTCONFIG_LIBS=""
 FONTCONFIG_PKG=""
 if test "x$with_fontconfig" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(FONTCONFIG,[fontconfig >= 2.1.0], have_fontconfig=yes, have_fontconfig=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(FONTCONFIG,[fontconfig >= 2.1.0], have_fontconfig=yes, have_fontconfig=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_fontconfig" = 'yes'; then
   AC_DEFINE(FONTCONFIG_DELEGATE,1,Define if you have FONTCONFIG library)
-  if test "$build_modules" = 'no'; then
-    CPPFLAGS="$FONTCONFIG_CFLAGS $CPPFLAGS"
-  fi
+  CFLAGS="$FONTCONFIG_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(FONTCONFIG_DELEGATE,test "$have_fontconfig" = 'yes')
@@ -2040,14 +1999,14 @@
 FREETYPE_LIBS=""
 FREETYPE_PKG=""
 if test "x$with_freetype" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(FREETYPE,[freetype2], have_freetype=yes, have_freetype=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(FREETYPE,[freetype2], have_freetype=yes, have_freetype=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_freetype" = 'yes'; then
-    AC_DEFINE(FREETYPE_DELEGATE,1,Define if you have FREETYPE library)
-    CFLAGS="$FREETYPE_CFLAGS $CFLAGS"
+  AC_DEFINE(FREETYPE_DELEGATE,1,Define if you have FREETYPE library)
+  CFLAGS="$FREETYPE_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(FREETYPE_DELEGATE, test "$have_freetype" = 'yes')
@@ -2157,16 +2116,14 @@
 
 GVC_PKG=""
 if test "x$with_gvc" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(GVC,[libgvc >= 2.9.0], have_gvc=yes, have_gvc=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(GVC,[libgvc >= 2.9.0], have_gvc=yes, have_gvc=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_gvc" = 'yes'; then
-    AC_DEFINE(GVC_DELEGATE,1,Define if you have GVC library)
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$GVC_CFLAGS $CPPFLAGS"
-    fi
+  AC_DEFINE(GVC_DELEGATE,1,Define if you have GVC library)
+  CFLAGS="$GVC_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(GVC_DELEGATE, test "$have_gvc" = 'yes')
@@ -2286,7 +2243,6 @@
 #
 # Check for LCMS delegate library.
 #
-# Disable LCMS.
 AC_ARG_WITH(lcms,
         [  --without-lcms          disable lcms (v1.1X) support],
         [with_lcms=$withval],
@@ -2295,126 +2251,25 @@
     DISTCHECK_CONFIG_FLAGS="${DISTCHECK_CONFIG_FLAGS} --with-lcms=$with_lcms "
 fi
 
-# Disable LCMS2.
-AC_ARG_WITH(lcms2,
-        [  --without-lcms2         disable lcms (v2.X) support],
-        [with_lcms2=$withval],
-        [with_lcms2='yes'])
-if test "$with_lcms2" != 'yes' ; then
-    DISTCHECK_CONFIG_FLAGS="${DISTCHECK_CONFIG_FLAGS} --with-lcms2=$with_lcms2 "
-fi
-
-have_lcms2='no'
-LCMS_LIBS=''
-if test "$with_lcms2" != 'no'; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    AC_MSG_CHECKING([for LCMS v2])
-    AC_MSG_RESULT()
-    failed=0
-    passed=0
-    have_lcms_header='no'
-
-    # Check for <lcms2.h>
-    AC_CHECK_HEADER(lcms2.h,have_lcms_header='yes',,)
-    if test "$have_lcms_header" = 'yes'; then
-       AC_DEFINE(HAVE_LCMS2_H,1,Define if you have the <lcms2.h> header file.)
-       passed=`expr $passed + 1`
-    fi
-
-    # Check for <lcms2/lcms2.h)
-    if test "$have_lcms_header" != 'yes'; then
-      AC_CHECK_HEADER(lcms2/lcms2.h,have_lcms_header='yes',,)
-      if test "$have_lcms_header" = 'yes'; then
-        passed=`expr $passed + 1`
-        AC_DEFINE(HAVE_LCMS2_LCMS2_H,1,Define if you have the <lcms2/lcms2.h> header file.)
-      fi
-    fi
-
-    # Failed to find lcms header?
-    if test "$have_lcms_header" != 'yes'; then
-      failed=`expr $failed + 1`
-    fi
-
-    AC_CHECK_LIB(lcms2,cmsSetLogErrorHandler,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_MSG_CHECKING(if LCMS v2 package is complete)
-    if test $passed -gt 0; then
-      if test $failed -gt 0; then
-        AC_MSG_RESULT(no -- some components failed test)
-        have_lcms2='no (failed tests)'
-      else
-        LCMS_LIBS='-llcms2'
-        LIBS="$LCMS_LIBS $LIBS"
-        AC_MSG_RESULT(yes)
-        have_lcms2='yes'
-      fi
-    else
-      AC_MSG_RESULT(no)
-    fi
-fi
-
-#
-# Check for LCMS v1 (1.11 or later)
-#
-if test $have_lcms2 = 'yes'; then
-  with_lcms='no'
-fi
-
 have_lcms='no'
-if test "$with_lcms" != 'no'; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    AC_MSG_CHECKING([for LCMS v1.1X])
-    AC_MSG_RESULT()
-    failed=0
-    passed=0
-    have_lcms_header='no'
-
-    # Check for <lcms.h>
-    if test "$have_lcms_header" != 'yes'; then
-      AC_CHECK_HEADER(lcms.h,have_lcms_header='yes',,)
-      if test "$have_lcms_header" = 'yes'; then
-        passed=`expr $passed + 1`
-        AC_DEFINE(HAVE_LCMS_H,1,Define if you have the <lcms.h> header file.)
-      fi
-    fi
-
-    # Check for <lcms/lcms.h>
-    if test "$have_lcms_header" != 'yes'; then
-      AC_CHECK_HEADER(lcms/lcms.h,have_lcms_header='yes',,)
-      if test "$have_lcms_header" = 'yes'; then
-        passed=`expr $passed + 1`
-        AC_DEFINE(HAVE_LCMS_LCMS_H,1,Define if you have the <lcms/lcms.h> header file.)
-      fi
-    fi
-
-    # Failed to find lcms header?
-    if test "$have_lcms_header" != 'yes'; then
-      failed=`expr $failed + 1`
-    fi
-
-    AC_CHECK_LIB(lcms,cmsSetErrorHandler,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_MSG_CHECKING(if LCMS package is complete)
-    if test $passed -gt 0; then
-      if test $failed -gt 0; then
-        AC_MSG_RESULT(no -- some components failed test)
-        have_lcms='no (failed tests)'
-      else
-        LCMS_LIBS='-llcms'
-        LIBS="$LCMS_LIBS $LIBS"
-        AC_MSG_RESULT(yes)
-        have_lcms='yes'
-      fi
-    else
-      AC_MSG_RESULT(no)
-    fi
+LCMS_CFLAGS=""
+LCMS_LIBS=""
+LCMS_PKG=""
+if test "x$with_lcms" = "xyes"; then
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(LCMS,[lcms >= 1.0.0], have_lcms=yes, have_lcms=no)
+  AC_MSG_RESULT([])
 fi
 
-AM_CONDITIONAL(LCMS_DELEGATE, test "$have_lcms2" = 'yes' -o "$have_lcms" = 'yes')
-if test "$have_lcms2" = 'yes' -o "$have_lcms" = 'yes'; then
-  AC_DEFINE(LCMS_DELEGATE,1,[Define if you have LCMS (v1.11 or later) library])
+if test "$have_lcms" = 'yes'; then
+  AC_DEFINE(LCMS_DELEGATE,1,Define if you have LCMS library)
+  CFLAGS="$LCMS_CFLAGS $CFLAGS"
 fi
+
+AM_CONDITIONAL(LCMS_DELEGATE, test "$have_lcms" = 'yes')
+AC_SUBST(LCMS_CFLAGS)
 AC_SUBST(LCMS_LIBS)
 
-
 dnl ===========================================================================
 
 #
@@ -2435,16 +2290,14 @@
 LIBOPENJP2_LIBS=""
 LIBOPENJP2_PKG=""
 if test "x$with_openjp2" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(LIBOPENJP2,[libopenjp2 >= 2.1.0], have_openjp2=yes, have_openjp2=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(LIBOPENJP2,[libopenjp2 >= 2.1.0], have_openjp2=yes, have_openjp2=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_openjp2" = 'yes'; then
-    AC_DEFINE(LIBOPENJP2_DELEGATE,1,Define if you have OPENJP2 library)
-    if test "$build_modules" = 'no'; then
-        CFLAGS="$LIBOPENJP2_CFLAGS $CFLAGS"
-    fi
+  AC_DEFINE(LIBOPENJP2_DELEGATE,1,Define if you have OPENJP2 library)
+  CFLAGS="$LIBOPENJP2_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(LIBOPENJP2_DELEGATE, test "$have_openjp2" = 'yes')
@@ -2472,14 +2325,14 @@
 LQR_LIBS=""
 LQR_PKG=""
 if test "x$with_lqr" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(LQR,[lqr-1 >= 0.1.0], have_lqr=yes, have_lqr=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(LQR,[lqr-1 >= 0.1.0], have_lqr=yes, have_lqr=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_lqr" = 'yes'; then
-    AC_DEFINE(LQR_DELEGATE,1,Define if you have LQR library)
-    CFLAGS="$LQR_CFLAGS $CFLAGS"
+  AC_DEFINE(LQR_DELEGATE,1,Define if you have LQR library)
+  CFLAGS="$LQR_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(LQR_DELEGATE, test "$have_lqr" = 'yes')
@@ -2499,16 +2352,14 @@
 
 LZMA_PKG=""
 if test "x$with_lzma" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(LZMA,[liblzma >= 2.9.0], have_lzma=yes, have_lzma=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(LZMA,[liblzma >= 2.9.0], have_lzma=yes, have_lzma=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_lzma" = 'yes'; then
-    AC_DEFINE(LZMA_DELEGATE,1,Define if you have LZMA library)
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$LZMA_CFLAGS $CPPFLAGS"
-    fi
+  AC_DEFINE(LZMA_DELEGATE,1,Define if you have LZMA library)
+  CFLAGS="$LZMA_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(LZMA_DELEGATE, test "$have_lzma" = 'yes')
@@ -2535,16 +2386,14 @@
 OPENEXR_LIBS=""
 OPENEXR_PKG=""
 if test "x$with_openexr" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(OPENEXR,[OpenEXR >= 1.0.6], have_openexr=yes, have_openexr=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(OPENEXR,[OpenEXR >= 1.0.6], have_openexr=yes, have_openexr=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_openexr" = 'yes'; then
-    AC_DEFINE(OPENEXR_DELEGATE,1,Define if you have OPENEXR library)
-    if test "$build_modules" = 'no'; then
-        CFLAGS="$OPENEXR_CFLAGS $CFLAGS"
-    fi
+  AC_DEFINE(OPENEXR_DELEGATE,1,Define if you have OPENEXR library)
+  CFLAGS="$OPENEXR_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(OPENEXR_DELEGATE, test "$have_openexr" = 'yes')
@@ -2572,25 +2421,21 @@
 PANGO_LIBS=""
 PANGO_PKG=""
 if test "x$with_pango" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(PANGO, [pangocairo >= 1.28.1], have_pangocairo=yes, have_pangocairo=no)
-    AC_MSG_RESULT([])
-    PKG_CHECK_MODULES(PANGO, [pango >= 1.28.1], have_pango=yes, have_pango=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(PANGO, [pangocairo >= 1.28.1], have_pangocairo=yes, have_pangocairo=no)
+  AC_MSG_RESULT([])
+  PKG_CHECK_MODULES(PANGO, [pango >= 1.28.1], have_pango=yes, have_pango=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_pango" = 'yes'; then
-    AC_DEFINE(PANGO_DELEGATE,1,Define if you have PANGO library)
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$PANGO_CFLAGS $CPPFLAGS"
-    fi
+  AC_DEFINE(PANGO_DELEGATE,1,Define if you have PANGO library)
+  CFLAGS="$PANGO_CFLAGS $CFLAGS"
 fi
 
 if test "$have_pangocairo" = 'yes'; then
-    AC_DEFINE(PANGOCAIRO_DELEGATE,1,Define if you have PANGOCAIRO library)
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$PANGOCAIRO_CFLAGS $CPPFLAGS"
-    fi
+  AC_DEFINE(PANGOCAIRO_DELEGATE,1,Define if you have PANGOCAIRO library)
+  CFLAGS="$PANGOCAIRO_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(PANGO_DELEGATE, test "$have_pango" = 'yes')
@@ -2614,118 +2459,23 @@
 fi
 
 have_png='no'
-PNG_LIBS=''
-
-if test "$with_png" != 'no' -a  "$have_zlib" != 'no' ; then
+PNG_CFLAGS=""
+PNG_LIBS=""
+PNG_PKG=""
+if test "x$with_png" = "xyes"; then
   AC_MSG_RESULT([-------------------------------------------------------------])
-  AC_MSG_CHECKING(for PNG support )
-  AC_MSG_RESULT()
-  failed=0
-  passed=0
-  AC_CHECK_HEADER(png.h,passed=`expr $passed + 1`,
-     failed=`expr $failed + 1`,)
-
-  if test $passed -gt 0; then
-    for var in 7 6 5 4 2 '' ; do
-      if test "$have_png" = 'no' ; then
-        if test "x${var}" = 'x' ; then
-          pnglib='png'
-        else
-          pnglib="png1${var}"
-        fi
-
-#       Test for compatible LIBPNG library
-        failed=0
-        passed=0
-        if test "$with_png" = 'yes' -o "$with_png" = "libpng1${var}" ; then
-          if test "${pnglib}" != 'png' ; then
-            AC_MSG_CHECKING(for LIBPNG1${var} support )
-            AC_TRY_COMPILE(
-#include <stdio.h>
-#include <stdlib.h>
-#include <png.h>
-,
-changequote(<<, >>)dnl
-<<
-#if PNG_LIBPNG_VER_MINOR != ${var}
-#error LIBPNG library must be version 1${var}!
-Kaboom, Kaboom
-#endif
-return 0;
->>,
-            changequote([, ])dnl
-            ac_cv_libpng_ok='yes',
-            ac_cv_libpng_ok='no')
-            if test "$ac_cv_libpng_ok" = 'yes' ; then
-              passed=`expr $passed + 1`
-              AC_MSG_RESULT(yes)
-            else
-              failed=`expr $failed + 1`
-              AC_MSG_RESULT(no)
-            fi
-          else
-            passed=`expr $passed + 1`
-            AC_MSG_RESULT(yes)
-          fi
-        fi
-
-        if test $passed -gt 0 -a $failed -le 0; then
-          if test "1${var}" = '17' ; then
-            AC_CHECK_LIB(png17,png_get_io_ptr,passed=`expr $passed + 1`,
-               failed=`expr $failed + 1`,)
-            AC_CHECK_LIB(png17,png_longjmp,passed=`expr $passed + 1`,
-               failed=`expr $failed + 1`,)
-          fi
-          if test "1${var}" = '16' ; then
-            AC_CHECK_LIB(png16,png_get_io_ptr,passed=`expr $passed + 1`,
-               failed=`expr $failed + 1`,)
-            AC_CHECK_LIB(png16,png_longjmp,passed=`expr $passed + 1`,
-               failed=`expr $failed + 1`,)
-          fi
-          if test "1${var}" = '15' ; then
-            AC_CHECK_LIB(png15,png_get_io_ptr,passed=`expr $passed + 1`,
-               failed=`expr $failed + 1`,)
-            AC_CHECK_LIB(png15,png_longjmp,passed=`expr $passed + 1`,
-               failed=`expr $failed + 1`,)
-          fi
-          if test "1${var}" = '14' ; then
-            AC_CHECK_LIB(png14,png_get_io_ptr,passed=`expr $passed + 1`,
-               failed=`expr $failed + 1`,)
-            AC_CHECK_LIB(png14,png_get_io_state,passed=`expr $passed + 1`,
-               failed=`expr $failed + 1`,)
-          fi
-          if test "1${var}" = '12' ; then
-            AC_CHECK_LIB(png12,png_get_io_ptr,passed=`expr $passed + 1`,
-               failed=`expr $failed + 1`,)
-          fi
-          if test "1${var}" = '1' ; then
-              AC_CHECK_LIB(png,png_get_io_ptr,passed=`expr $passed + 1`,
-                 failed=`expr $failed + 1`,)
-          fi
-          if test $passed -gt 0 -a $failed -le 0 ; then
-            AC_MSG_CHECKING(if ${pnglib} 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
-                  PNG_LIBS="-l${pnglib}"
-                  LIBS="$PNG_LIBS $LIBS"
-                  AC_DEFINE(PNG_DELEGATE,1,Define if you have PNG library)
-                  AC_MSG_RESULT(yes)
-                  have_png='yes'
-              fi
-            fi
-          fi
-        fi
-      fi
-    done
-  fi
+  PKG_CHECK_MODULES(PNG,[libpng >= 1.0.0], have_png=yes, have_png=no)
+  AC_MSG_RESULT([])
 fi
 
-AM_CONDITIONAL(PNG_DELEGATE,test "$have_png" = 'yes')
-AC_SUBST(PNG_LIBS)
+if test "$have_png" = 'yes'; then
+  AC_DEFINE(PNG_DELEGATE,1,Define if you have PNG library)
+  CFLAGS="$PNG_CFLAGS $CFLAGS"
+fi
 
+AM_CONDITIONAL(PNG_DELEGATE, test "$have_png" = 'yes')
+AC_SUBST(PNG_CFLAGS)
+AC_SUBST(PNG_LIBS)
 
 dnl ===========================================================================
 
@@ -2748,25 +2498,21 @@
 RSVG_LIBS=""
 RSVG_PKG=""
 if test "x$with_rsvg" = "xyes"; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    PKG_CHECK_MODULES(RSVG,[librsvg-2.0 >= 2.9.0], have_rsvg=yes, have_rsvg=no)
-    AC_MSG_RESULT([])
-    PKG_CHECK_MODULES(CAIRO_SVG, cairo-svg, have_cairo=yes, have_cairo=no)
-    AC_MSG_RESULT([])
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(RSVG,[librsvg-2.0 >= 2.9.0], have_rsvg=yes, have_rsvg=no)
+  AC_MSG_RESULT([])
+  PKG_CHECK_MODULES(CAIRO_SVG, cairo-svg, have_cairo=yes, have_cairo=no)
+  AC_MSG_RESULT([])
 fi
 
 if test "$have_rsvg" = 'yes'; then
-    AC_DEFINE(RSVG_DELEGATE,1,Define if you have RSVG library)
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$RSVG_CFLAGS $CPPFLAGS"
-    fi
+  AC_DEFINE(RSVG_DELEGATE,1,Define if you have RSVG library)
+  CFLAGS="$RSVG_CFLAGS $CFLAGS"
 fi
 
 if test "$have_cairo" = 'yes'; then
-    AC_DEFINE(CAIRO_DELEGATE,1,Define if you have CAIRO library)
-    if test "$build_modules" = 'no'; then
-        CPPFLAGS="$CAIRO_SVG_CFLAGS $CPPFLAGS"
-    fi
+  AC_DEFINE(CAIRO_DELEGATE,1,Define if you have CAIRO library)
+  CFLAGS="$CAIRO_SVG_CFLAGS $CFLAGS"
 fi
 
 AM_CONDITIONAL(RSVG_DELEGATE, test "$have_rsvg" = 'yes')
@@ -2896,65 +2642,30 @@
     [AC_HELP_STRING([--with-wmf],
                     [enable WMF support])],
     [with_wmf=$withval],
-    [with_wmf='no'])
+    [with_wmf='yes'])
 
 if test "$with_wmf" != 'yes'; then
     DISTCHECK_CONFIG_FLAGS="${DISTCHECK_CONFIG_FLAGS} --with-wmf=$with_wmf "
 fi
 
 have_wmf='no'
-WMF_LIBS=''
-WMF_LIBS_DEPS=''
-OLIBS="$LIBS"
-if test "$with_wmf" != 'no'; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    AC_MSG_CHECKING([for WMF])
-    AC_MSG_RESULT([])
-    have_libwmf='no'
-    have_libwmflite='no'
-    have_libwmf_ipa_h='no'
-
-    AC_CHECK_HEADER([libwmf/ipa.h],[have_libwmf_ipa_h='yes'],,[$FT2BUILD_H])
-    if test "$have_libwmf_ipa_h" = 'yes'; then
-        AC_CHECK_LIB(wmflite,wmf_lite_create,have_libwmflite='yes',,)
-        if test "$have_libwmflite" = 'yes'; then
-            AC_DEFINE(WMFLITE_DELEGATE,1,Define if you have wmflite library)
-            WMF_LIBS='-lwmflite'
-            LIBS="$WMF_LIBS $LIBS"
-            have_wmf='yes'
-        else
-            WMF_LIBS_DEPS=''
-            WMF_CONFIG_LIBS=`libwmf-config --libs`
-            for lib in xml2 expat freetype jpeg png z; do
-                testlib="-l${lib}"
-                echo "$WMF_CONFIG_LIBS" | grep -- "$testlib" > /dev/null && WMF_LIBS_DEPS="$WMF_LIBS_DEPS $testlib"
-            done
-            AC_CHECK_LIB(wmf,wmf_api_create,have_libwmf='yes',,$WMF_LIBS_DEPS)
-            if test "$have_libwmf" = 'yes'; then
-                AC_DEFINE(WMF_DELEGATE,1,Define if you have wmf library)
-                WMF_LIBS='-lwmf'
-                LIBS="$WMF_LIBS $LIBS"
-                have_wmf='yes'
-            else
-                AC_MSG_RESULT([no -- some components failed test])
-                have_wmf='no (failed tests)'
-                have_wmflite='no (failed tests)'
-                LIBS="$OLIBS"
-                WMF_LIBS=''
-            fi
-        fi
-    fi
-    AC_MSG_CHECKING([if WMF package is complete])
-    if test "$have_wmf" = 'yes'; then
-        AC_MSG_RESULT([yes])
-    else
-        AC_MSG_RESULT([no])
-    fi
+WMF_CFLAGS=""
+WMF_LIBS=""
+WMF_PKG=""
+if test "x$with_wmf" = "xyes"; then
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(WMF,[wmf >= 0.2.8], have_wmf=yes, have_wmf=no)
+  AC_MSG_RESULT([])
 fi
-AM_CONDITIONAL(WMF_DELEGATE, test "$have_wmf" = 'yes')
-AC_SUBST(WMF_LIBS)
-AC_SUBST(WMF_LIBS_DEPS)
 
+if test "$have_wmf" = 'yes'; then
+  AC_DEFINE(WMF_DELEGATE,1,Define if you have WMF library)
+  CFLAGS="$WMF_CFLAGS $CFLAGS"
+fi
+
+AM_CONDITIONAL(WMF_DELEGATE, test "$have_wmf" = 'yes')
+AC_SUBST(WMF_CFLAGS)
+AC_SUBST(WMF_LIBS)
 
 dnl ===========================================================================
 
@@ -2972,52 +2683,22 @@
 fi
 
 have_xml='no'
-XML_LIBS=''
-if test "$with_xml" != 'no'; then
-    AC_MSG_RESULT([-------------------------------------------------------------])
-    AC_MSG_CHECKING([for XML])
-    AC_MSG_RESULT([])
-    PERSIST_LDFLAGS=$LDFLAGS
-    PERSIST_CPPFLAGS=$CPPFLAGS
-    xml2_config=''
-    AC_PATH_PROG(xml2_config,xml2-config,)dnl
-    if test -n "$xml2_config"; then
-        # Debian installs libxml headers under /usr/include/libxml2/libxml with
-        # the shared library installed under /usr/lib, whereas the package
-        # installs itself under $prefix/libxml and $prefix/lib.
-        xml2_prefix=`${xml2_config} --prefix`
-        if test -d "${xml2_prefix}/include/libxml2"; then
-            CPPFLAGS="$CPPFLAGS -I${xml2_prefix}/include/libxml2"
-        fi
-        if test "${xml2_prefix}" != '/usr'; then
-            LDFLAGS="$LDFLAGS -L${xml2_prefix}/lib"
-        fi
-    fi
-    failed=0
-    passed=0
-    AC_CHECK_HEADER(libxml/parser.h,passed=`expr $passed + 1`,failed=`expr $failed + 1`)
-    AC_CHECK_LIB(xml2,xmlSAXVersion,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_CHECK_LIB(xml2,xmlParseChunk,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_CHECK_LIB(xml2,xmlCreatePushParserCtxt,passed=`expr $passed + 1`,failed=`expr $failed + 1`,)
-    AC_MSG_CHECKING([if XML package is complete])
-    if test $passed -gt 0; then
-        if test $failed -gt 0; then
-            AC_MSG_RESULT([no -- some components failed test])
-            have_xml='no (failed tests)'
-            LDFLAGS="$PERSIST_LDFLAGS"
-            CPPFLAGS="$PERSIST_CPPFLAGS"
-        else
-            XML_LIBS='-lxml2'
-            LIBS="$XML_LIBS $LIBS"
-            AC_DEFINE(XML_DELEGATE,1,Define if you have XML library)
-            AC_MSG_RESULT([yes])
-            have_xml='yes'
-        fi
-    else
-        AC_MSG_RESULT([no])
-    fi
+XML_CFLAGS=""
+XML_LIBS=""
+XML_PKG=""
+if test "x$with_xml" = "xyes"; then
+  AC_MSG_RESULT([-------------------------------------------------------------])
+  PKG_CHECK_MODULES(XML,[libxml-2.0 >= 2.0.0], have_xml=yes, have_xml=no)
+  AC_MSG_RESULT([])
 fi
-AM_CONDITIONAL(XML_DELEGATE,test "$have_xml" = 'yes')
+
+if test "$have_xml" = 'yes'; then
+  AC_DEFINE(XML_DELEGATE,1,Define if you have XML library)
+  CFLAGS="$XML_CFLAGS $CFLAGS"
+fi
+
+AM_CONDITIONAL(XML_DELEGATE, test "$have_xml" = 'yes')
+AC_SUBST(XML_CFLAGS)
 AC_SUBST(XML_LIBS)
 
 dnl ===========================================================================
@@ -3996,16 +3677,16 @@
 #
 
 if test "$build_modules" != 'no'; then
-    MAGICK_DEP_LIBS="$USER_LIBS $LCMS_LIBS $FREETYPE_LIBS $LQR_LIBS $FFTW_LIBS $FONTCONFIG_LIBS $XEXT_LIBS $IPC_LIBS $X11_LIBS $XT_LIBS $LZMA_LIBS $BZLIB_LIBS $ZLIB_LIBS $LTDL_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $JEMALLOC_LIBS $THREAD_LIBS"
+    MAGICK_DEP_LIBS="$USER_LIBS $LCMS_LIBS $FREETYPE_LIBS $LQR_LIBS $fftw3_LIBS $FONTCONFIG_LIBS $XEXT_LIBS $IPC_LIBS $X11_LIBS $XT_LIBS $LZMA_LIBS $BZLIB_LIBS $ZLIB_LIBS $LTDL_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $JEMALLOC_LIBS $THREAD_LIBS"
 else
-    MAGICK_DEP_LIBS="$USER_LIBS $JBIG_LIBS $LCMS_LIBS $TIFF_LIBS $FREETYPE_LIBS $JPEG_LIBS $GS_LIBS $LQR_LIBS $PNG_LIBS $AUTOTRACE_LIBS $DJVU_LIBS $FFTW_LIBS $FPX_LIBS $FONTCONFIG_LIBS $WEBP_LIBS $WMF_LIBS $DPS_LIBS $XEXT_LIBS $XT_LIBS $IPC_LIBS $X11_LIBS $LZMA_LIBS $BZLIB_LIBS $OPENEXR_LIBS $LIBOPENJP2_LIBS $PANGO_LIBS $RSVG_LIBS $XML_LIBS $GVC_LIBS $ZLIB_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $JEMALLOC_LIBS $THREAD_LIBS"
+    MAGICK_DEP_LIBS="$USER_LIBS $JBIG_LIBS $LCMS_LIBS $TIFF_LIBS $FREETYPE_LIBS $JPEG_LIBS $GS_LIBS $LQR_LIBS $PNG_LIBS $AUTOTRACE_LIBS $DDJVUAP_LIBS $fftw3_LIBS $FPX_LIBS $FONTCONFIG_LIBS $WEBP_LIBS $WMF_LIBS $DPS_LIBS $XEXT_LIBS $XT_LIBS $IPC_LIBS $X11_LIBS $LZMA_LIBS $BZLIB_LIBS $OPENEXR_LIBS $LIBOPENJP2_LIBS $PANGO_LIBS $RSVG_LIBS $XML_LIBS $GVC_LIBS $ZLIB_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $JEMALLOC_LIBS $THREAD_LIBS"
 fi
 AC_SUBST(MAGICK_DEP_LIBS)
 
 #
 # Sanitize output variables (asthetic).
 #
-for variable in CC CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MAGICK_DEP_LIBS TESTED_LIBS X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS; do
+for variable in CFLAGS CPPFLAGS CXXFLAGS LDFLAGS PCFLAGS X_CFLAGS; do
   sanitize=''
   eval value=$`echo $variable`
   for component in $value