# -*- 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
PortGroup           xcodeversion 1.0

name                tiff
version             4.7.2
revision            0
categories          graphics
maintainers         {ryandesign @ryandesign} openmaintainer
license             BSD

description         Library and tools for dealing with Tag Image File Format
long_description    \
    This software provides support for the Tag Image File       \
    Format (TIFF), a widely used format for storing image       \
    data. Included in this software distribution is             \
    a library, libtiff, for reading and writing TIFF, a small   \
    collection of tools for doing simple manipulations of       \
    TIFF images on UNIX systems, documentation on the library   \
    and tools. A small assortment of TIFF-related software      \
    for UNIX that has been contributed by others is also        \
    included. The library is capable of dealing with images     \
    that are written to follow the 5.0 or 6.0 TIFF spec.        \
    There is also considerable support for some of the more     \
    esoteric portions of the 6.0 TIFF spec.

homepage            https://libtiff.gitlab.io/libtiff
master_sites        https://download.osgeo.org/libtiff/ \
                    freebsd

checksums           rmd160  470c5697c210453335869009d0f42427b5abf1f6 \
                    sha256  672bd7d10aee4606171afb864f3570b83340f6a33e2c186dc0512f7145ffdf6a \
                    size    4083368

depends_lib-append  port:lerc \
                    port:libdeflate \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:xz \
                    port:zlib \
                    port:zstd

# Remove pragmas inside functions:
if [string match *gcc-4.* ${configure.compiler}] {
    patchfiles-append   patch-gcc4.diff
}

compiler.c_standard 1999

configure.args      --disable-jbig \
                    --disable-webp \
                    --with-docdir=${prefix}/share/doc/${name} \
                    --with-jpeg-include-dir=${prefix}/include \
                    --with-jpeg-lib-dir=${prefix}/lib \
                    --with-lerc-include-dir=${prefix}/include \
                    --with-lerc-lib-dir=${prefix}/lib \
                    --with-libdeflate-include-dir=${prefix}/include \
                    --with-libdeflate-lib-dir=${prefix}/lib \
                    --with-lzma-include-dir=${prefix}/include \
                    --with-lzma-lib-dir=${prefix}/lib \
                    --with-x=no \
                    --with-zlib-include-dir=${prefix}/include \
                    --with-zlib-lib-dir=${prefix}/lib \
                    --with-zstd-include-dir=${prefix}/include \
                    --with-zstd-lib-dir=${prefix}/lib

# https://trac.macports.org/ticket/73042
configure.cflags-append -std=c99

minimum_xcodeversions {9 3.1}

set merger_dont_diff ${prefix}/include/tiffconf.h

variant jbig description "Enable JBIG support" {
    depends_lib-append      port:jbigkit
    configure.args-replace  --disable-jbig --enable-jbig
    configure.args-append   --with-jbig-include-dir=${prefix}/include \
                            --with-jbig-lib-dir=${prefix}/lib
}

test.run            yes
test.target         check

livecheck.type  regex
livecheck.url   [lindex ${master_sites} 0]
livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
