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