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

# This is a Go project, but cannot use the golang PortGroup right now because
# the project is hosted at an unsupported domain (at the moment).
PortGroup legacysupport    1.1
PortGroup compiler_wrapper 1.0

name                bombadillo
version             2.4.0
revision            0

homepage            https://bombadillo.colorfield.space

description         Bombabillo is a non-web client for the terminal, \
                    supporting Gopher, Gemini and much more.

long_description    {*}${description}

categories          net
installs_libs       no
license             GPL-3
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

set project_url     https://tildegit.org/sloum/${name}
master_sites        "${project_url}/archive"
distname            ${version}
dist_subdir         ${name}

checksums           rmd160  2fa99027e7862e94c25aa8da9d3f9b9705f25e19 \
                    sha256  e0daed1d9d0fe7cbea52bc3e6ecff327749b54e792774e6b985e0d64b7a36437 \
                    size    104412

post-extract {
    ln -s ${workpath}/${name} ${worksrcpath}
}

patch {
    reinplace -E {/GOOS=(linux|windows)/d} ${worksrcpath}/Makefile
}

depends_build-append \
                    port:go

pre-build {

    if { ${os.major} <= [option legacysupport.newest_darwin_requires_legacy] } {
        # Note, go annoyingly uses CC for both building and linking, and thus in order to get it to correctly
        # link to the legacy support library, the ldflags need to be added to the cc and ccx wrappers.
        # To then prevent 'clang linker input unused' errors we must append -Wno-error at the end.
        # Also remove '-static' from compilation options as this is not supported on older systems.
        compwrap.compiler_args_forward \$\{\@\//-static/\}
        compwrap.compiler_pre_flags    ${configure.ldflags}
        compwrap.compiler_post_flags   -Wno-error
    }

    build.env-append \
        "CC=[compwrap::wrap_compiler cc]" \
        "CXX=[compwrap::wrap_compiler cxx]" \
        "OBJC=[compwrap::wrap_compiler objc]" \
        "OBJCXX=[compwrap::wrap_compiler objcxx]" \
        "FC=[compwrap::wrap_compiler fc]" \
        "F90=[compwrap::wrap_compiler f90]" \
        "F77=[compwrap::wrap_compiler f77]"

    if { ${os.major} <= [option legacysupport.newest_darwin_requires_legacy] } {
        build.env-append \
            "GO_EXTLINK_ENABLED=1" \
            "BOOT_GO_LDFLAGS=-extldflags='${configure.ldflags}'" \
            "CGO_CFLAGS=${configure.cflags} [get_canonical_archflags cc]" \
            "CGO_CXXFLAGS=${configure.cxxflags} [get_canonical_archflags cxx]" \
            "CGO_LDFLAGS=${configure.cflags} ${configure.ldflags} [get_canonical_archflags ld]" \
            "GO_LDFLAGS=-extldflags='${configure.ldflags} [get_canonical_archflags ld]'"
    }

}

use_configure       no

build.target        build

destroot.pre_args-append \
                    DESTDIR=${destroot} \
                    PREFIX=${prefix}
destroot.target     install

livecheck.url       "${project_url}/releases"
livecheck.type      regex
livecheck.regex     {archive/([0-9.]+)\.}
