github.com/dorkamotorka/go/src@v0.0.0-20230614113921-187095f0e316/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  if x%3==x-no-local goto nolocal
    45  if x%4==x-no-local goto nolocal
    46  if x%1==x--no-local goto nolocal
    47  if x%2==x--no-local goto nolocal
    48  if x%3==x--no-local goto nolocal
    49  if x%4==x--no-local goto nolocal
    50  setlocal
    51  :nolocal
    52  
    53  set GOBUILDFAIL=0
    54  
    55  if exist make.bat goto ok
    56  echo Must run make.bat from Go src directory.
    57  goto fail
    58  :ok
    59  
    60  :: Clean old generated file that will cause problems in the build.
    61  del /F ".\pkg\runtime\runtime_defs.go" 2>NUL
    62  
    63  :: Set GOROOT for build.
    64  cd ..
    65  set GOROOT_TEMP=%CD%
    66  set GOROOT=
    67  cd src
    68  set vflag=
    69  if x%1==x-v set vflag=-v
    70  if x%2==x-v set vflag=-v
    71  if x%3==x-v set vflag=-v
    72  if x%4==x-v set vflag=-v
    73  
    74  if not exist ..\bin\tool mkdir ..\bin\tool
    75  
    76  :: Calculating GOROOT_BOOTSTRAP
    77  if not "x%GOROOT_BOOTSTRAP%"=="x" goto bootstrapset
    78  for /f "tokens=*" %%g in ('where go 2^>nul') do (
    79  	if "x%GOROOT_BOOTSTRAP%"=="x" (
    80  		for /f "tokens=*" %%i in ('"%%g" env GOROOT 2^>nul') do (
    81  			if /I not "%%i"=="%GOROOT_TEMP%" (
    82  				set GOROOT_BOOTSTRAP=%%i
    83  			)
    84  		)
    85  	)
    86  )
    87  
    88  set bootgo=1.17.13
    89  if "x%GOROOT_BOOTSTRAP%"=="x" if exist "%HOMEDRIVE%%HOMEPATH%\go%bootgo%" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\go%bootgo%
    90  if "x%GOROOT_BOOTSTRAP%"=="x" if exist "%HOMEDRIVE%%HOMEPATH%\sdk\go%bootgo%" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\sdk\go%bootgo%
    91  if "x%GOROOT_BOOTSTRAP%"=="x" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\Go1.4
    92  
    93  :bootstrapset
    94  if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" goto bootstrapfail
    95  set GOROOT=%GOROOT_TEMP%
    96  set GOROOT_TEMP=
    97  
    98  setlocal
    99  set GOOS=
   100  set GOARCH=
   101  set GOEXPERIMENT=
   102  for /f "tokens=*" %%g IN ('"%GOROOT_BOOTSTRAP%\bin\go" version') do (set GOROOT_BOOTSTRAP_VERSION=%%g)
   103  set GOROOT_BOOTSTRAP_VERSION=%GOROOT_BOOTSTRAP_VERSION:go version =%
   104  echo Building Go cmd/dist using %GOROOT_BOOTSTRAP%. (%GOROOT_BOOTSTRAP_VERSION%)
   105  if x%vflag==x-v echo cmd/dist
   106  set GOROOT=%GOROOT_BOOTSTRAP%
   107  set GOBIN=
   108  set GO111MODULE=off
   109  set GOENV=off
   110  set GOFLAGS=
   111  "%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist
   112  endlocal
   113  if errorlevel 1 goto fail
   114  .\cmd\dist\dist.exe env -w -p >env.bat
   115  if errorlevel 1 goto fail
   116  call .\env.bat
   117  del env.bat
   118  if x%vflag==x-v echo.
   119  
   120  if x%1==x-dist-tool goto copydist
   121  if x%2==x-dist-tool goto copydist
   122  if x%3==x-dist-tool goto copydist
   123  if x%4==x-dist-tool goto copydist
   124  if x%1==x--dist-tool goto copydist
   125  if x%2==x--dist-tool goto copydist
   126  if x%3==x--dist-tool goto copydist
   127  if x%4==x--dist-tool goto copydist
   128  
   129  set bootstrapflags=
   130  if x%1==x-no-clean set bootstrapflags=-no-clean
   131  if x%2==x-no-clean set bootstrapflags=-no-clean
   132  if x%3==x-no-clean set bootstrapflags=-no-clean
   133  if x%4==x-no-clean set bootstrapflags=-no-clean
   134  if x%1==x--no-clean set bootstrapflags=-no-clean
   135  if x%2==x--no-clean set bootstrapflags=-no-clean
   136  if x%3==x--no-clean set bootstrapflags=-no-clean
   137  if x%4==x--no-clean set bootstrapflags=-no-clean
   138  if x%1==x-no-banner set bootstrapflags=%bootstrapflags% -no-banner
   139  if x%2==x-no-banner set bootstrapflags=%bootstrapflags% -no-banner
   140  if x%3==x-no-banner set bootstrapflags=%bootstrapflags% -no-banner
   141  if x%4==x-no-banner set bootstrapflags=%bootstrapflags% -no-banner
   142  if x%1==x--no-banner set bootstrapflags=%bootstrapflags% -no-banner
   143  if x%2==x--no-banner set bootstrapflags=%bootstrapflags% -no-banner
   144  if x%3==x--no-banner set bootstrapflags=%bootstrapflags% -no-banner
   145  if x%4==x--no-banner set bootstrapflags=%bootstrapflags% -no-banner
   146  if x%1==x-distpack set bootstrapflags=%bootstrapflags% -distpack
   147  if x%2==x-distpack set bootstrapflags=%bootstrapflags% -distpack
   148  if x%3==x-distpack set bootstrapflags=%bootstrapflags% -distpack
   149  if x%4==x-distpack set bootstrapflags=%bootstrapflags% -distpack
   150  if x%1==x--distpack set bootstrapflags=%bootstrapflags% -distpack
   151  if x%2==x--distpack set bootstrapflags=%bootstrapflags% -distpack
   152  if x%3==x--distpack set bootstrapflags=%bootstrapflags% -distpack
   153  if x%4==x--distpack set bootstrapflags=%bootstrapflags% -distpack
   154  
   155  :: Run dist bootstrap to complete make.bash.
   156  :: Bootstrap installs a proper cmd/dist, built with the new toolchain.
   157  :: Throw ours, built with the bootstrap toolchain, away after bootstrap.
   158  .\cmd\dist\dist.exe bootstrap -a %vflag% %bootstrapflags%
   159  if errorlevel 1 goto fail
   160  del .\cmd\dist\dist.exe
   161  goto end
   162  
   163  :: DO NOT ADD ANY NEW CODE HERE.
   164  :: The bootstrap+del above are the final step of make.bat.
   165  :: If something must be added, add it to cmd/dist's cmdbootstrap,
   166  :: to avoid needing three copies in three different shell languages
   167  :: (make.bash, make.bat, make.rc).
   168  
   169  :copydist
   170  mkdir "%GOTOOLDIR%" 2>NUL
   171  copy cmd\dist\dist.exe "%GOTOOLDIR%\"
   172  goto end
   173  
   174  :bootstrapfail
   175  echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe
   176  echo Set GOROOT_BOOTSTRAP to a working Go tree ^>= Go %bootgo%.
   177  
   178  :fail
   179  set GOBUILDFAIL=1
   180  if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
   181  
   182  :end