# $Id: Portfile 86679 2011-10-31 18:47:38Z singingwolfboy@macports.org $

PortSystem          1.0

name                go
conflicts           go-devel
epoch               1
version             60.3
revision            1
categories          lang
platforms           darwin freebsd linux
license             BSD
maintainers         singingwolfboy
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/
fetch.type          hg
hg.url              https://go.googlecode.com/hg/
hg.tag              release.r${version}

depends_build       bin:bison:bison \
                    bin:make:gmake \
                    bin:awk:gawk \
                    bin:ed:ed

set GOROOT          ${worksrcpath}
set GOBIN           ${workpath}/bin

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

pre-build {
    xinstall -m 755 -d ${GOROOT} ${GOBIN}
}
build.dir           ${worksrcpath}/src
build.cmd           ./make.bash
build.target    
build.env           GOROOT=${GOROOT} GOBIN=${GOBIN} GOARCH=${GOARCH} \
                    GOROOT_FINAL=${prefix}
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 {
    # bin files
    file delete ${destroot}${prefix}/bin
    file copy ${GOBIN} ${destroot}${prefix}
    # on Darwin, have to install and setgid; see ${GOROOT}/src/sudo.bash 
    foreach i {prof cov} { 
        xinstall -g procmod -m 2755 ${worksrcpath}/src/cmd/$i/${cmd_prefix}$i \
            ${destroot}${prefix}/bin
    } 
        
    # lib files
    file delete -force ${destroot}${prefix}/lib
    file copy ${worksrcpath}/lib ${destroot}${prefix}
    
    # compiled packages: violates mtree
    file copy ${worksrcpath}/pkg ${destroot}${prefix}

    # do not install include files: see #30203
    
    # documentation
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/
    file copy ${worksrcpath}/doc ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} favicon.ico \
        ${destroot}${prefix}/share/doc/${name}/${name}.ico
    # godoc command required documentation 
    xinstall -m 755 -d ${destroot}${prefix}/src/go 
    file copy ${worksrcpath} ${destroot}${prefix}/src/go 
    system "cd ${destroot}${prefix}/src/${name}/${name}-${version}/src && ./clean.bash" 
    file delete ${destroot}${prefix}/src/${name}/${name}-${version}/bin 
    file delete ${destroot}${prefix}/src/${name}/${name}-${version}/pkg 
    ln -s ${prefix}/src/${name}/${name}-${version}/src/pkg ${destroot}${prefix}/src/pkg 
    # gomake command required makefiles 
    foreach f [glob -tails -directory ${destroot}${prefix}/src/${name}/${name}-${version}/src/ Make.*] {
        ln -s ${name}/${name}-${version}/src/${f} ${destroot}${prefix}/src
    }

    # 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
}
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     {>release\.r([0-9.]+)<}
