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

name                tk
version             8.6.15
revision            0
categories          x11
license             Tcl/Tk
maintainers         {mcalhoun @MarcusCalhoun-Lopez} {gmx.us:chrischavez @chrstphrchvz} openmaintainer
description         Tcl Tool Kit
homepage            https://www.tcl-lang.org/
long_description    This is Tk version ${version}, a GUI toolkit for Tcl. The best way to get \
                    started with Tcl is to read ``Tcl and the Tk Toolkit'' by John K.         \
                    Ousterhout, Addison-Wesley, ISBN 0-201-63337-X.

master_sites        sourceforge:project/tcl/Tcl/${version}
dist_subdir         tcltk
distname            ${name}${version}-src
worksrcdir          ${name}${version}

checksums           md5 6d64b6eb021062f378017d403fedcbe6 \
                    sha1 ef44f7be00d0249e281ad87785650f5475bbc939 \
                    rmd160 3cb0ef6823829ed2f7ff0870c7754ea8be20b82a \
                    sha256 550969f35379f952b3020f3ab7b9dd5bfd11c1ef7c9b7c6a75f5c49aca793fec

depends_build       port:pkgconfig

# force usage of MacPorts Tcl
depends_lib         port:fontconfig \
                    port:tcl \
                    port:Xft2 \
                    port:xorg-libXScrnSaver

configure.dir      ${worksrcpath}/unix
build.dir          ${configure.dir}

configure.args      --mandir=${prefix}/share/man --with-tcl=${prefix}/lib
# see https://trac.macports.org/ticket/58447
configure.cppflags-replace -I${prefix}/include -isystem${prefix}/include
configure.ldflags   -L${worksrcpath} -L${prefix}/lib -lfontconfig

# see https://trac.macports.org/ticket/17189
destroot.target-append \
                    install-private-headers
post-destroot {
    ln -s wish8.6 ${destroot}${prefix}/bin/wish
    ln -s libtk8.6.dylib ${destroot}${prefix}/lib/libtk.dylib
}

configure.args.x86_64-append    --enable-64bit
configure.args.ppc64-append     --enable-64bit

if {${os.platform} eq "darwin" && ${os.subplatform} eq "macosx" && ${os.major} >= 10} {
    variant quartz conflicts x11 {
        depends_lib-delete \
                    port:fontconfig \
                    port:Xft2 \
                    port:xorg-libXScrnSaver
        configure.ldflags-delete \
                    -lfontconfig
        configure.args-append \
                    --enable-aqua
        post-destroot {
            move \
                ${destroot}${prefix}/include/X11 \
                ${destroot}${prefix}/include/X11_tk
            fs-traverse fl ${destroot}${prefix}/include {
                if {[file extension ${fl}] eq ".h"} {
                    reinplace -q "s|include <X11/|include <X11_tk/|g" ${fl}
                    reinplace -q "s|include \"X11/|include \"X11_tk/|g" ${fl}
                }
            }
        }
    }

    variant x11 conflicts quartz {}

    if {![variant_isset x11]} {
        default_variants +quartz
    }
} else {
    # Even though X11 is the only option, make a variant so that other ports
    # can check for it being set with require_active_variants.
    variant x11 {}
    default_variants +x11
}

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

post-destroot {
    foreach fl {tk3d.h tkFont.h} {
        xinstall -m 0644 ${workpath}/tk${version}/generic/${fl} ${destroot}${prefix}/include/
    }
}

test.run            yes

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