github.com/roboticscm/goman@v0.0.0-20210203095141-87c07b4a0a55/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 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  :: cgo is not generally supported on 1.4.
    41  :: Disable unless explicitly requested.
    42  if not x%CGO_ENABLED%==x goto cgodone
    43  set CGO_ENABLED=0
    44  :cgodone
    45  
    46  if exist make.bat goto ok
    47  echo Must run make.bat from Go src directory.
    48  goto fail 
    49  :ok
    50  
    51  :: Clean old generated file that will cause problems in the build.
    52  del /F ".\pkg\runtime\runtime_defs.go" 2>NUL
    53  
    54  :: Grab default GOROOT_FINAL and set GOROOT for build.
    55  :: The expression %VAR:\=\\% means to take %VAR%
    56  :: and apply the substitution \ = \\, escaping the
    57  :: backslashes.  Then we wrap that in quotes to create
    58  :: a C string.
    59  cd ..
    60  set GOROOT=%CD%
    61  cd src
    62  if "x%GOROOT_FINAL%"=="x" set GOROOT_FINAL=%GOROOT%
    63  set DEFGOROOT=-DGOROOT_FINAL="\"%GOROOT_FINAL:\=\\%\""
    64  
    65  echo # Building C bootstrap tool.
    66  echo cmd/dist
    67  if not exist ..\bin\tool mkdir ..\bin\tool
    68  :: Windows has no glob expansion, so spell out cmd/dist/*.c.
    69  gcc -O2 -Wall -Werror -o cmd/dist/dist.exe -Icmd/dist %DEFGOROOT% cmd/dist/buf.c cmd/dist/build.c cmd/dist/buildgc.c cmd/dist/buildgo.c cmd/dist/buildruntime.c cmd/dist/main.c cmd/dist/windows.c cmd/dist/arm.c
    70  if errorlevel 1 goto fail
    71  .\cmd\dist\dist env -wp >env.bat
    72  if errorlevel 1 goto fail
    73  call env.bat
    74  del env.bat
    75  echo.
    76  
    77  if x%1==x--dist-tool goto copydist
    78  if x%2==x--dist-tool goto copydist
    79  
    80  echo # Building compilers and Go bootstrap tool.
    81  set buildall=-a
    82  if x%1==x--no-clean set buildall=
    83  .\cmd\dist\dist bootstrap %buildall% -v
    84  if errorlevel 1 goto fail
    85  :: Delay move of dist tool to now, because bootstrap cleared tool directory.
    86  move .\cmd\dist\dist.exe "%GOTOOLDIR%\dist.exe"
    87  "%GOTOOLDIR%\go_bootstrap" clean -i std
    88  echo.
    89  
    90  if not %GOHOSTARCH% == %GOARCH% goto localbuild
    91  if not %GOHOSTOS% == %GOOS% goto localbuild
    92  goto mainbuild
    93  
    94  :localbuild
    95  echo # Building tools for local system. %GOHOSTOS%/%GOHOSTARCH%
    96  setlocal
    97  set GOOS=%GOHOSTOS%
    98  set GOARCH=%GOHOSTARCH%
    99  "%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -v std
   100  endlocal
   101  if errorlevel 1 goto fail
   102  echo.
   103  
   104  :mainbuild
   105  echo # Building packages and commands.
   106  "%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -a -v std
   107  if errorlevel 1 goto fail
   108  del "%GOTOOLDIR%\go_bootstrap.exe"
   109  echo.
   110  
   111  if x%1==x--no-banner goto nobanner
   112  "%GOTOOLDIR%\dist" banner
   113  :nobanner
   114  
   115  goto end
   116  
   117  :copydist
   118  mkdir "%GOTOOLDIR%" 2>NUL
   119  copy cmd\dist\dist.exe "%GOTOOLDIR%\"
   120  goto end
   121  
   122  :fail
   123  set GOBUILDFAIL=1
   124  if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
   125  
   126  :end