--- /opt/local/var/macports/sources/default-ports/devel/qca.orig/Portfile	2014-11-13 10:30:32.000000000 +0100
+++ /opt/local/site-ports/devel/qca/Portfile	2016-02-01 13:24:07.000000000 +0100
@@ -2,14 +2,38 @@
 # $Id: Portfile 128101 2014-11-13 09:19:56Z ryandesign@macports.org $
 
 PortSystem          1.0
-PortGroup           qt4 1.0
 
 name                qca
-version             2.0.3
-revision            1
-set branch          [join [lrange [split ${version} .] 0 1] .]
+
+# Qt version handling logic
+global Qt_Major
+subport ${name}-qt5 {}
+if {[string match "${name}-qt5*" ${subport}]} {
+    version         2.1.0.3
+    PortGroup       qt5 1.0
+    set Qt_Major    5
+    master_sites    http://download.kde.org/stable/qca-qt5/${version}/src
+    checksums       rmd160  cc4040d013170ca5f21fbcefd0607daa8191d333 \
+                    sha256  ab0170696a8ff87588d38a72d36d0b4b42db9080c991d1a40ceb3f8311d289f9
+    use_xz          yes
+    distname        "qca-qt5-${version}"
+    livecheck.regex "qca-qt5-(\\d+(?:\\.\\d+)*)"
+} else {
+    version         2.1.0
+    set branch      [join [lrange [split ${version} .] 0 0] .]
+    PortGroup       qt4 1.0
+    set Qt_Major    4
+    master_sites    http://delta.affinix.com/download/qca/${branch}.0/
+    checksums       md5     c2b00c732036244701bae4853a2101cf \
+                    sha1    2b582b3ccc7e6098cd14d6f52a829ae1539e9cc8 \
+                    rmd160  30358bbd182cfeb9eaa696b5b39fa9e6d1f99b4c
+    livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)"
+}
+PortGroup           cmake 1.0
+cmake.out_of_source yes
+
 categories          devel crypto security
-maintainers         michaelld openmaintainer
+maintainers         michaelld gmail.com:rjvbertin openmaintainer
 license             LGPL-2.1
 description         Qt Cryptographic Architecture
 long_description \
@@ -17,55 +41,46 @@
     features: SSL/TLS, X509, SASL, RSA, Hashing (SHA1, MD5), Ciphers \
     (BlowFish, 3DES, AES).  Functionality is supplied via plugins.
 
-platforms            darwin
+platforms           darwin
 
-homepage             http://delta.affinix.com/qca/
-master_sites         http://delta.affinix.com/download/qca/${branch}/
-use_bzip2            yes
-
-checksums            md5     fc15bd4da22b8096c51fcfe52d2fa309 \
-                     sha1    9c868b05b81dce172c41b813de4de68554154c60 \
-                     rmd160  333cfdce91fedfaec09c205528de52d7b569c521
-
-# (1) correct pkgconfig file for framework install, if selected.
-# (2) allow for 'debug' and 'framework' options at the same time.
-#     This change is needed to allow for +debug [+framework] --
-#     disallow just debug framework via no variants for it.
-# (3) allow simple replacement for universal arch arguments, if that
-#     variant is requested.
-patchfiles           patch-configure.diff
+homepage            http://delta.affinix.com/qca/
 
-# fix C++ inheritance for a specific class to make clang happy
-patchfiles-append    patch-src_botantools_botan_botan_secmem.h.diff
+depends_lib-append  port:botan \
+                    port:libgcrypt \
+                    port:nss
 
 # remove unnecessary Carbon #include, which fails on 10.8
-patchfiles-append    patch-src_qac_systemstore_mac.cpp.diff
+patchfiles-append   patch-src_qac_systemstore_mac.cpp.diff
 
