# -*- 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 91718 2012-04-09 03:19:16Z ryandesign@macports.org $

PortSystem          1.0
PortGroup           cmake 1.0

name                gerbil
version             0.3
revision            1
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  8f34bf75227161fab1a6771be4e28028027b456a \
                    sha256  0c4d779d6ce402d2c93bcc23d1898d49f442803a0f4c489bcd687d87d9a02dd9

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

# opencv is not universal
universal_variant   no

if {${configure.compiler} == "clang"} {
    # gerbil 0.3 doesn't build with clang++
    configure.compiler llvm-gcc-4.2
}

configure.post_args -DOpenCV_DIR="${prefix}/share/opencv" \
                    -DVOLE_BUNDLE_CORE=on \
                    -DVOLE_BUNDLE_GERBIL=on

post-configure {
    configure.post_args \
                    -DGerbil_Viewer=on \
                    -DGerbil_Edge_Detect=on \
                    -DVole_Seg_Graphs=on \
                    -DVOLE_SHELL=ON \
                    -DCMAKE_EXE_LINKER_FLAGS=\"-framework OpenGL\"

    system -W "${worksrcpath}" "${configure.cmd} ${configure.pre_args} [join ${configure.args}] [join ${configure.post_args}]"
}

# the gerbil makefiles do not provide an install target
destroot {
    # install binaries
    xinstall -m 755 "${worksrcpath}/gerbil" "${destroot}${prefix}/bin/"
    xinstall -m 755 "${worksrcpath}/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 "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 \
                    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}"
            }
        }
    }
}

