# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 103772 2013-03-06 22:59:30Z larryv@macports.org $

PortSystem          1.0
PortGroup           cmake 1.0

name                gerbil
version             0.4a
categories          science
license             GPL-3
maintainers         cal openmaintainer
platforms           darwin
description         Gerbil is a visualization tool targeted at multispectral\
                    and hyperspectral image data, and a toolbox of common\
                    algorithms

long_description    ${description}

homepage            http://gerbil.sourceforge.net/
master_sites        sourceforge:project/gerbil/gerbil
use_bzip2           yes

checksums           rmd160  bacfe1fe4a6d11bce6eba279464c9b272b43d5b4 \
                    sha256  bc41bf0ea805ff51be76b3e6c61a93029901fbd17ec458578657dd6e23553d18

livecheck.regex     "/${name}/${name}-(\[0-9\]+(\\.\[0-9\]+)*\[a-z\]?)\.tar"

depends_lib         port:qt4-mac \
                    port:opencv \
                    port:boost \
                    port:python27

# opencv is not universal
universal_variant   no

worksrcdir          ${name}-0.4

configure.post_args -DOpenCV_DIR="${prefix}/lib/cmake" \
                    -DCMAKE_BUILD_TYPE=Release \
                    -DGerbil_Viewer=on \
                    -DGerbil_Edge_Detect=on \
                    -DVole_Seg_Graphs=on \
                    -DVole_Shell=on \
                    -DCMAKE_EXE_LINKER_FLAGS=\"-framework OpenGL\" \
                    -DBoost_DIR="${prefix}" \
                    -DPYTHON_EXECUTABLE="${prefix}/bin/python2.7" \
                    -DPYTHON_INCLUDE_DIR="${prefix}/Library/Frameworks/Python.framework/Versions/2.7/Headers" \
                    -DPYTHON_LIBRARY="${prefix}/lib/libpython2.7.dylib"

# the gerbil makefiles do not provide an install target
destroot {
    # install binaries
    xinstall -m 755 "${worksrcpath}/bin/gerbil" "${destroot}${prefix}/bin/"
    xinstall -m 755 "${worksrcpath}/bin/qgerbil" "${destroot}${prefix}/bin/"

    # create directories for shared files
    xinstall -d -m 755 "${destroot}${prefix}/share/${name}"
    xinstall -d -m 755 "${destroot}${prefix}/share/${name}/doc"

    # install shared files
    set sharefiles [list "AUTHORS" "COPYING" "README.txt" "doc/file_format.txt" "doc/introduction.txt" "doc/license.txt"]
    foreach file $sharefiles {
        xinstall -m 644 "${worksrcpath}/${file}" "${destroot}${prefix}/share/${name}/${file}"
    }
}

variant doc description {Generate and install gerbil documentation} {
    depends_build-append \
                    port:doxygen \
                    path:bin/dot:graphviz \
                    bin:latex:texlive-latex \
                    bin:makeindex:texlive-basic \
                    bin:dvips:texlive-basic

    build.target-append \
                    doc

    post-destroot {
        set basepath "${worksrcpath}/doc/html"
        fs-traverse docfile "${basepath}" {
            set docfilename [string range "${docfile}" [string length "${basepath}"] end]
            if {[file isdirectory "${docfile}"]} {
                xinstall -d -m 755 "${destroot}${prefix}/share/${name}/doc/html/${docfilename}"
            } else {
                xinstall -m 644 "${docfile}" "${destroot}${prefix}/share/${name}/doc/html/${docfilename}"
            }
        }
    }
}

