# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 45048 2009-01-07 17:46:51Z mcalhoun@macports.org $

PortSystem 1.0

name             openjpeg
version          1.3
revision         3
categories       graphics
maintainers      mcalhoun
description      Library for manipulating JPEG-2000 images
long_description \
	The OpenJPEG library is an open-source JPEG 2000 codec. \
	It has been developed in order to promote the use of JPEG 2000, \
	the new still-image compression standard from the \
	Joint Photographic Experts Group (JPEG).

platforms        darwin

homepage         http://www.openjpeg.org/
master_sites     ${homepage}

checksums \
    md5     f9a3ccfa91ac34b589e9bf7577ce8ff9          \
    sha1    8d6870d9500ea09e0b1d30b981bea1c8de534de4  \
    rmd160  2a22cc123058b1974cd1bf3898044acabceba26c

use_configure    no

patchfiles       patch-opj_malloc.h.diff \
                 patch-Makefile.osx.diff

post-patch {
    reinplace \
        "s| -o root -g wheel | -o ${install.user} -g ${install.group} |g" \
        ${worksrcpath}/Makefile.osx
    reinplace \
        "s|VER_MINOR = 1.2|VER_MINOR = ${version}|g" \
        ${worksrcpath}/Makefile.osx
}

post-configure {
    # Patch is done in post-configure so that ${configure.cc} is available.
    reinplace -E \
        "s|^CC = .*$|CC = ${configure.cc}|g" \
        ${worksrcpath}/Makefile.osx
    reinplace -E \
        "s|^LIBTOOLDYN = .*$|LIBTOOLDYN = ${configure.cc}|g" \
        ${worksrcpath}/Makefile.osx
}

set verDir       [join [split ${version} {.}] {_}]
distname         ${name}_v${verDir}
worksrcdir       OpenJPEG_v${verDir}

build.args \
    -f Makefile.osx \
    PREFIX=${prefix}

destroot.args    ${build.args}

variant universal {
    post-configure {
        reinplace -E \
            "s|^\(COMPILERFLAGS = .*\)$|\\1 ${configure.universal_cflags}|" \
            ${worksrcpath}/Makefile.osx
        reinplace -E \
            "s|^\(LIBTOOLDYN = .*\)$|\\1 ${configure.universal_ldflags}|g" \
            ${worksrcpath}/Makefile.osx
    }
}

livecheck.url    http://www.openjpeg.org/index.php?menu=news
livecheck.regex  "\[vV\]ersion (\\d+(\\.\\d+)+)"
