# -*- 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 80316 2011-07-09 00:36:54Z takeshi@macports.org $

PortSystem      1.0

name            vis5d
version         1.3.0-beta
revision        7
distname        ${name}+-${version}
categories      science graphics
maintainers     takeshi
description     OpenGL-based scientific visualization program
long_description \
    Vis5D+ is a system for interactive visualization of large 5-D         \
    gridded data sets such as those produced by numerical weather models. \
    One can make isosurfaces, contour line slices, colored slices,        \
    volume renderings, etc of data in a 3-D grid, then rotate and         \
    animate the images in real time. There's also a feature for wind      \
    trajectory tracing, a way to make text anotations for publications,   \
    support for interactive data analysis, etc.
homepage        http://vis5d.sourceforge.net/
platforms       darwin
master_sites    sourceforge:vis5d
use_bzip2       yes

checksums       md5    68df5737a4569c5f10749ca87959f9cb         \
                sha1   14d673f533521ea402cf7bee14b6ebda54466ef8 \
                rmd160 d8390deea19ec8bc1da0f27c779afd25dfa1a42a

depends_build   port:pkgconfig \
                port:libtool
depends_lib     port:netcdf \
                port:ImageMagick \
                port:gettext \
                port:tcl \
                port:libiconv \
                port:mesa \
                port:xorg-libsm

patchfiles      patch-graph_labels.c.diff
post-patch {
#    reinplace "s|-undefined|-flat_namespace -undefined|" \
#                                  ${worksrcpath}/configure
    reinplace "s|-undefined suppress|-undefined dynamic_lookup|" \
                                  ${worksrcpath}/configure
    reinplace "s|^ac_save_positional|#ac_save_positional|" \
                                  ${worksrcpath}/configure
    reinplace "s|LIBTOOL='\$\(SHELL\) \$\(top_builddir\)/libtool'|LIBTOOL=${prefix}/bin/glibtool|" ${worksrcpath}/configure
    reinplace "s|round|roundv5d|" ${worksrcpath}/src/misc.h
    reinplace "s|round|roundv5d|" ${worksrcpath}/src/misc.c
    reinplace "s| round| roundv5d|" ${worksrcpath}/src/work.c
    reinplace "s|MISS/'80808080'X/|MISS/X'80808080'/|" ${worksrcpath}/util/igmk3d.f
    reinplace "s|ZERO/'30'X/|ZERO/X'30'/|" ${worksrcpath}/util/sdest.f
    reinplace "s|IMASK/'1FF'X/|IMASK/X'1FF'/|" ${worksrcpath}/util/topo.f
    reinplace "s|ENDMRK/'80808080'X/|ENDMRK/X'80808080'/|" \
      ${worksrcpath}/util/gg3d.f ${worksrcpath}/util/igg3d.f
    reinplace "s|NULL/'80808080'X/|NULL/X'80808080'/|" ${worksrcpath}/util/igg3d.f
}

post-configure {
    reinplace -E {s|-arch [^ ]+||g} ${worksrcpath}/vis5d+.pc
    if {[variant_isset universal]} {
        reinplace "s|-dynamiclib|-dynamiclib ${configure.universal_ldflags}|" \
            ${worksrcpath}/libtool
    }
}

#configure.env-append        PTHREAD_LIBS=-lpthread
configure.env-append        RANLIB=/usr/bin/ranlib
configure.args              -disable-fortran            \
                            -disable-dependency-tracing \
                            --x-includes=${prefix}/include \
                            --x-libraries=${prefix}/lib
if {![variant_isset universal]} {
    configure.ldflags-append    ${configure.cc_archflags}
}

# seems to use up CPU all the time
#                            -enable-threads

use_parallel_build          yes

post-destroot {
    xinstall -d ${destroot}${prefix}/share/${name}/convert
    eval xinstall -m 644 [glob ${worksrcpath}/convert/*.c] \
        ${destroot}${prefix}/share/${name}/convert
    eval xinstall -m 644 [glob ${worksrcpath}/convert/*.m] \
        ${destroot}${prefix}/share/${name}/convert
    eval xinstall -m 644 [glob ${worksrcpath}/convert/*.f] \
        ${destroot}${prefix}/share/${name}/convert
    xinstall -d ${destroot}${prefix}/share/${name}/userfuncs
    foreach foo {example.f externf.m probe.f README \
                 externf externf_all spd3d.f} {
        xinstall -m 644 ${worksrcpath}/userfuncs/${foo} \
        ${destroot}${prefix}/share/${name}/userfuncs
    }
    xinstall -d ${destroot}${prefix}/share/${name}/scripts
    eval xinstall -m 644 [glob ${worksrcpath}/scripts/*.tcl] \
        ${destroot}${prefix}/share/${name}/scripts
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${destroot}${prefix}/share/doc/${name}/html
    xinstall -d ${destroot}${prefix}/share/doc/${name}/html/stylesheet-images
    xinstall -m 644 ${worksrcpath}/doc/vis5d.pdf \
        ${destroot}${prefix}/share/doc/${name}
    eval xinstall -m 644 [glob ${worksrcpath}/doc/html/*.html] \
        ${destroot}${prefix}/share/doc/${name}/html
    eval xinstall -m 644 \
        [glob ${worksrcpath}/doc/html/stylesheet-images/*.gif] \
        ${destroot}${prefix}/share/doc/${name}/html/stylesheet-images
}

variant g95 description {compiles fortran interface for g95} { \
        depends_build           port:g95
        configure.args-delete   -disable-fortran
        configure.f77           ${prefix}/bin/g95
        configure.env-append    FLIBS=${prefix}/lib/libf95.a
}

#variant gcc43 description {compiles fortran interface for gcc43} \
#    conflicts g95 {
#        depends_build           port:gcc43
#        configure.args-delete   -disable-fortran \
#        configure.f77           ${prefix}/bin/gfortran-mp-4.3
#        configure.env-delete    PTHREAD_LIBS=-lpthread
#}
