# -*- 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

PortSystem          1.0

name                vapor
version             2.2.4
revision            34
categories          science
maintainers         nomaintainer
description         interactive 3D scientific visualization environment
long_description    VAPOR is the Visualization and Analysis Platform \
                    for Ocean, Atmosphere and Solar Researchers. \
                    VAPOR provides an interactive 3D visualization environment \
                    that runs on most UNIX and Windows systems \
                    equipped with modern 3D graphics cards.
homepage            https://www.vapor.ucar.edu
master_sites        ${homepage}/sites/default/files/
distname            ${name}-${version}-src

checksums           rmd160  a690f7f587f858195db8bdbb6736ccb4f5ba8626 \
                    sha256  e43721801c89dc31766ae9304768670f24bea022690cefdd5cc73684249999af \
                    size    46854681

# proj9 supplies a header which is pulled in via libgeotiff.
depends_build-append \
                    port:gmake \
                    port:proj9

depends_lib         port:assimp2 \
                    port:expat \
                    port:glew \
                    port:hdf5 \
                    port:libgeotiff \
                    port:netcdf \
                    port:proj4 \
                    port:py27-numpy \
                    port:py27-scipy \
                    port:udunits2

# TODO: build with either of Qt4 ports. Currently qt4-mac paths are hardcoded.

# if {[file exists ${prefix}/libexec/qt4/bin/qmake]} {
    depends_lib-append \
                    port:qt4-mac
# } else {
#     depends_lib-append \
#                     port:qt4-mac-devel
# }

patchfiles          patch-options.mk.diff \
                    patch-make-config-Darwin.mk.diff \
                    patch-Makefile.diff

# GetAppPath.cpp:45:42: error: could not convert 'false' from 'bool' to 'std::string' {aka 'std::basic_string<char>'}
patchfiles-append   patch-GetAppPath.cpp.diff
# VaporFlow.cpp:1206:24: error: cannot convert 'bool' to 'VAPoR::FieldData*' in return
patchfiles-append   patch-VaporFlow.cpp.diff
# flowparams.cpp:1186:24: error: cannot convert 'bool' to 'VAPoR::FlowLineData*' in return
patchfiles-append   patch-flowparams.cpp.diff
# Fix frameworks paths:
patchfiles-append   patch-vaporgui.diff
# An ugly hack to build tiff2geotiff: libgeotiff includes a header which does not exist in proj4:
patchfiles-append   patch-tiff2geotiff.diff

if {${os.platform} eq "darwin" && ${configure.cxx_stdlib} ne "libc++"} {
    patchfiles-append \
                    patch-cxx11.diff
}

# hdf5 requires it now:
# /opt/local/include/H5public.h:27:21: error: cinttypes: No such file or directory
compiler.cxx_standard   2011

# FIXME: vaporgui crashes on launch.
# 0x02e3fbc8 QGLWidget::glDraw() + 248

use_configure       no

post-configure {
    reinplace "s|@@MP_INSTALL_PREFIX@@|${destroot}${prefix}|g" ${worksrcpath}/options.mk
    reinplace "s|@@MP_PREFIX@@|${prefix}|g" ${worksrcpath}/options.mk ${worksrcpath}/make/config/Darwin.mk \
         ${worksrcpath}/apps/tiff2geotiff/Makefile ${worksrcpath}/apps/vaporgui/Makefile ${worksrcpath}/apps/vaporgui/main/Makefile
    # This assumes qt4-mac specifically:
    reinplace "s|@@QTROOT@@|${prefix}/libexec/qt4|g" ${worksrcpath}/options.mk
    reinplace "s|@@MP_FRAMEWORKS_DIR@@|${frameworks_dir}|g" ${worksrcpath}/options.mk
    reinplace "s|@@MP_CC@@|${configure.cc}|g" ${worksrcpath}/options.mk ${worksrcpath}/make/config/Darwin.mk
    reinplace "s|@@MP_CXX@@|${configure.cxx}|g" ${worksrcpath}/options.mk ${worksrcpath}/make/config/Darwin.mk
    reinplace "s|-F.*/lib|-F${frameworks_dir}|" ${worksrcpath}/apps/vaporgui/Makefile ${worksrcpath}/apps/asciitf2vtf/Makefile
    if {${configure.build_arch} in [list i386 ppc]} {
        reinplace "s|@@ARCHFLAG@@|-m32|g" ${worksrcpath}/make/config/Darwin.mk
    } else {
        reinplace "s|@@ARCHFLAG@@|-m64|g" ${worksrcpath}/make/config/Darwin.mk
    }
    if {${configure.build_arch} eq "x86_64"} {
        set f [open ${worksrcpath}/site.mk "w"]
        puts $f "MACHTYPE=x86_64"
        close $f
    }
}

use_parallel_build  no

build.cmd           gmake
destroot.cmd        gmake

post-destroot {
    file delete -force ${destroot}${prefix}/share/udunits
}

universal_variant   no

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "Version (\\d+(?:\\.\\d+)*) of VAPOR"
