+IF NOT EXIST "%EDK_TOOLS_BIN%\BootSectImage.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\EfiLdrImage.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\EfiRom.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\GenBootSector.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%\GenPage.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%\GenVtf.exe" goto check_c_tools\r
+IF NOT EXIST "%EDK_TOOLS_BIN%\Split.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 requried to be built from BaseTools Source.\r
+ echo.\r
+\r
+:check_build_environment\r
+ if defined BASETOOLS_PYTHON_SOURCE goto VisualStudioAvailable\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
+ if not defined PYTHON_HOME (\r
+ if defined PYTHONHOME (\r
+ set PYTHON_HOME=%PYTHONHOME%\r
+ ) else (\r
+ echo.\r
+ echo !!! ERROR !!! Binary python tools are missing. PYTHON_HOME environment variable is not set.\r
+ echo PYTHON_HOME is required to build or execute the python tools.\r
+ echo.\r
+ goto end\r
+ )\r
+ )\r
+\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
+\r
+ echo PATH = %PATH%\r
+ echo PYTHON_HOME = %PYTHON_HOME%\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
+ call "%EDK_TOOLS_PATH%\get_vsvars.bat"\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]]"\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.\r