github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/src/cmd/dist/buildruntime.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "os" 10 "strings" 11 ) 12 13 /* 14 * Helpers for building runtime. 15 */ 16 17 // mkzversion writes zversion.go: 18 // 19 // package sys 20 // const DefaultGoroot = <goroot> 21 // const TheVersion = <version> 22 // const Goexperiment = <goexperiment> 23 // const StackGuardMultiplier = <multiplier value> 24 // 25 func mkzversion(dir, file string) { 26 out := fmt.Sprintf( 27 "// auto generated by go tool dist\n"+ 28 "\n"+ 29 "package sys\n"+ 30 "\n"+ 31 "const DefaultGoroot = `%s`\n"+ 32 "const TheVersion = `%s`\n"+ 33 "const Goexperiment = `%s`\n"+ 34 "const StackGuardMultiplier = %d\n\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier()) 35 36 writefile(out, file, writeSkipSame) 37 } 38 39 // mkzbootstrap writes cmd/internal/obj/zbootstrap.go: 40 // 41 // package obj 42 // 43 // const defaultGOROOT = <goroot> 44 // const defaultGO386 = <go386> 45 // const defaultGOARM = <goarm> 46 // const defaultGOOS = runtime.GOOS 47 // const defaultGOARCH = runtime.GOARCH 48 // const defaultGO_EXTLINK_ENABLED = <goextlinkenabled> 49 // const version = <version> 50 // const stackGuardMultiplier = <multiplier value> 51 // const goexperiment = <goexperiment> 52 // 53 // The use of runtime.GOOS and runtime.GOARCH makes sure that 54 // a cross-compiled compiler expects to compile for its own target 55 // system. That is, if on a Mac you do: 56 // 57 // GOOS=linux GOARCH=ppc64 go build cmd/compile 58 // 59 // the resulting compiler will default to generating linux/ppc64 object files. 60 // This is more useful than having it default to generating objects for the 61 // original target (in this example, a Mac). 62 func mkzbootstrap(file string) { 63 out := fmt.Sprintf( 64 "// auto generated by go tool dist\n"+ 65 "\n"+ 66 "package obj\n"+ 67 "\n"+ 68 "import \"runtime\"\n"+ 69 "\n"+ 70 "const defaultGOROOT = `%s`\n"+ 71 "const defaultGO386 = `%s`\n"+ 72 "const defaultGOARM = `%s`\n"+ 73 "const defaultGOOS = runtime.GOOS\n"+ 74 "const defaultGOARCH = runtime.GOARCH\n"+ 75 "const defaultGO_EXTLINK_ENABLED = `%s`\n"+ 76 "const version = `%s`\n"+ 77 "const stackGuardMultiplier = %d\n"+ 78 "const goexperiment = `%s`\n", 79 goroot_final, go386, goarm, goextlinkenabled, findgoversion(), stackGuardMultiplier(), os.Getenv("GOEXPERIMENT")) 80 81 writefile(out, file, writeSkipSame) 82 } 83 84 // stackGuardMultiplier returns a multiplier to apply to the default 85 // stack guard size. Larger multipliers are used for non-optimized 86 // builds that have larger stack frames. 87 func stackGuardMultiplier() int { 88 for _, s := range strings.Split(os.Getenv("GO_GCFLAGS"), " ") { 89 if s == "-N" { 90 return 2 91 } 92 } 93 return 1 94 }