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