ArmPkg: only attempt buildin MmCommunicationDxe for AArch64
[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 Over-writing 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 over-write ... 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 over-write ... 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%\Split.exe" goto check_c_tools
303 IF NOT EXIST "%EDK_TOOLS_BIN%\TianoCompress.exe" goto check_c_tools
304 IF NOT EXIST "%EDK_TOOLS_BIN%\VfrCompile.exe" goto check_c_tools
305 IF NOT EXIST "%EDK_TOOLS_BIN%\VolInfo.exe" goto check_c_tools
306
307 goto check_build_environment
308
309 :check_c_tools
310 echo.
311 echo !!! ERROR !!! Binary C tools are missing. They are required to be built from BaseTools Source.
312 echo.
313
314 :check_build_environment
315 set PYTHONHASHSEED=1
316
317 if not defined BASE_TOOLS_PATH (
318 if not exist "Source\C\Makefile" (
319 if not exist "%EDK_TOOLS_PATH%\Source\C\Makefile" goto no_source_files
320 set BASE_TOOLS_PATH=%EDK_TOOLS_PATH%
321 ) else (
322 set BASE_TOOLS_PATH=%CD%
323 )
324 )
325
326 :defined_python
327 if defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
328 goto check_python_available
329 )
330 if defined PYTHON3_ENABLE (
331 if "%PYTHON3_ENABLE%" EQU "TRUE" (
332 set PYTHON_COMMAND=py -3
333 goto check_python_available
334 ) else (
335 goto check_python2
336 )
337 )
338 if not defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
339 set PYTHON_COMMAND=py -3
340 py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
341 setlocal enabledelayedexpansion
342 set /p PythonCheck=<"PythonCheck.txt"
343 del PythonCheck.txt
344 if "!PythonCheck!" NEQ "TRUE" (
345 if not defined PYTHON_HOME if not defined PYTHONHOME (
346 endlocal
347 set PYTHON_COMMAND=
348 echo.
349 echo !!! ERROR !!! Binary python tools are missing.
350 echo PYTHON_COMMAND, PYTHON3_ENABLE or PYTHON_HOME
351 echo Environment variable is not set successfully.
352 echo They is required to build or execute the python tools.
353 echo.
354 goto end
355 ) else (
356 goto check_python2
357 )
358 ) else (
359 goto check_freezer_path
360 )
361 )
362
363 :check_python2
364 endlocal
365 if defined PYTHON_HOME (
366 if EXIST "%PYTHON_HOME%" (
367 set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
368 goto check_python_available
369 )
370 )
371 if defined PYTHONHOME (
372 if EXIST "%PYTHONHOME%" (
373 set PYTHON_HOME=%PYTHONHOME%
374 set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
375 goto check_python_available
376 )
377 )
378 echo.
379 echo !!! ERROR !!! PYTHON_HOME is not defined or The value of this variable does not exist
380 echo.
381 goto end
382 :check_python_available
383 %PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
384 setlocal enabledelayedexpansion
385 set /p PythonCheck=<"PythonCheck.txt"
386 del PythonCheck.txt
387 if "!PythonCheck!" NEQ "TRUE" (
388 echo.
389 echo ! ERROR ! "%PYTHON_COMMAND%" is not installed or added to environment variables
390 echo.
391 goto end
392 ) else (
393 goto check_freezer_path
394 )
395
396 :check_freezer_path
397 endlocal
398 if defined BASETOOLS_PYTHON_SOURCE goto print_python_info
399 set "PATH=%BASE_TOOLS_PATH%\BinWrappers\WindowsLike;%PATH%"
400 set BASETOOLS_PYTHON_SOURCE=%BASE_TOOLS_PATH%\Source\Python
401 set PYTHONPATH=%BASETOOLS_PYTHON_SOURCE%;%PYTHONPATH%
402
403 :print_python_info
404 echo PATH = %PATH%
405 if defined PYTHON3_ENABLE if "%PYTHON3_ENABLE%" EQU "TRUE" (
406 echo PYTHON3_ENABLE = %PYTHON3_ENABLE%
407 echo PYTHON3 = %PYTHON_COMMAND%
408 ) else (
409 echo PYTHON3_ENABLE = FALSE
410 echo PYTHON_COMMAND = %PYTHON_COMMAND%
411 )
412 echo PYTHONPATH = %PYTHONPATH%
413 echo.
414
415 :VisualStudioAvailable
416 if not defined FORCE_REBUILD (
417 if not defined REBUILD (
418 goto end
419 )
420 )
421
422 if not defined VCINSTALLDIR (
423 @echo.
424 @echo !!! ERROR !!!! Cannot find Visual Studio, required to build C tools !!!
425 @echo.
426 goto end
427 )
428 if not defined FORCE_REBUILD goto IncrementalBuild
429
430 :CleanAndBuild
431 pushd .
432 cd %BASE_TOOLS_PATH%
433 call nmake cleanall
434 del /f /q %BASE_TOOLS_PATH%\Bin\Win32\*.*
435 popd
436 @REM Let CleanAndBuild fall through to IncrementalBuild
437
438
439 :IncrementalBuild
440 pushd .
441 cd %BASE_TOOLS_PATH%
442 call nmake c
443 popd
444 goto end
445
446
447 :no_source_files
448 echo.
449 echo !!! ERROR !!! Cannot build BaseTools applications - no source directory located !!!
450 echo.
451 goto end
452
453 :Usage
454 @echo.
455 echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [base_tools_path [edk_tools_path]] [VS2019] [VS2017] [VS2015] [VS2013] [VS2012]"
456 @echo.
457 @echo base_tools_path BaseTools project path, BASE_TOOLS_PATH will be set to this path.
458 @echo edk_tools_path EDK_TOOLS_PATH will be set to this path.
459 @echo Rebuild If sources are available perform an Incremental build, only
460 @echo build those updated tools.
461 @echo ForceRebuild If sources are available, rebuild all tools regardless of
462 @echo whether they have been updated or not.
463 @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt.
464 @echo VS2012 Set the env for VS2012 build.
465 @echo VS2013 Set the env for VS2013 build.
466 @echo VS2015 Set the env for VS2015 build.
467 @echo VS2017 Set the env for VS2017 build.
468 @echo VS2019 Set the env for VS2019 build.
469 @echo.
470
471 :end
472 set REBUILD=
473 set FORCE_REBUILD=
474 set RECONFIG=
475 set VS2019=
476 set VS2017=
477 set VS2015=
478 set VS2013=
479 set VS2012=
480 set VSTool=
481 popd
482