--- Portfile.orig	2008-06-26 14:58:22.000000000 +0200
+++ Portfile	2008-08-01 12:02:15.000000000 +0200
@@ -3,29 +3,50 @@
 PortSystem 1.0
 
 name        poppler
-version     0.8.3
+version     0.8.5
 maintainers nomaintainer
 categories  graphics
 platforms   darwin
 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 d5631bdbde9dda89ff20796005ece4d4 \
-				rmd160 f6553fdf468bd67ec8a7f943ba2cc7f141052302 \
-				sha1 763d18d9f0e625a936b3a3fbbcd00b58ddd2f84f
-depends_lib     port:cairo port:gtk2 port:poppler-data
+checksums       md5 00593d56340b4a635f4a34590c445800 \
+                sha1 993c7ac0e12c20674908a44542f49b43bd417574 \
+                rmd160 26634a62d77471ed668507bd0c287bfff291f881
+
+depends_build   port:pkgconfig
+
+depends_lib     port:freetype \
+                port:fontconfig \
+                port:cairo \
+                port:gtk2 \
+                port:pango \
+                port:glib2 \
+                port:gettext \
+                port:expat \
+                port:libiconv \
+                port:libpixman \
+                port:XFree86 \
+                port:xrender \
+                port:jpeg \
+                port:tiff \
+                port:libpng \
+                port:libxml2 \
+                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 \
@@ -38,7 +59,404 @@
     configure.args-append --disable-gtk-test --without-x
 }
 
