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

github.setup            refi64 uterm b5784fe9008d94615c9fd8de51901e54691d47bf
version                 20190424
revision                1
categories              aqua sysutils x11
license                 BSD
maintainers             {@barracuda156 macos-powerpc.org:barracuda} openmaintainer

description             terminal emulator, written in C++11
long_description        GPU-accelerated {*}${description} and using Skia, libtsm and GLFW.

github.tarball_from     archive

# Build against modern parallel-hashmap fails, use specific old version:
set phm_hash            8d6fa521c8a8cb05f96e2f94d19ff15c2636af0c

master_sites-append     https://github.com/greg7mdp/parallel-hashmap/archive/${phm_hash}/:phm
distfiles-append        parallel-hashmap-${phm_hash}${extract.suffix}:phm

checksums               ${distname}${extract.suffix} \
                        rmd160  9cc22e9517306005251fe322e47ba67021763314 \
                        sha256  89e3386f099115173b81f3770429561f597aa35df4e3b3c0ca159a74ca2291f5 \
                        size    27232 \
                        parallel-hashmap-${phm_hash}${extract.suffix} \
                        rmd160  9b775f2c107879666165c9615a20457ae69b5355 \
                        sha256  ab7319463028a5684d17f1ff74dd0e14cab51d1d1a66c6cdcda57f0f735ed41b \
                        size    1937133

post-extract {
    delete ${worksrcpath}/deps/parallel-hashmap
    move ${workpath}/parallel-hashmap-${phm_hash} ${worksrcpath}/deps/parallel-hashmap
}

cmake.generator         Ninja

patchfiles              patch-CMakeLists.txt.diff \
                        patch-src-attrs.h.diff \
                        patch-src-display.h.diff \
                        patch-src-error.cc.diff \
                        patch-src-text.h.diff \
                        patch-src-text.cc.diff \
                        patch-uterm.cc.diff \
                        patch-src-uterm.cc.diff \
                        patch-src-uterm.h.diff \
                        patch-src-window.h.diff \
                        patch-src-window.cc.diff

# https://github.com/refi64/uterm/issues/8
patchfiles-append       patch-cassert.diff

if {${os.platform} eq "darwin" && ${os.major} < 13} {
    patchfiles-append   patch-src-gl_manager.cc.diff \
                        patch-src-gl_manager.h.diff
}

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    patchfiles-append   patch-src-pty.cc.diff
}

# https://github.com/refi64/uterm/issues/7
if {${configure.build_arch} in [list arm i386 ppc]} {
    patchfiles-append   patch-src-config.cc-32bit.diff

    configure.cxxflags-append \
                        -Wno-error=narrowing
}

# Use C++17 instead of C++14 for abseil sake:
compiler.cxx_standard   2017

set libfmt_v            11
cmake.prefix_path-append \
                        ${prefix}/lib/libfmt${libfmt_v}/cmake

depends_build-append    path:bin/pkg-config:pkgconfig

depends_lib-append      port:abseil \
                        port:gettext-runtime \
                        path:lib/pkgconfig/glfw3.pc:glfw \
                        port:libconfuse \
                        port:libepoxy \
                        port:libfmt${libfmt_v} \
                        port:libtsm \
                        port:libxkbcommon \
                        port:skia \
                        port:utfcpp

configure.args-append   -DUSE_SYSTEM_DEPS=ON

# Disable tcmalloc on macOS - not typically available/needed
configure.args-append   -DTCMALLOC=""

post-destroot {
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 ${worksrcpath}/README.rst ${destroot}${prefix}/share/doc/${name}/
}

notes "
To configure uterm, create ~/.config/uterm/uterm.conf
See ${prefix}/share/doc/${name}/README.rst for configuration options.
"
