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