]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/toolsetup.bat
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / toolsetup.bat
old mode 100644 (file)
new mode 100755 (executable)
index 3f474a0..58fd26a
+@REM @file\r
+@REM   This stand-alone program is typically called by the edksetup.bat file,\r
+@REM   however it may be executed directly from the BaseTools project folder\r
+@REM   if the file is not executed within a WORKSPACE\BaseTools folder.\r
 @REM\r
-@REM Copyright (c) 2006, Intel Corporation\r
-@REM All rights reserved. This program and the accompanying materials\r
-@REM are licensed and made available under the terms and conditions of the BSD License\r
-@REM which accompanies this distribution.  The full text of the license may be found at\r
-@REM http://opensource.org/licenses/bsd-license.php\r
+@REM Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+@REM (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 @REM\r
-@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+@REM SPDX-License-Identifier: BSD-2-Clause-Patent\r
 @REM\r
 \r
 @echo off\r
+pushd .\r
+set SCRIPT_ERROR=0\r
 \r
-REM ##############################################################\r
-REM # You should not have to modify anything below this line\r
-REM #\r
+@REM ##############################################################\r
+@REM # You should not have to modify anything below this line\r
+@REM #\r
 \r
-if /I "%1"=="-h" goto usage\r
-if /I "%1"=="-help" goto usage\r
-if /I "%1"=="--help" goto usage\r
-if /I "%1"=="/h" goto usage\r
-if /I "%1"=="/?" goto usage\r
-if /I "%1"=="/help" goto usage\r
+if /I "%1"=="-h" goto Usage\r
+if /I "%1"=="-help" goto Usage\r
+if /I "%1"=="--help" goto Usage\r
+if /I "%1"=="/h" goto Usage\r
+if /I "%1"=="/help" goto Usage\r
+if /I "%1"=="/?" goto Usage\r
 \r
-if NOT "%1"=="" set EDK_TOOLS_PATH=%1\r
 \r
-REM\r
-REM Check the required system environment variables\r
-REM\r
+:loop\r
+  if "%1"=="" goto setup_workspace\r
+  if /I "%1"=="Reconfig" (\r
+    shift\r
+    set RECONFIG=TRUE\r
+    goto loop\r
+  )\r
+  if /I "%1"=="Rebuild" (\r
+    shift\r
+    set REBUILD=TRUE\r
+    goto loop\r
+  )\r
+  if /I "%1"=="ForceRebuild" (\r
+    shift\r
+    set FORCE_REBUILD=TRUE\r
+    goto loop\r
+  )\r
+  if /I "%1"=="VS2019" (\r
+    shift\r
+    set VS2019=TRUE\r
+    set VSTool=VS2019\r
+    goto loop\r
+  )\r
+  if /I "%1"=="VS2017" (\r
+    shift\r
+    set VS2017=TRUE\r
+    set VSTool=VS2017\r
+    goto loop\r
+  )\r
+  if /I "%1"=="VS2015" (\r
+    shift\r
+    set VS2015=TRUE\r
+    set VSTool=VS2015\r
+    goto loop\r
+  )\r
+  if /I "%1"=="VS2013" (\r
+    shift\r
+    set VS2013=TRUE\r
+    set VSTool=VS2013\r
+    goto loop\r
+  )\r
+  if /I "%1"=="VS2012" (\r
+    shift\r
+    set VS2012=TRUE\r
+    set VSTool=VS2012\r
+    goto loop\r
+  )\r
+  if "%1"=="" goto setup_workspace\r
+  if exist %1 (\r
+    if not defined BASE_TOOLS_PATH (\r
+      if exist %1\Source set BASE_TOOLS_PATH=%1\r
+      shift\r
+      goto loop\r
+    )\r
+    if not defined EDK_TOOLS_PATH (\r
+      if exist %1\Bin\Win32 set EDK_TOOLS_PATH=%1\r
+      shift\r
+      goto loop\r
+    )\r
+    echo.\r
+    echo !!! ERROR !!! Unknown argument, %1 !!!\r
+    echo.\r
+    goto end\r
+  ) else (\r
+    echo.\r
+    echo !!! ERROR !!! Unknown argument, %1 !!!\r
+    echo.\r
+    goto end\r
+  )\r
+  goto loop\r
 \r
-:check_vc\r
-if defined VCINSTALLDIR goto setup_workspace\r
-if defined VS71COMNTOOLS (\r
-  call "%VS71COMNTOOLS%\vsvars32.bat"\r
-) else (\r
-  echo.\r
-  echo !!!WARNING!!! Cannot find Visual Studio !!!\r
-  echo.\r
-)\r
+\r
+@REM\r
+@REM Check the required system environment variables\r
+@REM\r
 \r
 :setup_workspace\r
+  REM\r
+  REM check the EDK_TOOLS_PATH\r
+  REM\r
+  if not defined EDK_TOOLS_PATH goto no_EDK_TOOLS_PATH\r
+  if exist %EDK_TOOLS_PATH% goto set_PATH\r
+\r
+:no_EDK_TOOLS_PATH\r
+  if not defined WORKSPACE (\r
+    if defined BASE_TOOLS_PATH (\r
+      set EDK_TOOLS_PATH=%BASE_TOOLS_PATH%\r
+      goto set_PATH\r
+    ) else (\r
+      echo.\r
+      echo !!! ERROR !!! Neither BASE_TOOLS_PATH nor EDK_TOOLS_PATH are set. !!!\r
+      echo.\r
+      goto end\r
+    )\r
+  ) else (\r
+    if exist %WORKSPACE%\BaseTools\Bin (\r
+      set EDK_TOOLS_PATH=%WORKSPACE%\BaseTools\r
+      goto set_PATH\r
+    ) else (\r
+      echo.\r
+      echo !!! ERROR !!! No tools path available. Please set EDK_TOOLS_PATH !!!\r
+      echo.\r
+      goto end\r
+    )\r
+  )\r
+\r
+:set_PATH\r
+  if defined WORKSPACE_TOOLS_PATH goto check_PATH\r
+  if not defined EDK_TOOLS_BIN (\r
+    set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32\r
+    if not exist %EDK_TOOLS_PATH%\Bin\Win32 (\r
+      echo.\r
+      echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!!\r
+      echo Please check the directory %EDK_TOOLS_PATH%\Bin\Win32\r
+      echo Or configure EDK_TOOLS_BIN env to point Win32 directory.\r
+      echo.\r
+    )\r
+  )\r
+  set PATH=%EDK_TOOLS_BIN%;%PATH%\r
+  set WORKSPACE_TOOLS_PATH=%EDK_TOOLS_PATH%\r
+  goto PATH_ok\r
+\r
+:check_PATH\r
+  if "%EDK_TOOLS_PATH%"=="%WORKSPACE_TOOLS_PATH%" goto PATH_ok\r
+  if not defined EDK_TOOLS_BIN (\r
+    set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32\r
+    if not exist %EDK_TOOLS_PATH%\Bin\Win32 (\r
+      echo.\r
+      echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!!\r
+      echo Please check the directory %EDK_TOOLS_PATH%\Bin\Win32\r
+      echo Or configure EDK_TOOLS_BIN env to point Win32 directory.\r
+      echo.\r
+    )\r
+  )\r
+  set PATH=%EDK_TOOLS_BIN%;%PATH%\r
+  set WORKSPACE_TOOLS_PATH=%EDK_TOOLS_PATH%\r
+  echo Resetting the PATH variable to include the EDK_TOOLS_PATH for this session.\r
+\r
+:PATH_ok\r
 REM\r
-REM check the EDK_TOOLS_PATH\r
+REM copy *.template to %CONF_PATH%\r
 REM\r
-if not defined EDK_TOOLS_PATH goto no_tools_path\r
-if exist %EDK_TOOLS_PATH% goto set_path\r
-echo.\r
-echo !!!WARNING!!! %EDK_TOOLS_PATH% doesn't exist. %WORKSPACE%\Tools will be used !!!\r
-echo.\r
+if not defined WORKSPACE (\r
+   if defined RECONFIG (\r
+     echo.\r
+     echo !!! WARNING !!! WORKSPACE environment variable was not set, cannot Reconfig !!!\r
+     echo.\r
+   )\r
+   goto skip_reconfig\r
+)\r
 \r
-:no_tools_path\r
-if exist %WORKSPACE%\BaseTools (\r
-  set EDK_TOOLS_PATH=%WORKSPACE%\BaseTools\r
+IF NOT exist "%EDK_TOOLS_PATH%\set_vsprefix_envs.bat" (\r
+  @echo.\r
+  @echo !!! ERROR !!! The set_vsprefix_envs.bat was not found !!!\r
+  @echo.\r
+  goto end\r
+)\r
+if defined VS2019 (\r
+  call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2019\r
+) else if defined VS2017 (\r
+  call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2017\r
+) else if defined VS2015 (\r
+  call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2015\r
+  call %EDK_TOOLS_PATH%\get_vsvars.bat VS2015\r
+) else if defined VS2013 (\r
+  call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2013\r
+  call %EDK_TOOLS_PATH%\get_vsvars.bat VS2013\r
+) else if defined VS2012 (\r
+  call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2012\r
+  call %EDK_TOOLS_PATH%\get_vsvars.bat VS2012\r
 ) else (\r
-  echo.\r
-  echo !!!WARNING!!! No tools path found. Please set EDK_TOOLS_PATH !!!\r
-  echo.\r
+  call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat\r
+  call %EDK_TOOLS_PATH%\get_vsvars.bat\r
+)\r
+if %SCRIPT_ERROR% NEQ 0 (\r
+  @echo.\r
+  @echo !!! ERROR !!! %VSTool% is not installed !!!\r
+  @echo.\r
   goto end\r
 )\r
 \r
-:set_path\r
-if defined WORKSPACE_TOOLS_PATH goto check_path\r
-set PATH=%EDK_TOOLS_PATH%\Bin;%EDK_TOOLS_PATH%\Bin\Win32;%PATH%\r
-set WORKSPACE_TOOLS_PATH=%EDK_TOOLS_PATH%\r
-goto path_ok\r
+if not defined CONF_PATH (\r
+  set CONF_PATH=%WORKSPACE%\Conf\r
+)\r
 \r
-:check_path\r
-if "%EDK_TOOLS_PATH%"=="%WORKSPACE_TOOLS_PATH%" goto path_ok\r
-set PATH=%EDK_TOOLS_PATH%\Bin;%EDK_TOOLS_PATH%\Bin\Win32;%PATH%\r
-set WORKSPACE_TOOLS_PATH=%EDK_TOOLS_PATH%\r
-echo Resetting the PATH variable to include the EDK_TOOLS_PATH for this WORKSPACE\r
+if NOT exist %CONF_PATH% (\r
+  if defined PACKAGES_PATH (\r
+    for %%i IN (%PACKAGES_PATH%) DO (\r
+      if exist %%~fi\Conf (\r
+        set CONF_PATH=%%i\Conf\r
+        goto CopyConf\r
+      )\r
+    )\r
+  )\r
+)\r
 \r
-:path_ok\r
-echo           PATH = %PATH%\r
-echo.\r
-echo      WORKSPACE = %WORKSPACE%\r
-echo EDK_TOOLS_PATH = %EDK_TOOLS_PATH%\r
-echo.\r
+:CopyConf\r
+if NOT exist %CONF_PATH% (\r
+  mkdir %CONF_PATH%\r
+) else (\r
+  if defined RECONFIG (\r
+    echo.\r
+    echo  Overwriting the files in the CONF_PATH directory\r
+    echo  using the default template files\r
+    echo.\r
+  )\r
+)\r
 \r
-REM\r
-REM copy *.template to %EDK_TOOLS_PATH%\Conf\r
-REM\r
-if NOT exist %EDK_TOOLS_PATH%\Conf mkdir %EDK_TOOLS_PATH%\Conf\r
-if NOT exist %EDK_TOOLS_PATH%\Conf\FrameworkDatabase.db (\r
-  echo copying ... FrameworkDatabase.template to %EDK_TOOLS_PATH%\Conf\FrameworkDatabase.db\r
-  copy %EDK_TOOLS_PATH%\Conf\FrameworkDatabase.template %EDK_TOOLS_PATH%\Conf\FrameworkDatabase.db > nul\r
+if NOT exist %CONF_PATH%\target.txt (\r
+  echo copying ... target.template to %CONF_PATH%\target.txt\r
+  if NOT exist %EDK_TOOLS_PATH%\Conf\target.template (\r
+    echo Error: target.template is missing at folder %EDK_TOOLS_PATH%\Conf\\r
+  )\r
+  copy %EDK_TOOLS_PATH%\Conf\target.template %CONF_PATH%\target.txt > nul\r
+) else (\r
+  if defined RECONFIG echo overwrite ... target.template to %CONF_PATH%\target.txt\r
+  if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\target.template %CONF_PATH%\target.txt > nul\r
+)\r
+\r
+if NOT exist %CONF_PATH%\tools_def.txt (\r
+  echo copying ... tools_def.template to %CONF_PATH%\tools_def.txt\r
+  if NOT exist %EDK_TOOLS_PATH%\Conf\tools_def.template (\r
+    echo Error: tools_def.template is missing at folder %EDK_TOOLS_PATH%\Conf\\r
+  )\r
+  copy %EDK_TOOLS_PATH%\Conf\tools_def.template %CONF_PATH%\tools_def.txt > nul\r
+) else (\r
+  if defined RECONFIG echo overwrite ... tools_def.template to %CONF_PATH%\tools_def.txt\r
+  if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\tools_def.template %CONF_PATH%\tools_def.txt > nul\r
+)\r
+\r
+if NOT exist %CONF_PATH%\build_rule.txt (\r
+  echo copying ... build_rule.template to %CONF_PATH%\build_rule.txt\r
+  if NOT exist %EDK_TOOLS_PATH%\Conf\build_rule.template (\r
+    echo Error: build_rule.template is missing at folder %EDK_TOOLS_PATH%\Conf\\r
+  )\r
+  copy %EDK_TOOLS_PATH%\Conf\build_rule.template %CONF_PATH%\build_rule.txt > nul\r
+) else (\r
+  if defined RECONFIG echo over-write ... build_rule.template to %CONF_PATH%\build_rule.txt\r
+  if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\build_rule.template %CONF_PATH%\build_rule.txt > nul\r
 )\r
-if NOT exist %EDK_TOOLS_PATH%\Conf\target.txt (\r
-  echo copying ... target.template to %EDK_TOOLS_PATH%\Conf\target.txt\r
-  copy %EDK_TOOLS_PATH%\Conf\target.template %EDK_TOOLS_PATH%\Conf\target.txt > nul\r
+\r
+echo           PATH      = %PATH%\r
+echo.\r
+if defined WORKSPACE (\r
+  echo      WORKSPACE      = %WORKSPACE%\r
+)\r
+if defined PACKAGES_PATH (\r
+  echo  PACKAGES_PATH      = %PACKAGES_PATH%\r
 )\r
-if NOT exist %EDK_TOOLS_PATH%\Conf\tools_def.txt (\r
-  echo copying ... tools_def.template to %EDK_TOOLS_PATH%\Conf\tools_def.txt\r
-  copy %EDK_TOOLS_PATH%\Conf\tools_def.template %EDK_TOOLS_PATH%\Conf\tools_def.txt > nul\r
+echo EDK_TOOLS_PATH      = %EDK_TOOLS_PATH%\r
+if defined BASE_TOOLS_PATH (\r
+  echo BASE_TOOLS_PATH     = %BASE_TOOLS_PATH%\r
 )\r
-if NOT exist %EDK_TOOLS_PATH%\Conf\build_rule.txt (\r
-  echo copying ... build_rule.template to %EDK_TOOLS_PATH%\Conf\build_rule.txt\r
-  copy %EDK_TOOLS_PATH%\Conf\build_rule.template %EDK_TOOLS_PATH%\Conf\build_rule.txt > nul\r
+if defined EDK_TOOLS_BIN (\r
+  echo  EDK_TOOLS_BIN      = %EDK_TOOLS_BIN%\r
 )\r
+echo      CONF_PATH      = %CONF_PATH%\r
+echo.\r
 \r
-REM\r
-REM copy XMLSchema to %EDK_TOOLS_PATH%\Conf\XMLSchema\r
-REM\r
-REM echo copying ... XMLSchema to %EDK_TOOLS_PATH%\Conf\XMLSchema\r
-REM xcopy %WORKSPACE%\Conf\XMLSchema %EDK_TOOLS_PATH%\Conf\XMLSchema /S /I /D /F /Q > nul\r
+:skip_reconfig\r
 \r
-REM\r
-REM Done!!!\r
-REM\r
-goto end\r
+@REM\r
+@REM Test if we are going to have to do a build\r
+@REM\r
+if defined FORCE_REBUILD goto check_build_environment\r
+if defined REBUILD goto check_build_environment\r
+if not exist "%EDK_TOOLS_PATH%" goto check_build_environment\r
+if not exist "%EDK_TOOLS_BIN%"  goto check_build_environment\r
 \r
-:usage\r
-echo.\r
-echo  "Usage: %0 [/? | /h | /help | -h | -help | --help] [tools_path]"\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\EfiRom.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\GenFfs.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\GenFv.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\GenFw.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\GenSec.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\TianoCompress.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\VfrCompile.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\VolInfo.exe" goto check_c_tools\r
+\r
+goto check_build_environment\r
+\r
+:check_c_tools\r
+  echo.\r
+  echo !!! ERROR !!! Binary C tools are missing. They are required to be built from BaseTools Source.\r
+  echo.\r
+\r
+:check_build_environment\r
+  set PYTHONHASHSEED=1\r
+\r
+  if not defined BASE_TOOLS_PATH (\r
+     if not exist "Source\C\Makefile" (\r
+       if not exist "%EDK_TOOLS_PATH%\Source\C\Makefile" goto no_source_files\r
+       set BASE_TOOLS_PATH=%EDK_TOOLS_PATH%\r
+     ) else (\r
+       set BASE_TOOLS_PATH=%CD%\r
+     )\r
+  )\r
+\r
+:defined_python\r
+if defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (\r
+  goto check_python_available\r
+)\r
+if defined PYTHON3_ENABLE (\r
+  if "%PYTHON3_ENABLE%" EQU "TRUE" (\r
+    set PYTHON_COMMAND=py -3\r
+    goto check_python_available\r
+  ) else (\r
+    goto check_python2\r
+  )\r
+)\r
+if not defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (\r
+  set PYTHON_COMMAND=py -3\r
+  py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1\r
+  setlocal enabledelayedexpansion\r
+  set /p PythonCheck=<"PythonCheck.txt"\r
+  del PythonCheck.txt\r
+  if "!PythonCheck!" NEQ "TRUE" (\r
+    if not defined PYTHON_HOME if not defined PYTHONHOME (\r
+      endlocal\r
+      set PYTHON_COMMAND=\r
+      echo.\r
+      echo !!! ERROR !!! Binary python tools are missing.\r
+      echo PYTHON_COMMAND, PYTHON3_ENABLE or PYTHON_HOME\r
+      echo Environment variable is not set successfully.\r
+      echo They is required to build or execute the python tools.\r
+      echo.\r
+      goto end\r
+    ) else (\r
+      goto check_python2\r
+    )\r
+  ) else (\r
+    goto check_freezer_path\r
+  )\r
+)\r
+\r
+:check_python2\r
+endlocal\r
+if defined PYTHON_HOME (\r
+  if EXIST "%PYTHON_HOME%" (\r
+    set PYTHON_COMMAND=%PYTHON_HOME%\python.exe\r
+    goto check_python_available\r
+  )\r
+)\r
+if defined PYTHONHOME (\r
+  if EXIST "%PYTHONHOME%" (\r
+    set PYTHON_HOME=%PYTHONHOME%\r
+    set PYTHON_COMMAND=%PYTHON_HOME%\python.exe\r
+    goto check_python_available\r
+  )\r
+)\r
 echo.\r
-echo                      tools_path       Tools' path. EDK_TOOLS_PATH will be set to this path.\r
+echo !!! ERROR !!!  PYTHON_HOME is not defined or The value of this variable does not exist\r
 echo.\r
+goto end\r
+:check_python_available\r
+%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1\r
+  setlocal enabledelayedexpansion\r
+  set /p PythonCheck=<"PythonCheck.txt"\r
+  del PythonCheck.txt\r
+  if "!PythonCheck!" NEQ "TRUE" (\r
+    echo.\r
+    echo ! ERROR !  "%PYTHON_COMMAND%" is not installed or added to environment variables\r
+    echo.\r
+    goto end\r
+  ) else (\r
+    goto check_freezer_path\r
+  )\r
+\r
+\r
+\r
+:check_freezer_path\r
+  endlocal\r
+\r
+  %PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL\r
+  if %ERRORLEVEL% EQU 0 (\r
+    goto use_pip_basetools\r
+  ) else (\r
+    REM reset ERRORLEVEL\r
+    type nul>nul\r
+    goto use_builtin_basetools\r
+  )\r
+\r
+:use_builtin_basetools\r
+  @echo Using EDK2 in-source Basetools\r
+  if defined BASETOOLS_PYTHON_SOURCE goto print_python_info\r
+  set "PATH=%BASE_TOOLS_PATH%\BinWrappers\WindowsLike;%PATH%"\r
+  set BASETOOLS_PYTHON_SOURCE=%BASE_TOOLS_PATH%\Source\Python\r
+  set PYTHONPATH=%BASETOOLS_PYTHON_SOURCE%;%PYTHONPATH%\r
+  goto print_python_info\r
+\r
+:use_pip_basetools\r
+  @echo Using Pip Basetools\r
+  set "PATH=%BASE_TOOLS_PATH%\BinPipWrappers\WindowsLike;%PATH%"\r
+  set BASETOOLS_PYTHON_SOURCE=edk2basetools\r
+  goto print_python_info\r
+\r
+:print_python_info\r
+  echo                PATH = %PATH%\r
+  if defined PYTHON3_ENABLE if "%PYTHON3_ENABLE%" EQU "TRUE" (\r
+    echo      PYTHON3_ENABLE = %PYTHON3_ENABLE%\r
+    echo             PYTHON3 = %PYTHON_COMMAND%\r
+  ) else (\r
+    echo      PYTHON3_ENABLE = FALSE\r
+    echo      PYTHON_COMMAND = %PYTHON_COMMAND%\r
+  )\r
+  echo          PYTHONPATH = %PYTHONPATH%\r
+  echo.\r
+\r
+:VisualStudioAvailable\r
+  if not defined FORCE_REBUILD (\r
+    if not defined REBUILD (\r
+      goto end\r
+    )\r
+  )\r
+\r
+  if not defined VCINSTALLDIR (\r
+    @echo.\r
+    @echo !!! ERROR !!!! Cannot find Visual Studio, required to build C tools !!!\r
+    @echo.\r
+    goto end\r
+  )\r
+  if not defined FORCE_REBUILD goto IncrementalBuild\r
+\r
+:CleanAndBuild\r
+  pushd .\r
+  cd %BASE_TOOLS_PATH%\r
+  call nmake cleanall\r
+  del /f /q %BASE_TOOLS_PATH%\Bin\Win32\*.*\r
+  popd\r
+  @REM Let CleanAndBuild fall through to IncrementalBuild\r
+\r
+\r
+:IncrementalBuild\r
+  pushd .\r
+  cd %BASE_TOOLS_PATH%\r
+  call nmake c\r
+  popd\r
+  goto end\r
+\r
+\r
+:no_source_files\r
+  echo.\r
+  echo !!! ERROR !!! Cannot build BaseTools applications - no source directory located !!!\r
+  echo.\r
+  goto end\r
+\r
+:Usage\r
+  @echo.\r
+  echo  Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [base_tools_path [edk_tools_path]] [VS2019] [VS2017] [VS2015] [VS2013] [VS2012]"\r
+  @echo.\r
+  @echo         base_tools_path   BaseTools project path, BASE_TOOLS_PATH will be set to this path.\r
+  @echo         edk_tools_path    EDK_TOOLS_PATH will be set to this path.\r
+  @echo         Rebuild           If sources are available perform an Incremental build, only\r
+  @echo                           build those updated tools.\r
+  @echo         ForceRebuild      If sources are available, rebuild all tools regardless of\r
+  @echo                           whether they have been updated or not.\r
+  @echo         Reconfig          Reinstall target.txt, tools_def.txt and build_rule.txt.\r
+  @echo         VS2012            Set the env for VS2012 build.\r
+  @echo         VS2013            Set the env for VS2013 build.\r
+  @echo         VS2015            Set the env for VS2015 build.\r
+  @echo         VS2017            Set the env for VS2017 build.\r
+  @echo         VS2019            Set the env for VS2019 build.\r
+  @echo.\r
 \r
 :end\r
-@echo on\r
+set REBUILD=\r
+set FORCE_REBUILD=\r
+set RECONFIG=\r
+set VS2019=\r
+set VS2017=\r
+set VS2015=\r
+set VS2013=\r
+set VS2012=\r
+set VSTool=\r
+popd\r
 \r