]> Cypherpunks.ru repositories - gostls13.git/blob - src/make.bat
build: update Windows make.bat for Go-based dist
[gostls13.git] / src / make.bat
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 :: Environment variables that control make.bat:
6 ::
7 :: GOROOT_FINAL: The expected final Go root, baked into binaries.
8 :: The default is the location of the Go tree during the build.
9 ::
10 :: GOHOSTARCH: The architecture for host tools (compilers and
11 :: binaries).  Binaries of this type must be executable on the current
12 :: system, so the only common reason to set this is to set
13 :: GOHOSTARCH=386 on an amd64 machine.
14 ::
15 :: GOARCH: The target architecture for installed packages and tools.
16 ::
17 :: GOOS: The target operating system for installed packages and tools.
18 ::
19 :: GO_GCFLAGS: Additional 5g/6g/8g arguments to use when
20 :: building the packages and commands.
21 ::
22 :: GO_LDFLAGS: Additional 5l/6l/8l arguments to use when
23 :: building the commands.
24 ::
25 :: CGO_ENABLED: Controls cgo usage during the build. Set it to 1
26 :: to include all cgo related files, .c and .go file with "cgo"
27 :: build directive, in the build. Set it to 0 to ignore them.
28
29 @echo off
30
31 :: Keep environment variables within this script
32 :: unless invoked with --no-local.
33 if x%1==x--no-local goto nolocal
34 if x%2==x--no-local goto nolocal
35 setlocal
36 :nolocal
37
38 set GOBUILDFAIL=0
39
40 if exist make.bat goto ok
41 echo Must run make.bat from Go src directory.
42 goto fail 
43 :ok
44
45 :: Clean old generated file that will cause problems in the build.
46 del /F ".\pkg\runtime\runtime_defs.go" 2>NUL
47
48 :: Grab default GOROOT_FINAL and set GOROOT for build.
49 :: The expression %VAR:\=\\% means to take %VAR%
50 :: and apply the substitution \ = \\, escaping the
51 :: backslashes.  Then we wrap that in quotes to create
52 :: a C string.
53 cd ..
54 set GOROOT=%CD%
55 cd src
56 if "x%GOROOT_FINAL%"=="x" set GOROOT_FINAL=%GOROOT%
57 set DEFGOROOT=-DGOROOT_FINAL="\"%GOROOT_FINAL:\=\\%\""
58
59 echo ##### Building Go bootstrap tool.
60 echo cmd/dist
61 if not exist ..\bin\tool mkdir ..\bin\tool
62 if "x%GOROOT_BOOTSTRAP%"=="x" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\Go1.4
63 if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" goto bootstrapfail
64 setlocal
65 set GOROOT=%GOROOT_BOOTSTRAP%
66 "%GOROOT_BOOTSTRAP%\bin\go" build -o cmd\dist\dist.exe .\cmd\dist
67 endlocal
68 if errorlevel 1 goto fail
69 .\cmd\dist\dist env -w -p >env.bat
70 if errorlevel 1 goto fail
71 call env.bat
72 del env.bat
73 echo.
74
75 if x%1==x--dist-tool goto copydist
76 if x%2==x--dist-tool goto copydist
77
78 echo ##### Building compilers and Go bootstrap tool.
79 set buildall=-a
80 if x%1==x--no-clean set buildall=
81 .\cmd\dist\dist bootstrap %buildall% -v
82 if errorlevel 1 goto fail
83 :: Delay move of dist tool to now, because bootstrap cleared tool directory.
84 move .\cmd\dist\dist.exe "%GOTOOLDIR%\dist.exe"
85 "%GOTOOLDIR%\go_bootstrap" clean -i std
86 echo.
87
88 if not %GOHOSTARCH% == %GOARCH% goto localbuild
89 if not %GOHOSTOS% == %GOOS% goto localbuild
90 goto mainbuild
91
92 :localbuild
93 echo ##### Building tools for local system. %GOHOSTOS%/%GOHOSTARCH%
94 setlocal
95 set GOOS=%GOHOSTOS%
96 set GOARCH=%GOHOSTARCH%
97 "%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -v std
98 endlocal
99 if errorlevel 1 goto fail
100 echo.
101
102 :mainbuild
103 echo ##### Building packages and commands.
104 "%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -a -v std
105 if errorlevel 1 goto fail
106 del "%GOTOOLDIR%\go_bootstrap.exe"
107 echo.
108
109 if x%1==x--no-banner goto nobanner
110 "%GOTOOLDIR%\dist" banner
111 :nobanner
112
113 goto end
114
115 :copydist
116 mkdir "%GOTOOLDIR%" 2>NUL
117 copy cmd\dist\dist.exe "%GOTOOLDIR%\"
118 goto end
119
120 :bootstrapfail
121 echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe
122 echo "Set GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4."
123
124 :fail
125 set GOBUILDFAIL=1
126 if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
127
128 :end