--- Portfile.orig	2008-03-13 13:24:33.000000000 -0600
+++ Portfile	2008-04-13 19:42:49.000000000 -0600
@@ -19,63 +19,87 @@
                     http://wftp.tu-chemnitz.de/pub/Qt/qt/source/
 distname            qt-mac-opensource-src-${version}
 checksums           md5 e3997f7c7620bcf03c635676c3b01fef \
-                    sha1 bdba9cd2a5ad79724d536f8a4a3010c3a223108b
+                    sha1 bdba9cd2a5ad79724d536f8a4a3010c3a223108b \
+                    rmd160 b02600a73ce54e367b3f362223cfafbaf337ca80
 
 depends_lib         port:libmng port:libpng port:jpeg port:tiff
 
 # have to build with Apple gcc because of -fconstant-cfstrings
 configure.compiler  gcc-4.0
 configure.cmd       "echo yes | ./configure"
-configure.env       QMAKESPEC='' QTDIR='' DYLD_LIBRARY_PATH=''
 configure.pre_args
+
+# directory to put .app and executable files
+# once installed there, should not be moved so they can find each other
+#   (e.g. assistant.app) and the examples directory
+set bindir ${prefix}/libexec/${name}/bin
+
 # See
 #   http://doc.trolltech.com/qtopia4.3/buildsystem/over-configure-options-qt-1.html
 # for options
 configure.args \
     -v         \
     -prefix         '${prefix}'                            \
-    -docdir         '${prefix}/share/doc/${portname}/html' \
-    -datadir        '${prefix}/share/qt4'                  \
-    -headerdir      '${prefix}/include/qt4'                \
-    -plugindir      '${prefix}/lib/qt4-plugins'            \
-    -translationdir '${prefix}/share/qt4/translations'     \
+    -bindir         '${bindir}'                            \
+    -docdir         '${prefix}/share/doc/${portname}'      \
+    -datadir        '${prefix}/share/${portname}'          \
+    -headerdir      '${prefix}/include/${portname}'        \
+    -plugindir      '${prefix}/lib/${portname}-plugins'    \
+    -translationdir '${prefix}/share/${portname}/translations' \
     -optimized-qmake    -release        -shared         -stl                \
     -no-openssl         -largefile                                          \
     -system-libpng      -system-libjpeg -system-libmng  -system-libtiff     \
     -system-zlib        -qt-gif                                             \
     -no-sql-ibase       -no-sql-mysql   -no-sql-odbc    -no-sql-psql        \
-    -no-sql-sqlite      -no-nis         -no-cups        -no-framework       \
+    -no-sql-sqlite      -no-nis         -no-cups                            \
+    -framework          -libdir '${prefix}/Library/Frameworks'              \
     -make libs          -make tools                                         \
     -I${worksrcpath}/include -I${prefix}/include \
     -L${worksrcpath}/lib -L${prefix}/lib
 
     # not made by default, anyway: -nomake demos -nomake examples
 
-build.env           QMAKESPEC='' QTDIR='' DYLD_LIBRARY_PATH="${worksrcpath}/lib"
 build.target        first
 
 destroot.destdir    INSTALL_ROOT="${destroot}"
 
