--- /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/lang/go/Portfile	2015-04-02 09:31:43.000000000 -0400
+++ /opt/ports/lang/go/Portfile	2015-10-01 23:59:08.000000000 -0400
@@ -2,10 +2,9 @@
 # $Id: Portfile 134659 2015-04-02 13:26:18Z ciserlohn@macports.org $
 
 PortSystem          1.0
+PortGroup           select 1.0
 
 name                go
-epoch               2
-version             1.4.2
 categories          lang
 platforms           darwin freebsd linux
 license             BSD
@@ -25,71 +24,106 @@
 
 homepage            https://golang.org/
 master_sites        https://storage.googleapis.com/golang/
-distfiles           ${name}${version}.src.tar.gz
-worksrcdir          ${name}
 
-checksums           rmd160  dea15b3b4c31554a47b40799f4b9a926ea760e70 \
-                    sha256  299a6fd8f8adfdce15bc06bde926e7b252ae8e24dd5b16b7d8791ed79e7b5e9b
-
-set GOROOT          ${worksrcpath}
-set GOROOT_FINAL    ${prefix}/go
+# Stub port
+if {${name} eq ${subport}} {
+    version             nil
+    supported_archs     noarch
+    use_configure       no
+    build               {}
+    destroot {
+        puts "${name} is a stub port"
+    }
 
-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
+# Actual ports
+} else {
+    switch ${subport} {
+        go1.4 {
+            version     1.4.2
+            checksums   rmd160  dea15b3b4c31554a47b40799f4b9a926ea760e70 \
+                        sha256  299a6fd8f8adfdce15bc06bde926e7b252ae8e24dd5b16b7d8791ed79e7b5e9b
+        }
+        go1.5 {
+            version     1.5.1
+            checksums   rmd160  751d078789bcd6ec0d85e09f5f40d9959877e202 \
+                        sha256  a889873e98d9a72ae396a9b7dd597c29dcd709cafa9097d9c4ba04cff0ec436b
+        }
+    }
+    
+    distfiles           go${version}.src.tar.gz
+    worksrcdir          go
+
+    depends_run         port:go_select
+    select.group        go
+    select.file         ${filespath}/${subport}
+
+    set GOROOT          ${worksrcpath}
+    set GOROOT_FINAL    ${prefix}/lib/${subport}
+
+    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"
+    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
+    use_configure       no
 
-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"
-}
+    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} \
+                        CGO_ENABLED=1
+
+    use_parallel_build  no
+    post-build {
+        # extra tools
+        set tools_dir ${workpath}/tools
+        file mkdir ${tools_dir}
+        system "GOPATH=${tools_dir} GOROOT=${worksrcpath} ${worksrcpath}/bin/go get golang.org/x/tools/cmd/..."
+        system "cp -R ${tools_dir}/* ${worksrcpath}"
+        system "rm -r ${tools_dir}"
+    
+        # 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}
 
-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}
-
-    # binary symlinks
-    foreach f [list go gofmt] {
-        system "cd ${destroot}${prefix}/bin/ && ln -s ../go/bin/$f ./$f"
+    destroot {
+        file copy ${worksrcpath} ${destroot}${GOROOT_FINAL}
     }
 }
 
-destroot.violate_mtree     yes
+subport go1.4 {}
+
+subport go1.5 {
+    depends_build       port:go1.4
+    build.env-append    GOROOT_BOOTSTRAP=${prefix}/lib/go1.4
+}
 
 platform darwin {
     build.env-append GOOS=darwin
