]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/autogen/CommonDefinition.java
a99de4da4f4c0a0fbc58462457e190eea93b488f
[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 //
62 // The defintions for identifying current module
63 // is PEI Pcd driver or Dxe Pcd driver.
64 //
65 public static enum PCD_DRIVER_TYPE { NOT_PCD_DRIVER,
66 PEI_PCD_DRIVER,
67 DXE_PCD_DRIVER,
68 UNKNOWN_PCD_DRIVER};
69
70 //
71 // AutoGen.h and AutoGen.c file's header
72 //
73 public final static String autogenHNotation =
74 "/**\r\n" +
75 " DO NOT EDIT\r\n" +
76 " FILE auto-generated by GenBuild tasks\r\n" +
77 " Module name:\r\n" +
78 " AutoGen.h\r\n" +
79 " Abstract:" +
80 " Auto-generated AutoGen.h for building module or library.\r\n" +
81 "**/\r\n\r\n";
82
83 public final static String autogenCNotation =
84 "/**\r\n" +
85 " DO NOT EDIT\r\n" +
86 " FILE auto-generated by GenBuild tasks\r\n" +
87 " Module name:\r\n" +
88 " AutoGen.c\r\n" +
89 " Abstract:" +
90 " Auto-generated AutoGen.c for building module or library.\r\n" +
91 "**/\r\n\r\n";
92
93 //
94 // module type
95 //
96 public final static int ModuleTypeBase = 0;
97 public final static int ModuleTypeSec = 1;
98 public final static int ModuleTypePeiCore = 2;
99 public final static int ModuleTypePeim = 3;
100 public final static int ModuleTypeDxeCore = 4;
101 public final static int ModuleTypeDxeDriver = 5;
102 public final static int ModuleTypeDxeRuntimeDriver = 6;
103 public final static int ModuleTypeDxeSmmDriver = 7;
104 public final static int ModuleTypeDxeSalDriver = 8;
105 public final static int ModuleTypeUefiDriver = 9;
106 public final static int ModuleTypeUefiApplication = 10;
107 public final static int ModuleTypeUnknown = 11;
108
109
110 //
111 // component type
112 //
113 public final static int ComponentTypeNull = 0;
114 public final static int ComponentTypeApriori = 1;
115 public final static int ComponentTypeSec = 2;
116 public final static int ComponentTypeLibrary = 3;
117 public final static int ComponentTypeFvImageFile = 4;
118 public final static int ComponentTypeBsDriver = 5;
119 public final static int ComponentTypeRtDriver = 6;
120 public final static int ComponentTypeSalRtDriver =7;
121 public final static int ComponentTypePe32Peim = 8;
122 public final static int ComponentTypePicPeim =9;
123 public final static int ComponentTypeCombinedPeimDriver =10;
124 public final static int ComponentTypePeiCore = 11;
125 public final static int ComponentTypeDxeCore = 12;
126 public final static int ComponentTypeApplication = 13;
127 public final static int ComponentTypeBsDriverEfi = 14;
128 public final static int ComponentTypeShellApp = 15;
129 public final static int ComponentTypeBinary =16;
130 public final static int ComponentTypeLogo = 17;
131 public final static int ComponentTypeCustomBuild = 18;
132 public final static int ComponentTypeUnknown = 19;
133
134
135 //
136 // Usaged style
137 //
138 public final static String AlwaysConsumed = "ALWAYS_CONSUMED";
139 public final static String AlwaysProduced = "ALWAYS_PRODUCED";
140
141
142 public static class MyEnum {
143 String moduleTypeStr;
144 int type;
145
146 MyEnum (String str, int type) {
147 this.type = type;
148 this.moduleTypeStr = str;
149 }
150
151 int ForInt(String str) {
152 if (str.equals(this.moduleTypeStr)) {
153 return this.type;
154 } else
155 return -1;
156 }
157 }
158
159 //
160 // Module type
161 //
162 public static final MyEnum[] moduleEnum = new MyEnum[] {
163 new MyEnum("BASE", ModuleTypeBase),
164 new MyEnum("SEC", ModuleTypeSec),
165 new MyEnum("PEI_CORE", ModuleTypePeiCore),
166 new MyEnum("PEIM", ModuleTypePeim),
167 new MyEnum("DXE_CORE", ModuleTypeDxeCore),
168 new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),
169 new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),
170 new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),
171 new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),
172 new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),
173 new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication)};
174
175 //
176 // Component type
177 //
178 public static final MyEnum[] componentEnum = new MyEnum[]{
179 new MyEnum("APRIORI", ComponentTypeApriori),
180 new MyEnum("SEC", ComponentTypeSec),
181 new MyEnum("LIBRARY", ComponentTypeLibrary),
182 new MyEnum("FV_IMAGE_FILE", ComponentTypeFvImageFile),
183 new MyEnum("BS_DRIVER", ComponentTypeBsDriver),
184 new MyEnum("RT_DRIVER", ComponentTypeRtDriver),
185 new MyEnum("SAL_RT_DRIVER", ComponentTypeSalRtDriver),
186 new MyEnum("PE32_PEIM", ComponentTypePe32Peim),
187 new MyEnum("PIC_PEIM", ComponentTypePicPeim),
188 new MyEnum("COMBINED_PEIM_DRIVER", ComponentTypeCombinedPeimDriver),
189 new MyEnum("PEI_CORE", ComponentTypePeiCore),
190 new MyEnum("DXE_CORE", ComponentTypeDxeCore),
191 new MyEnum("APPLICATION", ComponentTypeApplication),
192 new MyEnum("BS_DRIVER_EFI", ComponentTypeBsDriverEfi),
193 new MyEnum("SHELLAPP", ComponentTypeShellApp),
194 new MyEnum("BINARY", ComponentTypeBinary),
195 new MyEnum("LOGO", ComponentTypeLogo),
196 new MyEnum("CUSTOM_BUILD", ComponentTypeCustomBuild)
197 };
198
199 /**
200 getModuleType
201
202 This function get the module type value according module type string.
203
204 @param moduleTypeStr String of modlue type.
205 @return
206 **/
207 static public int getModuleType(String moduleTypeStr) {
208 int returnValue = -1;
209 for (int i = 0; i < CommonDefinition.moduleEnum.length; i++) {
210 returnValue = CommonDefinition.moduleEnum[i].ForInt(moduleTypeStr);
211 if (returnValue != -1) {
212 return returnValue;
213 }
214 }
215 return CommonDefinition.ModuleTypeUnknown;
216 }
217
218 /**
219 getComponentType
220
221 This function get the component type value according commponet type
222 string.
223
224 @param componentTypeStr String of component type.
225 @return
226 **/
227 static public int getComponentType (String componentTypeStr){
228 int returnValue = -1;
229 for (int i = 0; i < CommonDefinition.componentEnum.length; i++) {
230 returnValue = CommonDefinition.componentEnum[i].ForInt(componentTypeStr);
231 if (returnValue != -1) {
232 return returnValue;
233 }
234 }
235 return CommonDefinition.ComponentTypeUnknown;
236 }
237
238 /**
239 getComponentTypeString
240
241 This function get the commponet type string according component type value.
242
243 @param componentType Integer value of component type.
244 @return
245 **/
246 static public String getComponentTypeString (int componentType) {
247 if ((componentType > CommonDefinition.ComponentTypeUnknown) ||
248 (componentType < CommonDefinition.ComponentTypeNull)) {
249 return null;
250 }
251 for (int index = 0; index < CommonDefinition.componentEnum.length; index ++) {
252 if (componentType == CommonDefinition.componentEnum[index].type) {
253 return CommonDefinition.componentEnum[index].moduleTypeStr;
254 }
255 }
256 return null;
257 }
258
259 /**
260 isLibraryComponent
261
262 This function is to check does componet is library according to commponet
263 type value.
264
265 @param componentType Integer value of component type.
266 @return
267 **/
268 static public boolean isLibraryComponent (int componentType) {
269 if (ComponentTypeLibrary == componentType) {
270 return true;
271 }
272 return false;
273 }
274
275 /**
276 * formateGuidName
277 *
278 * This function is to formate GUID to ANSI c form.
279 *
280 * @param guidNameCon
281 * String of GUID.
282 * @return Formated GUID.
283 */
284 public static String formatGuidName(String guidNameConv) {
285 String[] strList;
286 String guid = "";
287 int index = 0;
288 if (guidNameConv
289 .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}")) {
290 strList = guidNameConv.split("-");
291 guid = "0x" + strList[0] + ", ";
292 guid = guid + "0x" + strList[1] + ", ";
293 guid = guid + "0x" + strList[2] + ", ";
294 guid = guid + "{";
295 guid = guid + "0x" + strList[3].substring(0, 2) + ", ";
296 guid = guid + "0x" + strList[3].substring(2, 4);
297
298 while (index < strList[4].length()) {
299 guid = guid + ", ";
300 guid = guid + "0x" + strList[4].substring(index, index + 2);
301 index = index + 2;
302 }
303 guid = guid + "}";
304 return guid;
305 } else if (guidNameConv
306 .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}( )*(\\})?")) {
307 strList = guidNameConv.split(",");
308
309 //
310 // chang Microsoft specific form to ANSI c form
311 //
312 for (int i = 0; i < 3; i++) {
313 guid = guid + strList[i] + ",";
314 }
315 guid = guid + "{";
316
317 for (int i = 3; i < strList.length; i++) {
318 if (i == strList.length - 1) {
319 guid = guid + strList[i];
320 } else {
321 guid = guid + strList[i] + ",";
322 }
323 }
324 guid = guid + "}";
325 return guid;
326 } else {
327 System.out
328 .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");
329 return "0";
330
331 }
332 }
333
334 /**
335 * Remove deuplicat string in list
336 *
337 * This function is to duplicat string in list
338 *
339 * @param String[]
340 * String list.
341 * @return String[] String list which remove the duplicate string.
342 */
343 public static String[] remDupString (String[] orgList){
344 Set<String> strList = new LinkedHashSet<String>();
345 String[] desList ;
346 if (orgList == null) {
347 return new String[0];
348 }
349 for (int i = 0; i < orgList.length; i++) {
350 strList.add(orgList[i]);
351 }
352 desList = new String[strList.size()];
353 Iterator item = strList.iterator();
354 int index = 0;
355 while (item.hasNext()) {
356 desList[index] = (String)item.next();
357 index++;
358 }
359 return desList;
360 }
361
362 }