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

PortSystem          1.0

name                go
epoch               2
version             1.7.3
categories          lang
platforms           darwin freebsd linux
license             BSD
maintainers         ciserlohn
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           ${name}${version}.src.tar.gz
worksrcdir          ${name}

checksums           rmd160  a1fbbf8e0805989e2ca74d66912c87e58328c6b5 \
                    sha256  79430a0027a09b0b3ad57e214c4c1acfdd7af290961dd08d322818895af1ef44

depends_build       port:go-1.4

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

build.dir           ${worksrcpath}/src
build.cmd           ./make.bash
build.target
build.env           GOROOT_BOOTSTRAP=${prefix}/lib/go-1.4 \
                    GOROOT=${GOROOT} \
                    GOARCH=${GOARCH} \
                    GOOS=darwin \
                    GOROOT_FINAL=${GOROOT_FINAL} \
                    CC=${configure.cc}

use_parallel_build  no

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

destroot {

    set grfdir ${destroot}${GOROOT_FINAL}
    set docdir ${destroot}${prefix}/share/doc/${name}
    
    xinstall -d ${grfdir}
    xinstall -d ${docdir}
    
    foreach f {api bin lib misc pkg src test} {
        copy ${worksrcpath}/${f} ${grfdir}
    }

    foreach f {go gofmt} {
        system -W ${destroot}${prefix}/bin/ "ln -s ../lib/${name}/bin/$f ./$f"
    }

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

    copy {*}[glob -directory ${worksrcpath}/doc *] ${docdir}
}

if {${os.major} < 12} {
    pre-fetch {
        ui_error "${name} ${version} requires Mac OS X 10.8 or greater."
        return -code error "incompatible Mac OS X version"
    }
}

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