--- /opt/local/var/macports/sources/svn.macports.org/trunk/dports/_resources/port1.0/group/kde4-1.1.tcl	2015-11-06 17:45:53.000000000 +0100
+++ kde4-1.1.tcl	2016-10-24 10:36:57.000000000 +0200
@@ -1,5 +1,5 @@
 # -*- coding: utf-8; mode: tcl; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; truncate-lines: t -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
-# $Id: kde4-1.1.tcl 142093 2015-11-03 12:20:58Z nicos@macports.org $
+# $Id: kde4-1.1.tcl 133799 2015-03-11 19:45:29Z mk@macports.org $
 
 # Copyright (c) 2010-2014 The MacPorts Project
 # All rights reserved.
@@ -34,9 +34,14 @@
 # PortGroup     kde4 1.1
 
 # Use CMake and Qt4 port groups
-PortGroup               cmake 1.0
+PortGroup               cmake 1.1
 PortGroup               qt4 1.0
 
+namespace eval kde4 {
+    # our directory:
+    variable currentportgroupdir [file dirname [dict get [info frame 0] file]]
+}
+
 # Make sure to not use any already installed headers and libraries;
 # these are set in CPATH and LIBRARY_PATH anyway.
 configure.ldflags-delete  -L${prefix}/lib
@@ -60,21 +65,121 @@
 # set compiler to Apple's GCC 4.2
 switch ${os.platform}_${os.major} {
     darwin_8 {
-	    configure.compiler	apple-gcc-4.2
+        configure.compiler  apple-gcc-4.2
     }
     darwin_9 {
-	    configure.compiler  gcc-4.2
+        configure.compiler  gcc-4.2
+    }
+}
+
+configure.args-delete   -DCMAKE_BUILD_TYPE=Release
+# force cmake to use the compiler flags passed through CFLAGS, CXXFLAGS etc. in the environment
+configure.args-append   -DCMAKE_BUILD_TYPE:STRING=MacPorts \
+                        -DCMAKE_STRIP:FILEPATH=/bin/echo \
+                        -DCMAKE_USE_RELATIVE_PATHS:BOOL=ON
+
+# Install the kdelibs headerfiles in their own directory to prevent clashes with KF5 headers
+set kde4.include_prefix KDE4
+set kde4.include_dirs   ${prefix}/include/${kde4.include_prefix}
+set kde4.legacy_prefix  ${prefix}/libexec/kde4-legacy
+set kde4.cmake_module_dir \
+                        ${prefix}/lib/cmake/${kde4.include_prefix}
+
+# Certain ports will need to be installed in "KF5 compatibility mode" if they are to co-exist
+# with their KF5 counterparts. Call `kde4.use_legacy_prefix` to activate this mode, *before*
+# the configure step is executed and taking care not to undo the effects.
+# If a legacy prefix is used, the global variable kde4.legacy_prefix_restored will be defined
+# and set to 'no'; it is set to 'yes' by kde4.restore_from_legacy_prefix .
+# An optional boolean argument deactivates the automatic calling of kde4.restore_from_legacy_prefix .
+proc kde4.use_legacy_prefix {{autorestore 1}} {
+    upvar #0 kde4.legacy_prefix_restored restored
+    upvar #0 kde4.legacy_prefix_autorestore dorestore
+    global prefix
+    global kde4.legacy_prefix
+    global kde4.include_dirs
+    configure.pre_args-replace \
+                    -DCMAKE_INSTALL_PREFIX=${prefix} -DCMAKE_INSTALL_PREFIX=${kde4.legacy_prefix}
+    configure.args-replace \
+                    -DCMAKE_INSTALL_RPATH=${prefix}/lib -DCMAKE_INSTALL_RPATH="${prefix}/lib\;${kde4.legacy_prefix}/lib"
+    # changing the install prefix will override the KDE4_INCLUDE_INSTALL_DIR path normally set
+    # to ${kde4.include_dirs} by kdelibs4's cmake modules. Make sure to override it back to that setting.
+    configure.args-append \
+                    -DINCLUDE_INSTALL_DIR=${kde4.include_dirs}
+    set restored no
+    if {(${autorestore} eq 1) || (${autorestore} eq yes)} {
+        set dorestore yes
+    } else {
+        set dorestore no
+    }
+}
+
+# kde4.restore_from_legacy_prefix is called from the post-destroot phase of a port that uses
+# KF5 compatibility mode. That mode is very indiscriminate, installing everything into the
+# legacy_prefix initially. Most things will actually have to be moved back out into the
+# regular prefix. This procedure automates what can be automated, but may also overshoot
+# its goal.
+# See the post-destroot block at the end of this file.
+# After completion, the global variable kde4.legacy_prefix_restored will be set to 'yes'.
+# This procedure is called automatically after calling kde4.use_legacy_prefix ; it can be
+# avoided by calling `kde4.use_legacy_prefix no`
+# This procedure is bound to evolve.
+proc kde4.restore_from_legacy_prefix {} {
+    global destroot
+    global prefix
+    global kde4.legacy_prefix
+    global kde4.cmake_module_dir
+    upvar #0 kde4.legacy_prefix_restored restored
+    if {[info exists restored] && (${restored} eq yes)} {
+        ui_debug "kde4.restore_from_legacy_prefix already called"
+        return
+    }
+    if {[file exists ${destroot}${kde4.legacy_prefix}/lib/kde4]} {
+        # move back the kparts, libexec etc. to where they should be
+        file rename ${destroot}${kde4.legacy_prefix}/lib/kde4 ${destroot}${prefix}/lib/kde4
+    }
+    if {[file exists ${destroot}${kde4.legacy_prefix}/include]} {
+        ui_msg "WARNING: include directory \"${destroot}${kde4.legacy_prefix}/include\" exists!"
+#         # move back the include directory to where it should be;
+#         # first delete the include directory that was created for us and should be empty:
+#         file delete -force ${destroot}${prefix}/include
+#         file rename ${destroot}${kde4.legacy_prefix}/include ${destroot}${prefix}/include
+    }
+    if {[file exists ${destroot}${kde4.legacy_prefix}/share]} {
+        # move back the share directory to where it should be;
+        foreach J [glob -nocomplain ${destroot}${kde4.legacy_prefix}/share/*] {
+            set d [file tail ${J}]
+            file rename ${J} ${destroot}${prefix}/share/${d}
+        }
+    }
+    if {[file exists ${destroot}${kde4.legacy_prefix}/lib/cmake]} {
+        # move back the cmake modules to where they should be
+#         file rename ${destroot}${kde4.legacy_prefix}/lib/cmake ${destroot}${prefix}/lib/cmake
+        xinstall -m 755 -d [file dirname ${destroot}${kde4.cmake_module_dir}]
+        file rename ${destroot}${kde4.legacy_prefix}/lib/cmake ${destroot}${kde4.cmake_module_dir}
     }
+    # check if the "share" symlink is present: it's installed by port:kdelibs4 (which itself doesn't
+    # have need for a kf5compat variant or the legacy_prefix).
+    if {![file exists ${kde4.legacy_prefix}/share]} {
+        ui_msg "WARNING: the installed port:kdelibs4 does not provide ${kde4.legacy_prefix}/share!"
+        notes-append "WARNING: the installed port:kdelibs4 does not provide ${kde4.legacy_prefix}/share!"
+    }
+    set restored yes
 }
 
 # augment the CMake module lookup path, if necessary depending on
 # where Qt4 is installed.
 if {${qt_cmake_module_dir} ne ${cmake_share_module_dir}} {
-    set cmake_module_path ${cmake_share_module_dir}\;${qt_cmake_module_dir}
-    configure.args-delete -DCMAKE_MODULE_PATH=${cmake_share_module_dir}
-    configure.args-append -DCMAKE_MODULE_PATH="${cmake_module_path}"
-    unset cmake_module_path
+    ui_debug "set cmake_module_path kde4.cmake_module_dir\;cmake_share_module_dir\;qt_cmake_module_dir"
+    set cmake_module_path ${kde4.cmake_module_dir}\;${cmake_share_module_dir}\;${qt_cmake_module_dir}
+} else {
+    # prepend our own (new) install location for cmake modules:
+    ui_debug "set cmake_module_path kde4.cmake_module_dir\;cmake_share_module_dir"
+    set cmake_module_path ${kde4.cmake_module_dir}\;${cmake_share_module_dir}
 }
+ui_debug "cmake_module_path=${cmake_module_path}"
+configure.args-delete -DCMAKE_MODULE_PATH=${cmake_share_module_dir}
+configure.args-append -DCMAKE_MODULE_PATH="${cmake_module_path}" \
+                        -DCMAKE_PREFIX_PATH="${cmake_module_path}"
 
 # standard configure args; virtually all KDE ports use CMake and Qt4.
 configure.args-append   -DBUILD_doc=OFF \
@@ -86,6 +191,13 @@
 
 # explicitly define certain headers and libraries, to avoid
 # conflicts with those installed into system paths by the user.
+# 20151015 RJVB : these are handled in FindMySQL.cmake :
+#                         -DMYSQL_INCLUDE_DIR=${prefix}/include/mysql5/mysql \
+#                         -DMYSQL_LIB_DIR=${prefix}/lib/mysql5/mysql \
+# 20151015 RJVB : these are best left to port select ...
+#                         -DMYSQLCONFIG_EXECUTABLE=${prefix}/bin/mysql_config5 \
+#                         -DMYSQLD_EXECUTABLE=${prefix}/libexec/mysqld \
+
 configure.args-append   -DDOCBOOKXSL_DIR=${prefix}/share/xsl/docbook-xsl \
                         -DGETTEXT_INCLUDE_DIR=${prefix}/include \
                         -DGETTEXT_LIBRARY=${prefix}/lib/libgettextlib.dylib \
@@ -121,11 +233,6 @@
 # These two can be removed (see #46240):
 #                        -DQCA2_INCLUDE_DIR=${prefix}/include/QtCrypto \
 #                        -DQCA2_LIBRARIES=${prefix}/lib/libqca.dylib \
-# These ones are obsolete, as purely based on mysql5 paths (see #49296):
-#                        -DMYSQLD_EXECUTABLE=${prefix}/libexec/mysqld \
-#                        -DMYSQL_INCLUDE_DIR=${prefix}/include/mysql5/mysql \
-#                        -DMYSQL_LIB_DIR=${prefix}/lib/mysql5/mysql \
-#                        -DMYSQLCONFIG_EXECUTABLE=${prefix}/bin/mysql_config5 \
 
 # standard variant for building documentation
 variant docs description "Build documentation" {
@@ -133,7 +240,54 @@
     configure.args-delete   -DBUILD_doc=OFF -DBUILD_docs=OFF
 }
 
-notes "
+if {[info exist ::env(MACPORTS_COMPRESS_WORKDIR)] && $::env(MACPORTS_COMPRESS_WORKDIR)} {
+    post-build {
+        if {[file exists ${prefix}/bin/afsctool]} {
+            ui_msg "--->  Compressing build directory ..."
+            if {[catch {system "${prefix}/bin/afsctool -cfvv -8 -J${build.jobs} ${build.dir} 2>&1"} result context]} {
+                ui_msg "Compression failed: ${result}, ${context}; port:afsctool is probably installed without support for parallel compression"
+            } else {
+                ui_debug "Compressing ${build.dir}: ${result}"
+            }
+        }
+    }
+}
+
+post-destroot {
+    if {[info exists kde4.legacy_prefix_autorestore]} {
+        # check if we need to do automatic restoring (the default). We do that here because this post-destroot
+        # block should be the first such block. In other words, the calling Portfile should not yet have had
+        # a chance to modify the destroot in ways that kde4.restore_from_legacy_prefix might overwrite.
+        # kde4.restore_from_legacy_prefix checks itself if it already completed once.
+        if {(${kde4.legacy_prefix_autorestore} eq yes) || (${kde4.legacy_prefix_autorestore} eq 1)} {
+            ui_debug "doing requested auto kde4.restore_from_legacy_prefix (${kde4.legacy_prefix_autorestore})"
+            kde4.restore_from_legacy_prefix
+        }
+    }
+    if {![info exists kde4.legacy_prefix_restored] || ${kde4.legacy_prefix_restored} eq no} {
+        # move the port's cmake modules to ${kde4.cmake_module_dir}. This is an operation that might
+        # be overwritten if the Portfile calls kde4.restore_from_legacy_prefix afterwards, hence the
+        # call to that function just above.
+        if {[file exists ${destroot}${prefix}/lib/cmake]} {
+            # avoid a loop construct here (and a direct rename may not work, e.g. lib/cmake -> lib/cmake/KDE4 won't)
+            # move the directory out of the way
+            file rename ${destroot}${prefix}/lib/cmake ${destroot}/cmake_temp_dir
+            # create the parent for ${kde4.cmake_module_dir}
+            xinstall -m 755 -d [file dirname ${destroot}${kde4.cmake_module_dir}]
+            # move the temp dir into place
+            file rename ${destroot}/cmake_temp_dir ${destroot}${kde4.cmake_module_dir}
+        }
+    }
+}
+
+post-activate {
+    if {[file exists ${prefix}/bin/kbuildsycoca4]} {
+        ui_msg "--->  Updating KDE's global desktop file system configuration cache ..."
+        system "${prefix}/bin/kbuildsycoca4 --global"
+    }
+}
+
+notes-append "
 Don't forget that dbus needs to be started as the local\
 user (not with sudo) before any KDE programs will launch.
 To start it run the following command:
