# -*- 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
# $Id: Portfile 74451 2010-12-18 01:24:52Z ryandesign@macports.org $

PortSystem              1.0

name                    argyll
version                 1.3.2
revision                1
categories              graphics
platforms               darwin
maintainers             nomaintainer
license                 gpl

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                http://www.argyllcms.com/

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

checksums               md5     dd0b8e2da65e4bb7fc38aef377e73afd \
                        sha1    51af2f880fa209dbc658cedf19c11abadbdc43e6 \
                        rmd160  a447041d7fb05078c627aeeeca6837f908991c76

worksrcdir              Argyll_V${version}

depends_build           port:jam

depends_lib             port:tiff \
                        port:libusb-compat

patchfiles              patch-jamfiles.diff \
                        patch-spectro_usbio.c.diff

# parts of Argyll (plot and spectra) use 32-bit Carbon;
# restrict build arches
supported_archs         i386 ppc

post-patch {
    # hard-wire libusb-compat info for now
    reinplace "s,@LIBUSBLIBDIR@,${prefix}/lib,g" \
        ${worksrcpath}/Jamtop
    reinplace "s,@LIBUSBINCDIR@,${prefix}/include,g" \
        ${worksrcpath}/Jamtop
    reinplace "s,@LIBUSBNAME@,libusb,g" \
        ${worksrcpath}/Jamtop

    # fix IOKit header include: G -> g, for case sensitive file systems
    reinplace "/include/s,IOKit/Graphics/IOGraphicsLib,IOKit/graphics/IOGraphicsLib,g" ${worksrcpath}/spectro/dispwin.h

    # set to install all libraries
    foreach fixfile [exec find ${worksrcpath} -name Jamfile] {
        reinplace "s,#InstallLib,InstallLib,g" ${fixfile}
    }
}

configure {
    # fix CC / CXX / LD arch flag settings
    reinplace "s,@CCFLAGS@,${configure.cc_archflags},g" \
         ${worksrcpath}/Jambase
    reinplace "s,@CXXFLAGS@,${configure.cxx_archflags},g" \
         ${worksrcpath}/Jambase
    reinplace "s,@LDFLAGS@,${configure.ld_archflags},g" \
         ${worksrcpath}/Jambase
}

# 'destroot' actually just installed files locally to
# the worksrcpath

post-destroot {
    # Install documentation.
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} \
        notes.txt Readme.txt ttbd.txt \
        ${destroot}${prefix}/share/doc/${name}
    system "cp -r ${worksrcpath}/doc/* \
        ${destroot}${prefix}/share/doc/${name} && \
        chmod 0644 ${destroot}${prefix}/share/doc/${name}/*"

    # Install binaries
    delete ${worksrcpath}/bin/License.txt
    xinstall -m 755 -d ${destroot}${prefix}/bin
    eval xinstall -m 755 [glob ${worksrcpath}/bin/*] \
        ${destroot}${prefix}/bin

    # Install headers
    xinstall -m 755 -d ${destroot}${prefix}/include/${name}
    foreach thisdir {cgats gamut h icc imdi jcnf numlib plot \
                         render rspl scanin spectro target \
                         ucmm xicc} {
        eval xinstall -m 644 [glob ${worksrcpath}/${thisdir}/*.h] \
            ${destroot}${prefix}/include/${name}
    }
    # correct some headers: #include <../Y/X> -> <X>
    foreach header {scanrd_.h gam.h refi.h gamut.h} {
        reinplace "s,\.\./\[^ /\]*/,,g" \
            ${destroot}/${prefix}/include/${name}/${header}
    }

    # Install libraries
    xinstall -m 755 -d ${destroot}${prefix}/lib
    eval xinstall -m 644 [glob ${worksrcpath}/lib/lib*] \
        ${destroot}${prefix}/lib

    # Install references
    xinstall -m 755 -d ${destroot}${prefix}/share/${name}/ref
    eval 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}"
        }
    }
}
