Debian Codegraph @

src/cmd/dist/buildruntime.go

raw
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 //
21 // (Nothing right now!)
22 func mkzversion(dir, file string) {
23 var buf strings.Builder
24 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 buildcfg
32 //
33 // const defaultGOROOT = <goroot>
34 // const defaultGO386 = <go386>
35 // ...
36 // const defaultGOOS = runtime.GOOS
37 // const defaultGOARCH = runtime.GOARCH
38 //
39 // The use of runtime.GOOS and runtime.GOARCH makes sure that
40 // a cross-compiled compiler expects to compile for its own target
41 // system. That is, if on a Mac you do:
42 //
43 // GOOS=linux GOARCH=ppc64 go build cmd/compile
44 //
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 the
47 // original target (in this example, a Mac).
48 func mkbuildcfg(file string) {
49 var buf strings.Builder
50 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 objabi
78 //
79 // (Nothing right now!)
80 func mkobjabi(file string) {
81 var buf strings.Builder
82 writeHeader(&buf)
83 fmt.Fprintf(&buf, "package objabi\n")
84
85 writefile(buf.String(), file, writeSkipSame)
86 }