# -*- 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                    tkimg
version                 1.4.17
revision                0
checksums               rmd160  cd1a130eb937385862f2f12dba0c82315e1f5e6d \
                        sha256  aeab762f5c11979508974b35c354559a8ffb99404438f38dfd295e70abecc1cf \
                        size    6695711

categories              graphics
license                 Tcl/Tk
maintainers             {mcalhoun @MarcusCalhoun-Lopez} {gmx.us:chrischavez @chrstphrchvz} openmaintainer
homepage                https://tkimg.sourceforge.net
description             adds a lot of image formats to Tcl/Tk
long_description        The \"Img\" package adds a lot of image formats to Tcl/Tk.

master_sites            sourceforge:tkimg/tkimg/[join [lrange [split ${version} .] 0 1] .]/tkimg%20${version}
distname                Img-${version}
use_7z                  yes

post-extract {
    # All files in the 7z archive have 0644 permission
    # and all directories have 0700 permission. Brilliant!
    fs-traverse item ${worksrcpath} {
        file attributes ${item} -permissions 0755
    }

    # DOS to UNIX line endings so we can patch.
    reinplace -W ${worksrcpath} "s|\r||g" \
        compat/zlib/zutil.h \
        pixmap/pixmapUnix.c \
        window/window.c
}

patchfiles-append       patch-quartz.diff \
                        libpng-fp.h.patch \
                        zlib-fdopen.patch

# tkimg builds local copies of jpeg, libpng, and tiff
# Other package management systems have patches that allow tkimg to use external (MacPorts) versions.
# Unfortunately, these patches are highly intrusive and difficult to maintain.
# This really is an upstream issue.
# See
#    https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-tcltk/tkimg
#    https://packages.debian.org/sid/libtk-img


# for dtplite
depends_build-append    port:tcllib

depends_lib-append      port:tcl \
                        port:zlib

# Do an out-of-source build.
build.dir               ${workpath}/build
configure.dir           ${build.dir}
configure.cmd           ${worksrcpath}/configure
pre-configure {
    file mkdir ${build.dir}
}

configure.args-append   --with-tcl=${prefix}/lib

destroot.destdir        INSTALL_ROOT=${destroot}

if {${os.platform} eq "darwin" && ${os.subplatform} eq "macosx"
    && ${os.major} >= 10 && ![string match ppc* ${build_arch}]} {

    variant quartz conflicts x11 {
        depends_lib-append  port:tk-quartz
        configure.args-append   --with-tk=${prefix}/lib/tk-quartz \
                                --with-tkinclude=${prefix}/include/tk-quartz
    }
    if {![variant_isset x11]} {
        default_variants +quartz
    }
    set x11conflicts quartz
} else {
    default_variants +x11
    set x11conflicts {}
}

variant x11 conflicts {*}${x11conflicts} {
    depends_lib-append  port:tk-x11
    configure.args-append   --with-tk=${prefix}/lib/tk-x11 \
                            --with-tkinclude=${prefix}/include/tk-x11
}

livecheck.type          regex
livecheck.url           ${homepage}
livecheck.regex         {>Version +(\d+\.\d+\.\d+)}
