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
;
25 This class is to define some common marcos, which used by AutoGen.
28 public class CommonDefinition
{
30 public final static String LibraryStr
= "LIBRARY";
31 public final static String autoGenHbegin
= "extern int __make_me_compile_correctly;\r\n";
32 public final static String include
= "#include";
33 public final static String autoGenCLine1
= "\r\n";
35 public final static String autoGenCLine2
= "const UINT8 _gDebugPropertyMask "
36 + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"
37 + " | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"
38 + " | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;\r\n";
40 public final static String autoGenCLine3
= "const UINTN _gModuleDefaultErrorLevel"
41 + " = EFI_D_ERROR | EFI_D_LOAD;\r\n";
43 public final static String autoGenHLine1
= "#define EFI_SPECIFICATION_VERSION 0x00020000\r\n";
44 public final static String autoGenHVersionDefault
= "#define EFI_SPECIFICATION_VERSION 0x00000000\r\n";
45 public final static String autoGenHLine2
= "#define EDK_RELEASE_VERSION 0x00090000\r\n";
46 public final static String autoGenHReleaseDefault
= "#define EDK_RELEASE_VERSION 0x00000000\r\n";
48 public final static String includeAutogenH
= "#include <AutoGen.h>\r\n" ;
49 public final static String marcDefineStr
= "#define ";
51 public final static String gEfi
= "gEfi";
52 public final static String protocolGuid
= "ProtocolGuid";
53 public final static String ppiGuid
= "PpiGuid";
54 public final static String guidGuid
= "Guid";
56 public final static String tianoR8FlashMapH
= "TianoR8FlashMap.h";
57 public final static String flashMapH
= "FlashMap.h";
60 /// The defintions for identifying current module
61 /// is PEI Pcd driver or Dxe Pcd driver.
63 public static enum PCD_DRIVER_TYPE
{ NOT_PCD_DRIVER
,
69 /// AutoGen.h and AutoGen.c file's header
71 public final static String autogenHNotation
=
74 " FILE auto-generated by GenBuild tasks\r\n" +
78 " Auto-generated AutoGen.h for building module or library.\r\n" +
81 public final static String autogenCNotation
=
84 " FILE auto-generated by GenBuild tasks\r\n" +
88 " Auto-generated AutoGen.c for building module or library.\r\n" +
94 public final static int ModuleTypeBase
= 0;
95 public final static int ModuleTypeSec
= 1;
96 public final static int ModuleTypePeiCore
= 2;
97 public final static int ModuleTypePeim
= 3;
98 public final static int ModuleTypeDxeCore
= 4;
99 public final static int ModuleTypeDxeDriver
= 5;
100 public final static int ModuleTypeDxeRuntimeDriver
= 6;
101 public final static int ModuleTypeDxeSmmDriver
= 7;
102 public final static int ModuleTypeDxeSalDriver
= 8;
103 public final static int ModuleTypeUefiDriver
= 9;
104 public final static int ModuleTypeUefiApplication
= 10;
105 public final static int ModuleTypeUnknown
= 11;
110 public final static String AlwaysConsumed
= "ALWAYS_CONSUMED";
111 public final static String AlwaysProduced
= "ALWAYS_PRODUCED";
114 public static class MyEnum
{
115 String moduleTypeStr
;
118 MyEnum (String str
, int type
) {
120 this.moduleTypeStr
= str
;
123 int ForInt(String str
) {
124 if (str
.equals(this.moduleTypeStr
)) {
134 public static final MyEnum
[] moduleEnum
= new MyEnum
[] {
135 new MyEnum("BASE", ModuleTypeBase
),
136 new MyEnum("SEC", ModuleTypeSec
),
137 new MyEnum("PEI_CORE", ModuleTypePeiCore
),
138 new MyEnum("PEIM", ModuleTypePeim
),
139 new MyEnum("DXE_CORE", ModuleTypeDxeCore
),
140 new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver
),
141 new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver
),
142 new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver
),
143 new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver
),
144 new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver
),
145 new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication
)};
150 This function get the module type value according module type string.
152 @param moduleTypeStr String of modlue type.
155 static public int getModuleType(String moduleTypeStr
) {
156 int returnValue
= -1;
157 for (int i
= 0; i
< CommonDefinition
.moduleEnum
.length
; i
++) {
158 returnValue
= CommonDefinition
.moduleEnum
[i
].ForInt(moduleTypeStr
);
159 if (returnValue
!= -1) {
163 return CommonDefinition
.ModuleTypeUnknown
;
169 This function is to formate GUID to ANSI c form.
173 @return Formated GUID.
175 public static String
formatGuidName(String guidNameConv
) {
180 .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}")) {
181 strList
= guidNameConv
.split("-");
182 guid
= "0x" + strList
[0] + ", ";
183 guid
= guid
+ "0x" + strList
[1] + ", ";
184 guid
= guid
+ "0x" + strList
[2] + ", ";
186 guid
= guid
+ "0x" + strList
[3].substring(0, 2) + ", ";
187 guid
= guid
+ "0x" + strList
[3].substring(2, 4);
189 while (index
< strList
[4].length()) {
191 guid
= guid
+ "0x" + strList
[4].substring(index
, index
+ 2);
196 } else if (guidNameConv
197 .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}( )*(\\})?")) {
198 strList
= guidNameConv
.split(",");
201 // chang Microsoft specific form to ANSI c form
203 for (int i
= 0; i
< 3; i
++) {
204 guid
= guid
+ strList
[i
] + ",";
208 for (int i
= 3; i
< strList
.length
; i
++) {
209 if (i
== strList
.length
- 1) {
210 guid
= guid
+ strList
[i
];
212 guid
= guid
+ strList
[i
] + ",";
219 .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");
226 Remove deuplicat string in list
228 This function is to duplicat string in list
232 @return String[] String list which remove the duplicate string.
234 public static String
[] remDupString (String
[] orgList
){
235 Set
<String
> strList
= new LinkedHashSet
<String
>();
237 if (orgList
== null) {
238 return new String
[0];
240 for (int i
= 0; i
< orgList
.length
; i
++) {
241 strList
.add(orgList
[i
]);
243 desList
= new String
[strList
.size()];
244 Iterator item
= strList
.iterator();
246 while (item
.hasNext()) {
247 desList
[index
] = (String
)item
.next();