# -*- 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 92396 2012-04-27 18:49:48Z ryandesign@macports.org $

PortSystem                  1.0
PortGroup                   archcheck 1.0

# Keep relevant lines in sync between ImageMagick and p5-perlmagick.

name                        ImageMagick
conflicts                   cryptlib
version                     6.7.6-7
set reasonable_version      [lindex [split ${version} -] 0]
homepage                    http://www.imagemagick.org/
categories                  graphics devel
maintainers                 ryandesign
license                     Apache-2
use_xz                      yes
platforms                   darwin
use_parallel_build          yes

description                 Tools and libraries to manipulate images in many formats

long_description            ImageMagick is a robust collection of tools and \
                            libraries to create, edit and compose bitmap images \
                            in a wide variety of formats. You can crop, resize, \
                            rotate, sharpen, color reduce or add effects or text \
                            or straight or curved lines to an image or image \
                            sequence and save your completed work in the same or \
                            differing image format. You can even create images \
                            from scratch. Image processing operations are \
                            available from the command line as well as through \
                            C, Ch, C++, Java, Perl, PHP, Python, Ruby and Tcl/Tk \
                            programming interfaces. Over 90 image formats are \
                            supported, including GIF, JPEG, JPEG 2000, PNG, PDF, \
                            PhotoCD and TIFF.

master_sites                http://image_magick.veidrodis.com/image_magick/ \
                            http://imagemagick.linux-mirror.org/download/ \
                            ftp://ftp.imagemagick.org/pub/ImageMagick/ \
                            ftp://ftp.fifi.org/pub/ImageMagick/
#                            sourceforge:imagemagick
#                            http://ftp.surfnet.nl/pub/ImageMagick/
#                            ftp://ftp.nluug.nl/pub/${name}/

checksums                   rmd160  bbedf3b193dfa98d24f11c290f6490451652b1a4 \
                            sha256  049f52999c45d28ab5ffbb5436b34ca97f0a96412c63c3e3bae8fa86227e77eb

depends_build               port:pkgconfig

depends_lib                 port:xorg-libXext \
                            port:xorg-libXt \
                            port:bzip2 \
                            port:liblzma \
                            port:jpeg \
                            port:lcms2 \
                            port:libpng \
                            port:tiff \
                            port:webp \
                            port:zlib \
                            port:freetype \
                            port:fontconfig \
                            port:ghostscript \
                            port:libiconv \
                            port:libtool \
                            port:expat \
                            port:libxml2

depends_run                 port:urw-fonts

archcheck.files             lib/libXext.dylib \
                            lib/libXt.dylib \
                            lib/libbz2.dylib \
                            lib/libjpeg.dylib \
                            lib/liblcms2.dylib \
                            lib/libpng.dylib \
                            lib/libtiff.dylib \
                            lib/libwebp.dylib \
                            lib/libfreetype.dylib \
                            lib/libfontconfig.dylib \
                            lib/libgs.dylib \
                            lib/libiconv.dylib \
                            lib/libltdl.dylib \
                            lib/libexpat.dylib \
                            lib/libxml2.dylib

pre-configure {
    foreach {badport badfile} "cryptlib ${prefix}/lib/libcl.dylib" {
        if {[file exists ${badfile}]} {
            ui_error "${name} cannot be built while ${badport} is active."
            ui_error "Please deactivate ${badport} and try again."
            ui_error "You can reactivate ${badport} again later."
            return -code error "${badport} is installed"
        }
    }
}

configure.ccache            no

configure.args              --enable-shared \
                            --enable-static \
                            --disable-ltdl-install \
                            --with-frozenpaths \
                            --without-openexr \
                            --disable-hdri \
                            --with-dps \
                            --with-bzlib \
                            --with-fontconfig \
                            --with-gslib \
                            --with-jpeg \
                            --with-lcms \
                            --with-png \
                            --with-tiff \
                            --with-webp \
                            --with-zlib \
                            --with-modules \
                            --with-xml \
                            --with-x \
                            --without-perl \
                            --without-fpx \
                            --without-jbig \
                            --without-jp2 \
                            --without-wmf \
                            --without-gvc \
                            --without-rsvg \
                            --without-lqr \
                            --without-pango \
                            --with-gs-font-dir=${prefix}/share/fonts/urw-fonts

