Vlv2TbltDevicePkg: Add /m flag for multi-processor build
[mirror_edk2.git] / Vlv2TbltDevicePkg / bld_vlv.bat
1 @REM @file
2 @REM Windows batch file to build BIOS ROM
3 @REM
4 @REM Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 @REM This program and the accompanying materials
6 @REM are licensed and made available under the terms and conditions of the BSD License
7 @REM which accompanies this distribution. The full text of the license may be found at
8 @REM http://opensource.org/licenses/bsd-license.php
9 @REM
10 @REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 @REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 @REM
13
14 @echo off
15 setlocal EnableDelayedExpansion EnableExtensions
16 echo.
17 echo %date% %time%
18 echo.
19
20 ::**********************************************************************
21 :: Initial Setup
22 ::**********************************************************************
23 set WORKSPACE=%CD%
24 if %WORKSPACE:~-1%==\ set WORKSPACE=%WORKSPACE:~0,-1%
25 set /a build_threads=1
26 set "Build_Flags= "
27 set exitCode=0
28 set Arch=X64
29 set Source=0
30
31 :: Clean up previous build files.
32 if exist %WORKSPACE%\%PLATFORM_PACKAGE%\EDK2_%PLATFORM_PACKAGE%.log del %WORKSPACE%\%PLATFORM_PACKAGE%\EDK2_%PLATFORM_PACKAGE%.log
33 if exist %WORKSPACE%\%PLATFORM_PACKAGE%\EDK2_%PLATFORM_PACKAGE%.report del %WORKSPACE%\%PLATFORM_PACKAGE%\EDK2_%PLATFORM_PACKAGE%.report
34 if exist %WORKSPACE%\unitool.log del %WORKSPACE%\unitool.log
35 if exist %WORKSPACE%\Conf\target.txt del %WORKSPACE%\Conf\target.txt
36 if exist %WORKSPACE%\Conf\tools_def.txt del %WORKSPACE%\Conf\tools_def.txt
37 if exist %WORKSPACE%\Conf\build_rule.txt del %WORKSPACE%\Conf\build_rule.txt
38 if exist %WORKSPACE%\Conf\FrameworkDatabase.db del %WORKSPACE%\Conf\FrameworkDatabase.db
39 if exist conf\.cache rmdir /q/s conf\.cache
40
41 :: Setup EDK environment. Edksetup puts new copies of target.txt, tools_def.txt, build_rule.txt in WorkSpace\Conf
42 :: Also run edksetup as soon as possible to avoid it from changing environment variables we're overriding
43 call edksetup.bat > nul
44 @echo off
45
46 :: Define platform specific environment variables.
47 set PLATFORM_PACKAGE=Vlv2TbltDevicePkg
48 set config_file=.\%PLATFORM_PACKAGE%\PlatformPkgConfig.dsc
49 set auto_config_inc=.\%PLATFORM_PACKAGE%\AutoPlatformCFG.txt
50
51 set EDK_SOURCE=%WORKSPACE%\EdkCompatibilityPkg
52
53 ::create new AutoPlatformCFG.txt file
54 copy /y nul %auto_config_inc% >nul
55
56 ::**********************************************************************
57 :: Parse command line arguments
58 ::**********************************************************************
59
60 :: Optional arguments
61 :OptLoop
62 if /i "%~1"=="/?" goto Usage
63
64 if /i "%~1"=="/l" (
65 set Build_Flags=%Build_Flags% -j %PLATFORM_PACKAGE%\EDK2_%PLATFORM_PACKAGE%.log
66 shift
67 goto OptLoop
68 )
69 if /i "%~1"=="/y" (
70 set Build_Flags=%Build_Flags% -y %PLATFORM_PACKAGE%\EDK2_%PLATFORM_PACKAGE%.report
71 shift
72 goto OptLoop
73 )
74 if /i "%~1"=="/m" (
75 if defined NUMBER_OF_PROCESSORS (
76 set /a build_threads=%NUMBER_OF_PROCESSORS%+1
77 )
78 shift
79 goto OptLoop
80 )
81 if /i "%~1" == "/c" (
82 echo Removing previous build files ...
83 if exist build (
84 del /f/s/q build > nul
85 rmdir /s/q build
86 )
87 if exist conf\.cache (
88 del /f/s/q conf\.cache > nul
89 rmdir /s/q conf\.cache
90 )
91 echo.
92 shift
93 goto OptLoop
94 )
95
96 if /i "%~1"=="/x64" (
97 set Arch=X64
98 shift
99 goto OptLoop
100 )
101 if /i "%~1"=="/IA32" (
102 set Arch=IA32
103 shift
104 goto OptLoop
105 )
106
107 :: Required argument(s)
108 if "%~1"=="" goto Usage
109
110 ::Remove the values for Platform_Type and Build_Target from BiosIdX.env and stage in Conf\
111 if "%Arch%"=="IA32" (
112 findstr /b /v "BOARD_ID BUILD_TYPE" %PLATFORM_PACKAGE%\BiosIdR.env > Conf\BiosId.env
113 echo DEFINE X64_CONFIG = FALSE >> %auto_config_inc%
114 ) else if "%Arch%"=="X64" (
115 findstr /b /v "BOARD_ID BUILD_TYPE" %PLATFORM_PACKAGE%\BiosIdx64R.env > Conf\BiosId.env
116 echo DEFINE X64_CONFIG = TRUE >> %auto_config_inc%
117 )
118
119 :: -- Build flags settings for each Platform --
120 echo Setting %1 platform configuration and BIOS ID...
121 if /i "%~1" == "MNW2" (
122 echo BOARD_ID = MNW2MAX >> %Conf\BiosId.env
123 echo DEFINE ENBDT_PF_BUILD = TRUE >> %auto_config_inc%
124
125 ) else (
126 echo Error - Unsupported PlatformType: %1
127 goto Usage
128 )
129 set Platform_Type=%~1
130
131 if /i "%~2" == "RELEASE" (
132 set target=RELEASE
133 echo BUILD_TYPE = R >> Conf\BiosId.env
134 ) else (
135 set target=DEBUG
136 echo BUILD_TYPE = D >> Conf\BiosId.env
137 )
138
139 ::**********************************************************************
140 :: Additional EDK Build Setup/Configuration
141 ::**********************************************************************
142 echo.
143 echo Setting the Build environment for VS2008/VS2010/VS2012/VS2013...
144 if defined VS90COMNTOOLS (
145 if not defined VSINSTALLDIR call "%VS90COMNTOOLS%\vsvars32.bat"
146 if /I "%VS90COMNTOOLS%" == "C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\" (
147 set TOOL_CHAIN_TAG=VS2008
148 ) else (
149 set TOOL_CHAIN_TAG=VS2008x86
150 )
151 ) else if defined VS100COMNTOOLS (
152 if not defined VSINSTALLDIR call "%VS100COMNTOOLS%\vsvars32.bat"
153 if /I "%VS100COMNTOOLS%" == "C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\" (
154 set TOOL_CHAIN_TAG=VS2010
155 ) else (
156 set TOOL_CHAIN_TAG=VS2010x86
157 )
158 ) else if defined VS110COMNTOOLS (
159 if not defined VSINSTALLDIR call "%VS110COMNTOOLS%\vsvars32.bat"
160 if /I "%VS110COMNTOOLS%" == "C:\Program Files\Microsoft Visual Studio 11.0\Common7\Tools\" (
161 set TOOL_CHAIN_TAG=VS2012
162 ) else (
163 set TOOL_CHAIN_TAG=VS2012x86
164 )
165 ) else if defined VS120COMNTOOLS (
166 if not defined VSINSTALLDIR call "%VS120COMNTOOLS%\vsvars32.bat"
167 if /I "%VS120COMNTOOLS%" == "C:\Program Files\Microsoft Visual Studio 12.0\Common7\Tools\" (
168 set TOOL_CHAIN_TAG=VS2013
169 ) else (
170 set TOOL_CHAIN_TAG=VS2013x86
171 )
172 ) else (
173 echo --ERROR: VS2008/VS2010/VS2012/VS2013 not installed correctly. VS90COMNTOOLS/VS100COMNTOOLS/VS110COMNTOOLS/VS120COMNTOOLS not defined ^^!
174 echo.
175 goto :BldFail
176 )
177
178 echo Ensuring correct build directory is present for GenBiosId...
179 set BUILD_PATH=Build\%PLATFORM_PACKAGE%\%TARGET%_%TOOL_CHAIN_TAG%
180
181 echo Modifing Conf files for this build...
182 :: Remove lines with these tags from target.txt
183 findstr /V "TARGET TARGET_ARCH TOOL_CHAIN_TAG BUILD_RULE_CONF ACTIVE_PLATFORM MAX_CONCURRENT_THREAD_NUMBER" Conf\target.txt > Conf\target.txt.tmp
184
185 echo TARGET = %TARGET% >> Conf\target.txt.tmp
186 if "%Arch%"=="IA32" (
187 echo TARGET_ARCH = IA32 >> Conf\target.txt.tmp
188 ) else if "%Arch%"=="X64" (
189 echo TARGET_ARCH = IA32 X64 >> Conf\target.txt.tmp
190 )
191 echo TOOL_CHAIN_TAG = %TOOL_CHAIN_TAG% >> Conf\target.txt.tmp
192 echo BUILD_RULE_CONF = Conf/build_rule.txt >> Conf\target.txt.tmp
193 if %Source% == 0 (
194 echo ACTIVE_PLATFORM = %PLATFORM_PACKAGE%/PlatformPkg%Arch%.dsc >> Conf\target.txt.tmp
195 ) else (
196 echo ACTIVE_PLATFORM = %PLATFORM_PACKAGE%/PlatformPkg%Arch%Source.dsc >> Conf\target.txt.tmp
197 )
198 echo MAX_CONCURRENT_THREAD_NUMBER = %build_threads% >> Conf\target.txt.tmp
199
200 move /Y Conf\target.txt.tmp Conf\target.txt >nul
201
202 ::**********************************************************************
203 :: Build BIOS
204 ::**********************************************************************
205
206 echo Creating BiosId...
207 pushd %PLATFORM_PACKAGE%
208 if not exist ..\%BUILD_PATH%\IA32 mkdir ..\%BUILD_PATH%\IA32
209 GenBiosId.exe -i ..\Conf\BiosId.env -o ..\%BUILD_PATH%\IA32\BiosId.bin -ob ..\Conf\BiosId.bat
210 if "%Arch%"=="X64" (
211 if not exist ..\%BUILD_PATH%\X64 mkdir ..\%BUILD_PATH%\X64
212 GenBiosId.exe -i ..\Conf\BiosId.env -o ..\%BUILD_PATH%\X64\BiosId.bin -ob ..\Conf\BiosId.bat
213 )
214 popd
215
216
217 if %ERRORLEVEL% NEQ 0 goto BldFail
218
219 echo.
220 echo Invoking EDK2 build...
221 call build %Build_Flags%
222
223 if %ERRORLEVEL% NEQ 0 goto BldFail
224
225 ::**********************************************************************
226 :: Post Build processing and cleanup
227 ::**********************************************************************
228
229 echo Running fce...
230
231 pushd %PLATFORM_PACKAGE%
232 :: Extract Hii data from build and store in HiiDefaultData.txt
233 fce read -i ..\%BUILD_PATH%\FV\Vlv.fd > ..\%BUILD_PATH%\FV\HiiDefaultData.txt
234
235 :: save changes to VlvXXX.fd
236 fce update -i ..\%BUILD_PATH%\FV\Vlv.fd -s ..\%BUILD_PATH%\FV\HiiDefaultData.txt -o ..\%BUILD_PATH%\FV\Vlv%Arch%.fd
237
238 popd
239
240 if %ERRORLEVEL% NEQ 0 goto BldFail
241 ::echo FD successfully updated with default Hii values.
242
243 :: Set the Board_Id, Build_Type, Version_Major, and Version_Minor environment variables
244 find /v "#" Conf\BiosId.env > ver_strings
245 for /f "tokens=1,3" %%i in (ver_strings) do set %%i=%%j
246 del /f/q ver_strings >nul
247
248 set BIOS_Name=%BOARD_ID%_%Arch%_%BUILD_TYPE%_%VERSION_MAJOR%_%VERSION_MINOR%.ROM
249 copy /y/b %BUILD_PATH%\FV\Vlv%Arch%.fd %WORKSPACE%\%BIOS_Name% >nul
250 copy /y/b %BUILD_PATH%\FV\Vlv%Arch%.fd %BUILD_PATH%\FV\Vlv.ROM >nul
251
252 echo.
253 echo Build location: %BUILD_PATH%
254 echo BIOS ROM Created: %BIOS_Name%
255 echo.
256 echo -------------------- The EDKII BIOS build has successfully completed. --------------------
257 echo.
258
259 @REM build capsule here
260 if "%openssl_path%" == "" goto Exit
261 echo > %BUILD_PATH%\FV\SYSTEMFIRMWAREUPDATECARGO.Fv
262 build -p %PLATFORM_PACKAGE%\PlatformCapsule.dsc
263
264 goto Exit
265
266 :Usage
267 echo.
268 echo ***************************************************************************
269 echo Build BIOS rom for VLV platforms.
270 echo.
271 echo Usage: bld_vlv.bat [options] PlatformType [Build Target]
272 echo.
273 echo /c CleanAll before building
274 echo /l Generate build log file
275 echo /y Generate build report file
276 echo /m Enable multi-processor build
277 echo /IA32 Set Arch to IA32 (default: X64)
278 echo /X64 Set Arch to X64 (default: X64)
279 echo.
280 echo Platform Types: MNW2
281 echo Build Targets: Debug, Release (default: Debug)
282 echo.
283 echo Examples:
284 echo bld_vlv.bat MNW2 : X64 Debug build for MinnowMax
285 echo bld_vlv.bat /IA32 MNW2 release : IA32 Release build for MinnowMax
286 echo.
287 echo ***************************************************************************
288 set exitCode=1
289 goto Exit
290
291 :BldFail
292 set exitCode=1
293 echo -- Error: EDKII BIOS Build has failed!
294 echo See EDK2.log for more details
295
296 :Exit
297 echo %date% %time%
298 exit /b %exitCode%
299
300 EndLocal