]> Cypherpunks.ru repositories - gostls13.git/blob - src/make.bash
cmd,std: add go.mod files
[gostls13.git] / src / make.bash
1 #!/usr/bin/env bash
2 # Copyright 2009 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
6 # See golang.org/s/go15bootstrap for an overview of the build process.
7
8 # Environment variables that control make.bash:
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 #
22 # GO_GCFLAGS: Additional go tool compile arguments to use when
23 # building the packages and commands.
24 #
25 # GO_LDFLAGS: Additional go tool link arguments to use when
26 # building the commands.
27 #
28 # 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 #
32 # GO_EXTLINK_ENABLED: Set to 1 to invoke the host linker when building
33 # packages that use cgo.  Set to 0 to do all linking internally.  This
34 # controls the default behavior of the linker's -linkmode option.  The
35 # default value depends on the system.
36 #
37 # GO_LDSO: Sets the default dynamic linker/loader (ld.so) to be used
38 # by the internal linker.
39 #
40 # CC: Command line to run to compile C code for GOHOSTARCH.
41 # Default is "gcc". Also supported: "clang".
42 #
43 # CC_FOR_TARGET: Command line to run to compile C code for GOARCH.
44 # This is used by cgo.  Default is CC.
45 #
46 # CXX_FOR_TARGET: Command line to run to compile C++ code for GOARCH.
47 # This is used by cgo. Default is CXX, or, if that is not set,
48 # "g++" or "clang++".
49 #
50 # FC: Command line to run to compile Fortran code for GOARCH.
51 # This is used by cgo. Default is "gfortran".
52 #
53 # PKG_CONFIG: Path to pkg-config tool. Default is "pkg-config".
54 #
55 # GO_DISTFLAGS: extra flags to provide to "dist bootstrap".
56 # (Or just pass them to the make.bash command line.)
57 #
58 # GOBUILDTIMELOGFILE: If set, make.bash and all.bash write
59 # timing information to this file. Useful for profiling where the
60 # time goes when these scripts run.
61 #
62 # GOROOT_BOOTSTRAP: A working Go tree >= Go 1.4 for bootstrap.
63 # If $GOROOT_BOOTSTRAP/bin/go is missing, $(go env GOROOT) is
64 # tried for all "go" in $PATH. $HOME/go1.4 by default.
65
66 set -e
67
68 unset GOBIN # Issue 14340
69 unset GOFLAGS
70 unset GO111MODULE
71
72 if [ ! -f run.bash ]; then
73         echo 'make.bash must be run from $GOROOT/src' 1>&2
74         exit 1
75 fi
76
77 if [ "$GOBUILDTIMELOGFILE" != "" ]; then
78         echo $(LC_TIME=C date) start make.bash >"$GOBUILDTIMELOGFILE"
79 fi
80
81 # Test for Windows.
82 case "$(uname)" in
83 *MINGW* | *WIN32* | *CYGWIN*)
84         echo 'ERROR: Do not use make.bash to build on Windows.'
85         echo 'Use make.bat instead.'
86         echo
87         exit 1
88         ;;
89 esac
90
91 # Test for bad ld.
92 if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then
93         echo 'ERROR: Your system has gold 2.20 installed.'
94         echo 'This version is shipped by Ubuntu even though'
95         echo 'it is known not to work on Ubuntu.'
96         echo 'Binaries built with this linker are likely to fail in mysterious ways.'
97         echo
98         echo 'Run sudo apt-get remove binutils-gold.'
99         echo
100         exit 1
101 fi
102
103 # Test for bad SELinux.
104 # On Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux,
105 # so loop through the possible selinux mount points.
106 for se_mount in /selinux /sys/fs/selinux
107 do
108         if [ -d $se_mount -a -f $se_mount/booleans/allow_execstack -a -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
109                 if ! cat $se_mount/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; then
110                         echo "WARNING: the default SELinux policy on, at least, Fedora 12 breaks "
111                         echo "Go. You can enable the features that Go needs via the following "
112                         echo "command (as root):"
113                         echo "  # setsebool -P allow_execstack 1"
114                         echo
115                         echo "Note that this affects your system globally! "
116                         echo
117                         echo "The build will continue in five seconds in case we "
118                         echo "misdiagnosed the issue..."
119
120                         sleep 5
121                 fi
122         fi
123 done
124
125 # Test for debian/kFreeBSD.
126 # cmd/dist will detect kFreeBSD as freebsd/$GOARCH, but we need to
127 # disable cgo manually.
128 if [ "$(uname -s)" = "GNU/kFreeBSD" ]; then
129         export CGO_ENABLED=0
130 fi
131
132 # On Alpine Linux, use the musl dynamic linker/loader
133 if [ -f "/etc/alpine-release" ]; then
134         if type readelf >/dev/null 2>&1; then
135                 echo "int main() { return 0; }" | ${CC:-gcc} -o ./test-alpine-ldso -x c -
136                 export GO_LDSO=$(readelf -l ./test-alpine-ldso | grep 'interpreter:' | sed -e 's/^.*interpreter: \(.*\)[]]/\1/')
137                 rm -f ./test-alpine-ldso
138         fi
139 fi
140
141 # Clean old generated file that will cause problems in the build.
142 rm -f ./runtime/runtime_defs.go
143
144 # Finally!  Run the build.
145
146 verbose=false
147 vflag=""
148 if [ "$1" = "-v" ]; then
149         verbose=true
150         vflag=-v
151         shift
152 fi
153
154 export GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4}
155 export GOROOT="$(cd .. && pwd)"
156 IFS=$'\n'; for go_exe in $(type -ap go); do
157         if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
158                 goroot=$(GOROOT='' GOOS='' GOARCH='' "$go_exe" env GOROOT)
159                 if [ "$goroot" != "$GOROOT" ]; then
160                         GOROOT_BOOTSTRAP=$goroot
161                 fi
162         fi
163 done; unset IFS
164 echo "Building Go cmd/dist using $GOROOT_BOOTSTRAP."
165 if $verbose; then
166         echo cmd/dist
167 fi
168 if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
169         echo "ERROR: Cannot find $GOROOT_BOOTSTRAP/bin/go." >&2
170         echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2
171         exit 1
172 fi
173 if [ "$GOROOT_BOOTSTRAP" = "$GOROOT" ]; then
174         echo "ERROR: \$GOROOT_BOOTSTRAP must not be set to \$GOROOT" >&2
175         echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2
176         exit 1
177 fi
178 rm -f cmd/dist/dist
179 GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" GO111MODULE=off "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
180
181 # -e doesn't propagate out of eval, so check success by hand.
182 eval $(./cmd/dist/dist env -p || echo FAIL=true)
183 if [ "$FAIL" = true ]; then
184         exit 1
185 fi
186
187 if $verbose; then
188         echo
189 fi
190
191 if [ "$1" = "--dist-tool" ]; then
192         # Stop after building dist tool.
193         mkdir -p "$GOTOOLDIR"
194         if [ "$2" != "" ]; then
195                 cp cmd/dist/dist "$2"
196         fi
197         mv cmd/dist/dist "$GOTOOLDIR"/dist
198         exit 0
199 fi
200
201 buildall="-a"
202 if [ "$1" = "--no-clean" ]; then
203         buildall=""
204         shift
205 fi
206
207 # Run dist bootstrap to complete make.bash.
208 # Bootstrap installs a proper cmd/dist, built with the new toolchain.
209 # Throw ours, built with Go 1.4, away after bootstrap.
210 ./cmd/dist/dist bootstrap $buildall $vflag $GO_DISTFLAGS "$@"
211 rm -f ./cmd/dist/dist
212
213 # DO NOT ADD ANY NEW CODE HERE.
214 # The bootstrap+rm above are the final step of make.bash.
215 # If something must be added, add it to cmd/dist's cmdbootstrap,
216 # to avoid needing three copies in three different shell languages
217 # (make.bash, make.bat, make.rc).