--- /opt/local/var/macports/sources/svn.macports.org/trunk/dports/aqua/qt5-mac/Portfile	2015-06-14 22:18:50.000000000 +0200
+++ /Users/bertin/mnt/qt5macnew/Portfile	2015-06-17 17:04:28.000000000 +0200
@@ -3,6 +3,10 @@
 
 PortSystem          1.0
 
+# RJVB: at the time of the initial request for a Qt5 port, the opinion was voiced and supported by michaelld
+# that it should be called simply qt5 . I adhere to that opinion because there will be no "non-mac" Qt5 port.
+# Instead, it is possible to create (and I have implemented) a qt5-x11 subport that installs the xcb platform
+# plugin in the Qt5 plugin directory. Semantics, but it would be weird to call it qt5-mac-x11 ...
 name                qt5-mac
 version             5.4.2
 set branch          [join [lrange [split ${version} .] 0 1] .]
@@ -12,15 +16,15 @@
 maintainers         mcalhoun openmaintainer
 license             {LGPL-2.1 GPL-3}
 
-homepage            http://qt-project.org
-description         Qt Tool Kit
+homepage            http://qt.io
+description         Qt Tool Kit ${branch}
 long_description    Qt Tool Kit: A cross-platform framework \
     (headers, data, and libraries) for writing \
     cross-platform GUI-based applications.
 
 distname            qt-everywhere-opensource-src-${version}
 
-master_sites        http://download.qt-project.org/official_releases/qt/${branch}/${version}/single/
+master_sites        http://download.qt.io/official_releases/qt/${branch}/${version}/single/
 
 checksums           rmd160  3382c482a99e114560f56a9fe9501b8cabf334a9 \
                     sha256  cfc768c55f0a0cd232bed914a9022528f8f2e50cb010bf0e4f3f62db3dfa17bd
@@ -73,10 +77,6 @@
     # See https://bugreports.qt.io/browse/QTBUG-34902
     conflicts_build-append  qt4-mac
 
-    # Kuba states in https://trac.macports.org/ticket/44207#comment:7 
-    #  "There's no reason to have parallel building disabled. Really."
-    #use_parallel_build no
-
     # qtwebengine/src/core/gyp_run.pro buils an executable using g++
     # This causes an error if UsingTheRightCompiler (https://trac.macports.org/wiki/UsingTheRightCompiler)
     # Quick fix is to use full path to g++ (should use ${configure.cxx} instead?)
@@ -135,7 +135,10 @@
         set libreplace [string repeat ../ [llength ${qt_list}]][join ${framework_list} /]
         if { ${libreplace} ne "lib" } {
             patchfiles-append patch-shared.diff
-            reinplace "s|__MACPORTS_FRAMWORK_DIR__|${libreplace}|g" ${worksrcpath}/qttools/src/macdeployqt/shared/shared.cpp
+            # RJVB: reinplace should be done in the post-patch
+            post-patch {
+                reinplace "s|__MACPORTS_FRAMWORK_DIR__|${libreplace}|g" ${worksrcpath}/qttools/src/macdeployqt/shared/shared.cpp
+            }
         }
     }
 
@@ -152,10 +155,10 @@
     #-hostbindir    HOSTPREFIX/bin
     #-hostlibdir    HOSTPREFIX/lib
     configure.args-append                      \
-        -prefix         ${qt_dir}              \
+        -prefix         ${prefix}              \
         -bindir         ${qt_bins_dir}         \
         -headerdir      ${qt_includes_dir}     \
-        -libdir         ${qt_libs_dir}         \
+        -libdir         ${qt_frameworks_dir}   \
         -archdatadir    ${qt_archdata_dir}     \
         -plugindir      ${qt_plugins_dir}      \
         -importdir      ${qt_imports_dir}      \
@@ -166,9 +169,14 @@
         -sysconfdir     ${qt_sysconf_dir}      \
         -examplesdir    ${qt_examples_dir}     \
         -testsdir       ${qt_tests_dir}        \
-        -hostdatadir    ${qt_host_data_dir}
+        -hostdatadir    ${qt_host_data_dir}    \
+        -hostbindir     ${qt_bins_dir}         \
+        -hostlibdir     ${qt_frameworks_dir}
+
 
     # Configure options:
+    # RJVB : -c++11 is the default (when auto-detection detects it's supported) and it
+    # is probably best left implicit (e.g. for building on earlier OS X versions) => remove -c++11
     configure.args-append \
         -release          \
         -opensource       \
