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