blob: 37087d6357c8b868e89e7163906ec0563636bba9 [file] [log] [blame]
Brent Austinba3052e2015-04-21 16:08:23 -07001#!/bin/rc -e
2# Copyright 2012 The Go Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style
4# license that can be found in the LICENSE file.
5
Dan Willemsen09eb3b12015-09-16 14:34:17 -07006# See golang.org/s/go15bootstrap for an overview of the build process.
7
Brent Austinba3052e2015-04-21 16:08:23 -07008# Environment variables that control make.rc:
9#
10# GOROOT_FINAL: The expected final Go root, baked into binaries.
11# The default is the location of the Go tree during the build.
12#
13# GOHOSTARCH: The architecture for host tools (compilers and
14# binaries). Binaries of this type must be executable on the current
15# system, so the only common reason to set this is to set
16# GOHOSTARCH=386 on an amd64 machine.
17#
18# GOARCH: The target architecture for installed packages and tools.
19#
20# GOOS: The target operating system for installed packages and tools.
21#
Dan Willemsen09eb3b12015-09-16 14:34:17 -070022# GO_GCFLAGS: Additional go tool compile arguments to use when
Brent Austinba3052e2015-04-21 16:08:23 -070023# building the packages and commands.
24#
Dan Willemsen09eb3b12015-09-16 14:34:17 -070025# GO_LDFLAGS: Additional go tool link arguments to use when
Brent Austinba3052e2015-04-21 16:08:23 -070026# building the commands.
27#
Brent Austinba3052e2015-04-21 16:08:23 -070028# CGO_ENABLED: Controls cgo usage during the build. Set it to 1
29# to include all cgo related files, .c and .go file with "cgo"
30# build directive, in the build. Set it to 0 to ignore them.
31
32rfork e
33if(! test -f run.rc){
34 echo 'make.rc must be run from $GOROOT/src' >[1=2]
35 exit wrongdir
36}
37
Brent Austinba3052e2015-04-21 16:08:23 -070038# Clean old generated file that will cause problems in the build.
39rm -f ./runtime/runtime_defs.go
40
41# Determine the host compiler toolchain.
42eval `{grep '^(CC|LD|O)=' /$objtype/mkfile}
43
Dan Willemsena3223282018-02-27 19:41:43 -080044vflag=()
45if(~ $1 -v) {
46 vflag=(-v)
47 shift
48}
49
Colin Cross430342c2019-09-07 08:36:04 -070050GOENV=off
Dan Willemsenc7413322018-08-27 23:21:26 -070051GOFLAGS=()
Colin Crossd9c6b802019-03-19 21:10:31 -070052GO111MODULE=()
Brent Austinba3052e2015-04-21 16:08:23 -070053GOROOT = `{cd .. && pwd}
Dan Willemsenbc60c3c2021-12-15 01:09:00 -080054goroot_bootstrap_set = 'true'
55if(! ~ $#GOROOT_BOOTSTRAP 1){
56 goroot_bootstrap_set = 'false'
Dan Willemsen09eb3b12015-09-16 14:34:17 -070057 GOROOT_BOOTSTRAP = $home/go1.4
Dan Willemsenbc60c3c2021-12-15 01:09:00 -080058 for(d in sdk/go1.17 go1.17)
59 if(test -d $home/$d)
60 GOROOT_BOOTSTRAP = $home/$d
61}
Dan Willemsena3223282018-02-27 19:41:43 -080062for(p in $path){
63 if(! test -x $GOROOT_BOOTSTRAP/bin/go){
64 if(go_exe = `{path=$p whatis go}){
65 goroot = `{GOROOT='' $go_exe env GOROOT}
66 if(! ~ $goroot $GOROOT){
Dan Willemsenbc60c3c2021-12-15 01:09:00 -080067 if(~ $goroot_bootstrap_set 'true'){
68 echo 'WARNING: '$GOROOT_BOOTSTRAP'/bin/go does not exist, found '$go_exe' from env' >[1=2]
69 echo 'WARNING: set '$goroot' as GOROOT_BOOTSTRAP' >[1=2]
70 }
Dan Willemsena3223282018-02-27 19:41:43 -080071 GOROOT_BOOTSTRAP = $goroot
72 }
73 }
74 }
75}
Dan Willemsen09eb3b12015-09-16 14:34:17 -070076if(! test -x $GOROOT_BOOTSTRAP/bin/go){
77 echo 'ERROR: Cannot find '$GOROOT_BOOTSTRAP'/bin/go.' >[1=2]
78 echo 'Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.' >[1=2]
79 exit bootstrap
80}
Dan Willemsena3223282018-02-27 19:41:43 -080081if(~ $GOROOT_BOOTSTRAP $GOROOT){
82 echo 'ERROR: $GOROOT_BOOTSTRAP must not be set to $GOROOT' >[1=2]
83 echo 'Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.' >[1=2]
84 exit bootstrap
85}
86
87echo 'Building Go cmd/dist using '^$GOROOT_BOOTSTRAP
88if(~ $#vflag 1)
89 echo cmd/dist
Colin Cross430342c2019-09-07 08:36:04 -070090GOROOT=$GOROOT_BOOTSTRAP GOOS='' GOARCH='' GO111MODULE=off $GOROOT_BOOTSTRAP/bin/go build -o cmd/dist/dist ./cmd/dist
Brent Austinba3052e2015-04-21 16:08:23 -070091
92eval `{./cmd/dist/dist env -9}
Dan Willemsena3223282018-02-27 19:41:43 -080093if(~ $#vflag 1)
94 echo
Brent Austinba3052e2015-04-21 16:08:23 -070095
96if(~ $1 --dist-tool){
97 # Stop after building dist tool.
98 mkdir -p $GOTOOLDIR
99 if(! ~ $2 '')
100 cp cmd/dist/dist $2
101 mv cmd/dist/dist $GOTOOLDIR/dist
102 exit
103}
104
Dan Willemsena3223282018-02-27 19:41:43 -0800105# Run dist bootstrap to complete make.bash.
106# Bootstrap installs a proper cmd/dist, built with the new toolchain.
107# Throw ours, built with Go 1.4, away after bootstrap.
Dan Willemsencc753b72021-08-31 13:25:42 -0700108./cmd/dist/dist bootstrap -a $vflag $*
Dan Willemsena3223282018-02-27 19:41:43 -0800109rm -f ./cmd/dist/dist
Brent Austinba3052e2015-04-21 16:08:23 -0700110
Dan Willemsena3223282018-02-27 19:41:43 -0800111# DO NOT ADD ANY NEW CODE HERE.
112# The bootstrap+rm above are the final step of make.rc.
113# If something must be added, add it to cmd/dist's cmdbootstrap,
114# to avoid needing three copies in three different shell languages
115# (make.bash, make.bat, make.rc).