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

name                go-1.4

version             1.4.3
revision            1
categories          lang
# https://trac.macports.org/ticket/63673
platforms           {darwin < 21}
license             BSD
maintainers         {ciserlohn @ci42}
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.

homepage            https://golang.org/
master_sites        https://storage.googleapis.com/golang/
distfiles           go${version}.src.tar.gz
worksrcdir          go

checksums           rmd160  b1fbb2805a777c8107e7c946f36a881303ac5e35 \
                    sha256  9947fc705b0b841b5938c48b22dc33e9647ec0752bae66e50278df4f23f64959

set GOROOT          ${worksrcpath}
set GOROOT_FINAL    ${prefix}/lib/${name}

supported_archs     i386 x86_64

switch ${build_arch} {
    i386 {
        set GOARCH 386
    }
    x86_64 {
        set GOARCH amd64
    }
    default {
        set GOARCH {}
    }
}

use_configure       no

if {${os.platform} eq "darwin" && ${os.major} >= 16} {
    patchfiles-append patch-src-runtime-sys_darwin_386-sierra-clock_gettime.diff
}

build.dir           ${worksrcpath}/src
build.cmd           ./make.bash
build.target
build.env           GOROOT=${GOROOT} \
                    GOARCH=${GOARCH} \
                    GOOS=darwin \
                    GOROOT_FINAL=${GOROOT_FINAL} \
                    CC=${configure.cc} \
                    GCC=${configure.cc} \
                    CGO_ENABLED=0

if {${configure.build_arch} eq "i386"} {
    # Build system is defunct and may not respect GOARCH.
    build.env-append \
                    GOHOSTARCH=${GOARCH}
}

use_parallel_build  no

post-build {
    system "find ${worksrcpath} -type d -name .hg* -print0 | xargs -0 rm -rf"
}

destroot {

    set grfdir ${destroot}${GOROOT_FINAL}
    set bindir ${grfdir}/bin
    set docdir ${destroot}${prefix}/share/doc/${name}

    xinstall -d ${grfdir}
    xinstall -d ${bindir}
    xinstall -d ${docdir}

    xinstall -m 755 -W ${worksrcpath} \
        bin/go \
        ${bindir}

    foreach f {pkg src} {
        copy ${worksrcpath}/${f} ${grfdir}
    }

    xinstall -m 644 -W ${worksrcpath} \
        AUTHORS \
        CONTRIBUTORS \
        LICENSE \
        README \
        PATENTS \
        VERSION \
        ${docdir}
}

livecheck.type      regex
livecheck.url       ${homepage}/dl/
livecheck.regex     {go(1\.4\.[0-9.]+)\.src\.tar\.gz}
