# $Id: Portfile 67164 2010-04-30 13:55:00Z singingwolfboy@macports.org $

PortSystem          1.0

name                go-devel
set real_name       go
version             0.0.1
revision            3
categories          lang
platforms           darwin freebsd linux
license             BSD
maintainers         singingwolfboy
description         Systems programming language developed by Google (development version)
long_description    \
    A systems programming language developed by Google Inc. Go is similar to C, \
    but with fast builds, clean syntax, garbage collection, methods for any \
    type, and run-time reflection. Go promotes writing systems and servers as \
    sets of lightweight communicating processes, called goroutines, with \
    strong support from the language. It feels like a dynamic language but has \
    the speed and safety of a static language. 

homepage            http://golang.org/
fetch.type          hg
hg.url              https://go.googlecode.com/hg/
#hg.tag              release
hg.tag              7a932654bb51

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
    }
    x86_64 {
        set GOARCH amd64
    }
    default {
        # unsupported arch, but GOARCH needs to be set to something to prevent errors
        set GOARCH x
    }
}

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}
use_parallel_build  no

test.run            yes
test.dir            ${worksrcpath}/src
test.cmd            ./run.bash
test.target 
test.env            GOROOT=${GOROOT} GOBIN=${GOBIN} GOARCH=${GOARCH}

destroot {
    # bin files
    file delete ${destroot}${prefix}/bin
    file copy ${GOBIN} ${destroot}${prefix}
        
    # lib files
    file delete -force ${destroot}${prefix}/lib
    file copy ${worksrcpath}/lib ${destroot}${prefix}
    
    # compiled packages (in lib dir)
    file delete ${worksrcpath}/pkg/~place-holder~
    eval file copy [glob ${worksrcpath}/pkg/*] ${destroot}${prefix}/lib/gopkg

    # include files
    file copy ${worksrcpath}/include ${destroot}${prefix}/include/${real_name}
    
    # documentation
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/
    file copy ${worksrcpath}/doc ${destroot}${prefix}/share/doc/${real_name}
    xinstall -m 644 -W ${worksrcpath} favicon.ico \
        ${destroot}${prefix}/share/doc/${real_name}
        
    # bash completion
    xinstall -m 755 -d ${destroot}${prefix}/etc/bash_completion.d
    xinstall -m 644 -W ${worksrcpath}/misc/bash ${real_name} \
        ${destroot}${prefix}/etc/bash_completion.d/${real_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
    xinstall -m 755 -d ${destroot}${prefix}/share/vim/vim72/syntax/
    xinstall -m 644 ${worksrcpath}/misc/vim/${real_name}.vim \
        ${destroot}${prefix}/share/vim/vim72/syntax/
}

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
}
variant nacl description {Native Client platform} {
    build.env-append GOOS=nacl
    test.env-append GOOS=nacl
}
