github.com/karrick/go@v0.0.0-20170817181416-d5b0ec858b37/src/make.bat (about)

     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 go tool compile arguments to use when
    20  :: building the packages and commands.
    21  ::
    22  :: GO_LDFLAGS: Additional go tool link 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  :: CC: Command line to run to compile C code for GOHOSTARCH.
    30  :: Default is "gcc".
    31  ::
    32  :: CC_FOR_TARGET: Command line to run compile C code for GOARCH.
    33  :: This is used by cgo. Default is CC.
    34  ::
    35  :: FC: Command line to run to compile Fortran code.
    36  :: This is used by cgo. Default is "gfortran".
    37  
    38  @echo off
    39  
    40  :: Keep environment variables within this script
    41  :: unless invoked with --no-local.
    42  if x%1==x--no-local goto nolocal
    43  if x%2==x--no-local goto nolocal
    44  setlocal
    45  :nolocal
    46  
    47  set GOBUILDFAIL=0
    48  
    49  if exist make.bat goto ok
    50  echo Must run make.bat from Go src directory.
    51  goto fail 
    52  :ok
    53  
    54  :: Clean old generated file that will cause problems in the build.
    55  del /F ".\pkg\runtime\runtime_defs.go" 2>NUL
    56  
    57  :: Set GOROOT for build.
    58  cd ..
    59  set GOROOT=%CD%
    60  cd src
    61  
    62  echo ##### Building Go bootstrap tool.
    63  echo cmd/dist
    64  if not exist ..\bin\tool mkdir ..\bin\tool
    65  if "x%GOROOT_BOOTSTRAP%"=="x" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\Go1.4
    66  if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" goto bootstrapfail
    67  setlocal
    68  set GOROOT=%GOROOT_BOOTSTRAP%
    69  set GOOS=
    70  set GOARCH=
    71  set GOBIN=
    72  "%GOROOT_BOOTSTRAP%\bin\go" build -o cmd\dist\dist.exe .\cmd\dist
    73  endlocal
    74  if errorlevel 1 goto fail
    75  .\cmd\dist\dist env -w -p >env.bat
    76  if errorlevel 1 goto fail
    77  call env.bat
    78  del env.bat
    79  echo.
    80  
    81  if x%1==x--dist-tool goto copydist
    82  if x%2==x--dist-tool goto copydist
    83  
    84  set buildall=-a
    85  if x%1==x--no-clean set buildall=
    86  .\cmd\dist\dist bootstrap %buildall% -v
    87  if errorlevel 1 goto fail
    88  :: Delay move of dist tool to now, because bootstrap cleared tool directory.
    89  move .\cmd\dist\dist.exe "%GOTOOLDIR%\dist.exe"
    90  echo.
    91  
    92  if not %GOHOSTARCH% == %GOARCH% goto localbuild
    93  if not %GOHOSTOS% == %GOOS% goto localbuild
    94  goto mainbuild
    95  
    96  :localbuild
    97  echo ##### Building packages and commands for host, %GOHOSTOS%/%GOHOSTARCH%.
    98  :: CC_FOR_TARGET is recorded as the default compiler for the go tool. When building for the
    99  :: host, however, use the host compiler, CC, from `cmd/dist/dist env` instead.
   100  setlocal
   101  set GOOS=%GOHOSTOS%
   102  set GOARCH=%GOHOSTARCH%
   103  "%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -v std cmd
   104  endlocal
   105  if errorlevel 1 goto fail
   106  echo.
   107  
   108  :mainbuild
   109  echo ##### Building packages and commands for %GOOS%/%GOARCH%.
   110  setlocal
   111  set CC=%CC_FOR_TARGET%
   112  "%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -a -v std cmd
   113  endlocal
   114  if errorlevel 1 goto fail
   115  del "%GOTOOLDIR%\go_bootstrap.exe"
   116  echo.
   117  
   118  if x%1==x--no-banner goto nobanner
   119  "%GOTOOLDIR%\dist" banner
   120  :nobanner
   121  
   122  goto end
   123  
   124  :copydist
   125  mkdir "%GOTOOLDIR%" 2>NUL
   126  copy cmd\dist\dist.exe "%GOTOOLDIR%\"
   127  goto end
   128  
   129  :bootstrapfail
   130  echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe
   131  echo "Set GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4."
   132  
   133  :fail
   134  set GOBUILDFAIL=1
   135  if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
   136  
   137  :end