# -*- 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
PortGroup           cxx11 1.1

name                terra
version             0.7
revision            4

categories          gis science
maintainers         {gmail.com:tlockhart1976 @lockhart} openmaintainer

description         Generate polygonal approximations of terrains and other height fields.

long_description \
Generate polygonal approximations of terrains and other height fields. \
Terra is based on algorithms described in: \
Fast Polygonal Approximation of Terrains and Height Fields \
by Michael Garland and Paul Heckbert (Technical Report CMU-CS-95-181).

license             public-domain
platforms           darwin

homepage            http://mgarland.org/software/scape.html
master_sites        http://mgarland.org/dist/

checksums           rmd160  885639282ffe5244f5289ef3f453390c8acdb30f \
                    sha256  22470e13e1f0659d23dbf7e0ecbfd8f6490bcd1d0a953537c1dfec18f4df3bd7 \
                    size    206256

depends_lib         port:freeglut

worksrcdir          ${name}

# add proper stdlib and set std=c++11 if building with clang
if {[string match *clang* ${configure.compiler}]} {
    configure.cxx   ${configure.cxx} -stdlib=${configure.cxx_stdlib} -std=c++11
}

# gcc requires std=gnu++11 to enable build
if {[string match *gcc* ${configure.compiler}]} {
    configure.cxx   ${configure.cxx} -std=gnu++11
}

patchfiles          patch-compiler.diff patch-opengl.diff

# add proper archflags set compiler for build
post-patch {
    reinplace -E "s,@CC@,${configure.cc} [get_canonical_archflags cc],g" ${worksrcpath}/Makefile
    reinplace -E "s,@CXX@,${configure.cxx} [get_canonical_archflags cxx],g" ${worksrcpath}/Makefile
    reinplace -E "s,@OPTFLAGS@,${configure.optflags},g" ${worksrcpath}/Makefile
    reinplace -E "s,@PREFIX@,${prefix},g" ${worksrcpath}/Makefile
}

use_configure       no

destroot {
    xinstall -m 755 ${worksrcpath}/terra ${destroot}${prefix}/bin/terra
    xinstall -m 755 ${worksrcpath}/xterra ${destroot}${prefix}/bin/xterra

    # documentation
    xinstall -m 755 -d ${destroot}${prefix}/share/${name}
    xinstall -m 644 ${worksrcpath}/README.html ${destroot}${prefix}/share/${name}
    xinstall -m 644 ${worksrcpath}/crater.pgm ${destroot}${prefix}/share/${name}
}
