1@REM @file 2@REM Windows batch file, Edk2Setup.bat, to set up an EDK II build environment 3@REM 4@REM This script will be renamed to edksetup.bat after initial testing and 5@REM acceptance by the open source community. 6@REM 7@REM This script will set the following system environment variables: 8@REM WORKSPACE, EDK_TOOLS_PATH, PATH 9@REM If rebuilding the tools: 10@REM BASE_TOOLS_PATH, PYTHON_FREEZER_PATH, PYTHONPATH 11@REM It will also create a Conf/target.txt, tools_def.txt and build_rule.txt files 12@REM if they do not exist 13@REM If the reset flag is set, all environment variables will be reset and 14@REM the Conf/target.txt, tools_def.txt and build_rule.txt files will be overwritten 15@REM 16@REM Three other scripts, located in the BaseTools\Scripts directory, may be called 17@REM by this script. 18@REM SetVisualStudio.bat - will set the Visual Studio environment based on the --vs* flags 19@REM it is also used to build the Win32 binaries, calling nmake 20@REM using the WORKSPACE\BaseTools\Makefile 21@REM ShowEnvironment.bat - will display the current EDK II Build environment 22@REM UpdateBuildVersions.py - script is called prior to building the EDK II BaseTools from 23@REM Sources. This tool will modify the BuildVersion.* files so that 24@REM when the tools get built, they will have a custom version entry 25@REM similar to the following: 26@REM e:\edk2>build --version 27@REM build.exe Version 0.51 Developer Build based on Revision: 15668 28@REM 29@REM Copyright (c) 2014, Intel Corporation. All rights reserved.<BR> 30@REM (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR> 31@REM This program and the accompanying materials 32@REM are licensed and made available under the terms and conditions of the BSD License 33@REM which accompanies this distribution. The full text of the license may be found at 34@REM http://opensource.org/licenses/bsd-license.php 35@REM 36@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 37@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 38@REM 39@REM 40@REM usage: 41@REM Edk2Setup.bat [--help | -h] [-v | --version] [-r | --reset] 42@REM [--reconfig] [--edk-tools-path DirName] 43@REM [--pull [Directory]| --rebuild [Directory]] 44@REM [--nt32 [X64]] 45 46@REM ############################################################## 47@REM # You should not have to modify anything below this line 48@REM # 49@echo off 50@set SCRIPT_NAME=%0 51@set SCRIPT_VERSION=0.9.2. 52@set SVN_REVISION=$Revision$ 53@set RESET_ENVIRONMENT=FALSE 54@set NT32PKG=FALSE 55@set NT32_X64= 56@set BUILD_TOOLS_WITH= 57@set LOCATION= 58@set REBUILD_TOOLS= 59@set SVN_PULL= 60@set SRC_CONF= 61@set ARGUMENT= 62@set SCRIPT=EDKSETUP_BAT 63@set PYTHON_BUILD= 64 65@if not defined ORIGINAL_PATH set "ORIGINAL_PATH=%PATH%" 66@REM Always set the WORKSPACE environment variable to the current directory 67@if not defined WORKSPACE ( 68 @set "WORKSPACE=%CD%" 69) 70@if not exist "%BASE_TOOLS_PATH%" ( 71 @if exist "%WORKSPACE%\BaseTools" ( 72 set "BASE_TOOLS_PATH=%WORKSPACE%\BaseTools" 73 ) else ( 74 @if defined PACKAGES_PATH ( 75 @for %%i IN (%PACKAGES_PATH%) DO ( 76 @if exist %%~fi\BaseTools ( 77 @set BASE_TOOLS_PATH=%%~fi\BaseTools 78 @goto checkBaseTools 79 ) 80 ) 81 ) 82 ) 83) 84:checkBaseTools 85@if not defined BASE_TOOLS_PATH ( 86 @echo. 87 @echo !!! ERROR !!! The BaseTools Package was not found !!! 88 @echo. 89 @goto ExitFailure 90) 91@if not exist "%WORKSPACE%\Conf" @mkdir "%WORKSPACE%\Conf" 92 93@@if not defined EDK_TOOLS_PATH @set "EDK_TOOLS_PATH=%BASE_TOOLS_PATH%" 94 95@REM Keep the existing EDK_TOOLS_PATH value, the --reset flag will set it 96@REM back to WORKSPACE\BaseTools while the --location DIRECTORY flag will 97@REM still take precedence if the location option follows the reset option 98@REM on the command line. 99@if defined EDK_TOOLS_PATH @set "LOCATION=%EDK_TOOLS_PATH%" 100 101:parse_cmd_line 102@if "%1"=="" @goto MainRoutine 103@if /I "%1"=="-h" @goto Usage 104@if /I "%1"=="--help" @goto Usage 105@if /I "%1"=="/?" @goto Usage 106@if /I "%1"=="--version" @goto Version 107 108@REM These options will reset the system environment 109@if /I "%1"=="-r" ( 110 @setlocal EnableDelayedExpansion 111 @set "WORKSPACE=%CD%" 112 @set "EDK_TOOLS_PATH=%CD%\BaseTools" 113 @set "LOCATION=!EDK_TOOLS_PATH!" 114 @endlocal 115 @shift 116 @goto parse_cmd_line 117) 118@if /I "%1"=="--reset" ( 119 @set "WORKSPACE=%CD%" 120 @set "EDK_TOOLS_PATH=%WORKSPACE%\BaseTools" 121 @set "LOCATION=%WORKSPACE%\BaseTools" 122 @shift 123 @goto parse_cmd_line 124) 125 126@REM This option is used to overwrite the Conf/*.txt files with the 127@REM WORKSPACE\BaseTools\Conf\*.template files. 128@if /I "%1"=="--reconfig" ( 129 @set RECONFIG=TRUE 130 @shift 131 @goto parse_cmd_line 132) 133 134@REM This option can be used to set the EDK_TOOLS_PATH containing the Win32 binaries to an 135@REM alternate directory 136@if /I "%1"=="--edk-tools-path" ( 137 @setlocal EnableDelayedExpansion 138 @set ARGUMENT=%2 139 @if "!ARGUMENT:~0,2!"=="--" ( 140 @echo. 141 @echo ERROR : The --edk-tools-path flag requires an argument 142 @echo. 143 @endlocal 144 @goto Usage 145 ) 146 @endlocal 147 @set "LOCATION=%WORKSPACE%\%2" 148 @shift 149 @shift 150 @goto parse_cmd_line 151) 152 153@REM Force pulling updated (or checkout if they do not exist) from SVN for the BaseTools\Bin\Win32 directory 154@REM or the directory pointed to by the --location option 155@if /I "%1"=="--pull" ( 156 @if "%REBUILD_TOOLS%"=="TRUE" ( 157 @echo. 158 @echo ERROR: The --pull option may not be used with the --rebuild option 159 @shift 160 @goto ExitFailure 161 ) 162 @set SVN_PULL=TRUE 163 @setlocal EnableDelayedExpansion 164 @set ARGUMENT=%2 165 @if not "!ARGUMENT:~0,2!"=="--" ( 166 @endlocal 167 @set "LOCATION=%2" 168 @shift 169 ) 170 @shift 171 @goto parse_cmd_line 172) 173 174@REM This options forces rebuilding the tools (provided the required tools are available 175@if /I "%1"=="--rebuild" ( 176 @if "%SVN_PULL%"=="TRUE" ( 177 @echo. 178 @echo ERROR: The --reset option may not be used with the --pull option 179 @shift 180 @goto ExitFailure 181 ) 182 @set REBUILD_TOOLS=TRUE 183 @setlocal EnableDelayedExpansion 184 @set ARGUMENT=%2 185 @if not "!ARGUMENT:~0,2!"=="--" ( 186 @endlocal 187 @set "LOCATION=%2" 188 @shift 189 ) 190 @shift 191 goto parse_cmd_line 192) 193 194@REM This option will try to set the compiler environment for building Nt32Pkg/Nt32Pkg.dsc 195@REM If the compiler environment is already installed, then no additional work is required. 196@if /I "%1"=="--nt32" ( 197 @set NT32PKG=TRUE 198 @if not defined BUILD_TOOLS_WITH ( 199 @set BUILD_TOOLS_WITH=Latest 200 ) 201 @REM This option will try to set the environment for building the Nt32Pkg/Nt32Pkg; on a 64-bit 202 @REM Windows OS 203 @if /I "%2"=="X64" ( 204 @set NT32_X64=TRUE 205 @shift 206 ) 207 @shift 208 @goto parse_cmd_line 209) 210 211@if not "%1"=="" goto UnknownOptionOrArgument 212@goto MainRoutine 213 214:Usage 215@echo Usage: %SCRIPT_NAME% [Options] 216@echo Copyright(c) 2014, Intel Corporation. All rights reserved. 217@echo. 218@echo The system environment variable, WORKSPACE, is always set to the current 219@echo working directory. 220@echo. 221@echo Options: 222@echo --help, -h Print this help screen and exit. 223@echo. 224@echo --version Print this script's version and exit. 225@echo. 226@echo --reset, -r Reset the EDK_TOOLS_PATH and PATH system environment 227@echo variables. The EDK_TOOLS_PATH default is 228@echo WORKSPACE\BaseTools, however, it may be overridden by 229@echo arguments given to the --edk-tools-path, --pull and/or 230@echo --rebuild options. 231@echo Once set, the EDK_TOOLS_PATH environment variable reset 232@echo by opening up a new command prompt window or through one 233@echo of the options provided by this tool 234@echo. 235@echo --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the 236@echo template files from the BaseTools/Conf directory. 237@echo. 238@echo --edk-tools-path DIRECTORY 239@echo This option sets the EDK_TOOLS_PATH to the DIRECTORY 240@echo value instead of the default (WORKSPACE\BaseTools). 241@echo. 242@echo --nt32 [X64] If a compiler tool chain is not available in the 243@echo environment, call a script to attempt to set one up. 244@echo This flag is only required if building the 245@echo Nt32Pkg/Nt32Pkg.dsc system emulator. 246@echo If the X64 argument is set, and a compiler tool chain is 247@echo not available, attempt to set up a tool chain that will 248@echo create X64 binaries. Setting these two options have the 249@echo potential side effect of changing tool chains used for a 250@echo rebuild. 251@echo. 252@pause 253@echo. 254@echo --pull [DIRECTORY] Get the EDK II BaseTools binaries from source control 255@echo (must not be used with --rebuild). 256@echo If the optional DIRECTORY argument is specified, the tool 257@echo sets EDK_TOOLS_PATH to DIRECTORY. 258@echo If the DIRECTORY argument is not specified, the tools are 259@echo placed in the directory tree pointed to by the current 260@echo EDK_TOOLS_PATH environment variable. If the binaries 261@echo cannot be obtained from source control, the 262@echo EDK_TOOLS_PATH will be set to the default, 263@echo WORKSPACE\BaseTools directory. 264@echo. 265@echo --rebuild [DIRECTORY] 266@echo Force Rebuilding the EDK II BaseTools from source 267@echo (must not be used with --pull). 268@echo NOTE: The build will use whatever compiler tool set 269@echo is available in the environment prior to 270@echo running edksetup.bat. 271@echo If the optional DIRECTORY argument is specified, the tool 272@echo sets EDK_TOOLS_PATH to DIRECTORY. Tools binaries will be 273@echo placed in the appropriate subdirectory in the 274@echo EDK_TOOLS_PATH directory. If the build fails, the 275@echo EDK_TOOLS_PATH will be set to the default, 276@echo WORKSPACE\BaseTools directory. 277@goto ExitSuccess 278 279:Version 280@echo %SCRIPT_NAME% Version: %SCRIPT_VERSION%%SVN_REVISION:~11,-1% 281@echo Copyright(c) 2014, Intel Corporation. All rights reserved. 282@set HIDE_PATH=TRUE 283@call "%BASE_TOOLS_PATH%\Scripts\ShowEnvironment.bat" 284@set HIDE_PATH= 285@goto ExitSuccess 286 287:UnknownOptionOrArgument 288@echo. ERROR : This argument is not valid: %1 289@echo. 290@goto ExitFailure 291 292:NoVisualStudio 293@echo ERROR : Unable to determine if a compiler tool chain has been enabled in this 294@echo command-prompt window. Rebuilding of the tools with this script is not 295@echo possible. 296@echo Refer to the BaseTools\BuildNotes.txt for directions for building 297@echo the BaseTools binaries. 298@echo. 299@goto ExitFailure 300 301:NoPython 302@echo ERROR : Unable to rebuild the BaseTools binaries, python does not appear to be 303@echo installed. If python is installed, please set the environment 304@echo variable, PYTHONHOME to the Path to the python.exe, for example, 305@echo if python.exe is located in the C:\Python27 directory, then: 306@echo set PYTHONHOME=C:\Python27 307@echo. 308@goto ExitFailure 309 310:BadPython 311@echo ERROR : Unable to rebuild the BaseTools binaries, python does not appear to be 312@echo installed. 313@echo The python executable was not found in the PYTHONHOME: %PYTHONHOME% 314@echo If python is installed, please set the environment variable, PYTHONHOME 315@echo to the Path that contains python.exe, for example, if python.exe is 316@echo located in the C:\Python27 directory, then: 317@echo set PYTHONHOME=C:\Python27 318@echo. 319@goto ExitFailure 320 321:NoCxFreeze 322@echo ERROR : Unable to locate cx_Freeze 4.2.3. The cxfreeze.bat file must be located 323@echo in the %PYTHONHOME%\Scripts directoryin order to rebuild the BaseTools 324@echo binaries. 325@echo. 326@goto ExitFailure 327 328:NoBaseTools 329@echo ERROR: Unable to locate the BaseTools directory containing the Source tree 330@echo. 331@goto ExitFailure 332 333@REM ######################################################################################### 334@REM MAIN ROUTINE 335@REM Set up the Build System environment 336@REM ######################################################################################### 337:MainRoutine 338@if defined LOCATION @set "EDK_TOOLS_PATH=%LOCATION%" 339@REM SET the EDK_TOOLS_PATH. 340@if not exist "%EDK_TOOLS_PATH%" ( 341 @mkdir %EDK_TOOLS_PATH% 342) 343@if not defined NASM_PREFIX ( 344 @echo. 345 @echo WARNING : NASM_PREFIX environment variable is not set 346 @if exist "C:\nasm\nasm.exe" @set "NASM_PREFIX=C:\nasm\" 347 @if exist "C:\nasm\nasm.exe" @echo Found nasm.exe, setting the environment variable to C:\nasm\ 348 @if not exist "C:\nasm\nasm.exe" echo Attempting to build modules that require NASM will fail. 349) 350@REM Set up the path to include the EDK_TOOLS_PATH\Bin\Win32 directory; this test determines 351@REM whether the path is in the workspace or a fully qualified path that may be outside of 352@REM the workspace 353@if exist "%WORKSPACE%\%EDK_TOOLS_PATH%" @set "EDK_TOOLS_PATH=%WORKSPACE%\%EDK_TOOLS_PATH%" 354 355@if defined REBUILD_TOOLS goto SetConf 356@if defined SVN_PULL goto SetConf 357 358@REM call set_vsprefix_envs.bat to set up the PREFIX env for VS tool path. 359@IF NOT exist "%EDK_TOOLS_PATH%\set_vsprefix_envs.bat" ( 360 @echo. 361 @echo !!! ERROR !!! The set_vsprefix_envs.bat was not found !!! 362 @echo. 363 @goto ExitFailure 364) 365@call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat 366 367@echo. 368@echo Rebuilding of the tools is not required. Binaries of the latest, 369@echo tested versions of the tools have been tested and included in the 370@echo EDK II repository. 371@echo. 372@echo If you really want to build the tools, use the --rebuild option. 373@echo. 374@if not defined CYGWIN_HOME @echo "!!! WARNING !!! No CYGWIN_HOME set, gcc build may not be used !!!" 375@if not defined CYGWIN_HOME @echo. 376@REM Make sure the WORKSPACE\Conf directory contains the required text files that will be 377@REM copied or replaced from the WORKSPACE\BaseTools\Conf directories' template files. 378:SetConf 379@if not exist "%EDK_TOOLS_PATH%\Conf" ( 380 @if exist "%BASE_TOOLS_PATH%\Conf" ( 381 @set "SRC_CONF=%BASE_TOOLS_PATH%\Conf" 382 ) 383) else ( 384 @set "SRC_CONF=%EDK_TOOLS_PATH%\Conf" 385) 386@if not defined SRC_CONF ( 387 @echo ERROR : Unable to locate the BaseTools directory tree 388 @goto ExitFailure 389) 390 391@REM The script will test to see if the files exist, and also use the RESET_ENVIRONMENT flag 392@REM to overwrite the WORKSPACE\Conf *.txt files. 393@call "%BASE_TOOLS_PATH%\Scripts\ShowEnvironment.bat" 394@if errorlevel 1 ( 395 @echo Unable to copy the template files from "%SRC_CONF%" to "%WORKSPACE%\Conf" 396 @goto ExitFailure 397) 398@set SRC_CONF= 399 400@REM Set up Visual Studio if required to build the Nt32Pkg/Nt32Pkg.dsc emulator 401@if "%NT32PKG%"=="TRUE" ( 402 @if not defined VSINSTALLDIR @set "PATH=%ORIGINAL_PATH%" 403 @if not defined NT32_X64 @call "%BASE_TOOLS_PATH%\get_vsvars.bat" 404 @if defined NT32_X64 call "%BASE_TOOLS_PATH%\Scripts\SetVisualStudio.bat" 405) 406@if "%NT32PKG%"=="TRUE" ( 407 @if not defined VS_PATH set "VS_PATH=%PATH%" 408) 409@if defined VS_PATH @set "PATH=%VS_PATH%" 410@if not defined VS_PATH @set "PATH=%ORIGINAL_PATH%" 411@if not defined EDK_TOOLS_BIN ( 412 @if exist %EDK_TOOLS_PATH%\Bin\Win32 ( 413 @set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32 414 ) else ( 415 @echo. 416 @echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!! 417 @echo Please check the directory %EDK_TOOLS_PATH%\Bin\Win32 418 @echo Or configure EDK_TOOLS_BIN env to point Win32 directory. 419 @echo. 420 @goto ExitFailure 421 ) 422) 423@set "PATH=%EDK_TOOLS_BIN%;%PATH%" 424 425@if NOT EXIST "%EDK_TOOLS_BIN%\build.exe" @set PYTHON_BUILD=TRUE 426@if NOT EXIST "%EDK_TOOLS_BIN%\GenFds.exe" @set PYTHON_BUILD=TRUE 427@if NOT EXIST "%EDK_TOOLS_BIN%\TargetTool.exe" @set PYTHON_BUILD=TRUE 428@if NOT EXIST "%EDK_TOOLS_BIN%\Trim.exe" @set PYTHON_BUILD=TRUE 429 430@if not defined PYTHON_BUILD goto SvnPull 431 432@echo !!! WARNING !!! Setup environment to run Python scripts directly. 433 434@if not defined PYTHON_HOME ( 435 @if defined PYTHONHOME ( 436 @set PYTHON_HOME=%PYTHONHOME% 437 ) else ( 438 @echo. 439 @echo !!! ERROR !!! PYTHON_HOME is required to build or execute the tools, please set it. !!! 440 @echo. 441 @goto ExitFailure 442 ) 443) 444 445@set PATH=%PATH%;%BASE_TOOLS_PATH%\BinWrappers\WindowsLike 446@set BASETOOLS_PYTHON_SOURCE=%BASE_TOOLS_PATH%\Source\Python 447@set PYTHONPATH=%BASETOOLS_PYTHON_SOURCE%;%PYTHONPATH% 448 449:SvnPull 450@if "%REBUILD_TOOLS%"=="TRUE" @goto Rebuild 451@if "%SVN_PULL%"== "TRUE" ( 452 if defined PYTHONHOME ( 453 @REM Use the python script if possible to test is the svn command is available, if it fails, the user may be 454 @REM able to rebuild the Win32 binaries 455 @call "%BASE_TOOLS_PATH%\Scripts\UpdateBuildVersions.py" --svn-test -v 456 @if errorlevel 1 ( 457 @echo ERROR : The command-line svn tool is not available and the Win32 binaries do not exist 458 @echo Please re-run this script again with the --rebuild option to attempt to build 459 @echo the binaries 460 @echo. 461 @goto ExitFailure 462 ) 463 @if exist %EDK_TOOLS_PATH%\Bin\Win32 @rmdir /S /Q %EDK_TOOLS_PATH%\Bin\Win32 464 @call svn co https://svn.code.sf.net/p/edk2-toolbinaries/code/trunk/Win32 "%EDK_TOOLS_PATH%\Bin\Win32" 465 ) else ( 466 @call svn co https://svn.code.sf.net/p/edk2-toolbinaries/code/trunk/Win32 "%EDK_TOOLS_PATH%\Bin\Win32" 467 @if errorlevel 1 ( 468 @echo ERROR : The command-line svn tool is not available and the Win32 binaries do not exist 469 @echo Python does not appear to be available either. This script cannot be used to 470 @echo build the Win32 binaries or to obtain them from this repository: 471 @echo https://svn.code.sf.net/p/edk2-toolbinaries/code/trunk/Win32 472 @goto ExitFailure 473 ) 474 ) 475 @goto ShowAndExit 476) 477 478@if not "%REBUILD_TOOLS%"=="TRUE" @goto ShowAndExit 479 480@REM The following code is used to rebuild the Win32 BaseTools binaries - check that required tools are available 481:Rebuild 482@if not exist "%BASE_TOOLS_PATH%\Source" @goto NoBaseTools 483@endlocal 484@if not defined VCINSTALLDIR @goto NoVisualStudio 485@if not defined PYTHONHOME @goto NoPython 486@if not exist "%PYTHONHOME%\python.exe" @goto BadPython 487@REM python.exe has been located, now make sure it's in the PATH 488@call python --version > nul 2>&1 489@if errorlevel 1 @set "PATH=%PYTHONHOME%\python.exe;%PATH%" 490@if not defined PYTHON_FREEZER_PATH ( 491 @if not exist "%PYTHONHOME%\Scripts\cxfreeze.bat" @goto NoCxFreeze 492 @set "PYTHON_FREEZER_PATH=%PYTHONHOME%\Scripts" 493) 494@call "%BASE_TOOLS_PATH%\Scripts\SetVisualStudio.bat" 495@if errorlevel 1 @goto ExitFailure 496 497:ShowAndExit 498@call "%BASE_TOOLS_PATH%\Scripts\ShowEnvironment.bat" 499 500@REM ######################################################################################### 501@REM EXIT ROUTINES 502@REM ######################################################################################### 503:ExitSuccess 504@set SCRIPT_NAME= 505@set SCRIPT_VERSION= 506@set SVN_REVISION= 507@set RESET_ENVIRONMENT= 508@set RECONFIG= 509@set NT32PKG= 510@set BUILD_TOOLS_WITH= 511@set LOCATION= 512@set REBUILD_TOOLS= 513@set SVN_PULL= 514@set SRC_CONF= 515@set ARGUMENT= 516@set SCRIPT= 517@set LIST_VS_VERSIONS= 518@set PYTHON_FREEZER_PATH= 519@set PYTHON_BUILD= 520@echo on 521@exit /B 0 522 523:ExitFailure 524@set SCRIPT_NAME= 525@set SCRIPT_VERSION= 526@set SVN_REVISION= 527@set RESET_ENVIRONMENT= 528@set RECONFIG= 529@set NT32PKG= 530@set BUILD_TOOLS_WITH= 531@set LOCATION= 532@set REBUILD_TOOLS= 533@set SVN_PULL= 534@set SRC_CONF= 535@set ARGUMENT= 536@set SCRIPT= 537@set LIST_VS_VERSIONS= 538@set PYTHON_FREEZER_PATH= 539@set PYTHON_BUILD= 540@echo on 541@exit /B 1 542