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