# -*- 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

PortSystem          1.0
PortGroup           python 1.0
PortGroup           openssl 1.0

name                py-m2crypto
version             0.40.1
revision            0
categories-append   crypto devel
platforms           darwin
# demos include some Apache-2 and ZPL-2 files but are not installed
license             MIT
maintainers         {gmail.com:allan.que @aque} openmaintainer

description         Crypto and SSL toolkit for Python
long_description    M2Crypto is the most complete Python wrapper for OpenSSL.
homepage            https://pypi.python.org/pypi/${python.rootname}

master_sites        pypi:m/${python.rootname}/
distname            M2Crypto-${version}
checksums           size    1266138 \
                    rmd160  743a52c4da8ef7b06bba4009497f51117730744f \
                    sha256  bbfd113ec55708c05816252a4f09e4237df4f3bbfc8171cbbc33057d257bbb30

python.versions    27 310 311 312

if {${name} ne ${subport}} {
    depends_build           port:py${python.version}-setuptools
    depends_lib-append      port:swig-python \
                            path:lib/libssl.dylib:openssl

    if {${python.version} < 35} {
        depends_lib-append  port:py${python.version}-typing
    }

    if {${python.version} < 38} {
        openssl.branch      1.1
    } else {
        openssl.branch      3
    }
    set openssl_nodot       [string map {. {}} openssl${openssl.branch}]
    set openssl_path        ${prefix}/libexec/${openssl_nodot}

    if {${python.version} > 36} {
        depends_lib-append  port:py${python.version}-importlib-metadata
        build.cmd-append    --config-setting openssl=${openssl_path}

        if {${python.version} < 312} {
            depends_test-append port:py${python.version}-parameterized
        }
    } else {
        build.cmd-append    build_ext --openssl=${openssl_path}
    }

    patchfiles              patch-setup.py.diff

    if {${os.platform} eq "darwin" && ${os.major} >= 20} {
        build.env-append    "SWIG_FEATURES=\
            -I${openssl_path}/include \
            -I${configure.sdkroot}/usr/include \
            -cpperraswarn"
    } else {
        build.env-append    "SWIG_FEATURES=\
            -I${openssl_path}/include"
    }

    test.run                yes

    livecheck.type          none
}
