]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/toolsetup.bat
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 - 2019, Intel Corporation. All rights reserved.<BR>
7 @REM (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
8 @REM
9 @REM SPDX-License-Identifier: BSD-2-Clause-Patent
10 @REM
11
12 @echo off
13 pushd .
14 set SCRIPT_ERROR=0
15
16 @REM ##############################################################
17 @REM # You should not have to modify anything below this line
18 @REM #
19
20 if /I "%1"=="-h" goto Usage
21 if /I "%1"=="-help" goto Usage
22 if /I "%1"=="--help" goto Usage
23 if /I "%1"=="/h" goto Usage
24 if /I "%1"=="/help" goto Usage
25 if /I "%1"=="/?" goto Usage
26
27
28 :loop
29 if "%1"=="" goto setup_workspace
30 if /I "%1"=="Reconfig" (
31 shift
32 set RECONFIG=TRUE
33 goto loop
34 )
35 if /I "%1"=="Rebuild" (
36 shift
37 set REBUILD=TRUE
38 goto loop
39 )
40 if /I "%1"=="ForceRebuild" (
41 shift
42 set FORCE_REBUILD=TRUE
43 goto loop
44 )
45 if /I "%1"=="VS2019" (
46 shift
47 set VS2019=TRUE
48 set VSTool=VS2019
49 goto loop
50 )
51 if /I "%1"=="VS2017" (
52 shift
53 set VS2017=TRUE
54 set VSTool=VS2017
55 goto loop
56 )
57 if /I "%1"=="VS2015" (
58 shift
59 set VS2015=TRUE
60 set VSTool=VS2015
61 goto loop
62 )
63 if /I "%1"=="VS2013" (
64 shift
65 set VS2013=TRUE
66 set VSTool=VS2013
67 goto loop
68 )
69 if /I "%1"=="VS2012" (
70 shift
71 set VS2012=TRUE
72 set VSTool=VS2012
73 goto loop
74 )
75 if "%1"=="" goto setup_workspace
76 if exist %1 (
77 if not defined BASE_TOOLS_PATH (
78 if exist %1\Source set BASE_TOOLS_PATH=%1
79 shift
80 goto loop
81 )
82 if not defined EDK_TOOLS_PATH (
83 if exist %1\Bin\Win32 set EDK_TOOLS_PATH=%1
84 shift
85 goto loop
86 )
87 echo.
88 echo !!! ERROR !!! Unknown argument, %1 !!!
89 echo.
90 goto end
91 ) else (
92 echo.
93 echo !!! ERROR !!! Unknown argument, %1 !!!
94 echo.
95 goto end
96 )
97 goto loop
98
99
100 @REM
101 @REM Check the required system environment variables
102 @REM
103
104 :setup_workspace
105 REM
106 REM check the EDK_TOOLS_PATH
107 REM
108 if not defined EDK_TOOLS_PATH goto no_EDK_TOOLS_PATH
109 if exist %EDK_TOOLS_PATH% goto set_PATH
110
111 :no_EDK_TOOLS_PATH
112 if not defined WORKSPACE (
113 if defined BASE_TOOLS_PATH (
114 set EDK_TOOLS_PATH=%BASE_TOOLS_PATH%
115 goto set_PATH
116 ) else (
117 echo.
118 echo !!! ERROR !!! Neither BASE_TOOLS_PATH nor EDK_TOOLS_PATH are set. !!!
119 echo.
120 goto end
121 )
122 ) else (
123 if exist %WORKSPACE%\BaseTools\Bin (
124 set EDK_TOOLS_PATH=%WORKSPACE%\BaseTools
125 goto set_PATH
126 ) else (
127 echo.
128 echo !!! ERROR !!! No tools path available. Please set EDK_TOOLS_PATH !!!
129 echo.
130 goto end
131 )
132 )
133
134 :set_PATH
135 if defined WORKSPACE_TOOLS_PATH goto check_PATH
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 goto PATH_ok
149
150 :check_PATH
151 if "%EDK_TOOLS_PATH%"=="%WORKSPACE_TOOLS_PATH%" goto PATH_ok
152 if not defined EDK_TOOLS_BIN (
153 set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32
154 if not exist %EDK_TOOLS_PATH%\Bin\Win32 (
155 echo.
156 echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!!
157 echo Please check the directory %EDK_TOOLS_PATH%\Bin\Win32
158 echo Or configure EDK_TOOLS_BIN env to point Win32 directory.
159 echo.
160 )
161 )
162 set PATH=%EDK_TOOLS_BIN%;%PATH%
163 set WORKSPACE_TOOLS_PATH=%EDK_TOOLS_PATH%
164 echo Resetting the PATH variable to include the EDK_TOOLS_PATH for this session.
165
166 :PATH_ok
167 REM
168 REM copy *.template to %CONF_PATH%
169 REM
170 if not defined WORKSPACE (
171 if defined RECONFIG (
172 echo.
173 echo !!! WARNING !!! WORKSPACE environment variable was not set, cannot Reconfig !!!
174 echo.
175 )
176 goto skip_reconfig
177 )
178
179 IF NOT exist "%EDK_TOOLS_PATH%\set_vsprefix_envs.bat" (
180 @echo.
181 @echo !!! ERROR !!! The set_vsprefix_envs.bat was not found !!!
182 @echo.
183 goto end
184 )
185 if defined VS2019 (
186 call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2019
187 ) else if defined VS2017 (
188 call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2017
189 ) else if defined VS2015 (
190 call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2015
191 call %EDK_TOOLS_PATH%\get_vsvars.bat VS2015
192 ) else if defined VS2013 (
193 call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2013
194 call %EDK_TOOLS_PATH%\get_vsvars.bat VS2013
195 ) else if defined VS2012 (
196 call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2012
197 call %EDK_TOOLS_PATH%\get_vsvars.bat VS2012
198 ) else (
199 call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat
200 call %EDK_TOOLS_PATH%\get_vsvars.bat
201 )
202 if %SCRIPT_ERROR% NEQ 0 (
203 @echo.
204 @echo !!! ERROR !!! %VSTool% is not installed !!!
205 @echo.
206 goto end
207 )
208
209 if not defined CONF_PATH (
210 set CONF_PATH=%WORKSPACE%\Conf
211 )
212
213 if NOT exist %CONF_PATH% (
214 if defined PACKAGES_PATH (
215 for %%i IN (%PACKAGES_PATH%) DO (
216 if exist %%~fi\Conf (
217 set CONF_PATH=%%i\Conf
218 goto CopyConf
219 )
220 )
221 )
222 )
223
224 :CopyConf
225 if NOT exist %CONF_PATH% (
226 mkdir %CONF_PATH%
227 ) else (
228 if defined RECONFIG (
229 echo.
230 echo Overwriting the files in the CONF_PATH directory
231 echo using the default template files
232 echo.
233 )
234 )
235
236 if NOT exist %CONF_PATH%\target.txt (
237 echo copying ... target.template to %CONF_PATH%\target.txt
238 if NOT exist %EDK_TOOLS_PATH%\Conf\target.template (
239 echo Error: target.template is missing at folder %EDK_TOOLS_PATH%\Conf\
240 )
241 copy %EDK_TOOLS_PATH%\Conf\target.template %CONF_PATH%\target.txt > nul
242 ) else (
243 if defined RECONFIG echo overwrite ... target.template to %CONF_PATH%\target.txt
244 if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\target.template %CONF_PATH%\target.txt > nul
245 )
246
247 if NOT exist %CONF_PATH%\tools_def.txt (
248 echo copying ... tools_def.template to %CONF_PATH%\tools_def.txt
249 if NOT exist %EDK_TOOLS_PATH%\Conf\tools_def.template (
250 echo Error: tools_def.template is missing at folder %EDK_TOOLS_PATH%\Conf\
251 )
252 copy %EDK_TOOLS_PATH%\Conf\tools_def.template %CONF_PATH%\tools_def.txt > nul
253 ) else (
254 if defined RECONFIG echo overwrite ... tools_def.template to %CONF_PATH%\tools_def.txt
255 if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\tools_def.template %CONF_PATH%\tools_def.txt > nul
256 )
257
258 if NOT exist %CONF_PATH%\build_rule.txt (
259 echo copying ... build_rule.template to %CONF_PATH%\build_rule.txt
260 if NOT exist %EDK_TOOLS_PATH%\Conf\build_rule.template (
261 echo Error: build_rule.template is missing at folder %EDK_TOOLS_PATH%\Conf\
262 )
263 copy %EDK_TOOLS_PATH%\Conf\build_rule.template %CONF_PATH%\build_rule.txt > nul
264 ) else (
265 if defined RECONFIG echo over-write ... build_rule.template to %CONF_PATH%\build_rule.txt
266 if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\build_rule.template %CONF_PATH%\build_rule.txt > nul
267 )
268
269 echo PATH = %PATH%
270 echo.
271 if defined WORKSPACE (
272 echo WORKSPACE = %WORKSPACE%
273 )
274 if defined PACKAGES_PATH (
275 echo PACKAGES_PATH = %PACKAGES_PATH%
276 )
277 echo EDK_TOOLS_PATH = %EDK_TOOLS_PATH%
278 if defined BASE_TOOLS_PATH (
279 echo BASE_TOOLS_PATH = %BASE_TOOLS_PATH%
280 )
281 if defined EDK_TOOLS_BIN (
282 echo EDK_TOOLS_BIN = %EDK_TOOLS_BIN%
283 )
284 echo CONF_PATH = %CONF_PATH%
285 echo.
286
287 :skip_reconfig
288
289 @REM
290 @REM Test if we are going to have to do a build
291 @REM
292 if defined FORCE_REBUILD goto check_build_environment
293 if defined REBUILD goto check_build_environment
294 if not exist "%EDK_TOOLS_PATH%" goto check_build_environment
295 if not exist "%EDK_TOOLS_BIN%" goto check_build_environment
296
297 IF NOT EXIST "%EDK_TOOLS_BIN%\EfiRom.exe" goto check_c_tools
298 IF NOT EXIST "%EDK_TOOLS_BIN%\GenFfs.exe" goto check_c_tools
299 IF NOT EXIST "%EDK_TOOLS_BIN%\GenFv.exe" goto check_c_tools
300 IF NOT EXIST "%EDK_TOOLS_BIN%\GenFw.exe" goto check_c_tools
301 IF NOT EXIST "%EDK_TOOLS_BIN%\GenSec.exe" goto check_c_tools
302 IF NOT EXIST "%EDK_TOOLS_BIN%\TianoCompress.exe" goto check_c_tools
303 IF NOT EXIST "%EDK_TOOLS_BIN%\VfrCompile.exe" goto check_c_tools
304 IF NOT EXIST "%EDK_TOOLS_BIN%\VolInfo.exe" goto check_c_tools
305
306 goto check_build_environment
307
308 :check_c_tools
309 echo.
310 echo !!! ERROR !!! Binary C tools are missing. They are required to be built from BaseTools Source.
311 echo.
312
313 :check_build_environment
314 set PYTHONHASHSEED=1
315
316 if not defined BASE_TOOLS_PATH (
317 if not exist "Source\C\Makefile" (
318 if not exist "%EDK_TOOLS_PATH%\Source\C\Makefile" goto no_source_files
319 set BASE_TOOLS_PATH=%EDK_TOOLS_PATH%
320 ) else (
321 set BASE_TOOLS_PATH=%CD%
322 )
323 )
324
325 :defined_python
326 if defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
327 goto check_python_available
328 )
329 if defined PYTHON3_ENABLE (
330 if "%PYTHON3_ENABLE%" EQU "TRUE" (
331 set PYTHON_COMMAND=py -3
332 goto check_python_available
333 ) else (
334 goto check_python2
335 )
336 )
337 if not defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
338 set PYTHON_COMMAND=py -3
339 py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
340 setlocal enabledelayedexpansion
341 set /p PythonCheck=<"PythonCheck.txt"
342 del PythonCheck.txt
343 if "!PythonCheck!" NEQ "TRUE" (
344 if not defined PYTHON_HOME if not defined PYTHONHOME (
345 endlocal
346 set PYTHON_COMMAND=
347 echo.
348 echo !!! ERROR !!! Binary python tools are missing.
349 echo PYTHON_COMMAND, PYTHON3_ENABLE or PYTHON_HOME
350 echo Environment variable is not set successfully.
351 echo They is required to build or execute the python tools.
352 echo.
353 goto end
354 ) else (
355 goto check_python2
356 )
357 ) else (
358 goto check_freezer_path
359 )
360 )
361
362 :check_python2
363 endlocal
364 if defined PYTHON_HOME (
365 if EXIST "%PYTHON_HOME%" (
366 set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
367 goto check_python_available
368 )
369 )
370 if defined PYTHONHOME (
371 if EXIST "%PYTHONHOME%" (
372 set PYTHON_HOME=%PYTHONHOME%
373 set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
374 goto check_python_available
375 )
376 )
377 echo.
378 echo !!! ERROR !!! PYTHON_HOME is not defined or The value of this variable does not exist
379 echo.
380 goto end
381 :check_python_available
382 %PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
383 setlocal enabledelayedexpansion
384 set /p PythonCheck=<"PythonCheck.txt"
385 del PythonCheck.txt
386 if "!PythonCheck!" NEQ "TRUE" (
387 echo.
388 echo ! ERROR ! "%PYTHON_COMMAND%" is not installed or added to environment variables
389 echo.
390 goto end
391 ) else (
392 goto check_freezer_path
393 )
394
395
396
397 :check_freezer_path
398 endlocal
399
400 %PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL
401 if %ERRORLEVEL% EQU 0 (
402 goto use_pip_basetools
403 ) else (
404 REM reset ERRORLEVEL
405 type nul>nul
406 goto use_builtin_basetools
407 )
408
409 :use_builtin_basetools
410 @echo Using EDK2 in-source Basetools
411 if defined BASETOOLS_PYTHON_SOURCE goto print_python_info
412 set "PATH=%BASE_TOOLS_PATH%\BinWrappers\WindowsLike;%PATH%"
413 set BASETOOLS_PYTHON_SOURCE=%BASE_TOOLS_PATH%\Source\Python
414 set PYTHONPATH=%BASETOOLS_PYTHON_SOURCE%;%PYTHONPATH%
415 goto print_python_info
416
417 :use_pip_basetools
418 @echo Using Pip Basetools
419 set "PATH=%BASE_TOOLS_PATH%\BinPipWrappers\WindowsLike;%PATH%"
420 set BASETOOLS_PYTHON_SOURCE=edk2basetools
421 goto print_python_info
422
423 :print_python_info
424 echo PATH = %PATH%
425 if defined PYTHON3_ENABLE if "%PYTHON3_ENABLE%" EQU "TRUE" (
426 echo PYTHON3_ENABLE = %PYTHON3_ENABLE%
427 echo PYTHON3 = %PYTHON_COMMAND%
428 ) else (
429 echo PYTHON3_ENABLE = FALSE
430 echo PYTHON_COMMAND = %PYTHON_COMMAND%
431 )
432 echo PYTHONPATH = %PYTHONPATH%
433 echo.
434
435 :VisualStudioAvailable
436 if not defined FORCE_REBUILD (
437 if not defined REBUILD (
438 goto end
439 )
440 )
441
442 if not defined VCINSTALLDIR (
443 @echo.
444 @echo !!! ERROR !!!! Cannot find Visual Studio, required to build C tools !!!
445 @echo.
446 goto end
447 )
448 if not defined FORCE_REBUILD goto IncrementalBuild
449
450 :CleanAndBuild
451 pushd .
452 cd %BASE_TOOLS_PATH%
453 call nmake cleanall
454 del /f /q %BASE_TOOLS_PATH%\Bin\Win32\*.*
455 popd
456 @REM Let CleanAndBuild fall through to IncrementalBuild
457
458
459 :IncrementalBuild
460 pushd .
461 cd %BASE_TOOLS_PATH%
462 call nmake c
463 popd
464 goto end
465
466
467 :no_source_files
468 echo.
469 echo !!! ERROR !!! Cannot build BaseTools applications - no source directory located !!!
470 echo.
471 goto end
472
473 :Usage
474 @echo.
475 echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [base_tools_path [edk_tools_path]] [VS2019] [VS2017] [VS2015] [VS2013] [VS2012]"
476 @echo.
477 @echo base_tools_path BaseTools project path, BASE_TOOLS_PATH will be set to this path.
478 @echo edk_tools_path EDK_TOOLS_PATH will be set to this path.
479 @echo Rebuild If sources are available perform an Incremental build, only
480 @echo build those updated tools.
481 @echo ForceRebuild If sources are available, rebuild all tools regardless of
482 @echo whether they have been updated or not.
483 @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt.
484 @echo VS2012 Set the env for VS2012 build.
485 @echo VS2013 Set the env for VS2013 build.
486 @echo VS2015 Set the env for VS2015 build.
487 @echo VS2017 Set the env for VS2017 build.
488 @echo VS2019 Set the env for VS2019 build.
489 @echo.
490
491 :end
492 set REBUILD=
493 set FORCE_REBUILD=
494 set RECONFIG=
495 set VS2019=
496 set VS2017=
497 set VS2015=
498 set VS2013=
499 set VS2012=
500 set VSTool=
501 popd
502