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