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

name                tcl
version             8.6.14
revision            0
# Tk (x11/tk) port depends on this version
categories          lang
license             Tcl/Tk
maintainers         {mcalhoun @MarcusCalhoun-Lopez} {gmx.us:chrischavez @chrstphrchvz} openmaintainer
platforms           darwin freebsd
description         Tool Command Language
long_description    \
    Tcl (Tool Command Language) is a very powerful but easy to learn dynamic \
    programming language, suitable for a very wide range of uses, including web \
    and desktop applications, networking, administration, testing and many more. \
    Open source and business-friendly, Tcl is a mature yet evolving language \
    that is truly cross platform, easily deployed and highly extensible.

homepage            https://www.tcl-lang.org/
master_sites        sourceforge:project/tcl/Tcl/${version}

checksums           rmd160  9de599069a0fba1efe28951a010486bce793c80a \
                    sha256  5880225babf7954c58d4fb0f5cf6279104ce1cd6aa9b71e9a6322540e1c4de66 \
                    size    11627322

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

configure.args      --mandir=${prefix}/share/man \
                    --disable-corefoundation \
                    --disable-threads
configure.cppflags-delete  -I${prefix}/include
configure.ldflags-delete   -L${prefix}/lib

pre-configure {
    # sqlite3 package is provided by sqlite3-tcl
    delete [glob ${worksrcpath}/../pkgs/sqlite*]
}

post-configure {
    reinplace -E {s|-arch [^ ]+||g} ${worksrcpath}/tclConfig.sh
}

# see https://trac.macports.org/ticket/17189
destroot.target-append \
                    install-private-headers
destroot.destdir    INSTALL_ROOT=${destroot}
post-destroot {
    ln -s tclsh8.6 ${destroot}${prefix}/bin/tclsh
    ln -s libtcl8.6.dylib ${destroot}${prefix}/lib/libtcl.dylib

    if {${configure.ccache}} {
        reinplace {/TCL_CC/s/ccache //} ${destroot}${prefix}/lib/tclConfig.sh
    }
}

variant threads description {add multithreading support} {
    configure.args-replace --disable-threads \
                           --enable-threads
}

platform macosx {
    # CF is not fork()-safe and software e.g. using tk and fork() will crash
    variant corefoundation description {Enable CoreFoundation support (not fork-safe)} {
        configure.args-replace --disable-corefoundation \
                               --enable-corefoundation
    }
    # tk +quartz crashes at launch without CF support
    default_variants-append +corefoundation
}

variant memdebug description {enable memory debugging support} {
    configure.args-append --enable-symbols=mem
}

variant dtrace description {Enable DTrace static probes} {
    configure.args-append --enable-dtrace
}

platform darwin {
    configure.args-append tcl_cv_type_64bit="long long"
}

default_variants +threads

platform darwin 8 {
    # See http://trac.macports.org/ticket/32930 for why this is needed.
    configure.cppflags-append -DSQLITE_WITHOUT_ZONEMALLOC
}

notes "
The Sqlite3 Tcl package is now being provided by the sqlite3-tcl port:
sudo port install sqlite3-tcl
"

test.run            yes

livecheck.type      regex
livecheck.regex     {Tcl/Tk (\d+(?:\.\d+)*)</a>}
