2 @REM Windows batch file
, Edk2Setup.bat
, to
set up an EDK II build environment
4 @REM This script will be renamed to edksetup.bat after initial testing and
5 @REM acceptance by the open source community.
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
16 @REM Three other scripts
, located in the BaseTools\Scripts directory
, may be called
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
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
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.
41 @REM Edk2Setup.bat
[--help |
-h
] [-v |
--version
] [-r |
--reset
]
42 @REM
[--reconfig
] [--edk
-tools
-path DirName
]
43 @REM
[--pull
[Directory
]|
--rebuild
[Directory
]]
46 @REM ##############################################################
47 @REM # You should
not have to modify anything below this line
51 @
set SCRIPT_VERSION
=0.9.2.
52 @
set SVN_REVISION
=$Revision$
53 @
set RESET_ENVIRONMENT
=FALSE
56 @
set BUILD_TOOLS_WITH
=
62 @
set SCRIPT
=EDKSETUP_BAT
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
(
70 @
if not exist "%BASE_TOOLS_PATH%" (
71 @
if exist "%WORKSPACE%\BaseTools" (
72 set "BASE_TOOLS_PATH=%WORKSPACE%\BaseTools"
74 @
if defined PACKAGES_PATH
(
75 @
for %%i IN
(%PACKAGES_PATH%) DO (
76 @
if exist %%~fi\BaseTools
(
77 @
set BASE_TOOLS_PATH
=%%~fi\BaseTools
85 @
if not defined BASE_TOOLS_PATH
(
87 @
echo !!! ERROR
!!! The BaseTools Package was
not found
!!!
91 @
if not exist "%WORKSPACE%\Conf" @
mkdir "%WORKSPACE%\Conf"
93 @@
if not defined EDK_TOOLS_PATH @
set "EDK_TOOLS_PATH=%BASE_TOOLS_PATH%"
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%"
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
108 @REM These options will reset the system environment
110 @
setlocal EnableDelayedExpansion
111 @
set "WORKSPACE=%CD%"
112 @
set "EDK_TOOLS_PATH=%CD%\BaseTools"
113 @
set "LOCATION=!EDK_TOOLS_PATH!"
118 @
if /I
"%1"=="--reset" (
119 @
set "WORKSPACE=%CD%"
120 @
set "EDK_TOOLS_PATH=%WORKSPACE%\BaseTools"
121 @
set "LOCATION=%WORKSPACE%\BaseTools"
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" (
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
139 @
if "!ARGUMENT:~0,2!"=="--" (
141 @
echo ERROR
: The
--edk
-tools
-path flag requires an argument
147 @
set "LOCATION=%WORKSPACE%\%2"
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" (
158 @
echo ERROR
: The
--pull option may
not be used with the
--rebuild option
163 @
setlocal EnableDelayedExpansion
165 @
if not "!ARGUMENT:~0,2!"=="--" (
174 @REM This options forces rebuilding the tools
(provided the required tools are available
175 @
if /I
"%1"=="--rebuild" (
176 @
if "%SVN_PULL%"=="TRUE" (
178 @
echo ERROR
: The
--reset option may
not be used with the
--pull option
182 @
set REBUILD_TOOLS
=TRUE
183 @
setlocal EnableDelayedExpansion
185 @
if not "!ARGUMENT:~0,2!"=="--" (
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" (
198 @
if not defined BUILD_TOOLS_WITH
(
199 @
set BUILD_TOOLS_WITH
=Latest
201 @REM This option will try to
set the environment
for building the Nt32Pkg
/Nt32Pkg
; on a
64-bit
211 @
if not "%1"=="" goto UnknownOptionOrArgument
215 @
echo Usage
: %SCRIPT_NAME% [Options
]
216 @
echo Copyright
(c
) 2014, Intel Corporation. All rights reserved.
218 @
echo The system environment variable
, WORKSPACE
, is always
set to the current
219 @
echo working directory.
222 @
echo --help
, -h
Print this help screen and
exit.
224 @
echo --version
Print this script
's version and exit.
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
235 @echo --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the
236 @echo template files from the BaseTools/Conf directory.
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).
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
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.
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.
280 @echo %SCRIPT_NAME% Version: %SCRIPT_VERSION%%SVN_REVISION:~11,-1%
281 @echo Copyright(c) 2014, Intel Corporation. All rights reserved.
283 @call "%BASE_TOOLS_PATH%\Scripts\ShowEnvironment.bat"
287 :UnknownOptionOrArgument
288 @echo. ERROR : This argument is not valid: %1
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
296 @echo Refer to the BaseTools\BuildNotes.txt for directions for building
297 @echo the BaseTools binaries.
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
311 @echo ERROR : Unable to rebuild the BaseTools binaries, python does not appear to be
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
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
329 @echo ERROR: Unable to locate the BaseTools directory containing the Source tree
333 @REM #########################################################################################
335 @REM Set up the Build System environment
336 @REM #########################################################################################
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%
343 @if not defined NASM_PREFIX (
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.
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
353 @if exist "%WORKSPACE%\%EDK_TOOLS_PATH%" @set "EDK_TOOLS_PATH=%WORKSPACE%\%EDK_TOOLS_PATH%"
355 @if defined REBUILD_TOOLS goto SetConf
356 @if defined SVN_PULL goto SetConf
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" (
361 @echo !!! ERROR !!! The set_vsprefix_envs.bat was not found !!!
365 @call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat
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.
372 @echo If you really want to build the tools, use the --rebuild option.
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.
379 @
if not exist "%EDK_TOOLS_PATH%\Conf" (
380 @
if exist "%BASE_TOOLS_PATH%\Conf" (
381 @
set "SRC_CONF=%BASE_TOOLS_PATH%\Conf"
384 @
set "SRC_CONF=%EDK_TOOLS_PATH%\Conf"
386 @
if not defined SRC_CONF
(
387 @
echo ERROR
: Unable to locate the BaseTools directory
tree
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"
395 @
echo Unable to
copy the template
files from
"%SRC_CONF%" to
"%WORKSPACE%\Conf"
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"
406 @
if "%NT32PKG%"=="TRUE" (
407 @
if not defined VS_PATH
set "VS_PATH=%PATH%"
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
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.
423 @
set "PATH=%EDK_TOOLS_BIN%;%PATH%"
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
430 @
if not defined PYTHON_BUILD
goto SvnPull
432 @
echo !!! WARNING
!!! Setup environment to
run Python scripts directly.
434 @
if not defined PYTHON_HOME
(
435 @
if defined PYTHONHOME
(
436 @
set PYTHON_HOME
=%PYTHONHOME%
439 @
echo !!! ERROR
!!! PYTHON_HOME is required to build or execute the tools
, please
set it.
!!!
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%
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
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
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"
466 @
call svn co https
://svn.code.sf.
net/p
/edk2
-toolbinaries
/code
/trunk
/Win32
"%EDK_TOOLS_PATH%\Bin\Win32"
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
478 @
if not "%REBUILD_TOOLS%"=="TRUE" @
goto ShowAndExit
480 @REM The following code is used to rebuild the Win32 BaseTools binaries
- check that required tools are available
482 @
if not exist "%BASE_TOOLS_PATH%\Source" @
goto NoBaseTools
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"
494 @call "%BASE_TOOLS_PATH%\Scripts\SetVisualStudio.bat"
495 @if errorlevel 1 @goto ExitFailure
498 @call "%BASE_TOOLS_PATH%\Scripts\ShowEnvironment.bat"
500 @REM #########################################################################################
502 @REM #########################################################################################
507 @set RESET_ENVIRONMENT=
510 @set BUILD_TOOLS_WITH=
517 @set LIST_VS_VERSIONS=
518 @set PYTHON_FREEZER_PATH=
527 @set RESET_ENVIRONMENT=
530 @set BUILD_TOOLS_WITH=
537 @set LIST_VS_VERSIONS=
538 @set PYTHON_FREEZER_PATH=