2012-02-03 16:16:42 -07:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-07 09:38:00 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2015-04-30 17:57:23 -06:00
|
|
|
"strings"
|
2015-01-07 09:38:00 -07:00
|
|
|
)
|
2012-02-03 16:16:42 -07:00
|
|
|
|
|
|
|
/*
|
2014-09-07 22:06:45 -06:00
|
|
|
* Helpers for building runtime.
|
2012-02-03 16:16:42 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
// mkzversion writes zversion.go:
|
|
|
|
//
|
|
|
|
// package runtime
|
2015-11-11 10:39:30 -07:00
|
|
|
// const DefaultGoroot = <goroot>
|
|
|
|
// const TheVersion = <version>
|
|
|
|
// const Goexperiment = <goexperiment>
|
|
|
|
// const StackGuardMultiplier = <multiplier value>
|
|
|
|
// const BuildVersion = <build version>
|
2012-02-03 16:16:42 -07:00
|
|
|
//
|
2015-01-07 09:38:00 -07:00
|
|
|
func mkzversion(dir, file string) {
|
|
|
|
out := fmt.Sprintf(
|
|
|
|
"// auto generated by go tool dist\n"+
|
|
|
|
"\n"+
|
2015-11-11 10:39:30 -07:00
|
|
|
"package sys\n"+
|
2015-01-07 09:38:00 -07:00
|
|
|
"\n"+
|
2015-11-11 10:39:30 -07:00
|
|
|
"const DefaultGoroot = `%s`\n"+
|
|
|
|
"const TheVersion = `%s`\n"+
|
|
|
|
"const Goexperiment = `%s`\n"+
|
|
|
|
"const StackGuardMultiplier = %d\n\n"+
|
|
|
|
"var BuildVersion = TheVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())
|
2013-09-16 18:26:10 -06:00
|
|
|
|
2015-04-20 09:41:31 -06:00
|
|
|
writefile(out, file, writeSkipSame)
|
2013-09-16 18:26:10 -06:00
|
|
|
}
|
2015-01-21 10:09:20 -07:00
|
|
|
|
|
|
|
// mkzbootstrap writes cmd/internal/obj/zbootstrap.go:
|
|
|
|
//
|
|
|
|
// package obj
|
|
|
|
//
|
|
|
|
// const defaultGOROOT = <goroot>
|
2015-02-06 03:57:42 -07:00
|
|
|
// const defaultGO386 = <go386>
|
2015-01-21 10:09:20 -07:00
|
|
|
// const defaultGOARM = <goarm>
|
2015-03-01 17:42:03 -07:00
|
|
|
// const defaultGOOS = runtime.GOOS
|
|
|
|
// const defaultGOARCH = runtime.GOARCH
|
2015-02-27 20:50:01 -07:00
|
|
|
// const defaultGO_EXTLINK_ENABLED = <goextlinkenabled>
|
2015-01-21 10:09:20 -07:00
|
|
|
// const version = <version>
|
2015-04-30 17:57:23 -06:00
|
|
|
// const stackGuardMultiplier = <multiplier value>
|
2015-01-21 10:09:20 -07:00
|
|
|
// const goexperiment = <goexperiment>
|
|
|
|
//
|
2015-03-01 17:42:03 -07:00
|
|
|
// The use of runtime.GOOS and runtime.GOARCH makes sure that
|
|
|
|
// a cross-compiled compiler expects to compile for its own target
|
|
|
|
// system. That is, if on a Mac you do:
|
|
|
|
//
|
2015-06-23 17:50:12 -06:00
|
|
|
// GOOS=linux GOARCH=ppc64 go build cmd/compile
|
2015-03-01 17:42:03 -07:00
|
|
|
//
|
|
|
|
// the resulting compiler will default to generating linux/ppc64 object files.
|
|
|
|
// This is more useful than having it default to generating objects for the
|
|
|
|
// original target (in this example, a Mac).
|
2015-01-21 10:09:20 -07:00
|
|
|
func mkzbootstrap(file string) {
|
|
|
|
out := fmt.Sprintf(
|
|
|
|
"// auto generated by go tool dist\n"+
|
|
|
|
"\n"+
|
|
|
|
"package obj\n"+
|
|
|
|
"\n"+
|
2015-03-01 17:42:03 -07:00
|
|
|
"import \"runtime\"\n"+
|
|
|
|
"\n"+
|
2015-01-21 10:09:20 -07:00
|
|
|
"const defaultGOROOT = `%s`\n"+
|
2015-02-06 03:57:42 -07:00
|
|
|
"const defaultGO386 = `%s`\n"+
|
2015-01-21 10:09:20 -07:00
|
|
|
"const defaultGOARM = `%s`\n"+
|
2015-03-01 17:42:03 -07:00
|
|
|
"const defaultGOOS = runtime.GOOS\n"+
|
|
|
|
"const defaultGOARCH = runtime.GOARCH\n"+
|
2015-02-27 20:50:01 -07:00
|
|
|
"const defaultGO_EXTLINK_ENABLED = `%s`\n"+
|
2015-01-21 10:09:20 -07:00
|
|
|
"const version = `%s`\n"+
|
2015-04-30 17:57:23 -06:00
|
|
|
"const stackGuardMultiplier = %d\n"+
|
2015-01-21 10:09:20 -07:00
|
|
|
"const goexperiment = `%s`\n",
|
2015-04-30 17:57:23 -06:00
|
|
|
goroot_final, go386, goarm, goextlinkenabled, findgoversion(), stackGuardMultiplier(), os.Getenv("GOEXPERIMENT"))
|
2015-01-21 10:09:20 -07:00
|
|
|
|
2015-04-20 09:41:31 -06:00
|
|
|
writefile(out, file, writeSkipSame)
|
2015-01-21 10:09:20 -07:00
|
|
|
}
|
2015-04-30 17:57:23 -06:00
|
|
|
|
|
|
|
// stackGuardMultiplier returns a multiplier to apply to the default
|
|
|
|
// stack guard size. Larger multipliers are used for non-optimized
|
|
|
|
// builds that have larger stack frames.
|
|
|
|
func stackGuardMultiplier() int {
|
|
|
|
for _, s := range strings.Split(os.Getenv("GO_GCFLAGS"), " ") {
|
|
|
|
if s == "-N" {
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|