--- /opt/local/var/macports/sources/svn.macports.org/trunk/dports/devel/qca/Portfile	2016-10-25 21:27:15.000000000 +0200
+++ Portfile	2016-10-25 21:52:24.000000000 +0200
@@ -1,125 +1,94 @@
 # -*- 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 154192 2016-10-24 00:00:00Z michaelld@macports.org $
+# $Id: Portfile 128101 2014-11-13 09:19:56Z ryandesign@macports.org $
 
 PortSystem          1.0
-PortGroup           cmake 1.0
-PortGroup           active_variants 1.1
 
 name                qca
-version             2.1.0
-revision            3
-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
+    revision        4
+    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.1
+cmake.out_of_source yes
+
 categories          devel crypto security
-maintainers         nomaintainer
+maintainers         gmail.com:rjvbertin openmaintainer
 license             LGPL-2.1
-
-description "Qt Cryptographic Architecture"
+description         Qt Cryptographic Architecture
 long_description \
-    "Qt Cryptographic Architecture provides an easy API for the following \
-     features: SSL/TLS, X509, SASL, RSA, Hashing (SHA1, MD5), Ciphers \
-     (BlowFish, 3DES, AES).  Functionality is supplied via plugins."
+    Qt Cryptographic Architecture provides an easy API for the following \
+    features: SSL/TLS, X509, SASL, RSA, Hashing (SHA1, MD5), Ciphers \
+    (BlowFish, 3DES, AES).  Functionality is supplied via plugins.
 
 platforms           darwin
 
 homepage            http://delta.affinix.com/qca/
-master_sites        http://delta.affinix.com/download/qca/2.0/
-
-checksums           rmd160 30358bbd182cfeb9eaa696b5b39fa9e6d1f99b4c \
-                    sha256 226dcd76138c3738cdc15863607a96b3758a4c3efd3c47295939bcea4e7a9284
-
-# do VPATH (out of source tree) build
-
-cmake.out_of_source yes
-
-if {${name} eq ${subport}} {
-
-    # temporary patch to add including QIODevice to qca_basic.h
-
-    patchfiles-append patch-include_QtCrypto_qca_basic.h.diff
-
-    # fix install directories for certs and cmake files
-
-    patchfiles-append patch-CMakeLists.txt.diff
-
-    # remove unnecessary Carbon #include, which fails on 10.8
-
-    patchfiles-append patch-src_qac_systemstore_mac.cpp.diff
-
-} else {
-    # fix top-level CMakeLists.txt to build just plugins
-    patchfiles-append patch-CMakeLists.txt_plugins.diff
-}
-
-# Qt variants
-
-variant qt4 conflicts qt5 description "Build with qt4" {}
-
-variant qt5 conflicts qt4 description "Build with qt5" {}
-
-if {![variant_isset qt4] && ![variant_isset qt5]} {
-    default_variants +qt4
-}
-
-# make sure -qt4 wasn't specified alone
-
-if {![variant_isset qt4] && ![variant_isset qt5]} {
-    ui_error "\n\nYou must select either the +qt4 or +qt5 variant to build ${subport}\n"
-    return -code error "Invalid variant selection"
-}
-
-if {${name} eq ${subport}} {
-    if {[variant_isset qt4]} {
-        PortGroup qt4 1.0
-        configure.args-append -DQT4_BUILD=ON
-    } else {
-        PortGroup qt5 1.0
-    }
-} else {
-    # require qca to also have the selected Qt variant
-    if {[variant_isset qt4]} {
-        PortGroup qt4 1.0
-        require_active_variants port:qca qt4
-        configure.args-append -DQT4_BUILD=ON
-    } else {
-        PortGroup qt5 1.0
-        require_active_variants port:qca qt5
-    }
-}
-
-variant examples description {Include examples in install} {}
 
-# set install directory for mkspec files
-
-configure.args-append \
-    -DQCA_FEATURE_INSTALL_DIR=${qt_mkspecs_dir}
-
-# specify various configure options
-
-configure.args-append \
-    -DQCA_INSTALL_IN_QT_PREFIX=NO \
-    -DQCA_PLUGINS_INSTALL_DIR=${prefix}/share/${name}/plugins
-
-if {${name} eq ${subport}} {
-
-    # build as a framework
+depends_lib-append  port:botan \
+                    port:libgcrypt \
+                    port:nss
+
+# # check for standard port:qt4-mac and/or port:qt5 instead of port:qt5-kde
+# if {![file exists ${prefix}/lib/pkgconfig/QtCore.pc] && ![info exists qt5.using_kde] && !${qt5.using_kde}} {
+# }
+
+# remove unnecessary Carbon #include, which fails on 10.8
+patchfiles-append   patch-src_qac_systemstore_mac.cpp.diff
+
+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 \
-        -DOSX_FRAMEWORK=YES
-
-    # specify various configure options
-
+                        -DQT4_BUILD:BOOL=ON
+} elseif {${Qt_Major} eq "5"} {
+    patchfiles-append   patch-qca210-qt550.diff \
+                        patch-qca210-qt56x.diff
     configure.args-append \
-        -DBUILD_PLUGINS=NO \
-        -DQCA_MAN_INSTALL_DIR=${prefix}/share/man \
-        -DQCA_LIBRARY_INSTALL_DIR=${frameworks_dir} \
-        -DCMAKE_MODULES_DIR=${prefix}/share/cmake \
-        -DPKGCONFIG_INSTALL_PREFIX=${prefix}/lib/pkgconfig \
-        -DQCA_DOC_INSTALL_DIR=${prefix}/share/${name}/doc
-
+                        -DQCA_SUFFIX:STRING="qt5"
 }
 
 # allow ccache, if specified by the user
