Home | History | Annotate | Download | only in dist
      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 runtime
     20 //	const defaultGoroot = <goroot>
     21 //	const theVersion = <version>
     22 //	const goexperiment = <goexperiment>
     23 //	const stackGuardMultiplier = <multiplier value>
     24 //	const buildVersion = <build version>
     25 //
     26 func mkzversion(dir, file string) {
     27 	out := fmt.Sprintf(
     28 		"// auto generated by go tool dist\n"+
     29 			"\n"+
     30 			"package runtime\n"+
     31 			"\n"+
     32 			"const defaultGoroot = `%s`\n"+
     33 			"const theVersion = `%s`\n"+
     34 			"const goexperiment = `%s`\n"+
     35 			"const stackGuardMultiplier = %d\n"+
     36 			"var buildVersion = theVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())
     37 
     38 	writefile(out, file, writeSkipSame)
     39 }
     40 
     41 // mkzbootstrap writes cmd/internal/obj/zbootstrap.go:
     42 //
     43 //	package obj
     44 //
     45 //	const defaultGOROOT = <goroot>
     46 //	const defaultGO386 = <go386>
     47 //	const defaultGOARM = <goarm>
     48 //	const defaultGOOS = runtime.GOOS
     49 //	const defaultGOARCH = runtime.GOARCH
     50 //	const defaultGO_EXTLINK_ENABLED = <goextlinkenabled>
     51 //	const version = <version>
     52 //	const stackGuardMultiplier = <multiplier value>
     53 //	const goexperiment = <goexperiment>
     54 //
     55 // The use of runtime.GOOS and runtime.GOARCH makes sure that
     56 // a cross-compiled compiler expects to compile for its own target
     57 // system. That is, if on a Mac you do:
     58 //
     59 //	GOOS=linux GOARCH=ppc64 go build cmd/compile
     60 //
     61 // the resulting compiler will default to generating linux/ppc64 object files.
     62 // This is more useful than having it default to generating objects for the
     63 // original target (in this example, a Mac).
     64 func mkzbootstrap(file string) {
     65 	out := fmt.Sprintf(
     66 		"// auto generated by go tool dist\n"+
     67 			"\n"+
     68 			"package obj\n"+
     69 			"\n"+
     70 			"import \"runtime\"\n"+
     71 			"\n"+
     72 			"const defaultGOROOT = `%s`\n"+
     73 			"const defaultGO386 = `%s`\n"+
     74 			"const defaultGOARM = `%s`\n"+
     75 			"const defaultGOOS = runtime.GOOS\n"+
     76 			"const defaultGOARCH = runtime.GOARCH\n"+
     77 			"const defaultGO_EXTLINK_ENABLED = `%s`\n"+
     78 			"const version = `%s`\n"+
     79 			"const stackGuardMultiplier = %d\n"+
     80 			"const goexperiment = `%s`\n",
     81 		goroot_final, go386, goarm, goextlinkenabled, findgoversion(), stackGuardMultiplier(), os.Getenv("GOEXPERIMENT"))
     82 
     83 	writefile(out, file, writeSkipSame)
     84 }
     85 
     86 // stackGuardMultiplier returns a multiplier to apply to the default
     87 // stack guard size.  Larger multipliers are used for non-optimized
     88 // builds that have larger stack frames.
     89 func stackGuardMultiplier() int {
     90 	for _, s := range strings.Split(os.Getenv("GO_GCFLAGS"), " ") {
     91 		if s == "-N" {
     92 			return 2
     93 		}
     94 	}
     95 	return 1
     96 }
     97