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