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

name                go
epoch               5
revision            0
categories          lang
license             BSD

maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

homepage            https://go.dev

description         compiled, garbage-collected, concurrent programming \
                    language developed by Google Inc.

long_description    \
    The Go programming language is an open source project to make programmers \
    more productive. Go is expressive, concise, clean, and efficient. Its \
    concurrency mechanisms make it easy to write programs that get the most \
    out of multicore and networked machines, while its novel type system \
    enables flexible and modular program construction. Go compiles quickly \
    to machine code yet has the convenience of garbage collection and the \
    power of run-time reflection. It's a fast, statically typed, compiled \
    language that feels like a dynamically typed, interpreted language. Go \
    is developed by Google Inc.

# This port builds nothing. It provides `go` and `gofmt` for the newest Go
# release this system can actually run, by depending on the versioned toolchain
# that holds it and linking to its commands.
#
# Which release that is depends on the system: 10.13 High Sierra through 11
# Big Sur are offered nothing newer than 1.24, while 12 Monterey and later
# get the current release. The go_toolchain PortGroup owns that mapping; this
# port asks it rather than restating it, so `go` cannot come to disagree with
# the toolchains it is built from.
#
# See https://trac.macports.org/ticket/73086.
set go_wrapped      [go_toolchain.wrapped]

if {${go_wrapped} eq ""} {
    # Below every floor MacPorts packages. The platforms line excludes these
    # systems; this only keeps the Portfile parseable when it is read there.
    set go_wrapped  [go_toolchain.oldest_packaged]
}

# The version is the series, not a patch release. The wrapper's content -- two
# symlinks -- does not change when the toolchain it points at gets a patch
# update, so there is nothing to re-version, and nothing here to fall out of
# step with the toolchain Portfiles.
version             ${go_wrapped}

# Older than this there is no Go release MacPorts can provide. 10.6 in
# particular cannot build one: its dsymutil aborts on the debug information
# Go's linker emits. See lang/go-1.17.
platforms           "darwin >= [go_toolchain.floor]"

depends_lib         port:go-${go_wrapped}

# Only symlinks are installed, so nothing here is architecture specific. The
# toolchain behind them is not, though, and none is built for i386, so `go` is
# in practice unavailable for an i386 build even where this port is offered.
supported_archs     noarch

use_configure       no
distfiles
fetch               {}
extract             {}
build               {}

destroot {
    xinstall -d ${destroot}${prefix}/bin

    foreach f {go gofmt} {
        ln -s ../lib/go-${go_wrapped}/bin/${f} ${destroot}${prefix}/bin/${f}
    }

    # ${prefix}/lib/go was this port's own GOROOT before it became a wrapper,
    # and is referenced by anything that has GOROOT set by hand. The toolchain
    # does not need it -- its GOROOT is compiled in -- so this is purely so
    # that the path keeps working.
    xinstall -d ${destroot}${prefix}/lib
    ln -s go-${go_wrapped} ${destroot}${prefix}/lib/go

    xinstall -d ${destroot}${prefix}/share/doc
    ln -s go-${go_wrapped} ${destroot}${prefix}/share/doc/go
}

notes "
    This provides the Go ${go_wrapped} series, the newest release this version
    of macOS can run, from the go-${go_wrapped} port. Run `go version` for the
    exact release.
"

# Nothing to check here: this port has no upstream of its own and follows
# whichever versioned toolchain applies. Those carry their own livechecks.
livecheck.type      none
