# -*- coding: utf-8; mode: tcl; tab-width: 4; c-basic-offset: 4 -*-
# $Id: Portfile 92087 2012-04-17 22:18:29Z mmoll@macports.org $

PortSystem          1.0
PortGroup           python 1.0

set realname        graph-tool
name                py-${realname}
version             2.2.15
revision            1
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
# Latest release doesn't compile with current compilers and current version of Boost.
# We'll switch back to a regular release once 2.2.16 comes out.
# master_sites        http://downloads.skewed.de/graph-tool/
# use_bzip2           yes
# checksums           md5     24dd4aa307fc64c5988a4d827ee16bbd \
#                     sha1    6498ce3208b8d7b1325dcac38dafb24bb8b9ddfe \
#                     rmd160  c998c1110653a487d2ec1ae5aa27c61004f8e011
fetch.type          git
git.url             git://git.skewed.de/graph-tool
git.branch          4ffe8be388affe702e9a7c3a921ed6e2c85e1bf1

distname            ${realname}-${version}

python.versions     25 26 27
python.default_version 27

# graph-tool relies on Boost.Python, so make sure it is installed.
pre-fetch {
    if {![file exists ${prefix}/lib/libboost_python-mt.dylib]} {
        return -code error "Please reinstall boost with one of the python variants enabled."
    }
}

if {$subport != $name} {
    pre-configure {
        system "cd ${worksrcpath} && ./autogen.sh"
    }
    universal_variant  no
    depends_build-append port:autoconf port:automake
    depends_lib-append port:boost \
                       port:cgal \
                       port:expat \
                       path:bin/dot:graphviz \
                       port:py${python.version}-numpy \
                       port:py${python.version}-scipy 
    use_configure      yes
    configure.env-append PYTHON=${python.bin} \
                         PYTHON_VERSION=${python.branch} \
                         PYTHON_CPPFLAGS=-I${python.include} \
                         PYTHON_LDFLAGS="-L${python.libdir}/.. -lpython${python.branch}"
    configure.cflags-append   -I${prefix}/include
    configure.cxxflags-append -I${prefix}/include
    configure.ldflags-append -L${prefix}/lib
    configure.args-append --with-boost=${prefix}
    build.cmd          make
    build.target       all
    destroot.cmd       make
    destroot.destdir   DESTDIR=${destroot}
    if {${configure.compiler} == "clang"} {
        configure.compiler llvm-gcc-4.2
    }
    if {${configure.compiler} == "llvm-gcc-4.2" || 
        ${configure.compiler} == "gcc-4.0" ||
        ${configure.compiler} == "gcc-4.2" ||
        ${configure.compiler} == "apple-gcc-4.0" ||
        ${configure.compiler} == "apple-gcc-4.2" ||
        ${configure.compiler} == "macports-gcc-4.2" ||
        ${configure.compiler} == "macports-gcc-4.3"} {
        configure.cxxflags-append -DCGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES
    }

    # not supported by clang at the moment
    variant openmp description {Add support for openmp} {
        configure.args-append --enable-openmp
    }

    post-destroot {
        xinstall -d ${destroot}${python.pkgd}
        file rename ${destroot}${prefix}/lib/python${python.branch}/site-packages/graph_tool \
            ${destroot}${python.pkgd}
        file rename ${destroot}${prefix}/doc/graph-tool \
            ${destroot}${prefix}/share/doc/graph-tool 
    }
}

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