-post-patch {
-    # set arch type(s)
-    reinplace "s|@ARCHES@|${qt_arch_types}|g" \
-        ${worksrcpath}/configure
-
-    # since Qt now uses the correct install_name for libraries,
-    # remove that from QCA's library
-    reinplace "/QMAKE_LFLAGS_SONAME/d" \
-        ${worksrcpath}/src/src.pro
-}
-
-# set QCA to install into the QT4 directory
-configure.pre_args   --prefix=${qt_dir}
-
-# defaults: release only, no-framework, specific build_arch.
-# use variants to change everything except framework
-configure.args        --verbose         \
-                      --qtdir=${qt_dir} \
-                      --release         \
-                      --no-framework
-
-# QCA's configure does not handle this flag,
-# but does not generate an error either.
-configure.universal_args-delete --disable-dependency-tracking
-configure.args-delete  --disable-dependency-tracking
+patchfiles-append   patch-qca-ossl.diff
+
+# 1) it seems that configure.pre_args --prefix=${qt_dir} has the desired effect, but
+# I don't know to what extent that uses an undocumented cmake feature, so use
+# the exhaustive list of install variables.
+# 2) the QCA plugins have been rolled into the main source tarball and are built by default
+# when their dependencies are available. Allow this for all plugins that were not already
+# available through an individual port; no reason to impose new dependencies on our dependents.
+configure.args          -DCMAKE_INSTALL_PREFIX:PATH=${qt_dir} \
+                        -DQCA_PLUGINS_INSTALL_DIR:PATH=${qt_plugins_dir} \
+                        -DQCA_LIBRARY_INSTALL_DIR:PATH=${qt_libs_dir} \
+                        -DQCA_BINARY_INSTALL_DIR:PATH=${qt_bins_dir} \
+                        -DQCA_FEATURE_INSTALL_DIR:PATH=${qt_mkspecs_dir}/features \
+                        -DQCA_INCLUDE_INSTALL_DIR:PATH=${qt_includes_dir} \
+                        -DQCA_PRIVATE_INCLUDE_INSTALL_DIR:PATH=${qt_includes_dir} \
+                        -DQCA_DOC_INSTALL_DIR:PATH=${qt_docs_dir} \
+                        -DQCA_MAN_INSTALL_DIR:PATH=${prefix}/share/man \
+                        -DPKGCONFIG_INSTALL_PREFIX:PATH=${qt_pkg_config_dir} \
+                        -DOSX_FRAMEWORK:BOOL=OFF \
+                        -DBUILD_PLUGINS:STRING="botan\;gcrypt\;logger\;nss\;softstore"
+
+if {${Qt_Major} eq "4"} {
+    configure.args-append \
+                        -DQT4_BUILD:BOOL=ON
+} elseif {${Qt_Major} eq "5"} {
+    patchfiles-append   patch-qca210-qt550.diff
+    configure.args-append \
+                        -DQCA_SUFFIX:STRING="qt5"
+}
 
 # allow ccache, if specified by the user
 pre-build {
@@ -75,50 +90,86 @@
 }
 
 post-destroot {
-    # alias to destroot QCA top-level directory
-    set destroot_qt ${destroot}${qt_dir}
+    if {${subport} eq ${name} || ${subport} eq "${subport}-qt5"} {
+        # install docs
+        xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}
+        xinstall -m 644 -W ${worksrcpath} COPYING README TODO \
+            ${destroot}${prefix}/share/doc/${subport}
+    }
 
-    # install docs
-    xinstall -d -m 755 ${destroot_qt}/share/doc/${name}
-    xinstall -m 644 -W ${worksrcpath} COPYING README TODO \
-        ${destroot_qt}/share/doc/${name}
-
-    # install cmake file (taken from port 'kdelibs4'). To use this
-    # file, include '-DCMAKE_MODULE_PATH=...' in configure.args during
-    # the initial 'configure' stage (which uses CMake), to the full
-    # path of where the CMake files are installed.
-    xinstall -d -m 755 ${destroot}${qt_cmake_module_dir}
-    xinstall -m 644 -W ${filespath} FindQCA2.cmake \
-        ${destroot}${qt_cmake_module_dir}
+    if {${subport} eq "${name}"} {
+        # install cmake file (taken from port 'kdelibs4'). To use this
+        # file, include '-DCMAKE_MODULE_PATH=...' in configure.args during
+        # the initial 'configure' stage (which uses CMake), to the full
+        # path of where the CMake files are installed.
+        # note that QCA 2.1+ also installs .cmake files in ${qt_libs_dir}/cmake/Qca; I don't
+        # see a reason to move those so I'm leaving them there.
+        xinstall -d -m 755 ${destroot}${qt_cmake_module_dir}
+        xinstall -m 644 -W ${filespath} FindQCA2.cmake \
+            ${destroot}${qt_cmake_module_dir}
+
+    }
 }
 
