summaryrefslogtreecommitdiff
path: root/src/make.rc
blob: 834c1f1ba692a4f5a323319f030ef98074be6048 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/rc -e
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# See golang.org/s/go15bootstrap for an overview of the build process.

# Environment variables that control make.rc:
#
# GOROOT_FINAL: The expected final Go root, baked into binaries.
# The default is the location of the Go tree during the build.
#
# GOHOSTARCH: The architecture for host tools (compilers and
# binaries).  Binaries of this type must be executable on the current
# system, so the only common reason to set this is to set
# GOHOSTARCH=386 on an amd64 machine.
#
# GOARCH: The target architecture for installed packages and tools.
#
# GOOS: The target operating system for installed packages and tools.
#
# GO_GCFLAGS: Additional go tool compile arguments to use when
# building the packages and commands.
#
# GO_LDFLAGS: Additional go tool link arguments to use when
# building the commands.
#
# CGO_ENABLED: Controls cgo usage during the build. Set it to 1
# to include all cgo related files, .c and .go file with "cgo"
# build directive, in the build. Set it to 0 to ignore them.

rfork e
if(! test -f run.rc){
	echo 'make.rc must be run from $GOROOT/src' >[1=2]
	exit wrongdir
}

# Clean old generated file that will cause problems in the build.
rm -f ./runtime/runtime_defs.go

# Determine the host compiler toolchain.
eval `{grep '^(CC|LD|O)=' /$objtype/mkfile}

vflag=()
if(~ $1 -v) {
	vflag=(-v)
	shift
}

fn nogoenv {
	GO111MODULE=off GOENV=off GOOS=() GOARCH=() GOEXPERIMENT=() GOFLAGS=() $*
}

bootgo = 1.17.13
GOROOT = `{cd .. && pwd}
goroot_bootstrap_set = 'true'
if(! ~ $#GOROOT_BOOTSTRAP 1){
	goroot_bootstrap_set = 'false'
	GOROOT_BOOTSTRAP = $home/go1.4
	for(d in sdk/go$bootgo go$bootgo)
		if(test -d $home/$d)
			GOROOT_BOOTSTRAP = $home/$d
}
for(p in $path){
	if(! test -x $GOROOT_BOOTSTRAP/bin/go){
		if(go_exe = `{path=$p whatis go}){
			goroot = `{GOROOT=() nogoenv $go_exe env GOROOT}
			if(! ~ $goroot $GOROOT){
				if(~ $goroot_bootstrap_set 'true'){
					echo 'WARNING: '$GOROOT_BOOTSTRAP'/bin/go does not exist, found '$go_exe' from env' >[1=2]
					echo 'WARNING: set '$goroot' as GOROOT_BOOTSTRAP' >[1=2]
				}
				GOROOT_BOOTSTRAP = $goroot
			}
		}
	}
}
if(! test -x $GOROOT_BOOTSTRAP/bin/go){
	echo 'ERROR: Cannot find '$GOROOT_BOOTSTRAP'/bin/go.' >[1=2]
	echo 'Set $GOROOT_BOOTSTRAP to a working Go tree >= Go '$bootgo'.' >[1=2]
	exit bootstrap
}
if(~ $GOROOT_BOOTSTRAP $GOROOT){
	echo 'ERROR: $GOROOT_BOOTSTRAP must not be set to $GOROOT' >[1=2]
	echo 'Set $GOROOT_BOOTSTRAP to a working Go tree >= Go '$bootgo'.' >[1=2]
	exit bootstrap
}

# Get the exact bootstrap toolchain version to help with debugging.
# We clear GOOS and GOARCH to avoid an ominous but harmless warning if
# the bootstrap doesn't support them.
GOROOT_BOOTSTRAP_VERSION=`{nogoenv $GOROOT_BOOTSTRAP/bin/go version | sed 's/go version //'}
echo 'Building Go cmd/dist using '$GOROOT_BOOTSTRAP'. ('$"GOROOT_BOOTSTRAP_VERSION')'
if(~ $#vflag 1)
	echo cmd/dist
GOROOT=$GOROOT_BOOTSTRAP nogoenv $GOROOT_BOOTSTRAP/bin/go build -o cmd/dist/dist ./cmd/dist

eval `{./cmd/dist/dist env -9}
if(~ $#vflag 1)
	echo

if(~ $1 --dist-tool){
	# Stop after building dist tool.
	mkdir -p $GOTOOLDIR
	if(! ~ $2 '')
		cp cmd/dist/dist $2
	mv cmd/dist/dist $GOTOOLDIR/dist
	exit
}

# Run dist bootstrap to complete make.bash.
# Bootstrap installs a proper cmd/dist, built with the new toolchain.
# Throw ours, built with the bootstrap toolchain, away after bootstrap.
./cmd/dist/dist bootstrap -a $vflag $*
rm -f ./cmd/dist/dist

# DO NOT ADD ANY NEW CODE HERE.
# The bootstrap+rm above are the final step of make.rc.
# If something must be added, add it to cmd/dist's cmdbootstrap,
# to avoid needing three copies in three different shell languages
# (make.bash, make.bat, make.rc).