]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/autogen/CommonDefinition.java
244f2550b558009b7a01d53cc1af3608f317335a
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / CommonDefinition.java
1 /** @file
2 CommonDefinition class.
3
4 This class is to define some common marcos and funcions, which used by AutoGen.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16 package org.tianocore.build.autogen;
17
18 import java.util.Iterator;
19 import java.util.LinkedHashSet;
20 import java.util.Set;
21
22 /**
23 CommonDefinition
24
25 This class is to define some common marcos, which used by AutoGen.
26
27 **/
28 public class CommonDefinition {
29 public final static String spdSuffix = ".spd";
30 public final static String mbdSuffix = ".mbd";
31 public final static String msaSuffix = ".msa";
32 public final static String LibraryStr = "LIBRARY";
33 public final static String autoGenHbegin = "extern int __make_me_compile_correctly;\r\n";
34 public final static String include = "#include";
35 public final static String autoGenCLine1 = "\r\n";
36
37 public final static String autoGenCLine2 = "const UINT8 _gDebugPropertyMask "
38 + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"
39 + " | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"
40 + " | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;\r\n";
41
42 public final static String autoGenCLine3 = "const UINTN _gModuleDefaultErrorLevel"
43 + " = EFI_D_ERROR | EFI_D_LOAD;\r\n";
44
45 public final static String autoGenHLine1 = "#define EFI_SPECIFICATION_VERSION 0x00020000\r\n";
46 public final static String autoGenHVersionDefault = "#define EFI_SPECIFICATION_VERSION 0x00000000\r\n";
47 public final static String autoGenHLine2 = "#define EDK_RELEASE_VERSION 0x00090000\r\n";
48 public final static String autoGenHReleaseDefault = "#define EDK_RELEASE_VERSION 0x00000000\r\n";
49
50 public final static String includeAutogenH = "#include <AutoGen.h>\r\n" ;
51 public final static String marcDefineStr = "#define ";
52
53 public final static String gEfi = "gEfi";
54 public final static String protocolGuid = "ProtocolGuid";
55 public final static String ppiGuid = "PpiGuid";
56 public final static String guidGuid = "Guid";
57
58 public final static String tianoR8FlashMapH = "TianoR8FlashMap.h";
59 public final static String flashMapH = "FlashMap.h";
60
61 public final static String pcdLibName = "PcdLib";
62
63 //
64 // The defintions for identifying current module
65 // is PEI Pcd driver or Dxe Pcd driver.
66 //
67 public static enum PCD_DRIVER_TYPE { NOT_PCD_DRIVER,
68 PEI_PCD_DRIVER,
69 DXE_PCD_DRIVER,
70 UNKNOWN_PCD_DRIVER};
71
72 //
73 // AutoGen.h and AutoGen.c file's header
74 //
75 public final static String autogenHNotation =
76 "/**\r\n" +
77 " DO NOT EDIT\r\n" +
78 " FILE auto-generated by GenBuild tasks\r\n" +
79 " Module name:\r\n" +
80 " AutoGen.h\r\n" +
81 " Abstract:" +
82 " Auto-generated AutoGen.h for building module or library.\r\n" +
83 "**/\r\n\r\n";
84
85 public final static String autogenCNotation =
86 "/**\r\n" +
87 " DO NOT EDIT\r\n" +
88 " FILE auto-generated by GenBuild tasks\r\n" +
89 " Module name:\r\n" +
90 " AutoGen.c\r\n" +
91 " Abstract:" +
92 " Auto-generated AutoGen.c for building module or library.\r\n" +
93 "**/\r\n\r\n";
94
95 //
96 // module type
97 //
98 public final static int ModuleTypeBase = 0;
99 public final static int ModuleTypeSec = 1;
100 public final static int ModuleTypePeiCore = 2;
101 public final static int ModuleTypePeim = 3;
102 public final static int ModuleTypeDxeCore = 4;
103 public final static int ModuleTypeDxeDriver = 5;
104 public final static int ModuleTypeDxeRuntimeDriver = 6;
105 public final static int ModuleTypeDxeSmmDriver = 7;
106 public final static int ModuleTypeDxeSalDriver = 8;
107 public final static int ModuleTypeUefiDriver = 9;
108 public final static int ModuleTypeUefiApplication = 10;
109 public final static int ModuleTypeUnknown = 11;
110
111
112 //
113 // component type
114 //
115 public final static int ComponentTypeNull = 0;
116 public final static int ComponentTypeApriori = 1;
117 public final static int ComponentTypeSec = 2;
118 public final static int ComponentTypeLibrary = 3;
119 public final static int ComponentTypeFvImageFile = 4;
120 public final static int ComponentTypeBsDriver = 5;
121 public final static int ComponentTypeRtDriver = 6;
122 public final static int ComponentTypeSalRtDriver =7;
123 public final static int ComponentTypePe32Peim = 8;
124 public final static int ComponentTypePicPeim =9;
125 public final static int ComponentTypeCombinedPeimDriver =10;
126 public final static int ComponentTypePeiCore = 11;
127 public final static int ComponentTypeDxeCore = 12;
128 public final static int ComponentTypeApplication = 13;
129 public final static int ComponentTypeBsDriverEfi = 14;
130 public final static int ComponentTypeShellApp = 15;
131 public final static int ComponentTypeBinary =16;
132 public final static int ComponentTypeLogo = 17;
133 public final static int ComponentTypeCustomBuild = 18;
134 public final static int ComponentTypeUnknown = 19;
135
136
137 //
138 // Usaged style
139 //
140 public final static String AlwaysConsumed = "ALWAYS_CONSUMED";
141 public final static String AlwaysProduced = "ALWAYS_PRODUCED";
142
143
144 public static class MyEnum {
145 String moduleTypeStr;
146 int type;
147
148 MyEnum (String str, int type) {
149 this.type = type;
150 this.moduleTypeStr = str;
151 }
152
153 int ForInt(String str) {
154 if (str.equals(this.moduleTypeStr)) {
155 return this.type;
156 } else
157 return -1;
158 }
159 }
160
161 //
162 // Module type
163 //
164 public static final MyEnum[] moduleEnum = new MyEnum[] {
165 new MyEnum("BASE", ModuleTypeBase),
166 new MyEnum("SEC", ModuleTypeSec),
167 new MyEnum("PEI_CORE", ModuleTypePeiCore),
168 new MyEnum("PEIM", ModuleTypePeim),
169 new MyEnum("DXE_CORE", ModuleTypeDxeCore),
170 new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),
171 new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),
172 new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),
173 new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),
174 new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),
175 new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication)};
176
177 //
178 // Component type
179 //
180 public static final MyEnum[] componentEnum = new MyEnum[]{
181 new MyEnum("APRIORI", ComponentTypeApriori),
182 new MyEnum("SEC", ComponentTypeSec),
183 new MyEnum("LIBRARY", ComponentTypeLibrary),
184 new MyEnum("FV_IMAGE_FILE", ComponentTypeFvImageFile),
185 new MyEnum("BS_DRIVER", ComponentTypeBsDriver),
186 new MyEnum("RT_DRIVER", ComponentTypeRtDriver),
187 new MyEnum("SAL_RT_DRIVER", ComponentTypeSalRtDriver),
188 new MyEnum("PE32_PEIM", ComponentTypePe32Peim),
189 new MyEnum("PIC_PEIM", ComponentTypePicPeim),
190 new MyEnum("COMBINED_PEIM_DRIVER", ComponentTypeCombinedPeimDriver),
191 new MyEnum("PEI_CORE", ComponentTypePeiCore),
192 new MyEnum("DXE_CORE", ComponentTypeDxeCore),
193 new MyEnum("APPLICATION", ComponentTypeApplication),
194 new MyEnum("BS_DRIVER_EFI", ComponentTypeBsDriverEfi),
195 new MyEnum("SHELLAPP", ComponentTypeShellApp),
196 new MyEnum("BINARY", ComponentTypeBinary),
197 new MyEnum("LOGO", ComponentTypeLogo),
198 new MyEnum("CUSTOM_BUILD", ComponentTypeCustomBuild)
199 };
200
201 /**
202 getModuleType
203
204 This function get the module type value according module type string.
205
206 @param moduleTypeStr String of modlue type.
207 @return
208 **/
209 static public int getModuleType(String moduleTypeStr) {
210 int returnValue = -1;
211 for (int i = 0; i < CommonDefinition.moduleEnum.length; i++) {
212 returnValue = CommonDefinition.moduleEnum[i].ForInt(moduleTypeStr);
213 if (returnValue != -1) {
214 return returnValue;
215 }
216 }
217 return CommonDefinition.ModuleTypeUnknown;
218 }
219
220 /**
221 getComponentType
222
223 This function get the component type value according commponet type
224 string.
225
226 @param componentTypeStr String of component type.
227 @return
228 **/
229 static public int getComponentType (String componentTypeStr){
230 int returnValue = -1;
231 for (int i = 0; i < CommonDefinition.componentEnum.length; i++) {
232 returnValue = CommonDefinition.componentEnum[i].ForInt(componentTypeStr);
233 if (returnValue != -1) {
234 return returnValue;
235 }
236 }
237 return CommonDefinition.ComponentTypeUnknown;
238 }
239
240 /**
241 getComponentTypeString
242
243 This function get the commponet type string according component type value.
244
245 @param componentType Integer value of component type.
246 @return
247 **/
248 static public String getComponentTypeString (int componentType) {
249 if ((componentType > CommonDefinition.ComponentTypeUnknown) ||
250 (componentType < CommonDefinition.ComponentTypeNull)) {
251 return null;
252 }
253 for (int index = 0; index < CommonDefinition.componentEnum.length; index ++) {
254 if (componentType == CommonDefinition.componentEnum[index].type) {
255 return CommonDefinition.componentEnum[index].moduleTypeStr;
256 }
257 }
258 return null;
259 }
260
261 /**
262 isLibraryComponent
263
264 This function is to check does componet is library according to commponet
265 type value.
266
267 @param componentType Integer value of component type.
268 @return
269 **/
270 static public boolean isLibraryComponent (int componentType) {
271 if (ComponentTypeLibrary == componentType) {
272 return true;
273 }
274 return false;
275 }
276
277 /**
278 * formateGuidName
279 *
280 * This function is to formate GUID to ANSI c form.
281 *
282 * @param guidNameCon
283 * String of GUID.
284 * @return Formated GUID.
285 */
286 public static String formatGuidName(String guidNameConv) {
287 String[] strList;
288 String guid = "";
289 int index = 0;
290 if (guidNameConv
291 .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {
292 strList = guidNameConv.split("-");
293 guid = "0x" + strList[0] + ", ";
294 guid = guid + "0x" + strList[1] + ", ";
295 guid = guid + "0x" + strList[2] + ", ";
296 guid = guid + "{";
297 guid = guid + "0x" + strList[3].substring(0, 2) + ", ";
298 guid = guid + "0x" + strList[3].substring(2, 4);
299
300 while (index < strList[4].length()) {
301 guid = guid + ", ";
302 guid = guid + "0x" + strList[4].substring(index, index + 2);
303 index = index + 2;
304 }
305 guid = guid + "}";
306 return guid;
307 } else if (guidNameConv
308 .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {
309 strList = guidNameConv.split(",");
310
311 //
312 // chang Microsoft specific form to ANSI c form
313 //
314 for (int i = 0; i < 3; i++) {
315 guid = guid + strList[i] + ",";
316 }
317 guid = guid + "{";
318
319 for (int i = 3; i < strList.length; i++) {
320 if (i == strList.length - 1) {
321 guid = guid + strList[i];
322 } else {
323 guid = guid + strList[i] + ",";
324 }
325 }
326 guid = guid + "}";
327 return guid;
328 } else {
329 System.out
330 .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");
331 return "0";
332
333 }
334 }
335
336 /**
337 * Remove deuplicat string in list
338 *
339 * This function is to duplicat string in list
340 *
341 * @param String[]
342 * String list.
343 * @return String[] String list which remove the duplicate string.
344 */
345 public static String[] remDupString (String[] orgList){
346 Set<String> strList = new LinkedHashSet<String>();
347 String[] desList ;
348 if (orgList == null) {
349 return new String[0];
350 }
351 for (int i = 0; i < orgList.length; i++) {
352 strList.add(orgList[i]);
353 }
354 desList = new String[strList.size()];
355 Iterator item = strList.iterator();
356 int index = 0;
357 while (item.hasNext()) {
358 desList[index] = (String)item.next();
359 index++;
360 }
361 return desList;
362 }
363
364 }