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