post-configure {
    reinplace -E {s|-arch [a-z0-9_]+||g} \
        ${worksrcpath}/magick/Magick-config \
        ${worksrcpath}/magick/MagickCore-config \
        ${worksrcpath}/Magick++/bin/Magick++-config \
        ${worksrcpath}/wand/MagickWand-config \
        ${worksrcpath}/wand/Wand-config
}

test.run                    yes
test.target                 check
test.env                    DYLD_LIBRARY_PATH=${worksrcpath}/magick/.libs

variant graphviz description {Support Graphviz} {
    depends_lib-append      path:bin/dot:graphviz
    archcheck.files-append  lib/libgvc.dylib
    configure.args-delete   --without-gvc
    configure.args-append   --with-gvc
}

variant hdri description {Support High Dynamic Range Imaging using OpenEXR} {
    depends_lib-append      port:openexr
    archcheck.files-append  lib/libIlmImf.dylib
    configure.args-delete   --without-openexr \
                            --disable-hdri
    configure.args-append   --with-openexr \
                            --enable-hdri
}

variant jbig description {Support JBIG} {
    depends_lib-append      port:jbigkit
    archcheck.files-append  lib/libjbig.dylib
    configure.args-delete   --without-jbig
    configure.args-append   --with-jbig
}

variant jpeg2 description {Support JPEG-2000 using JasPer} {
    depends_lib-append      port:jasper
    archcheck.files-append  lib/libjasper.dylib
    configure.args-delete   --without-jp2
    configure.args-append   --with-jp2
}

variant lqr description {Support Liquid Rescale (experimental)} {
    depends_lib-append      port:liblqr
    archcheck.files-append  lib/liblqr-1.dylib
    configure.args-delete   --without-lqr
    configure.args-append   --with-lqr
}

variant pango description {Support Pango} {
    depends_lib-append      path:lib/pkgconfig/pango.pc:pango
    archcheck.files-append  lib/libpango-1.0.dylib
    configure.args-delete   --without-pango
    configure.args-append   --with-pango
}

variant mpeg description {Support MPEG-1 and MPEG-2 video} {
    depends_lib-append      port:mpeg2vidcodec
}

variant no_plus_plus description {Do not install Magick++} {
    configure.args-append   --without-magick-plus-plus
}

variant no_x11 {
    depends_lib-delete      port:xorg-libXext \
                            port:xorg-libXt
    archcheck.files-delete  lib/libXext.dylib \
                            lib/libXt.dylib
    configure.args-delete   --with-x
    configure.args-append   --without-x
}

variant perl description {Install PerlMagick} {
    depends_lib-append      path:bin/perl:perl5
    configure.args-delete   --without-perl
    configure.args-append   --with-perl=${prefix}/bin/perl
    post-destroot {
        foreach packlist [exec find ${destroot} -name .packlist] {
            ui_info "Fixing packlist ${packlist}"
            reinplace "s|${destroot}||" ${packlist}
        }
        foreach badfile [exec find ${destroot} -name perllocal.pod] {
            ui_info "Removing ${badfile}"
            file delete ${badfile}
        }
    }
}

variant q8 conflicts q16 q32 description {Use 8 bits per pixel quantum} {
    configure.args-append   --with-quantum-depth=8
}
variant q16 conflicts q8 q32 description {Use 16 bits per pixel quantum} {
    configure.args-append   --with-quantum-depth=16
}
variant q32 conflicts q8 q16 description {Use 32 bits per pixel quantum} {
    configure.args-append   --with-quantum-depth=32
}
if {![variant_isset q8] && ![variant_isset q32]} {
    default_variants +q16
}

variant rsvg description {Support SVG using librsvg} {
    depends_lib-append      port:librsvg
    archcheck.files-append  lib/librsvg-2.dylib
    configure.args-delete   --without-rsvg
    configure.args-append   --with-rsvg
}

variant wmf description {Support the Windows Metafile Format} {
    depends_lib-append      port:libwmf
    archcheck.files-append  lib/libwmf.dylib
    configure.args-delete   --without-wmf
    configure.args-append   --with-wmf
}

livecheck.version           ${reasonable_version}
livecheck.type              regex
livecheck.url               http://ftp.surfnet.nl/pub/ImageMagick/
livecheck.regex             ${name}-(\\d+(?:\\.\\d+)*)(?:-\\d+)?
