github.com/rsc/go@v0.0.0-20150416155037-e040fd465409/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 ) 11 12 /* 13 * Helpers for building runtime. 14 */ 15 16 // mkzversion writes zversion.go: 17 // 18 // package runtime 19 // const defaultGoroot = <goroot> 20 // const theVersion = <version> 21 // 22 func mkzversion(dir, file string) { 23 out := fmt.Sprintf( 24 "// auto generated by go tool dist\n"+ 25 "\n"+ 26 "package runtime\n"+ 27 "\n"+ 28 "const defaultGoroot = `%s`\n"+ 29 "const theVersion = `%s`\n"+ 30 "const goexperiment = `%s`\n"+ 31 "var buildVersion = theVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT")) 32 33 writefile(out, file, 0) 34 } 35 36 // mkzbootstrap writes cmd/internal/obj/zbootstrap.go: 37 // 38 // package obj 39 // 40 // const defaultGOROOT = <goroot> 41 // const defaultGO386 = <go386> 42 // const defaultGOARM = <goarm> 43 // const defaultGOOS = runtime.GOOS 44 // const defaultGOARCH = runtime.GOARCH 45 // const defaultGO_EXTLINK_ENABLED = <goextlinkenabled> 46 // const version = <version> 47 // const goexperiment = <goexperiment> 48 // 49 // The use of runtime.GOOS and runtime.GOARCH makes sure that 50 // a cross-compiled compiler expects to compile for its own target 51 // system. That is, if on a Mac you do: 52 // 53 // GOOS=linux GOARCH=ppc64 go build cmd/9g 54 // 55 // the resulting compiler will default to generating linux/ppc64 object files. 56 // This is more useful than having it default to generating objects for the 57 // original target (in this example, a Mac). 58 func mkzbootstrap(file string) { 59 out := fmt.Sprintf( 60 "// auto generated by go tool dist\n"+ 61 "\n"+ 62 "package obj\n"+ 63 "\n"+ 64 "import \"runtime\"\n"+ 65 "\n"+ 66 "const defaultGOROOT = `%s`\n"+ 67 "const defaultGO386 = `%s`\n"+ 68 "const defaultGOARM = `%s`\n"+ 69 "const defaultGOOS = runtime.GOOS\n"+ 70 "const defaultGOARCH = runtime.GOARCH\n"+ 71 "const defaultGO_EXTLINK_ENABLED = `%s`\n"+ 72 "const version = `%s`\n"+ 73 "const goexperiment = `%s`\n", 74 goroot_final, go386, goarm, goextlinkenabled, findgoversion(), os.Getenv("GOEXPERIMENT")) 75 76 writefile(out, file, 0) 77 }