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

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.3
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          devel security crypto
platforms           darwin
maintainers         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        ftp://ftp.franken.de/pub/crypt/cryptlib/ \
                    http://www.cypherpunks.to/~peter/
distname            cl[join [split $version .] ""]
use_zip             yes

checksums           rmd160  407a473d64cad30931f93b6d52bc3eb77c63e55f \
                    sha256  08b104442bb5c7281a3299853d5585cc63bd928454dff3150569c02b957427ad

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

patchfiles-append   patch-makefile.diff \
                    patch-random-unix.c.diff \
                    patch-tools-ccopts.sh.diff

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

use_configure       no

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

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

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

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

destroot.env        PREFIX="${prefix}"

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

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