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

# Quoth the makefile: "[Multiple-architecture building] is rather trouble-prone
# because the low-level crypto code has to configure itself for CPU endianness
# and word size for the algorithms that require low-level bit fiddling, and
# uses different code strategies depending on the CPU architecture and bit
# width. This single-pass build for multiple architectures often causes
# problems, and you're more or less on your own if you decide to try it."
PortGroup           muniversal 1.0

name                cryptlib
version             3.4.8
revision            0
checksums           rmd160  81b08bff5f48586788d5fcfa6677a84794df4dae \
                    sha256  ba34d50be7061b59d3cd49ff36c6c12603c3e23b9354b61d818ff8fd8843893a \
                    size    7170491

set branch          [join [lrange [split ${version} .] 0 1] .]
categories          devel security crypto
maintainers         {ryandesign @ryandesign} openmaintainer
license             {Sleepycat Restrictive}

description         cryptlib is a powerful security toolkit (library)

long_description    cryptlib is a powerful security toolkit that allows even \
                    inexperienced crypto programmers to easily add encryption \
                    and authentication services to their software. The \
                    high-level interface provides anyone with the ability to \
                    add strong security capabilities to an application in as \
                    little as half an hour, without needing to know any of \
                    the low-level details that make the encryption or \
                    authentication work.

homepage            https://www.cs.auckland.ac.nz/~pgut001/cryptlib/
master_sites        https://cryptlib-release.s3-ap-southeast-1.amazonaws.com/
distname            ${name}[join [split ${version} .] ""]
use_zip             yes

depends_lib         port:zlib

pre-extract {
    # DOS to UNIX line endings.
    extract.pre_args-append -a
}
extract.mkdir       yes

patchfiles-append   compiler.patch
patchfiles-append   patch-makefile.diff

# cert/certrev.c: error: implicit declaration of function 'static_assert'
patchfiles-append   patch-static_assert.diff

# Build fails when compiler is gcc or llvm-gcc; warnings are printed when compiler is clang.
conflicts_build     unixODBC

use_configure       no

configure.ldflags-append -lz

# crypt/chacha20.c:21: error: redefinition of typedef ‘chacha_ctx’
compiler.c_standard 2011

build.target        default shared
build.args          CC="${configure.cc}" \
                    PREFIX="${prefix}"

configure.cppflags-replace -I${prefix}/include -isystem${prefix}/include

foreach arch ${configure.universal_archs} {
    lappend merger_build_env(${arch}) \
                    "CFLAGS=${configure.cflags} ${configure.cppflags} -arch ${arch}" \
                    "LDFLAGS=${configure.ldflags} -arch ${arch}"
}

if {(!${universal_possible} || ![variant_isset universal]) && [info exists merger_build_env(${configure.build_arch})]} {
    build.env-append {*}$merger_build_env(${configure.build_arch})
}

destroot.args       PREFIX="${prefix}"

post-destroot {
    set docdir ${prefix}/share/doc/${subport}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} \
        COPYING \
        README \
        ${destroot}${docdir}
}

livecheck.type      regexm
livecheck.url       ${homepage}download.html
livecheck.regex     \\.zip">${name}\\s+(\[0-9.\]+)
