--- /opt/local/var/macports/sources/svn.macports.org/trunk/dports/audio/phonon/Portfile	2015-06-04 00:37:08.000000000 +0200
+++ /opt/local/site-ports/audio/phonon/Portfile	2015-06-20 23:20:16.000000000 +0200
@@ -1,12 +1,11 @@
 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
-# $Id: Portfile 134243 2015-03-20 14:52:09Z michaelld@macports.org $
+# $Id: Portfile 122949 2014-08-02 20:49:01Z michaelld@macports.org $
 
 PortSystem          1.0
 
 name                phonon
 version             4.8.3
 revision            1
-categories          audio kde kde4
 license             {LGPL-2.1 LGPL-3}
 maintainers         michaelld openmaintainer
 description         Cross Platform Multimedia API used by KDE4
@@ -22,68 +21,61 @@
     configure.args-append   -DPHONON_BUILD_DEMOS:BOOL=ON
 }
 
-# fix use of CMAKE_INSTALL_NAME to be an absolute path
-
-patchfiles-append   patch-cmake_FindPhononInternal.cmake.diff
-
-# fix MODULE names to end in .dylib instead of .so
-
-patchfiles-append   patch-cmake_PhononMacros.cmake.diff
-
-# (1) fix install location of cmake module files;
-# patch here and post-patch reinplace.
-# (2) fix library compatibility version to be 4.4.0,
-# because pretty much every KDE port expects it.
-
-patchfiles-append   patch-CMakeLists.txt.diff
-
-post-patch {
-    set rel_mp_qt_cmake_dir [strsed ${qt_cmake_module_dir} "g@${qt_dir}/@@"]
-    reinplace "s|@MACPORTS_CMAKE_DIR@|${rel_mp_qt_cmake_dir}|" \
-        ${worksrcpath}/CMakeLists.txt
-}
-
-# do VPATH (out of source tree) build
-
-cmake.out_of_source yes
-
-# standard args
+subport ${name}-qt5 {
+    PortGroup           qt5 1.0
+    PortGroup           cmake 1.0
+    categories          audio kde kf5
+    long_description    Phonon is a multimedia, multi-platform sound \
+        framework for the application developer. This is the  Phonon 4\
+        transitional library for Qt5 (API compatible with regular Phonon4)
 
-configure.args-append   \
-    ${qt_cmake_defines} \
-    -DPHONON_INSTALL_QT_EXTENSIONS_INTO_SYSTEM_QT=TRUE \
-    -DWITH_QZeitgeist=OFF
+    configure.args-append   -DPHONON_BUILD_PHONON4QT5:BOOL=ON
 
-if {${subport} ne "${name}-qt5"} {
-    PortGroup       qt4 1.0
-    PortGroup       cmake 1.0
-    categories      audio kde kde4
-    long_description    Phonon is a multimedia, multi-platform sound \
-        framework for the application developer.
-    depends_build-append  port:automoc
+    set LPH libphonon4qt5
+    post-destroot {
 
-    variant compversion440 description {Build libraries with compatibility version 4.4.0 for existing Qt4 installs expecting that} {
-        # fix the library compatibility version to be 4.4.0
-        patchfiles          patch-CMakeLists.txt.diff
+        if {[variant_isset demos]} {
+            set demos_dest_dir ${destroot}${prefix}/share/examples/phonon4qt5
+            xinstall -m 775 -d ${demos_dest_dir}
+            copy ${workpath}/build/demos/simpleplayer/simpleplayer ${demos_dest_dir}
+            copy ${workpath}/build/demos/metadatareader/metadatareader ${demos_dest_dir}
+            copy ${workpath}/build/demos/phota/phota ${demos_dest_dir}
+            copy ${workpath}/build/demos/simplecapture/simplecapture ${demos_dest_dir}
+        }
+
+        # fix library and plugin self-names
+        system "install_name_tool -id ${prefix}/lib/${LPH}.4.dylib ${destroot}${prefix}/lib/${LPH}.dylib"
+        system "install_name_tool -id ${prefix}/lib/${LPH}experimental.4.dylib ${destroot}${prefix}/lib/${LPH}experimental.dylib"
+
+        # fix use of libphonon4qt5
+        system "install_name_tool -change lib/${LPH}.4.dylib ${prefix}/lib/${LPH}.4.dylib \
+            ${destroot}${prefix}/lib/${LPH}experimental.dylib"
+        system "install_name_tool -change lib/${LPH}.4.dylib ${prefix}/lib/${LPH}.4.dylib \
+            ${destroot}${qt_plugins_dir}/designer/libphononwidgets.dylib"
+        system "install_name_tool -id libphononwidgets.dylib ${destroot}${qt_plugins_dir}/designer/libphononwidgets.dylib"
+        if {[variant_isset demos]} {
+            system "install_name_tool -change lib/${LPH}.4.dylib ${prefix}/lib/${LPH}.4.dylib \
+                ${demos_dest_dir}/simpleplayer"
+            system "install_name_tool -change lib/${LPH}.4.dylib ${prefix}/lib/${LPH}.4.dylib \
+                ${demos_dest_dir}/metadatareader"
+            system "install_name_tool -change lib/${LPH}.4.dylib ${prefix}/lib/${LPH}.4.dylib \
+                ${demos_dest_dir}/phota"
+            system "install_name_tool -change lib/${LPH}.4.dylib ${prefix}/lib/${LPH}.4.dylib \
+                ${demos_dest_dir}/simplecapture"
+        }
     }
+}
 
-    # link major library version name
+default_variants    +compversion440
 
-    ln -s libphonon.dylib ${destroot}${prefix}/lib/libphonon.4.dylib
-    ln -s libphononexperimental.dylib ${destroot}${prefix}/lib/libphononexperimental.4.dylib
+# fix use of CMAKE_INSTALL_NAME to be an absolute path
+# (RJVB: why is this necessary?)
+patchfiles-append   patch-cmake_FindPhononInternal.cmake.diff
 
-    if {[variant_isset demos]} {
-        set demos_dest_dir ${destroot}${prefix}/share/examples/phonon
-        xinstall -m 775 -d ${demos_dest_dir}
-        copy ${workpath}/build/demos/simpleplayer/simpleplayer ${demos_dest_dir}
-        copy ${workpath}/build/demos/metadatareader/metadatareader ${demos_dest_dir}
-        copy ${workpath}/build/demos/phota/phota ${demos_dest_dir}
-        copy ${workpath}/build/demos/simplecapture/simplecapture ${demos_dest_dir}
-    }
-}
+# fix MODULE names to end in .dylib instead of .so
+patchfiles-append   patch-cmake_PhononMacros.cmake.diff
 
 variant pulseaudio description "Build Phonon with additional support for PulseAudio" {
-
     depends_lib-append port:pulseaudio
     configure.args-append \
         -DWITH_PulseAudio=ON \
@@ -103,12 +95,67 @@
         -DPULSEAUDIO_MAINLOOP_LIBRARY=
 }
 
-variant demos description "Build Phonon demos" {
-    configure.args-append -DPHONON_BUILD_DEMOS=ON
+if {${subport} ne "${name}-qt5"} {
+    PortGroup           qt4 1.0
+    PortGroup           cmake 1.0
+    categories          audio kde kde4
+    long_description    Phonon is a multimedia, multi-platform sound \
+        framework for the application developer.
+    # do we really depend on port:automoc, because cmake prints
+    # -- Using CMake automoc builtin
+    depends_build-append    port:automoc
+
+    variant compversion440 description {Build libraries with compatibility version 4.4.0 for existing Qt4 installs expecting that} {
+        # fix the library compatibility version to be 4.4.0
+        patchfiles-append   patch-CMakeLists.txt.diff
+    }
+
+    set LPH libphonon
+    post-destroot {
+
+        global demos_dest_dir
+        if {[variant_isset demos]} {
+            set demos_dest_dir ${destroot}${prefix}/share/examples/phonon
+            xinstall -m 775 -d ${demos_dest_dir}
+            copy ${workpath}/build/demos/simpleplayer/simpleplayer ${demos_dest_dir}
+            copy ${workpath}/build/demos/metadatareader/metadatareader ${demos_dest_dir}
+            copy ${workpath}/build/demos/phota/phota ${demos_dest_dir}
+            copy ${workpath}/build/demos/simplecapture/simplecapture ${demos_dest_dir}
+        }
+
+        if {[variant_isset compversion440]} {
+            # link major library version name
+            ln -s ${prefix}/lib/${LPH}.dylib ${destroot}${prefix}/lib/${LPH}.4.dylib
+            ln -s ${prefix}/lib/${LPH}experimental.dylib ${destroot}${prefix}/lib/${LPH}experimental.4.dylib
+
+            set DLVERS  4.4.0
+        } else {
+            set DLVERS  4
+        }
+
+        # fix library and plugin self-names
+        system "install_name_tool -id ${prefix}/lib/${LPH}.4.dylib ${destroot}${prefix}/lib/${LPH}.dylib"
+        system "install_name_tool -id ${prefix}/lib/${LPH}experimental.4.dylib ${destroot}${prefix}/lib/${LPH}experimental.dylib"
+
+        # fix use of libphonon
+        system "install_name_tool -change lib/${LPH}.${DLVERS}.dylib ${prefix}/lib/${LPH}.4.dylib \
+            ${destroot}${prefix}/lib/${LPH}experimental.dylib"
+        system "install_name_tool -change lib/${LPH}.${DLVERS}.dylib ${prefix}/lib/${LPH}.4.dylib \
+            ${destroot}${qt_plugins_dir}/designer/libphononwidgets.dylib"
+        if {[variant_isset demos]} {
+            system "install_name_tool -change lib/${LPH}.${DLVERS}.dylib ${prefix}/lib/${LPH}.4.dylib \
+                ${demos_dest_dir}/simpleplayer"
+            system "install_name_tool -change lib/${LPH}.${DLVERS}.dylib ${prefix}/lib/${LPH}.4.dylib \
+                ${demos_dest_dir}/metadatareader"
+            system "install_name_tool -change lib/${LPH}.${DLVERS}.dylib ${prefix}/lib/${LPH}.4.dylib \
+                ${demos_dest_dir}/phota"
+            system "install_name_tool -change lib/${LPH}.${DLVERS}.dylib ${prefix}/lib/${LPH}.4.dylib \
+                ${demos_dest_dir}/simplecapture"
+        }
+    }
 }
 
-if {![variant_isset demos]} {
-    configure.args-append -DPHONON_BUILD_DEMOS=OFF
+cmake.out_of_source         yes
 
 post-patch {
     set rel_mp_qt_cmake_dir [strsed ${qt_cmake_module_dir} "g@${prefix}/@@"]
@@ -116,6 +163,15 @@
         ${worksrcpath}/CMakeLists.txt
 }
 
-livecheck.type   regex
-livecheck.url    http://www.gtlib.gatech.edu/pub/kde/stable/${name}/
-livecheck.regex  "\(\\d+(?:\\.\\d+)*)\/"
+# nb: there is no WITH_QZeitgeist option...
+configure.args-append   \
+    ${qt_cmake_defines} \
+    -DPHONON_INSTALL_QT_EXTENSIONS_INTO_SYSTEM_QT=true \
+    -DWITH_QZeitgeist=OFF
+
+configure.ldflags-append -F${qt_frameworks_dir}
+
+
+livecheck.type		regex
+livecheck.url		http://www.gtlib.gatech.edu/pub/kde/stable/${name}/
+livecheck.regex		"\(\\d+(?:\\.\\d+)*)\/"
