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

name                botan1
version             1.10.17
revision            2
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          security devel
maintainers         nomaintainer
license             BSD
description         legacy version of C++ cryptographic library
long_description    Botan is a C++ library implementing a variety of \
                    cryptographic algorithms and formats.

homepage            https://botan.randombit.net
master_sites        ${homepage}/releases/old
distname            Botan-${version}
extract.suffix      .tgz

checksums           rmd160  77336d0c9a10c03e86ad5946f1e357ec70cee9e7 \
                    sha256  6847ffb64b8d2f939dccfecc17bd2c80385d08f7621e2c56d3a335118e823613 \
                    size    2706678

depends_build       port:python27
depends_lib         port:zlib port:bzip2 port:openssl10

# respect MacPorts configure values
patchfiles-append   patch-compiler_flags.diff patch-botan1-use-openssl10.diff
post-patch {
    reinplace -W ${worksrcpath}/src/build-data/cc \
        "s|__MACPORTS_CXX_STDLIB__|${configure.cxx_stdlib}|g" \
        clang.txt
    reinplace -W ${worksrcpath}/src/build-data/cc \
        "s|__MACPORTS_OPT_FLAG__|${configure.optflags}|g" \
        clang.txt gcc.txt
    reinplace -W ${worksrcpath}/src/build-data/cc \
        "s|@@PREFIX@@|${prefix}|g" \
        clang.txt gcc.txt
}
configure.args-append   --cc-bin=${configure.cxx}

# the SSL interface requires TR1 (see doc/log.txt)
configure.args-append   --with-tr1-implementation=system
# TR1 is not supported on recent versions of clang
# see https://trac.macports.org/ticket/40968
if {[string match *clang* ${configure.compiler}] && ${configure.cxx_stdlib} eq "libc++"} {
    patchfiles-append   patch-tr1.diff
    post-patch {
        reinplace -W ${worksrcpath}/src/ssl \
            "s|std::tr1::|std::|g" \
            tls_record.h rec_wri.cpp tls_client.h tls_client.cpp tls_server.h tls_server.cpp
    }
}

configure.cmd       ${prefix}/bin/python2.7 ./configure.py
configure.args-append \
                    --docdir=share/doc \
                    --with-bzip2 \
                    --with-openssl \
                    --with-zlib \
                    --without-sphinx

if {[string match *clang* ${configure.compiler}]} {
    configure.args-append --cc=clang
    # default value in src/build-data/cc/clang.txt
    configure.optflags    -O2
} elseif {[string match *gcc* ${configure.compiler}]} {
    configure.args-append --cc=gcc
    # default value in src/build-data/cc/gcc.txt
    configure.optflags    -O3
}

destroot.destdir    DESTDIR=${destroot}${prefix}

platform darwin { configure.args-append --os=darwin }

# botan way of setting cpu type in build phase
array set merger_configure_args {
    ppc     --cpu=ppc
    i386    --cpu=ia32
    ppc64   --cpu=ppc64
    x86_64  --cpu=amd64
}

if {(!${universal_possible} || ![variant_isset universal]) && [info exists merger_configure_args(${build_arch})]} {
    configure.args-append $merger_configure_args(${build_arch})
}

# configure.py rejects this argument
configure.universal_args-delete --disable-dependency-tracking

notes "
This legacy version of Botan should not be used for current software.\
It exists on MacPorts only to support legacy software that can not\
be updated to the current version of Botan.
"

livecheck.type none