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