@@ -177,11 +185,15 @@
         -shared           \
         -largefile        \
         -accessibility
-    
-    foreach driver { db2 ibase mysql oci odbc psql sqlite sqlite2 tds } {
+
+    # RJVB/pixilla: the sqlite3 plugin ("sqlite") should  be re-absorbed into the main port
+    configure.args-append -system-sqlite
+    depends_lib-append port:sqlite3
+    foreach driver { db2 ibase mysql oci odbc psql sqlite2 tds } {
         configure.args-append -no-sql-${driver}
     }
 
+    # RJVB: -qml-debug is the default
     configure.args-append \
         -qml-debug
 
@@ -196,6 +208,7 @@
         -force-pkg-config
 
     # Third Party Libraries:
+    # RJVB : Qt has no business depending on PulseAudio on OS X; it only pulls in undesirable dependencies (like gnome...)
     configure.args-append   \
         -system-zlib        \
         -no-mtdev           \
@@ -216,6 +229,8 @@
         -no-gtkstyle
 
     # Additional options:
+    # RJVB: what's the point in not optimising qmake? Any increase in configure time (which I don't believe in)
+    # can be compensated by patching the configure script so it builds qmake with -j${build.jobs} .
     configure.args-append       \
         {-make libs}            \
         {-make tools}           \
@@ -243,7 +258,7 @@
         -no-linuxfb             \
         -no-kms                 \
         -no-system-proxies
-    
+
     # MacOS/iOS options:
     configure.args-append    \
         -framework
@@ -252,7 +267,7 @@
         configure.args-append \
             -sdk [string tolower [join [lrange [split [lindex [split ${configure.sdkroot} "/"] end] "."] 0 end-1] "."]]
     }
-    
+
     # configure options that don't show up in configure --help
     configure.args-append \
         -no-libudev       \