-
 pre-build {
     if {[tbool configure.ccache]} {
         build.post_args "CCACHE=ccache"
@@ -127,97 +96,102 @@
 }
 
 post-destroot {
-
-    if {${name} eq ${subport}} {
-
+    if {${subport} eq ${name} || ${subport} eq "${subport}-qt5"} {
         # install docs
-
-        xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
+        xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}
         xinstall -m 644 -W ${worksrcpath} COPYING README TODO \
-            ${destroot}${prefix}/share/doc/${name}
-
-        # get qca's version numbers
-
-        set qca_vers [split ${version} "."]
-        set qca_major [lindex ${qca_vers} 0]
-        set qca_minor [lindex ${qca_vers} 1]
-        set qca_patch [lindex ${qca_vers} 2]
-
-        # link includes and libraries for each actual installed framework
-
-        set tf_full ${frameworks_dir}/qca.framework/Versions/${version}
-
-        # link headers into ${prefix}/include, removing
-        # directories if they are already there first
-
-        set dr_inc_file ${destroot}${prefix}/include
-        ln -s ${tf_full}/Headers ${dr_inc_file}/qca
-        ln -s ${tf_full}/Headers ${dr_inc_file}/QtCrypto
-
-        # link libraries into ${dr_libs_dir}, all 4 number variants
+            ${destroot}${prefix}/share/doc/${subport}
+    }
 
-        set dr_libs_dir ${destroot}${prefix}/lib
-        ln -s ${tf_full}/qca ${dr_libs_dir}/libqca.dylib
-        ln -s ${tf_full}/qca ${dr_libs_dir}/libqca.${qca_major}.dylib
-        ln -s ${tf_full}/qca ${dr_libs_dir}/libqca.${qca_major}.${qca_minor}.dylib
-        ln -s ${tf_full}/qca ${dr_libs_dir}/libqca.${qca_major}.${qca_minor}.${qca_patch}.dylib
+    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}
 
-        if {[variant_isset examples]} {
-            xinstall -d -m 755 ${destroot}${prefix}/share/examples/${name}
-            eval file copy [glob ${worksrcpath}/examples/*] \
-                ${destroot}${prefix}/share/examples/${name}
-        }
     }
 }
 
-array set bindings {
-    botan       {port:botan       botan}
-    cyrus-sasl  {port:cyrus-sasl2 cyrus-sasl}
-    gcrypt      {port:libgcrypt   gcrypt}
-    gnupg       {port:gnupg       gnupg}
-    logger      {""               logger}
-    nss         {port:nss         nss}
-    ossl        {path:lib/libssl.dylib:openssl ossl}
-    softstore   {""               softstore}
-}
-#    pkcs11      {port:pkcs11      pkcs11}
-array set prettynames {
-    botan Botan cyrus-sasl Cyrus-SASL gcrypt GCrypt
-    gnupg GnuPG logger Logger nss NSS
-    ossl OpenSSL pkcs11 pkcs11 softstore SoftStore
-}
-
-options qca.plugin
-default qca.plugin ""
-
-foreach plugin [lsort [array names bindings]] {
-    set arg      [lindex $bindings($plugin) 1]
-    set arg_name [lindex [split ${arg} =] 0]
-    subport qca-${plugin} {
-        if {[lindex $bindings($plugin) 0] ne ""} {
-            depends_lib-append [lindex $bindings($plugin) 0]
-        }
-        configure.args-append  -DWITH_${arg}_PLUGIN=ON
-        qca.plugin             ${arg_name}
-    }
-    if {${qca.plugin} != ${arg_name}} {
-        configure.args-append -DWITH_${arg_name}_PLUGIN=OFF
-    }
+# 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} {
+    ui_msg "this variant is obsolete; use configure.optflags=\"-g\""
+    PortGroup   obsolete 1.0
 }
-if {${qca.plugin} ne ""} {
-    description $prettynames(${qca.plugin}) plugin for ${name}
-    long_description \
-        Qt Cryptographic Architecture. This is the \
-        $prettynames(${qca.plugin}) plugin.
-    depends_lib-append port:qca
-    livecheck.type none
-} else {
-    livecheck.type  regex
-    livecheck.url   ${homepage}
-    livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
+
+# avoid installing the examples into Qt's binary tree
+variant examples description \
+{Include examples in install} {
+    post-destroot {
+        xinstall -d -m 755 ${destroot}${prefix}/share/${subport}/examples/
+        eval file copy [glob ${worksrcpath}/examples/*] \
+            ${destroot}${prefix}/share/${subport}/examples/
+    }
 }
 
+# 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
+    }
+    foreach virtual {"botan" "gcrypt" "logger" "nss" "softstore"} {
+        subport ${name}${qv}-${virtual} {
+            archive_sites
+            distfiles
+            depends_lib         port:${name}${qv}
+            use_configure       no
+            supported_archs     noarch
+            patchfiles
+            build {}
+            destroot {
+                set stubdir ${destroot}${prefix}/share/doc/${subport}
+                xinstall -d -m 755 ${stubdir}
+                system "touch ${stubdir}/this.is.a.stubport"
+            }
+        }
+    }
+}
+
+livecheck.type  regex
+livecheck.url   ${master_sites}
