# -*- 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 114886 2013-12-19 10:42:05Z ryandesign@macports.org $

PortSystem              1.0
PortGroup               muniversal 1.0

name                    cyrus-sasl2
version                 2.1.26
revision                3
categories              security net
platforms               darwin
# license is BSD plus a fourth (almost redundant) acknowledgement clause
license                 Permissive
maintainers             jmpp landonf openmaintainer

description             SASL is an authentication library.

long_description        SASL is the Simple Authentication and Security Layer, \
                        a method for adding authentication support to \
                        connection-based protocols. To use SASL, a protocol \
                        includes a command for identifying and authenticating \
                        a user to a server and for optionally negotiating \
                        protection of subsequent protocol interactions. If \
                        its use is negotiated, a security layer is inserted \
                        between the protocol and the connection.

homepage                http://cyrusimap.org/
master_sites            http://cyrusimap.org/releases/ \
                        ftp://ftp.cyrusimap.org/cyrus-sasl/
distname                cyrus-sasl-${version}

checksums               rmd160  861a06d663cf3da37a198d0f971d99b249b5f4b8 \
                        sha256  8fbc5136512b59bb793657f36fadda6359cae3b08f01fd16b3d406f1345b7bc3

depends_lib             port:openssl \
                        port:zlib

default_variants        +kerberos

patchfiles              patch-libsasl2.pc.in.diff \
                        patch-ltconfig_rpath_fallback.diff \
                        patch-utils_Makefile.in.diff \
                        patch-sasl.h-size_t.diff

configure.args          --mandir=${prefix}/share/man \
                        --with-openssl=${prefix} \
                        --with-dbpath=${prefix}/etc/sasldb2 \
                        --with-plugindir=${prefix}/lib/sasl2 \
                        --with-saslauthd=${prefix}/var/state/saslauthd \
                        --with-pwcheck=${prefix}/var/pwcheck \
                        --disable-macos-framework \
                        --enable-srp \
                        --enable-srp-setpass \
                        --enable-login \
                        --enable-ntlm \
                        --with-rc4=openssl

use_parallel_build      no

#universal_variant       no

# This is a start towards universal... lib/Makefile.am and sasldb/Makefile.am need to be updated to not do blind ar-fu
#post-extract {
#    system "rm ${worksrcpath}/config/libtool.m4"
#}

#use_autoreconf          yes
#autoreconf.args         -fvi
#autoreconf.env          ACLOCAL="aclocal -I${worksrcpath}/cmulocal -I${worksrcpath}/config"

# This is a horrible hackaround as replacing the ar-fu as mentioned above is non-trivial
pre-build {
    if {[variant_isset universal]} {
        foreach arch ${universal_archs_to_use} {
            reinplace -E "s|^CC=\\\"(\[^\\\"\]+)\\\"|CC=\"\\1 [muniversal_get_arch_flag ${arch}]\"|g" ${worksrcpath}-${arch}/libtool
        }
    } else {
        reinplace -E "s|^CC=\\\"(\[^\\\"\]+)\\\"|CC=\"\\1 ${configure.cc_archflags}\"|g" ${worksrcpath}/libtool
    }
}

destroot.keepdirs       ${destroot}${prefix}/var/state/saslauthd \
                        ${destroot}${prefix}/var/pwcheck

post-destroot {
    xinstall -d \
        ${destroot}${prefix}/share/doc \
        ${destroot}${prefix}/var/state/saslauthd \
        ${destroot}${prefix}/var/pwcheck
    
    file copy ${worksrcpath}/doc ${destroot}${prefix}/share/doc/${name}
}

variant kerberos description "Enable Kerberos support" {
    configure.args-append   --enable-keep-db-open
    
    if {${os.platform} eq "darwin"} {
        depends_lib-append  port:kerberos5
        configure.args-append --with-gss_impl=mit \
            --enable-gssapi=${prefix}
    }
    if {${os.platform} eq "freebsd"} {
        depends_lib-append  port:heimdal
        configure.args-append --with-gss_impl=heimdal \
            --enable-gssapi=${prefix}/libexec/heimdal
    }
}

variant sql description "Enable SQL support" {
    depends_lib-append      port:sqlite3
    configure.args-append   --enable-sql
}

# doesn't work, ticket #22093
#variant static description "Build static library" {
#    configure.args-append   --enable-static
#}

livecheck.type          regex
livecheck.regex         {cyrus-sasl-(\d+(?:\.\d+)*)\.tar\.gz}