@@ -288,6 +303,7 @@
 }
 
 if { ${subport} eq ${name} } {
+    # RJVB: port:pulseaudio should disappear from this list when Qt is configured *without* PA support
     depends_lib                              \
         port:zlib                            \
         port:libpng                          \
@@ -325,8 +341,8 @@
 
                 reinplace "s|${worksrcpath}-${arch}|${worksrcpath}|g" ${dir}${qt_mkspecs_dir}/modules/qt_lib_bootstrap_private.pri
                 reinplace "s|macx-clang-32|macx-clang|g"              ${dir}${qt_libs_dir}/cmake/Qt5Core/Qt5CoreConfigExtrasMkspecDir.cmake
-                
-                
+
+
                 if { [variant_isset examples] } {
                     reinplace "s|${worksrcpath}-${arch}|${worksrcpath}|g" ${dir}${qt_examples_dir}/declarative/tutorials/gettingStarted/parts/part5/filedialog/Makefile
                     reinplace -E "/\\w*-arch \\\\/d"                      ${dir}${qt_examples_dir}/declarative/tutorials/gettingStarted/parts/part5/filedialog/Makefile
@@ -358,27 +374,197 @@
 
     post-destroot {
         # see #44204
-        foreach f [glob -nocomplain -tails -directory ${destroot}${qt_libs_dir} *.framework] {
-            set framework [file rootname ${f}]
+        # RJVB: use the code below ">>>..." instead of this block, which fails to populate qt_includes_dir completely.
+#         foreach f [glob -nocomplain -tails -directory ${destroot}${qt_libs_dir} *.framework] {
+#             set framework [file rootname ${f}]
+#
+#             set include_list   [split ${qt_includes_dir}   '/']
+#             set framework_list [split ${qt_libs_dir} '/']
+#
+#             while {[llength ${include_list}] && [llength ${framework_list}]} {
+#                 set var_include   [lindex $include_list   0]
+#                 set var_framework [lindex $framework_list 0]
+#
+#                 if { ${var_include} ne ${var_framework} } {
+#                     break
+#                 }
+#
+#                 # remove first element from list
+#                 set include_list   [lreplace ${include_list} 0 0]
+#                 set framework_list [lreplace ${framework_list} 0 0]
+#             }
+#
+#             ln -s [string repeat ../ [llength ${include_list}]][join ${framework_list} /]/${f}/Headers ${destroot}${qt_includes_dir}/${framework}
+#         }
+
+        # RJVB: tried and true logic copied from the qt4-mac port
+        # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+        # move items out of the Frameworks directory that are more appropriate to lib directory
+        xinstall -m 775 -d ${destroot}${qt_cmake_module_dir}
+        foreach d [glob -tails -nocomplain -directory ${destroot}${qt_frameworks_dir}/cmake *] {
+            xinstall -m 775 -d ${destroot}${qt_cmake_module_dir}/${d}
+            foreach f [glob -nocomplain -directory ${destroot}${qt_frameworks_dir}/cmake/${d} *.cmake] {
+                # ${qt_frameworks_dir} is  ${qt_dir}/Library/Frameworks while
+                # ${qt_libs_dir}       is  ${qt_dir}/lib
+                # unless modified, cmake files will point to a directory that is too high in the directory hierarchy
+                reinplace "s|/../../../../|/../../../${qt_dir_rel}/|g" ${f}
+                file rename ${f} ${destroot}${qt_cmake_module_dir}/${d}/
+            }
+        }
+        set qt_vers [split ${version} "."]
+        set qt_major [lindex ${qt_vers} 0]
+        set qt_minor [lindex ${qt_vers} 1]
+        set qt_patch [lindex ${qt_vers} 2]
+
+        # link includes and libraries for each actual installed framework
+        # make sure that the target directories exist
+        exec mkdir -p ${destroot}${qt_includes_dir} ${destroot}${qt_libs_dir}
+        foreach fixfile [exec find ${destroot}${qt_frameworks_dir} \
+                             -name "*.framework" | \
+                             sed -e "s@${destroot}@@g"] {
+
+                set tf_full [strsed ${fixfile} {s@\\.framework@@}]
+                set tf [strsed ${tf_full} {g@.*\/@@}]
+
+                # special for QtWebKit entries
+                set t_minor ${qt_minor}
+                set is_QtWebKit 0
+                if {[string compare ${tf} QtWebKit] == 0} {
+                    set t_minor 9
+                    set is_QtWebKit 1
+                }
+
+                # link headers into ${qt_includes_dir}, removing directories
+                # if they are already there first
+                set inc_file ${destroot}${qt_includes_dir}/${tf}
+                if {[file exists ${inc_file}]} {
+                    ui_msg "*Warning* replacing directory ${inc_file} with a symlink to ${tf_full}.framework/Headers!"
+                    file delete -force ${inc_file}
+                }
+                ln -s ${tf_full}.framework/Headers ${inc_file}
+
+                # link libraries into ${qt_libs_dir}, all 4 number variants
+                set dr_qt_libs_dir ${destroot}${qt_libs_dir}
+                ln -s ${tf_full}.framework/${tf} ${dr_qt_libs_dir}/lib${tf}.dylib
+                ln -s ${tf_full}.framework/${tf} ${dr_qt_libs_dir}/lib${tf}.${qt_major}.dylib
+                ln -s ${tf_full}.framework/${tf} ${dr_qt_libs_dir}/lib${tf}.${qt_major}.${t_minor}.dylib
+                ln -s ${tf_full}.framework/${tf} ${dr_qt_libs_dir}/lib${tf}.${qt_major}.${t_minor}.${qt_patch}.dylib
+
+                # copy .prl file, then correct it for library usage
+                copy ${destroot}${tf_full}.framework/${tf}.prl ${dr_qt_libs_dir}/lib${tf}.prl
+
+                # fix TARGET in .prl file
+                reinplace "/QMAKE_PRL_TARGET/s|Qt\\(\[^ \]*\\)|libQt\\1.${qt_major}.${t_minor}.${qt_patch}.dylib|" ${dr_qt_libs_dir}/lib${tf}.prl
+
+                # fix PRL_LIBS -F -> -L in .prl file
+                reinplace "/QMAKE_PRL_LIBS/s|-F${qt_frameworks_dir}|-L${qt_libs_dir}|" ${dr_qt_libs_dir}/lib${tf}.prl
+
+                # fix "-framework Qt*" -> "-lQt*" in .prl file
+                reinplace "/QMAKE_PRL_LIBS/s|-framework Qt|-lQt|g" \
+                    ${dr_qt_libs_dir}/lib${tf}.prl
 
-            set include_list   [split ${qt_includes_dir}   '/']
-            set framework_list [split ${qt_libs_dir} '/']
+                # remove the QMAKE_PRL_BUILD_DIR line from the .prl file
+                reinplace "/QMAKE_PRL_BUILD_DIR/d" ${dr_qt_libs_dir}/lib${tf}.prl
 
-            while {[llength ${include_list}] && [llength ${framework_list}]} {
-                set var_include   [lindex $include_list   0]
-                set var_framework [lindex $framework_list 0]
+                # deal with debug files
+                # RJVB: this is the only block I never tested
+                if {[variant_isset debug]} {
 
-                if { ${var_include} ne ${var_framework} } {
-                    break
+                    # but not if QtWebKit and +universal, since that one does
+                    # not exist (the 32-bit version of the debug library is
+                    # larger than fits into the 32-bit filespace).
+
+                    if {[variant_isset debug] && ${is_QtWebKit}} {
+                        continue
+                    }
+
+                    # link libraries into ${qt_libs_dir}, all 4 number variants
+                    ln -s ${tf_full}.framework/${tf}_debug ${dr_qt_libs_dir}/lib${tf}_debug.dylib
+                    ln -s ${tf_full}.framework/${tf}_debug ${dr_qt_libs_dir}/lib${tf}_debug.${qt_major}.dylib
+                    ln -s ${tf_full}.framework/${tf}_debug ${dr_qt_libs_dir}/lib${tf}_debug.${qt_major}.${t_minor}.dylib
+                    ln -s ${tf_full}.framework/${tf}_debug ${dr_qt_libs_dir}/lib${tf}_debug.${qt_major}.${t_minor}.${qt_patch}.dylib
+
+                    # copy .prl file, then correct it for library usage
+                    copy ${destroot}${tf_full}.framework/${tf}_debug.prl ${dr_qt_libs_dir}/lib${tf}_debug.prl
+
+                    # fix TARGET in .prl file
+                    reinplace "/QMAKE_PRL_TARGET/s|Qt\\(\[^ \]*\\)|libQt\\1.${qt_major}.${t_minor}.${qt_patch}.dylib|" ${dr_qt_libs_dir}/lib${tf}_debug.prl
+
+                    # fix PRL_LIBS -F -> -L in .prl file
+                    reinplace "/QMAKE_PRL_LIBS/s|-F${qt_frameworks_dir}|-L${qt_libs_dir}|" ${dr_qt_libs_dir}/lib${tf}_debug.prl
+
+                    # fix "-framework Qt*" -> "-lQt*_debug" in .prl file
+                    reinplace "/QMAKE_PRL_LIBS/s|-framework Qt\\(\[^ \]*\\)|-lQt\\1_debug|g" ${dr_qt_libs_dir}/lib${tf}_debug.prl
+                }
+            }
+            # RJVB: spoiler: reference to the qt5*-kde subport
+            if {${subport} eq ${name} || ${subport} eq "${name}-kde"} {
+                ln -s ${qt_qmake_cmd} ${destroot}/${prefix}/bin/qmake-qt${qt_major}
+                ln -s ${qt_moc_cmd} ${destroot}/${prefix}/bin/moc-qt${qt_major}
+                ln -s ${qt_uic_cmd} ${destroot}/${prefix}/bin/uic-qt${qt_major}
+                ln -s ${qt_lrelease_cmd} ${destroot}/${prefix}/bin/lrelease-qt${qt_major}
+            }
+            if {${qt_pkg_config_dir} ne "${qt_frameworks_dir}/pkgconfig"} {
+                # move the pkgconfig files to their assigned location
+                foreach f [glob -nocomplain -directory ${destroot}${qt_frameworks_dir}/pkgconfig *.pc] {
+                    file rename ${f} ${destroot}${qt_pkg_config_dir}
+                }
+            }
+            if {${qt_libs_dir} ne ${qt_frameworks_dir}} {
+                xinstall -m 775 -d ${destroot}${qt_libs_dir}/
+                foreach f [glob -nocomplain -directory ${destroot}${qt_frameworks_dir} *.{a,prl,la}] {
+                    file rename ${f} ${destroot}${qt_libs_dir}/
                 }
 
-                # remove first element from list
-                set include_list   [lreplace ${include_list} 0 0]
-                set framework_list [lreplace ${framework_list} 0 0]
+                # link back the static libraries to where some Qt components expect them:
+                foreach f [exec find ${destroot}${qt_libs_dir} \
+                                     -name "*.a" | \
+                                     sed -e "s@${destroot}@@g"] {
+                    ln -s ${f} ${destroot}${qt_frameworks_dir}/
+                }
+                # certain applications might expect to find the following .prl files in ${qt_frameworks_dir}
+                foreach fixfile { libQt5OpenGLExtensions_debug.prl libQt5PlatformSupport_debug.prl \
+                                    libQt5QmlDevTools.prl libQt5UiTools.prl libQt5UiTools_debug.prl } {
+                    if {[file exists ${destroot}${qt_libs_dir}/${fixfile}]} {
+                        ln -s ${qt_libs_dir}/${fixfile} ${destroot}${qt_frameworks_dir}/${fixfile}
+                    }
+                }
             }
 
-            ln -s [string repeat ../ [llength ${include_list}]][join ${framework_list} /]/${f}/Headers ${destroot}${qt_includes_dir}/${framework}
-        }
+            # Move .apps into the applications_dir, and link each .apps'
+            # executable back into ${qt_bins_dir}
+            set dr_qt_apps_dir ${destroot}${qt_apps_dir}
+            set dr_qt_bins_dir ${destroot}${qt_bins_dir}
+            xinstall -m 755 -d ${dr_qt_apps_dir}
+            foreach app [glob -nocomplain ${dr_qt_bins_dir}/*.app] {
+                # remove the leading stuff
+                set app [lindex [split ${app} /] end]
+                # move the .app
+                move ${dr_qt_bins_dir}/${app} ${dr_qt_apps_dir}
+                # link it back
+                ln -s ${qt_apps_dir}/${app} ${dr_qt_bins_dir}
+                # provide a proxy to the app's executable; symlinks won't
+                # be accepted by qtchooser if the user has that port installed.
+                # RJVB: requires ${filespath}/appProxy.sh
+#                 set texe [strsed ${app} {g@\.app@@}]
+#                 set appProxy ${dr_qt_bins_dir}/[string tolower ${texe}]
+#                 copy ${filespath}/appProxy.sh ${appProxy}
+#                 reinplace "s|@BUNDLEEXEC@|${qt_apps_dir}/${app}/Contents/MacOS/${texe}|g" ${appProxy}
+
+            }
+            if {[file exists ${destroot}${qt_mkspecs_dir}/qmodule.pri]} {
+                # clean up the generated mkspecs/qmodule.pri:
+                # undo any symlink normalisation that introduced the clang version number into QMAKE_CC/CXX (e.g. clang++-mp-3.5)
+                reinplace "s|bin/clang-mp-.*|bin/clang|g"  ${destroot}${qt_mkspecs_dir}/qmodule.pri
+                reinplace "s|bin/clang\+\+-mp-.*|bin/clang\+\+|g"  ${destroot}${qt_mkspecs_dir}/qmodule.pri
+            }
+            if {[file exists ${destroot}${qt_mkspecs_dir}/qmodule.pri]} {
+                # if the user used configure.optflags="-something" make sure that gets added to compiler options qmake
+                # determines, rather than replacing all of those
+                reinplace "s|QMAKE_CFLAGS = |QMAKE_CFLAGS \+= |g"  ${destroot}${qt_mkspecs_dir}/qmodule.pri
+                reinplace "s|QMAKE_CXXFLAGS = |QMAKE_CXXFLAGS \+= |g"  ${destroot}${qt_mkspecs_dir}/qmodule.pri
+            }
+            #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
     }
 
     variant tests description {Enable tests} {
@@ -394,6 +580,7 @@
     }
 }
 
+# RJVB: the docs subport should be renamed such that it comes last during an `upgrade outdated`
 subport ${name}-docs {
     depends_lib-append \
         path:${qt_bins_dir}/qdoc:${name} \
@@ -422,7 +609,11 @@
 
 # See http://doc.qt.io/qt-5/sql-driver.html for info on building SQL Database Drivers
 
+# RJVB/pixilla: applications built by the main port depend on the sqlite3 plugin. It should be built
+# with the main port and not be a separate subport.
 subport ${name}-sqlite3-plugin {
+    replaced_by         ${name}
+    PortGroup           obsolete 1.0
     PortGroup           qmake5 1.0
 
     depends_lib-append port:sqlite3
@@ -468,5 +659,5 @@
 }
 
 livecheck.type      regex
-livecheck.url       http://qt-project.org/downloads
-livecheck.regex     "Qt (5(?:\\.\\d+)*) for Mac"
+livecheck.url       http://download.qt.io/archive/qt/5.4/
+livecheck.regex     (\\d+(\\.\\d+)+)
