# -*- 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 85457 2011-10-14 01:10:46Z michaelld@macports.org $

PortSystem          1.0
PortGroup           qt4 1.0

name                qca
version             2.0.3
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          devel crypto security
maintainers         michaelld openmaintainer
license             LGPL-2.1
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.

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

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

# allow ccache, if specified by the user
pre-build {
    if {[tbool configure.ccache]} {
        build.post_args "CCACHE=ccache"
    }
}

post-destroot {
    # alias to destroot QCA top-level directory
    set destroot_qt ${destroot}${qt_dir}

    # install docs
    xinstall -d 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 755 ${destroot}${qt_cmake_module_dir}
    xinstall -m 644 -W ${filespath} FindQCA2.cmake \
        ${destroot}${qt_cmake_module_dir}
}

variant debug description \
{Build both release and debug library} {
    configure.args-delete --release
    configure.args-append --debug-and-release
}

variant examples description \
{Include examples in install} {
    post-destroot {
        xinstall -d 755 ${destroot}${qt_dir}/share/examples/${name}
        eval file copy [glob ${worksrcpath}/examples/*] \
            ${destroot}${qt_dir}/share/examples/${name}
    }
}

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
    }
}

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}"