-test.run		yes
-test.dir		${worksrcpath}/test
-test.target		all
+variant qt4 {
+    configure.args-delete --disable-poppler-qt4
+    depends_lib-append    port:qt4-mac
+}
+
+pre-fetch {
+#   variant "quartz" is only necessary if your active port "cairo"
+#   has been build without "X Window" support (variant "no_x11")
+#   (in addition: port "pango" and port "gtk2" build without x11)
+
+    set A [variant_isset qt3Splash]
+    set B [variant_isset qt4Splash]
+    set C [variant_isset glibSplash]
+    set D [variant_isset glibCairo]
+    set E [variant_isset abiword]
+    set F [variant_isset quartz]
+    set popplerWithoutVariants [expr !$A && !$B && !$C && !$D && !$E && !$F]
+
+    if { $popplerWithoutVariants || ($D && !$F) } then {
+        if {![cairoWithX11]} then {
+            ui_error "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+            ui_error "The active port \"cairo\" has been build without x11 support."
+            ui_error "To build Poppler, select variant \"quartz\""
+            ui_error "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+            return -code 1
+        }
+    }
+
+#   Variant "qt4" completes the maximal installation of poppler.
+#   This variant cannot be used together with any of the variants 
+#   "qt3Splash", "qt4Splash", "glibSplash", "glibCairo", and "abiword".
+#   These variants are each for a minimal installation of poppler.
+
+    if { [variant_isset qt4] && ($A || $B || $C || $D || $E) } then {
+        ui_error "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+        ui_error "variant \"qt4\" cannot be used together with any of the variants"
+        ui_error "\"qt3Splash\", \"qt4Splash\", \"glibSplash\", \"glibCairo\", and \"abiword\""
+        ui_error "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+        return -code 1
+    }
+}
+
+
+
+
+# The following variants are for minimal installation of Poppler 
+# and minimal port dependencies.
+#
+# Poppler with variants +glibSplash +glibCairo +abiword (+qt3Splash)
+# is the same as Poppler without any variant.
+# If you do not have port "qt3-mac" installed, poppler gets automatically 
+# configured without Qt3 bindings. 
+
+variant qt3Splash description {Qt3 bindings to poppler & Splash output device} {
+}
+
+variant qt4Splash description {Qt4 bindings to poppler & Splash output device} {
+}
+
+#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} {
+}
+
+variant glibCairo description {GLib bindings to poppler & Cairo output device} {
+}
+
+variant abiword description {rendering backend/output device, and pdftoabw command line utility} {
+}
+
+
+# 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
+}
+
+platform darwin 9 {
+    configure.env-append MACOSX_DEPLOYMENT_TARGET=10.5
+}
+
+
+pre-configure {
+    setConfigureOptionsForMinimalInstallationOfSelectedPopplerVariant
+    setListOfPortDependenciesOfSelectedPopplerVariant
+}
+
+
+# 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 "+++++++++++++++++++++++++++++++++++"
+}
+
+
+proc cairoWithX11 {} {
+    global prefix
+    set ret 1
+    if {[file exists "${prefix}/include/cairo/cairo.h"]} then {
+        if {![file exists "${prefix}/include/cairo/cairo-xlib.h"]} then {
+            set ret 0
+        }
+    } else {
+        ui_error "++++++++++++++++++++++++++++++++++++++++++"
+        ui_error "port \"cairo\" is not installed or activated"
+        ui_error "++++++++++++++++++++++++++++++++++++++++++" 
+        return -code 1
+    }
+
+    return $ret
+}
+
+
+# Poppler without any variant has a maximum of dependencies to other ports.
+# But variant "qt4Splash" is neither dependent on port "XFree86" nor on "gtk2".
+# To get the list of needed port dependencies, the following procedure 
+# accumulates the needed port dependencies of all selected poppler variants.
+
+proc setListOfPortDependenciesOfSelectedPopplerVariant {} {
+    global prefix depends_lib
+
+    set listOfPortDependenciesToAppend {}
+
+    proc dependencyToAppend {entry} {
+        # accumulate all port dependencies to be included
+        # of all selected poppler variants
+        upvar  listOfPortDependenciesToAppend listOfPortDependenciesToAppend
+        if {[lsearch -exact "$listOfPortDependenciesToAppend" "$entry"] == -1} then {
+            lappend listOfPortDependenciesToAppend "$entry"
+        }
+    }
+
+    if {   [variant_isset abiword]
+        || [variant_isset qt4Splash]
+        || [variant_isset glibCairo]
+        || [variant_isset glibSplash]} then {
+
+        foreach item $depends_lib {
+            depends_lib-delete $item
+        }
+
+        dependencyToAppend {port:freetype}
+        dependencyToAppend {port:fontconfig}
+        dependencyToAppend {port:expat}
+        dependencyToAppend {port:libiconv}
+        dependencyToAppend {port:zlib}
+        dependencyToAppend {port:poppler-data}
+    }
+
+    if {[variant_isset abiword]} then {
+        dependencyToAppend {port:libxml2}
+    }
+
+    if {[variant_isset qt3Splash]} then {
+        dependencyToAppend {port:qt3-mac}    
+        dependencyToAppend {port:jpeg}
+        dependencyToAppend {port:libpng} 
+    }   
+        
+    if {[variant_isset qt4Splash]} then {
+        dependencyToAppend {port:qt4-mac}
+        dependencyToAppend {port:jpeg}
+        dependencyToAppend {port:libpng}
+    }
+
+    if {   [variant_isset glibCairo]
+        && [variant_isset quartz]} then {
+        dependencyToAppend {port:cairo}
+        dependencyToAppend {port:glib2}
+        dependencyToAppend {port:gettext}
+        dependencyToAppend {port:libpixman}
+        dependencyToAppend {port:jpeg}
+        dependencyToAppend {port:libpng}
+        # no dependency on XFree86 and xrender
+        # no dependency on gtk2, pango, and tiff
+    }
+
+    if {   [variant_isset glibSplash]
+        && [variant_isset quartz]} then {
+        dependencyToAppend {port:gtk2}
+        dependencyToAppend {port:glib2}
+        dependencyToAppend {port:gettext}
+        dependencyToAppend {port:libpixman}
+        dependencyToAppend {port:jpeg}
+        dependencyToAppend {port:libpng}
+
+        # 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.
+        dependencyToAppend {port:pango}
+        dependencyToAppend {port:cairo}
+
+        dependencyToAppend {port:tiff}
+        # no dependency on XFree86 and xrender  
+    }
+
+    if {   [variant_isset glibCairo]
+        || [variant_isset glibSplash]} then {
+        dependencyToAppend {port:XFree86}
+        dependencyToAppend {port:xrender}
+        dependencyToAppend {port:gtk2}
+        dependencyToAppend {port:glib2}
+        dependencyToAppend {port:gettext}
+        dependencyToAppend {port:libpixman}
+        dependencyToAppend {port:jpeg}
+        dependencyToAppend {port:libpng}
+        dependencyToAppend {port:cairo}
+        dependencyToAppend {port:pango}
+        dependencyToAppend {port:tiff}
+    }
+
+    foreach entry $listOfPortDependenciesToAppend {
+        depends_lib-append $entry
+    }
+
+    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 )
+
 

