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

name                nanovg

categories          graphics
platforms           any
maintainers         @jasonliu-- openmaintainer

if {$subport eq "nanovg"} {

github.setup        wjakob $subport bf2320d1175122374a9b806d91e9e666c9336375
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             20190524
revision            0
epoch               1

license             zlib
description         antialiased 2-D vector drawing library on top of \
                    OpenGL for UI and visualizations
long_description    NanoVG is a small antialiased vector graphics \
                    rendering library for OpenGL. It has a lean API \
                    modeled after the HTML5 <canvas> API. It is \
                    intended to be a practical toolset for building \
                    scalable user interfaces and visualizations.

checksums           rmd160  d86f86dee2d1d00e8b012c765f4ab2057c0e8871 \
                    sha256  b170cf73e56b76827c3d3d745d3a75904be845ad0333334c892ab4b96fcf35bc \
                    size    2023722

}

subport metalnanovg {

github.setup        wjakob nanovg_metal 075b04f16c579728c693b46a2ce408f2325968cf
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             20190710
revision            0
epoch               1

license             MIT
description         Metal port of NanoVG
long_description    MetalNanoVG is the native Metal port of NanoVG \
                    that tries to get the most out of Apple's Graphics \
                    API.

checksums           rmd160  38c518b04026e3ef11a2efe6768509196be8e167 \
                    sha256  99dbf03e16faeaa60506438a46dba8126219cc78c1b00f4a0ad570554c73b769 \
                    size    159280

depends_lib-append  port:nanovg

}

post-patch {
    fs-traverse f ${worksrcpath}/src {
        if {[file isfile ${f}]} {
            switch [file extension ${f}] {
                .c -
                .m {
                    reinplace -q -E {s|(#.*include )"(.*)"|\1<\2>|g} ${f}
                }
            }
        }
    }
}

# Note: This is a no-compile/source-only library. All we need to do is
# move the various files into place.
supported_archs     noarch
use_configure       no
build {}
if {$subport eq "nanovg"} { set name.filesystem $subport }
if {$subport eq "metalnanovg"} { set name.filesystem nanovg_metal }
set destroot_src    ${destroot}${prefix}/src/${name.filesystem}
set destroot_inc    ${destroot}${prefix}/include/${name.filesystem}
set destroot_share  ${destroot}${prefix}/share/${name.filesystem}
set destroot_doc    ${destroot}${prefix}/share/doc/${name.filesystem}
destroot {
    xinstall -d $destroot_src
    xinstall -d $destroot_inc
    xinstall -d $destroot_share
    xinstall -d $destroot_doc
    copy ${worksrcpath}/README.md $destroot_doc/
}

if {$subport eq "nanovg"} {
    post-destroot {
        copy ${worksrcpath}/src/${subport}.c $destroot_src/

        set includes [glob -directory ${worksrcpath}/src *.h]
        foreach i $includes { copy $i $destroot_inc/ }

        copy ${worksrcpath}/example $destroot_share/
        copy ${worksrcpath}/premake4.lua $destroot_share/

        copy ${worksrcpath}/LICENSE.txt $destroot_doc/
    }
}

if {$subport eq "metalnanovg"} {
    post-destroot {
        copy ${worksrcpath}/src/nanovg_mtl.m $destroot_src/
        copy ${worksrcpath}/src/nanovg_mtl_shaders.metal \
             $destroot_src/

        copy ${worksrcpath}/src/nanovg_mtl.h $destroot_inc/
        copy ${worksrcpath}/src/mnvg_bitcode $destroot_inc/

        copy ${worksrcpath}/tools $destroot_share/

        copy ${worksrcpath}/LICENSE $destroot_doc/
    }
}
