# -*- 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                    ntl
version                 11.5.1
revision                0
categories              math devel
platforms               darwin
license                 LGPL-2.1+
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
description             NTL: A Library for doing Number Theory
long_description        NTL is a high-performance, portable C++ library providing\
                        data structures and algorithms for arbitrary length\
                        integers\; for vectors, matrices, and polynomials over the\
                        integers and over finite fields\; and for arbitrary\
                        precision floating point arithmetic.

homepage                https://shoup.net/ntl/
master_sites            ${homepage}

checksums               rmd160  9342e480ab21413534ce2606e0a87917561d86aa \
                        sha256  210d06c31306cbc6eaf6814453c56c776d9d8e8df36d74eb306f6a523d1c6a8a \
                        size    2304103

compiler.cxx_standard   2011

depends_build-append    path:bin/perl:perl5
depends_lib-append      port:gmp

worksrcdir              ${name}-${version}/src

# see configure script
configure.cmd           "${prefix}/bin/perl DoConfig"

configure.pre_args-replace \
                        --prefix=${prefix} \
                        PREFIX=\"${prefix}\"
# build shared library
# do not try to add -march=native
# look for external libraries (e.g. GMP) in ${prefix}
configure.args-append   SHARED=on \
                        NATIVE=off \
                        DEF_PREFIX=\"${prefix}\"

# respect MacPorts variables
foreach val {CXX CXXFLAGS CPPFLAGS LDFLAGS} {
    configure.args-append ${val}=\"\$${val}\"
}

post-destroot {
    system "cd ${destroot}${prefix}/share/doc && mv NTL tmp && mv tmp ${name}"
    xinstall -m 0644 ${worksrcpath}/../README \
                     ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 ${worksrcpath}/../doc/copying.txt \
                     ${destroot}${prefix}/share/doc/${name}/LICENSE
}

variant tuned description {Build with more optimizations} {
    configure.args-delete  NATIVE=off
    configure.args-append  TUNE=auto
}

test.run                yes
test.target             check

livecheck.url           https://shoup.net/ntl/download.html
livecheck.regex         "Download NTL (\\d+(?:\\.\\d+)*)"
