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