]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/toolsetup.bat
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / toolsetup.bat
1 @REM @file
2 @REM This stand-alone program is typically called by the edksetup.bat file,
3 @REM however it may be executed directly from the BaseTools project folder
4 @REM if the file is not executed within a WORKSPACE\BaseTools folder.
5 @REM
6 @REM Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
7 @REM (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
8 @REM
9 @REM This program and the accompanying materials are licensed and made available
10 @REM under the terms and conditions of the BSD License which accompanies this
11 @REM distribution. The full text of the license may be found at:
12 @REM http://opensource.org/licenses/bsd-license.php
13 @REM
14 @REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 @REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
16 @REM IMPLIED.
17 @REM
18
19 @echo off
20 pushd .
21
22 @REM ##############################################################
23 @REM # You should not have to modify anything below this line
24 @REM #
25
26 if /I "%1"=="-h" goto Usage
27 if /I "%1"=="-help" goto Usage
28 if /I "%1"=="--help" goto Usage
29 if /I "%1"=="/h" goto Usage
30 if /I "%1"=="/help" goto Usage
31 if /I "%1"=="/?" goto Usage
32
33
34 :loop
35 if "%1"=="" goto setup_workspace
36 if /I "%1"=="--nt32" (
37 if /I "%2" == "X64" (
38 shift
39 )
40 @REM Ignore --nt32 flag
41 shift
42 goto loop
43 )
44 if /I "%1"=="Reconfig" (
45 shift
46 set RECONFIG=TRUE
47 goto loop
48 )
49 if /I "%1"=="Rebuild" (
50 shift
51 set REBUILD=TRUE
52 goto loop
53 )
54 if /I "%1"=="ForceRebuild" (
55 shift
56 set FORCE_REBUILD=TRUE
57 goto loop
58 )
59 if "%1"=="" goto setup_workspace
60 if exist %1 (
61 if not defined BASE_TOOLS_PATH (
62 if exist %1\Source set BASE_TOOLS_PATH=%1
63 shift
64 goto loop
65 )
66 if not defined EDK_TOOLS_PATH (
67 if exist %1\Bin\Win32 set EDK_TOOLS_PATH=%1
68 shift
69 goto loop
70 )
71 echo.
72 echo !!! ERROR !!! Unknown argument, %1 !!!
73 echo.
74 goto end
75 ) else (
76 echo.
77 echo !!! ERROR !!! Unknown argument, %1 !!!
78 echo.
79 goto end
80 )
81 goto loop
82
83
84 @REM
85 @REM Check the required system environment variables
86 @REM
87
88 :setup_workspace
89 REM
90 REM check the EDK_TOOLS_PATH
91 REM
92 if not defined EDK_TOOLS_PATH goto no_EDK_TOOLS_PATH
93 if exist %EDK_TOOLS_PATH% goto set_PATH
94
95 :no_EDK_TOOLS_PATH
96 if not defined WORKSPACE (
97 if defined BASE_TOOLS_PATH (
98 set EDK_TOOLS_PATH=%BASE_TOOLS_PATH%
99 goto set_PATH
100 ) else (
101 echo.
102 echo !!! ERROR !!! Neither BASE_TOOLS_PATH nor EDK_TOOLS_PATH are set. !!!
103 echo.
104 goto end
105 )
106 ) else (
107 if exist %WORKSPACE%\BaseTools\Bin (
108 set EDK_TOOLS_PATH=%WORKSPACE%\BaseTools
109 goto set_PATH
110 ) else (
111 echo.
112 echo !!! ERROR !!! No tools path available. Please set EDK_TOOLS_PATH !!!
113 echo.
114 goto end
115 )
116 )
117
118 :set_PATH
119 if defined WORKSPACE_TOOLS_PATH goto check_PATH
120 if not defined EDK_TOOLS_BIN (
121 set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32
122 if not exist %EDK_TOOLS_PATH%\Bin\Win32 (
123 echo.
124 echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!!
125 echo Please check the directory %EDK_TOOLS_PATH%\Bin\Win32
126 echo Or configure EDK_TOOLS_BIN env to point Win32 directory.
127 echo.
128 )
129 )
130 set PATH=%EDK_TOOLS_BIN%;%PATH%
131 set WORKSPACE_TOOLS_PATH=%EDK_TOOLS_PATH%
132 goto PATH_ok
133
134 :check_PATH
135 if "%EDK_TOOLS_PATH%"=="%WORKSPACE_TOOLS_PATH%" goto PATH_ok
136 if not defined EDK_TOOLS_BIN (
137 set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32
138 if not exist %EDK_TOOLS_PATH%\Bin\Win32 (
139 echo.
140 echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!!
141 echo Please check the directory %EDK_TOOLS_PATH%\Bin\Win32
142 echo Or configure EDK_TOOLS_BIN env to point Win32 directory.
143 echo.
144 )
145 )
146 set PATH=%EDK_TOOLS_BIN%;%PATH%
147 set WORKSPACE_TOOLS_PATH=%EDK_TOOLS_PATH%
148 echo Resetting the PATH variable to include the EDK_TOOLS_PATH for this session.
149
150 :PATH_ok
151 REM
152 REM copy *.template to %CONF_PATH%
153 REM
154 if not defined WORKSPACE (
155 if defined RECONFIG (
156 echo.
157 echo !!! WARNING !!! WORKSPACE environment variable was not set, cannot Reconfig !!!
158 echo.
159 )
160 goto skip_reconfig
161 )
162
163 IF NOT exist "%EDK_TOOLS_PATH%\set_vsprefix_envs.bat" (
164 @echo.
165 @echo !!! ERROR !!! The set_vsprefix_envs.bat was not found !!!
166 @echo.
167 goto end
168 )
169 call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat
170
171 if not defined CONF_PATH (
172 set CONF_PATH=%WORKSPACE%\Conf
173 )
174
175 if NOT exist %CONF_PATH% (
176 if defined PACKAGES_PATH (
177 for %%i IN (%PACKAGES_PATH%) DO (
178 if exist %%~fi\Conf (
179 set CONF_PATH=%%i\Conf
180 goto CopyConf
181 )
182 )
183 )
184 )
185
186 :CopyConf
187 if NOT exist %CONF_PATH% (
188 mkdir %CONF_PATH%
189 ) else (
190 if defined RECONFIG (
191 echo.
192 echo Over-writing the files in the CONF_PATH directory
193 echo using the default template files
194 echo.
195 )
196 )
197
198 if NOT exist %CONF_PATH%\target.txt (
199 echo copying ... target.template to %CONF_PATH%\target.txt
200 if NOT exist %EDK_TOOLS_PATH%\Conf\target.template (
201 echo Error: target.template is missing at folder %EDK_TOOLS_PATH%\Conf\
202 )
203 copy %EDK_TOOLS_PATH%\Conf\target.template %CONF_PATH%\target.txt > nul
204 ) else (
205 if defined RECONFIG echo over-write ... target.template to %CONF_PATH%\target.txt
206 if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\target.template %CONF_PATH%\target.txt > nul
207 )
208
209 if NOT exist %CONF_PATH%\tools_def.txt (
210 echo copying ... tools_def.template to %CONF_PATH%\tools_def.txt
211 if NOT exist %EDK_TOOLS_PATH%\Conf\tools_def.template (
212 echo Error: tools_def.template is missing at folder %EDK_TOOLS_PATH%\Conf\
213 )
214 copy %EDK_TOOLS_PATH%\Conf\tools_def.template %CONF_PATH%\tools_def.txt > nul
215 ) else (
216 if defined RECONFIG echo over-write ... tools_def.template to %CONF_PATH%\tools_def.txt
217 if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\tools_def.template %CONF_PATH%\tools_def.txt > nul
218 )
219
220 if NOT exist %CONF_PATH%\build_rule.txt (
221 echo copying ... build_rule.template to %CONF_PATH%\build_rule.txt
222 if NOT exist %EDK_TOOLS_PATH%\Conf\build_rule.template (
223 echo Error: build_rule.template is missing at folder %EDK_TOOLS_PATH%\Conf\
224 )
225 copy %EDK_TOOLS_PATH%\Conf\build_rule.template %CONF_PATH%\build_rule.txt > nul
226 ) else (
227 if defined RECONFIG echo over-write ... build_rule.template to %CONF_PATH%\build_rule.txt
228 if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\build_rule.template %CONF_PATH%\build_rule.txt > nul
229 )
230
231 echo PATH = %PATH%
232 echo.
233 if defined WORKSPACE (
234 echo WORKSPACE = %WORKSPACE%
235 )
236 if defined PACKAGES_PATH (
237 echo PACKAGES_PATH = %PACKAGES_PATH%
238 )
239 echo EDK_TOOLS_PATH = %EDK_TOOLS_PATH%
240 if defined BASE_TOOLS_PATH (
241 echo BASE_TOOLS_PATH = %BASE_TOOLS_PATH%
242 )
243 if defined EDK_TOOLS_BIN (
244 echo EDK_TOOLS_BIN = %EDK_TOOLS_BIN%
245 )
246 echo CONF_PATH = %CONF_PATH%
247 echo.
248
249 :skip_reconfig
250
251 @REM
252 @REM Test if we are going to have to do a build
253 @REM
254 if defined FORCE_REBUILD goto check_build_environment
255 if defined REBUILD goto check_build_environment
256 if not exist "%EDK_TOOLS_PATH%" goto check_build_environment
257 if not exist "%EDK_TOOLS_BIN%" goto check_build_environment
258
259 IF NOT EXIST "%EDK_TOOLS_BIN%\EfiRom.exe" goto check_c_tools
260 IF NOT EXIST "%EDK_TOOLS_BIN%\GenFfs.exe" goto check_c_tools
261 IF NOT EXIST "%EDK_TOOLS_BIN%\GenFv.exe" goto check_c_tools
262 IF NOT EXIST "%EDK_TOOLS_BIN%\GenFw.exe" goto check_c_tools
263 IF NOT EXIST "%EDK_TOOLS_BIN%\GenSec.exe" goto check_c_tools
264 IF NOT EXIST "%EDK_TOOLS_BIN%\Split.exe" goto check_c_tools
265 IF NOT EXIST "%EDK_TOOLS_BIN%\TianoCompress.exe" goto check_c_tools
266 IF NOT EXIST "%EDK_TOOLS_BIN%\VfrCompile.exe" goto check_c_tools
267 IF NOT EXIST "%EDK_TOOLS_BIN%\VolInfo.exe" goto check_c_tools
268
269 goto check_build_environment
270
271 :check_c_tools
272 echo.
273 echo !!! ERROR !!! Binary C tools are missing. They are required to be built from BaseTools Source.
274 echo.
275
276 :check_build_environment
277 set PYTHONHASHSEED=1
278
279 if not defined BASE_TOOLS_PATH (
280 if not exist "Source\C\Makefile" (
281 if not exist "%EDK_TOOLS_PATH%\Source\C\Makefile" goto no_source_files
282 set BASE_TOOLS_PATH=%EDK_TOOLS_PATH%
283 ) else (
284 set BASE_TOOLS_PATH=%CD%
285 )
286 )
287
288 :defined_python
289 if defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
290 goto check_python_available
291 )
292 if defined PYTHON3_ENABLE (
293 if "%PYTHON3_ENABLE%" EQU "TRUE" (
294 set PYTHON_COMMAND=py -3
295 goto check_python_available
296 ) else (
297 goto check_python2
298 )
299 )
300 if not defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
301 set PYTHON_COMMAND=py -3
302 py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
303 setlocal enabledelayedexpansion
304 set /p PythonCheck=<"PythonCheck.txt"
305 del PythonCheck.txt
306 if "!PythonCheck!" NEQ "TRUE" (
307 if not defined PYTHON_HOME if not defined PYTHONHOME (
308 endlocal
309 set PYTHON_COMMAND=
310 echo.
311 echo !!! ERROR !!! Binary python tools are missing.
312 echo PYTHON_COMMAND, PYTHON3_ENABLE or PYTHON_HOME
313 echo Environment variable is not set successfully.
314 echo They is required to build or execute the python tools.
315 echo.
316 goto end
317 ) else (
318 goto check_python2
319 )
320 ) else (
321 goto check_freezer_path
322 )
323 )
324
325 :check_python2
326 endlocal
327 if defined PYTHON_HOME (
328 if EXIST "%PYTHON_HOME%" (
329 set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
330 goto check_python_available
331 )
332 )
333 if defined PYTHONHOME (
334 if EXIST "%PYTHONHOME%" (
335 set PYTHON_HOME=%PYTHONHOME%
336 set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
337 goto check_python_available
338 )
339 )
340 echo.
341 echo !!! ERROR !!! PYTHON_HOME is not defined or The value of this variable does not exist
342 echo.
343 goto end
344 :check_python_available
345 %PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
346 setlocal enabledelayedexpansion
347 set /p PythonCheck=<"PythonCheck.txt"
348 del PythonCheck.txt
349 if "!PythonCheck!" NEQ "TRUE" (
350 echo.
351 echo ! ERROR ! "%PYTHON_COMMAND%" is not installed or added to environment variables
352 echo.
353 goto end
354 ) else (
355 goto check_freezer_path
356 )
357
358 :check_freezer_path
359 endlocal
360 if defined BASETOOLS_PYTHON_SOURCE goto print_python_info
361 set "PATH=%BASE_TOOLS_PATH%\BinWrappers\WindowsLike;%PATH%"
362 set BASETOOLS_PYTHON_SOURCE=%BASE_TOOLS_PATH%\Source\Python
363 set PYTHONPATH=%BASETOOLS_PYTHON_SOURCE%;%PYTHONPATH%
364
365 :print_python_info
366 echo PATH = %PATH%
367 if defined PYTHON3_ENABLE if "%PYTHON3_ENABLE%" EQU "TRUE" (
368 echo PYTHON3_ENABLE = %PYTHON3_ENABLE%
369 echo PYTHON3 = %PYTHON_COMMAND%
370 ) else (
371 echo PYTHON3_ENABLE = FALSE
372 echo PYTHON_COMMAND = %PYTHON_COMMAND%
373 )
374 echo PYTHONPATH = %PYTHONPATH%
375 echo.
376
377 :VisualStudioAvailable
378 if not defined FORCE_REBUILD (
379 if not defined REBUILD (
380 goto end
381 )
382 )
383 call "%EDK_TOOLS_PATH%\get_vsvars.bat"
384 if not defined VCINSTALLDIR (
385 @echo.
386 @echo !!! ERROR !!!! Cannot find Visual Studio, required to build C tools !!!
387 @echo.
388 goto end
389 )
390 if not defined FORCE_REBUILD goto IncrementalBuild
391
392 :CleanAndBuild
393 pushd .
394 cd %BASE_TOOLS_PATH%
395 call nmake cleanall
396 del /f /q %BASE_TOOLS_PATH%\Bin\Win32\*.*
397 popd
398 @REM Let CleanAndBuild fall through to IncrementalBuild
399
400
401 :IncrementalBuild
402 pushd .
403 cd %BASE_TOOLS_PATH%
404 call nmake c
405 popd
406 goto end
407
408
409 :no_source_files
410 echo.
411 echo !!! ERROR !!! Cannot build BaseTools applications - no source directory located !!!
412 echo.
413 goto end
414
415 :Usage
416 @echo.
417 echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [base_tools_path [edk_tools_path]]"
418 @echo.
419 @echo base_tools_path BaseTools project path, BASE_TOOLS_PATH will be set to this path.
420 @echo edk_tools_path EDK_TOOLS_PATH will be set to this path.
421 @echo Rebuild If sources are available perform an Incremental build, only
422 @echo build those updated tools.
423 @echo ForceRebuild If sources are available, rebuild all tools regardless of
424 @echo whether they have been updated or not.
425 @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt.
426 @echo.
427
428 :end
429 set REBUILD=
430 set FORCE_REBUILD=
431 set RECONFIG=
432 popd
433