2 CommonDefinition class.
4 This class is to define some common marcos and funcions, which used by AutoGen.
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
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.
16 package org
.tianocore
.build
.autogen
;
18 import java
.util
.Iterator
;
19 import java
.util
.LinkedHashSet
;
21 import org
.tianocore
.common
.definitions
.EdkDefinitions
;
22 import org
.tianocore
.common
.definitions
.ToolDefinitions
;
26 This class is to define some common marcos, which used by AutoGen.
29 public class CommonDefinition
{
32 /// final static string
34 public final static String LIBRARY
= "LIBRARY";
36 public final static String AUTOGENHBEGIN
= "extern int __make_me_compile_correctly;"
37 + ToolDefinitions
.LINE_SEPARATOR
;
39 public final static String INCLUDE
= "#include";
41 //public final static String DEBUGPROPERYMASK = "const UINT8 _gDebugPropertyMask "
42 // + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"
43 // + " | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"
44 // + " | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;"
45 // + ToolDefinitions.LINE_SEPARATOR;
47 //public final static String DEFAULERROLEVEL = "const UINTN _gModuleDefaultErrorLevel"
48 // + " = EFI_D_ERROR | EFI_D_LOAD;"
49 // + ToolDefinitions.LINE_SEPARATOR;
52 public final static String INCLUDEAUTOGENH
= INCLUDE
54 + ToolDefinitions
.LINE_SEPARATOR
;
56 public final static String DEFINE
= "#define ";
58 public final static String GEFI
= "gEfi";
60 public final static String PRTOCOLGUID
= "ProtocolGuid";
62 public final static String PPIGUID
= "PpiGuid";
64 public final static String GUID
= "Guid";
66 public final static String TIANOR8PLASHMAPH
= "TianoR8FlashMap.h";
68 public final static String FLASHMAPH
= "FlashMap.h";
70 public final static String IFNDEF
= "#ifndef ";
72 public final static String AUTOGENH
= "_AUTOGENH_";
76 /// AutoGen.h and AutoGen.c file's header
78 public final static String AUTOGENHNOTATION
= "/**"
79 + ToolDefinitions
.LINE_SEPARATOR
81 + ToolDefinitions
.LINE_SEPARATOR
82 + " FILE auto-generated by GenBuild tasks"
83 + ToolDefinitions
.LINE_SEPARATOR
85 + ToolDefinitions
.LINE_SEPARATOR
87 + ToolDefinitions
.LINE_SEPARATOR
89 + " Auto-generated AutoGen.h for building module or library."
90 + ToolDefinitions
.LINE_SEPARATOR
92 + ToolDefinitions
.LINE_SEPARATOR
93 + ToolDefinitions
.LINE_SEPARATOR
;
95 public final static String AUTOGENCNOTATION
= "/**"
96 + ToolDefinitions
.LINE_SEPARATOR
98 + ToolDefinitions
.LINE_SEPARATOR
99 + " FILE auto-generated by GenBuild tasks"
100 + ToolDefinitions
.LINE_SEPARATOR
102 + ToolDefinitions
.LINE_SEPARATOR
104 + ToolDefinitions
.LINE_SEPARATOR
106 + " Auto-generated AutoGen.c for building module or library."
107 + ToolDefinitions
.LINE_SEPARATOR
109 + ToolDefinitions
.LINE_SEPARATOR
110 + ToolDefinitions
.LINE_SEPARATOR
;
113 /// The defintions for identifying current module
114 /// is PEI Pcd driver or Dxe Pcd driver.
116 public static enum PCD_DRIVER_TYPE
{ NOT_PCD_DRIVER
,
126 public final static int ModuleTypeBase
= 0;
127 public final static int ModuleTypeSec
= 1;
128 public final static int ModuleTypePeiCore
= 2;
129 public final static int ModuleTypePeim
= 3;
130 public final static int ModuleTypeDxeCore
= 4;
131 public final static int ModuleTypeDxeDriver
= 5;
132 public final static int ModuleTypeDxeRuntimeDriver
= 6;
133 public final static int ModuleTypeDxeSmmDriver
= 7;
134 public final static int ModuleTypeDxeSalDriver
= 8;
135 public final static int ModuleTypeUefiDriver
= 9;
136 public final static int ModuleTypeUefiApplication
= 10;
137 public final static int ModuleTypeUnknown
= 11;
142 public final static String ALWAYSCONSUMED
= "ALWAYS_CONSUMED";
143 public final static String ALWAYSPRODUCED
= "ALWAYS_PRODUCED";
146 public static class MyEnum
{
147 String moduleTypeStr
;
150 MyEnum (String str
, int type
) {
152 this.moduleTypeStr
= str
;
155 int ForInt(String str
) {
156 if (str
.equals(this.moduleTypeStr
)) {
166 public static final MyEnum
[] moduleEnum
= new MyEnum
[] {
167 new MyEnum(EdkDefinitions
.MODULE_TYPE_BASE
, ModuleTypeBase
),
168 new MyEnum(EdkDefinitions
.MODULE_TYPE_SEC
, ModuleTypeSec
),
169 new MyEnum(EdkDefinitions
.MODULE_TYPE_PEI_CORE
, ModuleTypePeiCore
),
170 new MyEnum(EdkDefinitions
.MODULE_TYPE_PEIM
, ModuleTypePeim
),
171 new MyEnum(EdkDefinitions
.MODULE_TYPE_DXE_CORE
, ModuleTypeDxeCore
),
172 new MyEnum(EdkDefinitions
.MODULE_TYPE_DXE_DRIVER
, ModuleTypeDxeDriver
),
173 new MyEnum(EdkDefinitions
.MODULE_TYPE_DXE_RUNTIME_DRIVER
, ModuleTypeDxeRuntimeDriver
),
174 new MyEnum(EdkDefinitions
.MODULE_TYPE_DXE_SAL_DRIVER
, ModuleTypeDxeSalDriver
),
175 new MyEnum(EdkDefinitions
.MODULE_TYPE_DXE_SMM_DRIVER
, ModuleTypeDxeSmmDriver
),
176 new MyEnum(EdkDefinitions
.MODULE_TYPE_UEFI_DRIVER
, ModuleTypeUefiDriver
),
177 new MyEnum(EdkDefinitions
.MODULE_TYPE_UEFI_APPLICATION
, ModuleTypeUefiApplication
)};
182 This function get the module type value according module type string.
184 @param moduleTypeStr String of modlue type.
187 public static int getModuleType(String moduleTypeStr
) {
188 int returnValue
= -1;
189 for (int i
= 0; i
< CommonDefinition
.moduleEnum
.length
; i
++) {
190 returnValue
= CommonDefinition
.moduleEnum
[i
].ForInt(moduleTypeStr
);
191 if (returnValue
!= -1) {
195 return CommonDefinition
.ModuleTypeUnknown
;
201 This function is to formate GUID to ANSI c form.
205 @return Formated GUID.
207 public static String
formatGuidName(String guidNameConv
) {
212 .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}")) {
213 strList
= guidNameConv
.split("-");
214 guid
= "0x" + strList
[0] + ", ";
215 guid
= guid
+ "0x" + strList
[1] + ", ";
216 guid
= guid
+ "0x" + strList
[2] + ", ";
218 guid
= guid
+ "0x" + strList
[3].substring(0, 2) + ", ";
219 guid
= guid
+ "0x" + strList
[3].substring(2, 4);
221 while (index
< strList
[4].length()) {
223 guid
= guid
+ "0x" + strList
[4].substring(index
, index
+ 2);
228 } else if (guidNameConv
229 .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}( )*(\\})?")) {
230 strList
= guidNameConv
.split(",");
233 // chang Microsoft specific form to ANSI c form
235 for (int i
= 0; i
< 3; i
++) {
236 guid
= guid
+ strList
[i
] + ",";
240 for (int i
= 3; i
< strList
.length
; i
++) {
241 if (i
== strList
.length
- 1) {
242 guid
= guid
+ strList
[i
];
244 guid
= guid
+ strList
[i
] + ",";
251 .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");
258 Remove deuplicat string in list
260 This function is to duplicat string in list
264 @return String[] String list which remove the duplicate string.
266 public static String
[] remDupString (String
[] orgList
){
267 Set
<String
> strList
= new LinkedHashSet
<String
>();
269 if (orgList
== null) {
270 return new String
[0];
272 for (int i
= 0; i
< orgList
.length
; i
++) {
273 strList
.add(orgList
[i
]);
275 desList
= new String
[strList
.size()];
276 Iterator item
= strList
.iterator();
278 while (item
.hasNext()) {
279 desList
[index
] = (String
)item
.next();