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