+# NB: it doesn't seem possible to build this way with the new cmake-based approach
 variant debug description \
 {Build both release and debug library} {
-    configure.args-delete --release
-    configure.args-append --debug-and-release
+    ui_msg "this variant is obsolete; use configure.optflags=\"-g\""
+    PortGroup   obsolete 1.0
 }
 
+# avoid installing the examples into Qt's binary tree
 variant examples description \
 {Include examples in install} {
     post-destroot {
-        xinstall -d -m 755 ${destroot}${qt_dir}/share/examples/${name}
+        xinstall -d -m 755 ${destroot}${prefix}/share/${subport}/examples/
         eval file copy [glob ${worksrcpath}/examples/*] \
-            ${destroot}${qt_dir}/share/examples/${name}
+            ${destroot}${prefix}/share/${subport}/examples/
     }
 }
 
-platform darwin 8 {
-    # might not be necessary
-    if {[variant_exists universal] && [variant_isset universal]} {
-        configure.args-append --mac-sdk=${developer_dir}/SDKs/MacOSX10.4u.sdk
+# NB: I haven't yet tested universal variants; those may require the muniversal portgroup
+# variant universal {
+#     # Add the universal flag understood by qmake
+#     configure.universal_args-append --universal
+# }
+
+subport qca-tls {
+    replaced_by qca-ossl
+    PortGroup obsolete 1.0
+    long_description "This port is obsolete."
+}
+
+### The ossl, cyrus-sasl and gnupg plugins that used to be standalone ports.
+### It makes more sense IMHO to implement them as subports. The other plugins
+### are built together with the main port; I don't see a reason to introduce
+### new subports for components that used to be built along with the main ports,
+### only to impose new dependencies on the ports that require qca.
+# Qt4 receives no suffix:
+set qt.versions     {"" "-qt5"}
+foreach qv ${qt.versions} {
+    subport ${name}${qv}-ossl {
+        license                 LGPL-2.1+
+        depends_lib-append      port:${name}${qv} port:openssl
+        configure.args-delete   -DBUILD_PLUGINS:STRING="botan\;gcrypt\;logger\;nss\;softstore"
+        configure.args-append   -DBUILD_PLUGINS:STRING="ossl"
+        build.dir               ${workpath}/build/plugins/qca-ossl
+    }
+    subport ${name}${qv}-cyrus-sasl {
+        license                 LGPL-2.1+
+        depends_lib-append      port:${name}${qv} port:cyrus-sasl2
+        configure.args-delete   -DBUILD_PLUGINS:STRING="botan\;gcrypt\;logger\;nss\;softstore"
+        configure.args-append   -DBUILD_PLUGINS:STRING="cyrus-sasl"
+        build.dir               ${workpath}/build/plugins/qca-cyrus-sasl
+    }
+    subport ${name}${qv}-gnupg {
+        license                 LGPL-2.1+
+        depends_lib-append      port:${name}${qv}
+        configure.args-delete   -DBUILD_PLUGINS:STRING="botan\;gcrypt\;logger\;nss\;softstore"
+        configure.args-append   -DBUILD_PLUGINS:STRING="gnupg"
+        build.dir               ${workpath}/build/plugins/qca-gnupg
     }
-}
-
-variant universal {
-    # Add the universal flag understood by qmake
-    configure.universal_args-append --universal
 }
 
 livecheck.type  regex
-livecheck.url   ${homepage}
-livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
+livecheck.url   ${master_sites}
