]> Cypherpunks.ru repositories - gostls13.git/blob - src/make.bat
make.bat, make.rc: show bootstrap toolchain version
[gostls13.git] / src / make.bat
1 :: Copyright 2012 The Go Authors. All rights reserved.\r
2 :: Use of this source code is governed by a BSD-style\r
3 :: license that can be found in the LICENSE file.\r
4 \r
5 :: Environment variables that control make.bat:\r
6 ::\r
7 :: GOROOT_FINAL: The expected final Go root, baked into binaries.\r
8 :: The default is the location of the Go tree during the build.\r
9 ::\r
10 :: GOHOSTARCH: The architecture for host tools (compilers and\r
11 :: binaries).  Binaries of this type must be executable on the current\r
12 :: system, so the only common reason to set this is to set\r
13 :: GOHOSTARCH=386 on an amd64 machine.\r
14 ::\r
15 :: GOARCH: The target architecture for installed packages and tools.\r
16 ::\r
17 :: GOOS: The target operating system for installed packages and tools.\r
18 ::\r
19 :: GO_GCFLAGS: Additional go tool compile arguments to use when\r
20 :: building the packages and commands.\r
21 ::\r
22 :: GO_LDFLAGS: Additional go tool link arguments to use when\r
23 :: building the commands.\r
24 ::\r
25 :: CGO_ENABLED: Controls cgo usage during the build. Set it to 1\r
26 :: to include all cgo related files, .c and .go file with "cgo"\r
27 :: build directive, in the build. Set it to 0 to ignore them.\r
28 ::\r
29 :: CC: Command line to run to compile C code for GOHOSTARCH.\r
30 :: Default is "gcc".\r
31 ::\r
32 :: CC_FOR_TARGET: Command line to run compile C code for GOARCH.\r
33 :: This is used by cgo. Default is CC.\r
34 ::\r
35 :: FC: Command line to run to compile Fortran code.\r
36 :: This is used by cgo. Default is "gfortran".\r
37 \r
38 @echo off\r
39 \r
40 :: Keep environment variables within this script\r
41 :: unless invoked with --no-local.\r
42 if x%1==x--no-local goto nolocal\r
43 if x%2==x--no-local goto nolocal\r
44 if x%3==x--no-local goto nolocal\r
45 if x%4==x--no-local goto nolocal\r
46 setlocal\r
47 :nolocal\r
48 \r
49 set GOBUILDFAIL=0\r
50 \r
51 if exist make.bat goto ok\r
52 echo Must run make.bat from Go src directory.\r
53 goto fail\r
54 :ok\r
55 \r
56 :: Clean old generated file that will cause problems in the build.\r
57 del /F ".\pkg\runtime\runtime_defs.go" 2>NUL\r
58 \r
59 :: Set GOROOT for build.\r
60 cd ..\r
61 set GOROOT_TEMP=%CD%\r
62 set GOROOT=\r
63 cd src\r
64 set vflag=\r
65 if x%1==x-v set vflag=-v\r
66 if x%2==x-v set vflag=-v\r
67 if x%3==x-v set vflag=-v\r
68 if x%4==x-v set vflag=-v\r
69 \r
70 if not exist ..\bin\tool mkdir ..\bin\tool\r
71 \r
72 :: Calculating GOROOT_BOOTSTRAP\r
73 if not "x%GOROOT_BOOTSTRAP%"=="x" goto bootstrapset\r
74 for /f "tokens=*" %%g in ('where go 2^>nul') do (\r
75         if "x%GOROOT_BOOTSTRAP%"=="x" (\r
76                 for /f "tokens=*" %%i in ('%%g env GOROOT 2^>nul') do (\r
77                         if /I not "%%i"=="%GOROOT_TEMP%" (\r
78                                 set GOROOT_BOOTSTRAP=%%i\r
79                         )\r
80                 )\r
81         )\r
82 )\r
83 if "x%GOROOT_BOOTSTRAP%"=="x" if exist "%HOMEDRIVE%%HOMEPATH%\go1.17" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\go1.17\r
84 if "x%GOROOT_BOOTSTRAP%"=="x" if exist "%HOMEDRIVE%%HOMEPATH%\sdk\go1.17" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\sdk\go1.17\r
85 if "x%GOROOT_BOOTSTRAP%"=="x" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\Go1.4\r
86 \r
87 :bootstrapset\r
88 if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" goto bootstrapfail\r
89 set GOROOT=%GOROOT_TEMP%\r
90 set GOROOT_TEMP=\r
91 \r
92 setlocal\r
93 set GOOS=\r
94 set GOARCH=\r
95 set GOEXPERIMENT=\r
96 for /f "tokens=*" %%g IN ('%GOROOT_BOOTSTRAP%\bin\go version') do (set GOROOT_BOOTSTRAP_VERSION=%%g)\r
97 set GOROOT_BOOTSTRAP_VERSION=%GOROOT_BOOTSTRAP_VERSION:go version =%\r
98 echo Building Go cmd/dist using %GOROOT_BOOTSTRAP%. (%GOROOT_BOOTSTRAP_VERSION%)\r
99 if x%vflag==x-v echo cmd/dist\r
100 set GOROOT=%GOROOT_BOOTSTRAP%\r
101 set GOBIN=\r
102 set GO111MODULE=off\r
103 set GOENV=off\r
104 set GOFLAGS=\r
105 "%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist\r
106 endlocal\r
107 if errorlevel 1 goto fail\r
108 .\cmd\dist\dist.exe env -w -p >env.bat\r
109 if errorlevel 1 goto fail\r
110 call .\env.bat\r
111 del env.bat\r
112 if x%vflag==x-v echo.\r
113 \r
114 if x%1==x--dist-tool goto copydist\r
115 if x%2==x--dist-tool goto copydist\r
116 if x%3==x--dist-tool goto copydist\r
117 if x%4==x--dist-tool goto copydist\r
118 \r
119 set bootstrapflags=\r
120 if x%1==x--no-clean set bootstrapflags=--no-clean\r
121 if x%2==x--no-clean set bootstrapflags=--no-clean\r
122 if x%3==x--no-clean set bootstrapflags=--no-clean\r
123 if x%4==x--no-clean set bootstrapflags=--no-clean\r
124 if x%1==x--no-banner set bootstrapflags=%bootstrapflags% --no-banner\r
125 if x%2==x--no-banner set bootstrapflags=%bootstrapflags% --no-banner\r
126 if x%3==x--no-banner set bootstrapflags=%bootstrapflags% --no-banner\r
127 if x%4==x--no-banner set bootstrapflags=%bootstrapflags% --no-banner\r
128 \r
129 :: Run dist bootstrap to complete make.bash.\r
130 :: Bootstrap installs a proper cmd/dist, built with the new toolchain.\r
131 :: Throw ours, built with Go 1.4, away after bootstrap.\r
132 .\cmd\dist\dist.exe bootstrap -a %vflag% %bootstrapflags%\r
133 if errorlevel 1 goto fail\r
134 del .\cmd\dist\dist.exe\r
135 goto end\r
136 \r
137 :: DO NOT ADD ANY NEW CODE HERE.\r
138 :: The bootstrap+del above are the final step of make.bat.\r
139 :: If something must be added, add it to cmd/dist's cmdbootstrap,\r
140 :: to avoid needing three copies in three different shell languages\r
141 :: (make.bash, make.bat, make.rc).\r
142 \r
143 :copydist\r
144 mkdir "%GOTOOLDIR%" 2>NUL\r
145 copy cmd\dist\dist.exe "%GOTOOLDIR%\"\r
146 goto end\r
147 \r
148 :bootstrapfail\r
149 echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe\r
150 echo Set GOROOT_BOOTSTRAP to a working Go tree ^>= Go 1.4.\r
151 \r
152 :fail\r
153 set GOBUILDFAIL=1\r
154 if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%\r
155 \r
156 :end\r