-set appPath         ${destroot}/Applications/MacPorts/Qt
-set docPath         ${destroot}${prefix}/share/doc/qt4-mac
-
 post-destroot {
-    xinstall -d -m 0755 ${appPath}
-    foreach app {assistant Designer Linguist pixeltool} {
-        move ${destroot}${prefix}/bin/${app}.app ${appPath}
+    xinstall -d -m 0755 ${destroot}${bindir}
+    xinstall -d -m 0755 ${destroot}/Applications/MacPorts/Qt
+    
+    # create link in ${prefix}/bin to executable files in ${bindir}
+    foreach bin [glob -type f -directory ${destroot}${bindir} *] {
+        system "ln -s ${bindir}/[file tail ${bin}] ${destroot}${prefix}/bin"
+    }
+    
+    # create link in /Applications/MacPorts/Qt to .app directories in ${bindir}
+    # create link in ${prefix}/bin to all *.app/Contents/MacOS/*
+    foreach app [glob -type d -directory ${destroot}${bindir} *.app] {
+        system "ln -s ${bindir}/[file tail ${app}] ${destroot}/Applications/MacPorts/Qt"
+        foreach bin [glob -type f -directory ${app} Contents/MacOS/*] {
+            system "ln -s ${bindir}/[file tail ${app}]/Contents/MacOS/[file tail ${bin}] ${destroot}${prefix}/bin"
+        }
+    }
+    
+    # append -mac to links in ${prefix}/bin to avoid conflict with qt4-x11
+    foreach bin [glob ${destroot}${prefix}/bin/*] {
+        move ${bin} ${bin}-mac
+    }
+    
+    # fix id of plugins shared libraries
+    foreach dirFull [glob -directory ${destroot}${prefix}/lib/${portname}-plugins -type d -nocomplain *] {
+        set dir [file tail ${dirFull}]
+        foreach libFull [glob -directory ${destroot}${prefix}/lib/${portname}-plugins/${dir} -nocomplain *.dylib] {
+            set lib [file tail ${libFull}]
+            system "install_name_tool -id ${prefix}/lib/${portname}-plugins/${dir}/${lib} ${libFull}"
+        }
     }
+    
+    # install documentation
     foreach doc {INSTALL LICENSE.GPL2 LICENSE.GPL3 OPENSOURCE-NOTICE.TXT README \
                  GPL_EXCEPTION_ADDENDUM.TXT GPL_EXCEPTION.TXT} {
-        xinstall -c -m 644 ${worksrcpath}/$doc ${docPath}
+        xinstall -c -m 644 ${worksrcpath}/$doc ${destroot}${prefix}/share/doc/${portname}
     }
-    if {![file exists ${destroot}${prefix}/lib/libqt.dylib]} {
-        set majorver [strsed ${version} {s/\.[0-9]*\.[0-9]*$//}]
-        set minorver [strsed ${version} {s/\.[0-9]*$//}]
-        system "cd ${destroot}${prefix}/lib &&
-            ln -s libqt-mt.${version}.dylib libqt.dylib &&
-            ln -s libqt-mt.${version}.dylib libqt.${majorver}.dylib &&
-            ln -s libqt-mt.${version}.dylib libqt.${minorver}.dylib"
-   }
 }
 
 variant dbus description "Include DBus support" {
@@ -83,24 +107,29 @@
     configure.args-append   -qdbus
 }
 
-variant framework description "Build frameworks" {
-    configure.args-delete   -no-framework
-    configure.args-append   -framework
+variant noframework description "Do not build frameworks" {
+    configure.args-delete   -framework -libdir '${prefix}/Library/Frameworks'
+    configure.args-append   -no-framework
 }
 
-variant ipv6 description "Include IPv6 support" {
-    configure.args-delete   -no-ipv6
-    configure.args-append   -ipv6
+variant nis description "Include Network Information Service (NIS) support" {
+    configure.args-delete   -no-nis
+    configure.args-append   -nis
 }
 
-variant mysql description "Include support for SQL via mysql driver" {
+variant cups description "Include Common Unix Printing System (CUPS) support" {
+    configure.args-delete   -no-cups
+    configure.args-append   -cups
+}
+
+variant mysql description conflicts mysql5 "Include support for SQL via mysql driver" {
     depends_lib-append      lib:libmysqlclient.12:mysql4
     configure.args-delete   -no-sql-mysql
     configure.args-append   -qt-sql-mysql -plugin-sql-mysql \
                             -I${prefix}/include/mysql -L${prefix}/lib/mysql
 }
 
-variant mysql5 description "Include support for SQL via mysql driver" {
+variant mysql5 conflicts mysql description "Include support for SQL via mysql5 driver" {
     depends_lib-append      lib:libmysqlclient.15:mysql5
     configure.args-delete   -no-sql-mysql
     configure.args-append   -qt-sql-mysql -plugin-sql-mysql \
@@ -112,29 +141,24 @@
 	configure.args-delete	-no-sql-sqlite
 	configure.args-append	-qt-sql-sqlite -plugin-sql-sqlite
     # -system-sqlite
-    post-destroot {
-        # fix install-name of plugin
-        system "install_name_tool -id ${prefix}/lib/qt4-plugins/sqldrivers/libqsqlite.dylib \
-            ${destroot}${prefix}/lib/qt4-plugins/sqldrivers/libqsqlite.dylib"
-    }
 }
 
 variant ssl description "Include OpenSSL support" {
-    depends_lib             port:openssl
+    depends_lib-append      port:openssl
     configure.args-delete   -no-openssl
     configure.args-append   -openssl
 }
 
 variant examples description "Build Qt examples" {
     # configure.args-delete   "-nomake examples"
-    configure.args-append   -make examples
+    configure.args-append   -make examples -examplesdir ${prefix}/share/${portname}/examples
 }
 
 variant demos description "Build Qt demos" {
     # configure.args-delete   "-nomake demos"
-    configure.args-append   -make demos
-    post-destroot {
-        move ${destroot}${prefix}/demos ${appPath}
-        move ${destroot}${prefix}/bin/qtdemo.app ${appPath}
-    }
+    configure.args-append   -make demos -demosdir ${prefix}/share/${portname}/demos
 }
+
+livecheck.check     regex
+livecheck.url       http://trolltech.com/developer/downloads/qt/mac
+livecheck.regex     "The current version of Qt/Mac Open Source Edition is (4(?:\\.\\d+)*)"
