# -*- 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 97517 2012-09-07 20:38:59Z devans@macports.org $

PortSystem      1.0

name            py27-exiv2
#
# conflict due to dependency on 
# Python version specific variant of boost
#
conflicts       py26-exiv2
platforms       darwin
set my_name     pyexiv2
version         0.3.2
set branch      [join [lrange [split ${version} .] 0 1] .]
categories      python graphics
license         GPL-2
maintainers     devans openmaintainer
description     Python bindings for exiv2.

long_description \
                pyexiv2 is a Python binding to exiv2, the C++ library for \
                manipulation of EXIF, IPTC and XMP image metadata.

homepage        http://tilloy.net/dev/pyexiv2/overview.html
master_sites    http://launchpad.net/pyexiv2/0.3.x/${version}/+download/
distname        ${my_name}-${version}
use_bzip2       yes

checksums       rmd160  cbc53e6f45b0f4251b90bfb6ffab8c659463ac5d \
                sha256  0abc117c6afa71f54266cb91979a5227f60361db1fcfdb68ae9615398d7a2127

depends_build   port:scons

depends_lib     port:boost \
                port:exiv2 \
                port:python27

#
# Make sure that boost is installed with the correct Python variant
#

pre-build {
    set boost_python_lib ${prefix}/lib/libboost_python-mt.dylib
    set boost_python_version "0"
    if {[file exists ${boost_python_lib}]} {
        set boost_python_version [exec /usr/bin/otool -L ${boost_python_lib} | /usr/bin/grep Python | /usr/bin/sed -e "s|^.*Versions/||" -e "s|/.*||"]
    }
    if {${boost_python_version} != "2.7"} {
            ui_error "This port requires 'boost +python27'. Please install as follows:"
            ui_error "    sudo port install boost +python27."
            return -code error
    }
}
 
patchfiles      patch-src-SConscript.diff

use_configure   no

#
# universal_variant is not set by default if configure is disabled
#

universal_variant yes

#
# scons (a python script) uses python builtin procedures
# to determine configuration options so correct configuation
# depends on the version of python used to run scons
#

build.cmd       ${prefix}/bin/python2.7 ${prefix}/bin/scons
build.target
build.args-append \
                BOOSTLIB=boost_python-mt \
                PYTHONLIB=python2.7
build.env-append \
                PREFIX=${prefix} \
                CXX=${configure.cxx} \

if {[variant_isset universal]} {
    build.env-append \
                CXXFLAGS="${configure.universal_cxxflags} -I${prefix}/include" \
                LDFLAGS="${configure.universal_ldflags} -L${prefix}/lib"
} else {
    build.env-append \
                CXXFLAGS="-I${prefix}/include" \
                LDFLAGS="-L${prefix}/lib"
}

destroot.cmd    ${prefix}/bin/python2.7 ${prefix}/bin/scons
destroot.args-append \
                BOOSTLIB=boost_python-mt \
                PYTHONLIB=python2.7
destroot.env-append \
                PREFIX=${prefix}\
                CXX=${configure.cxx} \

if {[variant_isset universal]} {
    destroot.env-append \
                CXXFLAGS="${configure.universal_cxxflags} -I${prefix}/include" \
                LDFLAGS="${configure.universal_ldflags} -L${prefix}/lib"
} else {
    destroot.env-append \
                CXXFLAGS="-I${prefix}/include" \
                LDFLAGS="-L${prefix}/lib"
}

livecheck.type  regex
livecheck.url   http://tilloy.net/dev/pyexiv2/download.html
livecheck.regex "${my_name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
