codekingpro/portable-devtools
114k
1// Copyright 2012 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4 5package main6 7import (8 "fmt"9 "os"10 "strings"11)12 13/*14 * Helpers for building runtime.15 */16 17// mkzversion writes zversion.go:18//19// package sys20//21// (Nothing right now!)22func mkzversion(dir, file string) {23 var buf strings.Builder24 writeHeader(&buf)25 fmt.Fprintf(&buf, "package sys\n")26 writefile(buf.String(), file, writeSkipSame)27}28 29// mkbuildcfg writes internal/buildcfg/zbootstrap.go:30//31// package buildcfg32//33// const defaultGOROOT = <goroot>34// const defaultGO386 = <go386>35// ...36// const defaultGOOS = runtime.GOOS37// const defaultGOARCH = runtime.GOARCH38//39// The use of runtime.GOOS and runtime.GOARCH makes sure that40// a cross-compiled compiler expects to compile for its own target41// system. That is, if on a Mac you do:42//43// GOOS=linux GOARCH=ppc64 go build cmd/compile44//45// the resulting compiler will default to generating linux/ppc64 object files.46// This is more useful than having it default to generating objects for the47// original target (in this example, a Mac).48func mkbuildcfg(file string) {49 var buf strings.Builder50 writeHeader(&buf)51 fmt.Fprintf(&buf, "package buildcfg\n")52 fmt.Fprintln(&buf)53 fmt.Fprintf(&buf, "import \"runtime\"\n")54 fmt.Fprintln(&buf)55 fmt.Fprintf(&buf, "const DefaultGO386 = `%s`\n", go386)56 fmt.Fprintf(&buf, "const DefaultGOAMD64 = `%s`\n", goamd64)57 fmt.Fprintf(&buf, "const DefaultGOARM = `%s`\n", goarm)58 fmt.Fprintf(&buf, "const DefaultGOARM64 = `%s`\n", goarm64)59 fmt.Fprintf(&buf, "const DefaultGOMIPS = `%s`\n", gomips)60 fmt.Fprintf(&buf, "const DefaultGOMIPS64 = `%s`\n", gomips64)61 fmt.Fprintf(&buf, "const DefaultGOPPC64 = `%s`\n", goppc64)62 fmt.Fprintf(&buf, "const DefaultGORISCV64 = `%s`\n", goriscv64)63 fmt.Fprintf(&buf, "const defaultGOEXPERIMENT = `%s`\n", goexperiment)64 fmt.Fprintf(&buf, "const defaultGO_EXTLINK_ENABLED = `%s`\n", goextlinkenabled)65 fmt.Fprintf(&buf, "const defaultGO_LDSO = `%s`\n", defaultldso)66 fmt.Fprintf(&buf, "const version = `%s`\n", findgoversion())67 fmt.Fprintf(&buf, "const defaultGOOS = runtime.GOOS\n")68 fmt.Fprintf(&buf, "const defaultGOARCH = runtime.GOARCH\n")69 fmt.Fprintf(&buf, "const DefaultGOFIPS140 = `%s`\n", gofips140)70 fmt.Fprintf(&buf, "const DefaultCGO_ENABLED = %s\n", quote(os.Getenv("CGO_ENABLED")))71 72 writefile(buf.String(), file, writeSkipSame)73}74 75// mkobjabi writes cmd/internal/objabi/zbootstrap.go:76//77// package objabi78//79// (Nothing right now!)80func mkobjabi(file string) {81 var buf strings.Builder82 writeHeader(&buf)83 fmt.Fprintf(&buf, "package objabi\n")84 85 writefile(buf.String(), file, writeSkipSame)86}87 