# -*- 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                    argyll
version                 3.2.0
revision                0
checksums               rmd160  4a28f7827c471e059ba06e26755ed33fd9c34978 \
                        sha256  4861ab87b41618fb6706843099aad2cc649115634dee1e60738792387b371176 \
                        size    14690714

categories              graphics
maintainers             nomaintainer
license                 AGPL-3

description             Argyll Color Management System
long_description        ArgyllCMS is an ICC compatible color management \
system. It supports accurate ICC profile creation for scanners, cameras \
and film recorders, and calibration and profiling of displays and RGB \& \
CMYK printers. Argyll includes a general purpose ICC V2 profile format \
access library, icclib, and a general purpose CGATS file format I/O library.

homepage                https://www.argyllcms.com/
master_sites            ${homepage}
use_zip                 yes
distname                Argyll_V${version}_src
worksrcdir              Argyll_V${version}

depends_build           port:jam

depends_lib-append      path:include/turbojpeg.h:libjpeg-turbo
depends_lib-append      port:libpng
depends_lib-append      path:lib/pkgconfig/libusb-1.0.pc:libusb
depends_lib-append      port:tiff
depends_lib-append      port:zlib

patchfiles-append       patch-ppc.diff

post-extract {
    # To make sure that in case of problems the build will fail instead
    # of silently falling back to the built-in versions:
    delete ${worksrcpath}/jpeg
    delete ${worksrcpath}/png
    delete ${worksrcpath}/tiff
    delete ${worksrcpath}/usb
    delete ${worksrcpath}/zlib
}

use_configure           no
configure.ldflags-append \
                        -ljpeg -lpng -ltiff -lusb-1.0 -lz

build.env-append        HAVE_JPEG=true
build.env-append        HAVE_PNG=true
build.env-append        HAVE_TIFF=true
build.env-append        HAVE_Z=true HAVE_ZLIB=true
build.env-append        "PREF_CCFLAGS=${configure.cflags} [get_canonical_archflags]"
build.env-append        "PREF_LINKFLAGS=${configure.ldflags} [get_canonical_archflags]"

destroot.env            {*}${build.env}
destroot.destdir        DESTDIR=${worksrcpath}

post-destroot {
    # Install documentation.
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} \
        License.txt License2.txt License3.txt log.txt ReadMe.txt \
        ${destroot}${prefix}/share/doc/${name}
    system "cp -r ${worksrcpath}/doc/* \
        ${destroot}${prefix}/share/doc/${name} && \
        find ${destroot}${prefix}/share/doc/${name} -type f -print0 | xargs -0 chmod 644 && \
        find ${destroot}${prefix}/share/doc/${name} -type d -print0 | xargs -0 chmod 755"
    # Install binaries
    delete ${worksrcpath}/bin/License.txt
    xinstall -m 755 {*}[glob ${worksrcpath}/bin/*] \
        ${destroot}${prefix}/bin
    # Install references
    xinstall -m 755 -d ${destroot}${prefix}/share/${name}/ref
    xinstall -m 644 {*}[glob ${worksrcpath}/ref/*] \
        ${destroot}${prefix}/share/${name}/ref
    # xinstall does not remove 'quarantine' attribute;
    # do that manually.
    fs-traverse fixfile ${destroot} {
        if {[exec xattr -l ${fixfile}] != ""} {
            system "xattr -d com.apple.quarantine ${fixfile}"
        }
    }
}

# conflicts with num-utils on ${prefix}/bin/average
conflicts-append    num-utils

livecheck.type      regex
livecheck.url       ${homepage}downloadsrc.html
livecheck.regex     Argyll_V(\[0-9.]+)_src${extract.suffix}
