]> git.proxmox.com Git - mirror_edk2.git/blob - Edk2Setup.bat
EmbeddedPkg/MmcDxe: eliminate deprecated string function calls
[mirror_edk2.git] / Edk2Setup.bat
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 @echo.
359 @echo Rebuilding of the tools is not required. Binaries of the latest,
360 @echo tested versions of the tools have been tested and included in the
361 @echo EDK II repository.
362 @echo.
363 @echo If you really want to build the tools, use the --rebuild option.
364 @echo.
365 @if not defined CYGWIN_HOME @echo "!!! WARNING !!! No CYGWIN_HOME set, gcc build may not be used !!!"
366 @if not defined CYGWIN_HOME @echo.
367 @REM Make sure the WORKSPACE\Conf directory contains the required text files that will be
368 @REM copied or replaced from the WORKSPACE\BaseTools\Conf directories' template files.
369 :SetConf
370 @if not exist "%EDK_TOOLS_PATH%\Conf" (
371 @if exist "%BASE_TOOLS_PATH%\Conf" (
372 @set "SRC_CONF=%BASE_TOOLS_PATH%\Conf"
373 )
374 ) else (
375 @set "SRC_CONF=%EDK_TOOLS_PATH%\Conf"
376 )
377 @if not defined SRC_CONF (
378 @echo ERROR : Unable to locate the BaseTools directory tree
379 @goto ExitFailure
380 )
381
382 @REM The script will test to see if the files exist, and also use the RESET_ENVIRONMENT flag
383 @REM to overwrite the WORKSPACE\Conf *.txt files.
384 @call "%BASE_TOOLS_PATH%\Scripts\ShowEnvironment.bat"
385 @if errorlevel 1 (
386 @echo Unable to copy the template files from "%SRC_CONF%" to "%WORKSPACE%\Conf"
387 @goto ExitFailure
388 )
389 @set SRC_CONF=
390
391 @REM Set up Visual Studio if required to build the Nt32Pkg/Nt32Pkg.dsc emulator
392 @if "%NT32PKG%"=="TRUE" (
393 @if not defined VSINSTALLDIR @set "PATH=%ORIGINAL_PATH%"
394 @if not defined NT32_X64 @call "%BASE_TOOLS_PATH%\get_vsvars.bat"
395 @if defined NT32_X64 call "%BASE_TOOLS_PATH%\Scripts\SetVisualStudio.bat"
396 )
397 @if "%NT32PKG%"=="TRUE" (
398 @if not defined VS_PATH set "VS_PATH=%PATH%"
399 )
400 @if defined VS_PATH @set "PATH=%VS_PATH%"
401 @if not defined VS_PATH @set "PATH=%ORIGINAL_PATH%"
402 @if not defined EDK_TOOLS_BIN (
403 @if exist %EDK_TOOLS_PATH%\Bin\Win32 (
404 @set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32
405 ) else (
406 @echo.
407 @echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!!
408 @echo Please check the directory %EDK_TOOLS_PATH%\Bin\Win32
409 @echo Or configure EDK_TOOLS_BIN env to point Win32 directory.
410 @echo.
411 @goto ExitFailure
412 )
413 )
414 @set "PATH=%EDK_TOOLS_BIN%;%PATH%"
415
416 @if NOT EXIST "%EDK_TOOLS_BIN%\build.exe" @set PYTHON_BUILD=TRUE
417 @if NOT EXIST "%EDK_TOOLS_BIN%\GenFds.exe" @set PYTHON_BUILD=TRUE
418 @if NOT EXIST "%EDK_TOOLS_BIN%\TargetTool.exe" @set PYTHON_BUILD=TRUE
419 @if NOT EXIST "%EDK_TOOLS_BIN%\Trim.exe" @set PYTHON_BUILD=TRUE
420
421 @if not defined PYTHON_BUILD goto SvnPull
422
423 @echo !!! WARNING !!! Setup environment to run Python scripts directly.
424
425 @if not defined PYTHON_HOME (
426 @if defined PYTHONHOME (
427 @set PYTHON_HOME=%PYTHONHOME%
428 ) else (
429 @echo.
430 @echo !!! ERROR !!! PYTHON_HOME is required to build or execute the tools, please set it. !!!
431 @echo.
432 @goto ExitFailure
433 )
434 )
435
436 @set PATH=%PATH%;%BASE_TOOLS_PATH%\BinWrappers\WindowsLike
437 @set BASETOOLS_PYTHON_SOURCE=%BASE_TOOLS_PATH%\Source\Python
438 @set PYTHONPATH=%BASETOOLS_PYTHON_SOURCE%;%PYTHONPATH%
439
440 :SvnPull
441 @if "%REBUILD_TOOLS%"=="TRUE" @goto Rebuild
442 @if "%SVN_PULL%"== "TRUE" (
443 if defined PYTHONHOME (
444 @REM Use the python script if possible to test is the svn command is available, if it fails, the user may be
445 @REM able to rebuild the Win32 binaries
446 @call "%BASE_TOOLS_PATH%\Scripts\UpdateBuildVersions.py" --svn-test -v
447 @if errorlevel 1 (
448 @echo ERROR : The command-line svn tool is not available and the Win32 binaries do not exist
449 @echo Please re-run this script again with the --rebuild option to attempt to build
450 @echo the binaries
451 @echo.
452 @goto ExitFailure
453 )
454 @if exist %EDK_TOOLS_PATH%\Bin\Win32 @rmdir /S /Q %EDK_TOOLS_PATH%\Bin\Win32
455 @call svn co https://svn.code.sf.net/p/edk2-toolbinaries/code/trunk/Win32 "%EDK_TOOLS_PATH%\Bin\Win32"
456 ) else (
457 @call svn co https://svn.code.sf.net/p/edk2-toolbinaries/code/trunk/Win32 "%EDK_TOOLS_PATH%\Bin\Win32"
458 @if errorlevel 1 (
459 @echo ERROR : The command-line svn tool is not available and the Win32 binaries do not exist
460 @echo Python does not appear to be available either. This script cannot be used to
461 @echo build the Win32 binaries or to obtain them from this repository:
462 @echo https://svn.code.sf.net/p/edk2-toolbinaries/code/trunk/Win32
463 @goto ExitFailure
464 )
465 )
466 @goto ShowAndExit
467 )
468
469 @if not "%REBUILD_TOOLS%"=="TRUE" @goto ShowAndExit
470
471 @REM The following code is used to rebuild the Win32 BaseTools binaries - check that required tools are available
472 :Rebuild
473 @if not exist "%BASE_TOOLS_PATH%\Source" @goto NoBaseTools
474 @endlocal
475 @if not defined VCINSTALLDIR @goto NoVisualStudio
476 @if not defined PYTHONHOME @goto NoPython
477 @if not exist "%PYTHONHOME%\python.exe" @goto BadPython
478 @REM python.exe has been located, now make sure it's in the PATH
479 @call python --version > nul 2>&1
480 @if errorlevel 1 @set "PATH=%PYTHONHOME%\python.exe;%PATH%"
481 @if not defined PYTHON_FREEZER_PATH (
482 @if not exist "%PYTHONHOME%\Scripts\cxfreeze.bat" @goto NoCxFreeze
483 @set "PYTHON_FREEZER_PATH=%PYTHONHOME%\Scripts"
484 )
485 @call "%BASE_TOOLS_PATH%\Scripts\SetVisualStudio.bat"
486 @if errorlevel 1 @goto ExitFailure
487
488 :ShowAndExit
489 @call "%BASE_TOOLS_PATH%\Scripts\ShowEnvironment.bat"
490
491 @REM #########################################################################################
492 @REM EXIT ROUTINES
493 @REM #########################################################################################
494 :ExitSuccess
495 @set SCRIPT_NAME=
496 @set SCRIPT_VERSION=
497 @set SVN_REVISION=
498 @set RESET_ENVIRONMENT=
499 @set RECONFIG=
500 @set NT32PKG=
501 @set BUILD_TOOLS_WITH=
502 @set LOCATION=
503 @set REBUILD_TOOLS=
504 @set SVN_PULL=
505 @set SRC_CONF=
506 @set ARGUMENT=
507 @set SCRIPT=
508 @set LIST_VS_VERSIONS=
509 @set PYTHON_FREEZER_PATH=
510 @set PYTHON_BUILD=
511 @echo on
512 @exit /B 0
513
514 :ExitFailure
515 @set SCRIPT_NAME=
516 @set SCRIPT_VERSION=
517 @set SVN_REVISION=
518 @set RESET_ENVIRONMENT=
519 @set RECONFIG=
520 @set NT32PKG=
521 @set BUILD_TOOLS_WITH=
522 @set LOCATION=
523 @set REBUILD_TOOLS=
524 @set SVN_PULL=
525 @set SRC_CONF=
526 @set ARGUMENT=
527 @set SCRIPT=
528 @set LIST_VS_VERSIONS=
529 @set PYTHON_FREEZER_PATH=
530 @set PYTHON_BUILD=
531 @echo on
532 @exit /B 1