# -*- coding: utf-8; mode: tcl; tab-width: 4; c-basic-offset: 4 -*-
# $Id: Portfile 106521 2013-05-29 18:52:23Z mmoll@macports.org $

PortSystem          1.0
PortGroup           python 1.0
PortGroup           active_variants 1.1

set realname        graph-tool
name                py-${realname}
version             2.2.24
categories          python science
platforms           darwin
license             GPL-3
maintainers         skewed.de:tiago mmoll
description         Efficient python graph module
long_description    graph-tool is an efficient python module for manipulation \
                    and statistical analysis of graphs. The internal data \
                    structures and most algorithms are implemented in C++ with \
                    the Boost Graph Library.
homepage            http://graph-tool.skewed.de
master_sites        http://downloads.skewed.de/graph-tool/
use_bzip2           yes
checksums           md5     1c1ec9e8df33fe1d1560736b98816743 \
                    sha1    0ba18967a749396c8a959e423cb6c9532add4432 \
                    rmd160  cc1979e17e4604b163bc2a620c4c76b9c4ff58d6
distname            ${realname}-${version}
python.versions     26 27 31 32 33
python.default_version 27

if {$subport != $name} {
    universal_variant  no
    depends_build-append port:pkgconfig
    depends_lib-append port:boost \
                       port:cairomm \
                       port:cgal \
                       port:expat \
                       path:bin/dot:graphviz \
                       port:py${python.version}-numpy \
                       port:py${python.version}-scipy \
                       port:py${python.version}-gobject3 \
                       port:py${python.version}-cairo
    use_configure      yes
    # parallel build starts swapping, even on a MacBook Pro with 8GB of RAM.
    use_parallel_build no

    # graph-tool relies on Boost.Python, so make sure it is installed.
    require_active_variants boost python${python.version}

    configure.env-append PYTHON=${python.bin} \
                         PYTHON_VERSION=${python.branch} \
                         PYTHON_CPPFLAGS=-I${python.include} \
                         PYTHON_LDFLAGS="-L${python.libdir}/.. -lpython${python.branch}"
    configure.cppflags-append -I${prefix}/include -I${python.include}/..
    configure.ldflags-append -L${prefix}/lib
    configure.args-append --with-boost=${prefix} --exec-prefix=${python.prefix}
    # Clang uses the old libstc++ from gcc 4.2 by default. Boost doesn't
    # include some of the tr1 headers in libstdc++ and defines its own tr1
    # classes. This causes conflicts with sparsehash which insists on using
    # the old tr1 headers. Remove this if/when clang switches to libc++ at
    # some point.
    if {[string match *clang* ${configure.compiler}]} {
        configure.args-append --disable-sparsehash
    } else {
        depends_lib-append port:sparsehash
        configure.cppflags-append -I${prefix}/include/sparsehash
    }
    build.cmd          make
    build.target       all
    destroot.cmd       make
    destroot.destdir   DESTDIR=${destroot}

    post-destroot {
        file rename ${destroot}${prefix}/share/doc/graph-tool \
            ${destroot}${prefix}/share/doc/py${python.version}-graph-tool
    }
}

if {$name == $subport} {
    livecheck.type      regex
    livecheck.url       $homepage
    livecheck.regex     Version (\[0-9.\]+) of graph-tool
} else {
    livecheck.type      none
}
