--- Portfile.orig	2008-08-02 14:33:56.000000000 +0200
+++ Portfile	2008-08-03 13:37:26.000000000 +0200
@@ -10,27 +10,32 @@
 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, AbiWord). \
+                 (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 \
@@ -53,7 +58,7 @@
     }
 }
 
-variant quartz conflicts x11 description { Support for the native Mac OS X interface } {
+variant quartz conflicts x11 requires glibCairo description { Support for the native Mac OS X interface } {
     configure.args-append --disable-gtk-test --without-x
 }
 
@@ -63,7 +68,7 @@
 	port:xrender
 }
 
-variant qt4 description { Support for the QT toolkit } {
+variant qt4 conflicts qt3Splash qt4Splash glibSplash glibCairo abiword description { Support for the QT toolkit } {
     configure.args-delete --disable-poppler-qt4
     if ([variant_isset quartz]) {
         depends_lib-append  port:qt4-mac
@@ -72,7 +77,275 @@
     }
 }
 
-test.run    yes
-test.dir    ${worksrcpath}/test
-test.target all
+variant qt3Splash description {Qt3 bindings to poppler & Splash output device} {
+    depends_lib-append  port:qt3-mac \
+                        port:jpeg \
+                        port:libpng
+}
+
+variant qt4Splash description {Qt4 bindings to poppler & Splash output device} {
+    depends_lib-append  port:qt4-mac \
+                        port:jpeg \
+                        port:libpng
+}
+
+#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
+}
+
+variant glibCairo description {GLib bindings to poppler & Cairo output device} {
+    pre-fetch {
+        if {   ![variant_isset quartz] 
+            && ![file exists "${prefix}/include/cairo/cairo-xlib.h"]} {
+            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
+        }
+    }
+
+    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
+    }
+}
+
+variant abiword description {rendering backend/output device, and pdftoabw command line utility} {
+    depends_lib-append  port:libxml2
+}
+
+if {   ![variant_isset qt3Splash] 
+    && ![variant_isset qt4Splash] 
+    && ![variant_isset glibSplash] 
+    && ![variant_isset glibCairo] 
+    && ![variant_isset abiword] 
+    && ![variant_isset quartz]} {
+    default_variants +glibSplash +glibCairo +abiword
+}
+
+# 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 {
+    setConfigureOptionsForMinimalInstallationOfSelectedPopplerVariant
+}
+
+
+# The following procedure has a lengthy body, but is simple in its purpose.
+# Each poppler variant has a set of configure options which are necessary 
+# to get a minimal installation of poppler. If a combination of variants is 
+# selected, what is the united set of configure options?
+# To get this set, the needed configure options of all selected poppler 
+# variants are accumulated. The same is done for the NOT needed configure options.
+# The difference of the two accumulated sets is the set of configure options 
+# needed for a minimal installation of poppler.
+
+proc setConfigureOptionsForMinimalInstallationOfSelectedPopplerVariant {} {
+    global prefix configure.args
+
+    set listOfConfigureOptions ${configure.args}
+    set listOfConfigureOptionsToAppend {}
+    set listOfConfigureOptionsToDelete {}
+
+    proc optionToAppend {option} {
+        # accumulate all configure options to be included 
+        # of all selected poppler variants
+        upvar  listOfConfigureOptionsToAppend listOfConfigureOptionsToAppend
+        if {[lsearch -exact "$listOfConfigureOptionsToAppend" "$option"] == -1} then {
+            lappend listOfConfigureOptionsToAppend "$option"
+        }
+    }
+
+    proc optionToDelete {option} {
+        # accumulate all configure options to be excluded 
+        # of all selected poppler variants
+        upvar  listOfConfigureOptionsToDelete listOfConfigureOptionsToDelete
+        if {[lsearch -exact "$listOfConfigureOptionsToDelete" "$option"] == -1} then {
+            lappend listOfConfigureOptionsToDelete "$option"
+        }
+    }
+
+    if {[variant_isset quartz]} then {
+        optionToAppend {--disable-gtk-test}
+        optionToAppend {--without-x}
+    }
+
+    if {   [variant_isset qt3Splash]
+        || [variant_isset qt4Splash]
+        || [variant_isset glibSplash]
+        || [variant_isset glibCairo]
+        || [variant_isset abiword]} then {
+        optionToAppend {--disable-cairo-output}
+        optionToAppend {--disable-splash-output}
+        optionToAppend {--disable-gdk}
+        optionToAppend {--disable-poppler-glib}
+        optionToAppend {--disable-poppler-qt}
+        optionToAppend {--disable-poppler-qt4}
+        optionToAppend {--disable-abiword-output}
+        optionToAppend {--enable-xpdf-headers}
+        optionToAppend {--enable-zlib}
+        optionToAppend "--mandir=${prefix}/share/man"
+    }
+
+    if {[variant_isset glibSplash]} then {
+        optionToAppend {--disable-poppler-qt}
+        optionToAppend {--disable-poppler-qt4}
+        optionToDelete {--disable-poppler-glib}
+        #------------------------------------
+        optionToAppend {--disable-cairo-output}
+        optionToAppend {--disable-abiword-output}
+        optionToDelete {--disable-splash-output}
+
+        # GDK (GIMP Drawing Kit) is required by the GLib wrapper 
+        # when splash output device is enabled.
+        optionToDelete {--disable-gdk}
+    }
+
+    if {[variant_isset glibCairo]} then {
+        optionToAppend {--disable-poppler-qt}
+        optionToAppend {--disable-poppler-qt4}
+        optionToDelete {--disable-poppler-glib}
+        #--------------------------------------
+        optionToAppend {--disable-splash-output}
+        optionToAppend {--disable-gdk}
+        optionToAppend {--disable-abiword-output}
+        optionToDelete {--disable-cairo-output}
+    }
+
+    if {[variant_isset qt3Splash]} then {
+        optionToAppend {--disable-poppler-glib}
+        optionToAppend {--disable-gdk}
+        optionToAppend {--disable-poppler-qt4}
+        optionToDelete {--disable-poppler-qt}
+        #--------------------------------------
+        optionToAppend {--disable-cairo-output}
+        optionToAppend {--disable-abiword-output}
+        optionToDelete {--disable-splash-output}
+    }
+
+    if {[variant_isset qt4Splash]} then {
+        optionToAppend {--disable-poppler-glib}
+        optionToAppend {--disable-gdk}
+        optionToAppend {--disable-poppler-qt}
+        optionToDelete {--disable-poppler-qt4}
+        #----------------------------------------
+        optionToAppend {--disable-cairo-output}
+        optionToAppend {--disable-abiword-output}
+        optionToDelete {--disable-splash-output}
+    }
+
+    if {[variant_isset abiword]} then {
+        optionToAppend {--disable-splash-output}
+        optionToAppend {--disable-gdk}
+        optionToAppend {--disable-cairo-output}
+        optionToDelete {--disable-abiword-output}
+    }
+
+    ################################
+    # balance of configure options #
+    ################################
+
+    foreach option $listOfConfigureOptionsToAppend {
+        if {[lsearch -exact "$listOfConfigureOptions" "$option"] == -1} then {
+            lappend listOfConfigureOptions "$option"
+            configure.args-append "$option"
+        }
+    }
+
+    foreach option $listOfConfigureOptionsToDelete {
+        set i [lsearch -exact "$listOfConfigureOptions" "$option"]
+        if {$i > -1} then {
+            set listOfConfigureOptions [lreplace $listOfConfigureOptions $i $i]
+            configure.args-delete "$option"
+        }
+    }
+
+    ui_debug "+++++++++++++++++++++++++++++++++++"
+    ui_debug "configure options:"
+    ui_debug "${configure.args}"
+    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 )
+
+ui_debug "+++++++++++++++++++++++++++++++++++"
+ui_debug "port dependencies:"
+ui_debug "$depends_lib"
+ui_debug "+++++++++++++++++++++++++++++++++++"
