--- Portfile.orig	2008-08-02 14:33:56.000000000 +0200
+++ Portfile	2008-08-05 23:13:44.000000000 +0200
@@ -10,34 +10,46 @@
 homepage    http://${name}.freedesktop.org/
 
 description	Poppler is a PDF rendering library based on the xpdf-3.0 code base.
-long_description \
-    ${description}
-
+long_description Poppler is a PDF rendering library based on the xpdf-3.0 code base. \
+                 It consists of frontends (GLib, Qt3, Qt4), the poppler core, \
+                 and rendering backends (Cairo, Splash). \
+                 (Poppler Wiki: http://freedesktop.org/wiki/Software/poppler)
 master_sites    ${homepage}
 checksums   \
     md5 00593d56340b4a635f4a34590c445800 \
     rmd160 26634a62d77471ed668507bd0c287bfff291f881 \
     sha1 993c7ac0e12c20674908a44542f49b43bd417574
 
-depends_lib \
-    port:cairo \
-    port:gtk2 \
-    port:poppler-data
+depends_build   port:pkgconfig
+
+depends_lib     port:freetype \
+                port:fontconfig \
+                port:expat \
+                port:libiconv \
+                port:zlib \
+                port:poppler-data 
 
 post-patch {
-    reinplace "s|-flat_namespace -undefined suppress||g" \
-        ${worksrcpath}/configure
-    reinplace "s|\$includedir|${prefix}/include|g" \
-        ${worksrcpath}/configure
     reinplace "s|tests||" \
         ${worksrcpath}/qt4/Makefile.in
+
+    # replace "\$allow_undefined_flag" with "$allow_undefined_flag":
+    reinplace {s|\\$allow_undefined_flag|\$allow_undefined_flag|g} \
+        ${worksrcpath}/configure
 }
 
 configure.args \
     --disable-poppler-qt4 \
     --enable-xpdf-headers \
     --enable-zlib \
-    --mandir=${prefix}/share/man
+    --mandir=${prefix}/share/man \
+    --disable-cairo-output \
+    --disable-splash-output \
+    --disable-gdk \
+    --disable-poppler-glib \
+    --disable-poppler-qt \
+    --disable-abiword-output
+
 
 if {[variant_isset no_x11]} {
     default_variants    +quartz
@@ -51,8 +63,44 @@
     if {![variant_isset quartz] && ![variant_isset x11]} {
         error "Either +x11 or +quartz is required"
     }
+
+    if {    [variant_isset glibCairo]
+        && ![variant_isset quartz] 
+        && ![file exists "${prefix}/include/cairo/cairo-xlib.h"]} {
+        # variant glibCairo requires quartz
+        ui_error "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+        ui_error "The active port \"cairo\" has been built without X11 support."
+        ui_error "To build Poppler, use the \"+quartz\" variant."
+        ui_error "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+        return -code error
+    }
+
+    if {    [variant_isset qt4Splash]
+        && ![variant_isset quartz]
+        && ![file exists "${prefix}/lib/libQtCore.dylib"]
+        &&  [file exists "${prefix}/Library/Frameworks/QtCore.framework/QtCore"]} {
+        # variant qt4Splash requires quartz
+        ui_error "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+        ui_error "Variant \"+qt4Splash\" requires variant \"+quartz\","
+        ui_error "because port \"qt4-mac\" is active"
+        ui_error "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+        return -code error
+    }
+
+    if {    [variant_isset qt4Splash]
+        && ![variant_isset x11]
+        &&  [file exists "${prefix}/lib/libQtCore.dylib"]
+        && ![file exists "${prefix}/Library/Frameworks/QtCore.framework/QtCore"]} {
+        # variant qt4Splash requires x11
+        ui_error "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+        ui_error "Variant \"+qt4Splash\" requires variant \"+x11\","
+        ui_error "because port \"qt4-x11\" is active"
+        ui_error "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+        return -code error
+    }
 }
 
+
 variant quartz conflicts x11 description { Support for the native Mac OS X interface } {
     configure.args-append --disable-gtk-test --without-x
 }
@@ -60,19 +108,170 @@
 variant x11 conflicts quartz description { Support for the X11 user interface } {
     depends_lib-append	\
         lib:libX11.6:XFree86 \
-	port:xrender
+        port:xrender
 }
 
-variant qt4 description { Support for the QT toolkit } {
-    configure.args-delete --disable-poppler-qt4
+variant qt3Splash requires quartz conflicts qt4Splash description {Qt3 bindings to poppler & Splash output device} {
+    depends_lib-append \
+        port:qt3-mac \
+        port:jpeg \
+        port:libpng
+
+    configure.args-delete \
+        --disable-poppler-qt \
+        --disable-splash-output
+}
+
+# variant qt4Splash requires quartz conflicts qt3Splash description {Qt4 bindings to poppler & Splash output device}
+variant qt4Splash conflicts qt3Splash description {Qt4 bindings to poppler & Splash output device} {
     if ([variant_isset quartz]) {
-        depends_lib-append  port:qt4-mac
+        depends_lib-append \
+            port:qt4-mac
     } else {
-        depends_lib-append  port:qt4-x11
+        depends_lib-append \
+            port:qt4-x11 \
+            port:glib2 \
+            port:gtk2 \
+            port:pango \
+            port:cairo
+
+        configure.args-delete \
+            --disable-poppler-glib \
+            --disable-gdk
+    }
+
+    depends_lib-append \
+        port:jpeg \
+        port:libpng
+
+    configure.args-delete \
+        --disable-poppler-qt4 \
+        --disable-splash-output
+}
+
+#variant qt4Arthur description {Qt4 bindings to poppler & Arthur output device (Qt4 Paint System)} {
+#}
+
+# There is no source code for a variant qt4Cairo (what about Qt3 ?)
+
+variant glibSplash description {GLib bindings to poppler & Splash output device} {
+    depends_lib-append \
+        port:gtk2 \
+        port:glib2 \
+        port:gettext \
+        port:libpixman \
+        port:jpeg \
+        port:libpng \
+        port:tiff
+
+    # GDK (GIMP Drawing Kit) is required by the GLib wrapper 
+    # when splash output device is enabled.
+    # GDK (part of GTK) depends on Pango, Pango depends on Cairo.
+
+    depends_lib-append \
+        port:pango \
+        port:cairo
+
+    configure.args-delete \
+        --disable-poppler-glib \
+        --disable-splash-output \
+        --disable-gdk
+}
+
+variant glibCairo description {GLib bindings to poppler & Cairo output device} {
+    depends_lib-append \
+        port:cairo \
+        port:glib2 \
+        port:gettext \
+        port:libpixman \
+        port:jpeg \
+        port:libpng
+                        
+    if {![variant_isset quartz]} {
+        depends_lib-append \
+            port:gtk2 \
+            port:pango \
+            port:tiff
     }
+
+    configure.args-delete \
+        --disable-poppler-glib \
+        --disable-cairo-output
+}
+
+if {   ![variant_isset qt3Splash] 
+    && ![variant_isset qt4Splash] 
+    && ![variant_isset glibSplash] 
+    && ![variant_isset glibCairo]} {
+
+    default_variants +glibSplash +glibCairo
 }
 
-test.run    yes
-test.dir    ${worksrcpath}/test
-test.target all
+# not testet:
+#platform darwin 6 {
+#    configure.env-append MACOSX_DEPLOYMENT_TARGET=10.2
+#}
+
+# not testet:
+#platform darwin 7 {
+#    configure.env-append MACOSX_DEPLOYMENT_TARGET=10.3
+#}
+
+platform darwin 8 {
+    configure.env-append MACOSX_DEPLOYMENT_TARGET=10.4
+}
+
+
+pre-configure {
+    ui_debug "+++++++++++++++++++++++++++++++++++"
+    ui_debug "configure options:"
+    ui_debug "${configure.args}"
+    ui_debug "+++++++++++++++++++++++++++++++++++"
+
+    ui_debug "+++++++++++++++++++++++++++++++++++"
+    ui_debug "port dependencies:"
+    ui_debug "$depends_lib"
+    ui_debug "+++++++++++++++++++++++++++++++++++"
+}
+
+
+
 
+# SOME NOTES TO "gtk test" (see variant "quartz"):
+#
+# After build of poppler the directory ${worksrcpath}/test 
+# contains five shell scripts:
+#
+# (1) gtk-cairo-test
+# (2) gtk-splash-test
+# (3) pdf_inspector
+# (4) pdf-fullrewrite
+# (5) perf-test
+#
+# These shell scripts are wrapper scripts for the identically 
+# named binaries contained in the directory "test/.libs".
+#
+# The first three scripts can only be launched on the command line 
+# in a window of the X Window system.
+#
+# Usage (change the current directory to ${worksrcpath}/test): 
+#
+#$ ./gtk-cairo-test PDF-FILES...  (opens each pdf file in a window)
+#
+#$ ./gtk-splash-test PDF-FILES... (opens each pdf file in a window)
+#
+#$ ./pdf_inspector  (no arguments, it opens a dialog window)
+#
+#$ ./pdf-fullrewrite INPUT-FILE OUTPUT-FILE
+#
+#$ ./perf-test [-preview|-slowpreview] [-loadonly] [-timings] [-text] 
+#              [-resolution NxM] [-recursive] [-page N] [-out out.txt] PDF-FILES...
+# 
+# ("perf-test" is a tool to stress-test poppler rendering and measure 
+# rendering times for very simplistic performance measuring.)
+#
+# The wrapper scripts should never be moved out of the build directory, 
+# otherwise they will not operate correctly.
+# Therefore it is not possible to install them in the directory ${prefix}/bin
+#
+# To use them, you must keep the work directory ( sudo port -k install poppler )

