# -*- 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
PortGroup               legacysupport 1.1
PortGroup               makefile 1.0

github.setup            jarun nnn 5.2 v
github.tarball_from     archive
revision                0
categories              sysutils
license                 BSD
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
description             tiny, lightning fast, feature-packed file manager
long_description        ${name} is a tiny, lightning fast, feature-packed file manager.

checksums               rmd160  9a84cb162ac1df09625bff9df87966ec6963fd65 \
                        sha256  f166eda5093ac8dcf8cbbc6224123a32c53cf37b82c5c1cb48e2e23352754030 \
                        size    270059

installs_libs           no

depends_build           path:bin/pkg-config:pkgconfig

depends_lib             port:readline \
                        port:ncurses \
                        port:pcre2

# https://trac.macports.org/ticket/70577
patchfiles-append       0001-Drop-a-defunct-fallback.patch

compiler.c_standard     2011
compiler.blacklist-append \
                        {clang < 602}

build.args-append       CFLAGS_OPTIMIZATION="" \
                        O_PCRE2=1

# https://github.com/jarun/nnn/issues/2111
if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
    configure.ldflags-append \
                        -latomic
}

post-destroot {
    set bash_completion ${prefix}/share/bash-completion/completions
    xinstall -d ${destroot}${bash_completion}
    xinstall -m 0644 ${worksrcpath}/misc/auto-completion/bash/nnn-completion.bash \
        ${destroot}${bash_completion}/nnn.bash

    set zsh_completion ${prefix}/share/zsh/site-functions
    xinstall -d ${destroot}${zsh_completion}
    xinstall -m 0644 ${worksrcpath}/misc/auto-completion/zsh/_nnn \
        ${destroot}${zsh_completion}/_nnn

    set fish_completion ${prefix}/share/fish/vendor_completions.d
    xinstall -d ${destroot}${fish_completion}
    xinstall -m 0644 ${worksrcpath}/misc/auto-completion/fish/nnn.fish \
        ${destroot}${fish_completion}/nnn.fish

    xinstall -d ${destroot}${prefix}/share/${name}/quitcd
    xinstall -m 0644 {*}[glob ${worksrcpath}/misc/quitcd/quitcd.*] \
        ${destroot}${prefix}/share/${name}/quitcd

    xinstall -d ${destroot}${prefix}/share/${name}/plugins
    xinstall -m 0644 {*}[glob ${worksrcpath}/plugins/*] \
        ${destroot}${prefix}/share/${name}/plugins
}
