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