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