# -*- 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: Portfile 106985 2013-06-13 08:44:14Z ciserlohn@macports.org $

PortSystem          1.0

name                go
epoch               2
version             1.1.1
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            http://golang.org/
master_sites        googlecode:${name}
distfiles           ${name}${version}.src.tar.gz
worksrcdir          ${name}

checksums           rmd160  ad1f043583b4eda92d10088ba4d51afb1688f77d \
                    sha256  257f74b8d812bbdec695e842de587a1495e7728b4e63d280586a14786adbb5af

set GOROOT          ${worksrcpath}
set GOROOT_FINAL    ${prefix}/go

switch ${build_arch} {
    i386 {
        set GOARCH 386
        set cmd_prefix 8
    }
    x86_64 {
        set GOARCH amd64
        set cmd_prefix 6
    }
    default {
        # unsupported arch, but GOARCH needs to be set to something to prevent errors
        set GOARCH x
        set cmd_prefix 6
    }
}

pre-fetch {
    if {"big" == ${os.endian}} {
        ui_error "${name} can only be used on an Intel Mac or other computer with a little-endian processor."
        return -code error "incompatible processor"
    }
}

use_configure       no

# attempting the build with clang fails on some go code
compiler.blacklist  clang

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

use_parallel_build  no
post-build {
    # remove mercurial extras
    system "find ${worksrcpath} -type d -name .hg -print0 | xargs -0 rm -rf"
}

test.run            yes
test.dir            ${worksrcpath}/src
test.cmd            ./run.bash
test.target
test.env            ${build.env}

destroot {
    # standard distribution
    file copy ${worksrcpath} ${destroot}${GOROOT_FINAL}

    # bash completion
    xinstall -m 755 -d ${destroot}${prefix}/etc/bash_completion.d
    xinstall -m 644 -W ${worksrcpath}/misc/bash ${name} \
        ${destroot}${prefix}/etc/bash_completion.d/${name}

    # emacs syntax highlighting
    xinstall -m 755 -d ${destroot}${prefix}/share/emacs/site-lisp/
    eval xinstall -m 644 [glob ${worksrcpath}/misc/emacs/*.el] \
        ${destroot}${prefix}/share/emacs/site-lisp/

    # vim syntax highlighting
    set vimdir ${destroot}${prefix}/share/vim/vim73
    xinstall -m 755 -d ${vimdir}/syntax ${vimdir}/ftdetect ${vimdir}/ftplugin
    xinstall -m 644 ${worksrcpath}/misc/vim/syntax/go.vim \
        ${vimdir}/syntax/go.vim
    xinstall -m 644 ${worksrcpath}/misc/vim/ftdetect/gofiletype.vim \
        ${vimdir}/ftdetect/go.vim
    xinstall -m 644 ${worksrcpath}/misc/vim/ftplugin/go/import.vim \
        ${vimdir}/ftplugin/go.vim

    # binary symlinks
    foreach f [list go godoc gofmt] {
        system "cd ${destroot}${prefix}/bin/ && ln -s ../go/bin/$f ./$f"
    }
}

destroot.violate_mtree     yes

platform darwin {
    build.env-append GOOS=darwin
    test.env-append GOOS=darwin
}
platform freebsd {
    build.env-append GOOS=freebsd
    test.env-append GOOS=freebsd
}
platform linux {
    build.env-append GOOS=linux
    test.env-append GOOS=linux
}

livecheck.type      regex
livecheck.url       http://code.google.com/p/go/source/browse
livecheck.regex     {>go([0-9.]+)<}
