# -*- 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 115709 2014-01-09 16:10:16Z eborisch@macports.org $

PortSystem          1.0
PortGroup           cmake 1.0
PortGroup           github 1.0
PortGroup           active_variants 1.1
PortGroup           compiler_blacklist_versions 1.0

github.setup        idiap bob 1.2.2 v
revision            2
set soversion       1.2
categories          science math devel
platforms           darwin
maintainers         idiap.ch:andre.anjos \
                    idiap.ch:laurent.el-shafey

description         Bob is a signal-processing and machine learning toolbox

long_description    Bob is a signal-processing and machine learning toolbox \
                    developed at the Idiap Research Institute, in Martigny, \
                    Switzerland. The toolbox is written in a mix of Python \
                    and C++ and is designed to be both efficient and to \
                    reduce development time.

license             GPL-3
homepage            http://idiap.github.com/bob/

checksums           rmd160  fa2ededccdee5cb2cf8db1900631490dd9f412a9 \
                    sha256  df88a3c41ea2be42f6695da13b861fb10b5bbf8bff85ad8f4b7f345543a789e1

depends_build-append \
    port:pkgconfig

depends_lib         port:blitz \
    path:lib/libavcodec.dylib:ffmpeg \
    port:matio \
    port:jpeg \
    port:netpbm \
    port:libpng \
    port:tiff \
    port:giflib \
    port:hdf5-18 \
    port:boost \
    port:fftw-3 \
    port:vlfeat \
    port:libsvm \
    port:qt4-mac

# compiler needs to support C++11 features
if {[lsearch [get_canonical_archs] ppc] != -1 || [lsearch [get_canonical_archs] ppc64] != -1} {
    # Until llvm better supports darwin/ppc, the only C++11 compiler for ppc is gcc
    compiler.whitelist macports-gcc-4.7
} else {
    compiler.blacklist gcc-4.0 gcc-4.2 apple-gcc-4.2 llvm-gcc-4.2 macports-llvm-gcc-4.2 {clang < 300}
}

configure.args      -DCMAKE_BUILD_TYPE=Release -DBOB_VERSION=${version} -DBOB_SOVERSION=${soversion}

# blitz is not universal
universal_variant   no

if { ![variant_isset python26] } {
    default_variants-append +python27
}

variant python26 conflicts python27 description "Build for python 2.6" {
    depends_build-append  port:py26-sphinx
    
    depends_lib-append    port:py26-setuptools \
      port:py26-numpy \
      port:py26-matplotlib \
      port:py26-sqlalchemy \
      port:py26-argparse \
      port:py26-scipy \
      port:py26-nose \
      port:py26-pillow
}

variant python27 conflicts python26 description "Build for python 2.7" {
    depends_build-append  port:py27-sphinx
    
    depends_lib-append    port:py27-setuptools \
      port:py27-numpy \
      port:py27-matplotlib \
      port:py27-sqlalchemy \
      port:py27-scipy \
      port:py27-nose \
      port:py27-pillow
}

variant doc description "Build documentation" {
    depends_build-append    port:dvipng \
        port:doxygen \
        path:bin/dot:graphviz \
        port:texlive-latex-extra \
        port:texlive-fonts-recommended
    destroot.target-append  sphinx-latex install-sphinx install-doxygen

    test.run yes
    test.target sphinx-doctest
}

pre-configure {
    if {[variant_isset python26]} {
        configure.args-append -DWITH_PYTHON=${prefix}/bin/python2.6
    } elseif {[variant_isset python27]} {
        configure.args-append -DWITH_PYTHON=${prefix}/bin/python2.7
    }
}

post-destroot {
    if {[variant_isset python26]} {
        set pypath ${prefix}/lib/python2.6/site-packages
        set pycompile ${prefix}/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
        xinstall -d ${destroot}/${pycompile}
        system "${prefix}/bin/python2.6 -m compileall ${destroot}/${pypath}/bob"
        move ${destroot}/${pypath}/bob ${destroot}/${pycompile}/bob
        move ${destroot}/${pypath}/bob-${version}-py2.6.egg-info ${destroot}/${pycompile}/
    } elseif {[variant_isset python27]} {
        set pypath ${prefix}/lib/python2.7/site-packages
        set pycompile ${prefix}/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
        xinstall -d ${destroot}/${pycompile}
        system "${prefix}/bin/python2.7 -m compileall ${destroot}/${pypath}/bob"
        move ${destroot}/${pypath}/bob ${destroot}/${pycompile}/bob
        move ${destroot}/${pypath}/bob-${version}-py2.7.egg-info ${destroot}/${pycompile}/
    }
}

# check if boost is installed with the required python variant
if {[variant_isset python26]} {
    set boost_python_variant    python26
} elseif {[variant_isset python27]} {
    set boost_python_variant    python27
}

require_active_variants boost   ${boost_python_variant}
