#-*- 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                    blt
version                 2.5.3
revision                1
categories              x11
license                 MIT
maintainers             nomaintainer

description             BLT is an extension to the Tk toolkit, adding new widgets, \
                        geometry managers, and miscellaneous commands.
long_description        {*}${description}

homepage                http://blt.sourceforge.net/

master_sites            sourceforge:wize
use_zip                 yes
distname                blt-src-${version}
worksrcdir              blt[join [lrange [split ${version} .] 0 1] .]

checksums               rmd160  a0e0882e19003bbdb8a89d7c3d410bd32b12b685 \
                        sha256  6ec778f58f60f17e241156d00e7e6ca79938ff40fd61df7d23cdedfe7ec49943 \
                        size    2724036

depends_build           port:tcl \
                        port:tk-x11 \
                        port:xorg-libX11

use_parallel_build      no

configure.args-append   --with-tcl=${prefix}/lib \
                        --with-tk=${prefix}/lib/tk-x11 \
                        --with-tkincls=${prefix}/include/tk-x11 \
                        --with-tklibs=${prefix}/lib/tk-x11

# prevent having to modify all of Debian patches
patch.pre_args-replace  -p0 -p1

# taken from Debian (https://packages.debian.org/unstable/devel/blt-dev)
patchfiles-append   02-debian-all.patch \
                    03-fedora-patch-2.patch \
                    04-fedora-tk8.5.6.patch \
                    05-tk8.5-zoomstack.patch \
                    doc-typos.patch \
                    tcl8.6.patch \
                    tk8.6.patch \
                    install.patch \
                    usetclint.patch \
                    usetkint.patch \
                    table.patch \
                    ldflags.patch \
                    pkgindex.patch \
                    decls.patch \
                    bltnsutil.patch \
                    blthash.patch \
                    const.patch \
                    uninitialized.patch \
                    unused.patch \
                    pointertoint.patch \
                    autoreconf.patch

# taken from Gentoo (https://packages.gentoo.org/packages/dev-tcltk/blt)
patchfiles-append   blt-2.4z-darwin.patch

# make sure AC_PROG_CC is called, otherwise configure fails
patchfiles-append   patch-ac_prog_cc.diff

# do not install files in ${prefix}/lib
destroot.args-append scriptdir=${prefix}/share/${name}

use_autoconf        yes

destroot.destdir    INSTALL_ROOT=${destroot}

post-patch {
    reinplace -q "s|../src/bltwish|${prefix}/bin/bltwish|g" \
        {*}[glob ${worksrcpath}/demos/*.tcl] \
        {*}[glob ${worksrcpath}/demos/scripts/*.tcl]
}

post-destroot {
    # prevent conflict with Tk and tcllib
    foreach fl [glob -tails -directory ${destroot}${prefix}/share/man/mann *.n] {
        move ${destroot}${prefix}/share/man/mann/${fl} ${destroot}${prefix}/share/man/mann/blt-${fl}
    }
}
