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