1. Update to just keep several line JAVA related msg; 2. Remove file PropertyManager...
[mirror_edk2.git] / Tools / Java / 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.Iterator;
19 import java.util.LinkedHashSet;
20 import java.util.Set;
21 import org.tianocore.common.definitions.EdkDefinitions;
22 import org.tianocore.common.definitions.ToolDefinitions;
23 /**
24 CommonDefinition
25
26 This class is to define some common marcos, which used by AutoGen.
27
28 **/
29 public class CommonDefinition {
30
31 ///
32 /// final static string
33 ///
34 public final static String LIBRARY = "LIBRARY";
35
36 public final static String AUTOGENHBEGIN = "extern int __make_me_compile_correctly;"
37 + ToolDefinitions.LINE_SEPARATOR;
38
39 public final static String INCLUDE = "#include";
40
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;
46
47 //public final static String DEFAULERROLEVEL = "const UINTN _gModuleDefaultErrorLevel"
48 // + " = EFI_D_ERROR | EFI_D_LOAD;"
49 // + ToolDefinitions.LINE_SEPARATOR;
50
51
52 public final static String INCLUDEAUTOGENH = INCLUDE
53 + " <AutoGen.h>"
54 + ToolDefinitions.LINE_SEPARATOR;
55
56 public final static String DEFINE = "#define ";
57
58 public final static String GEFI = "gEfi";
59
60 public final static String PRTOCOLGUID = "ProtocolGuid";
61
62 public final static String PPIGUID = "PpiGuid";
63
64 public final static String GUID = "Guid";
65
66 public final static String TIANOR8PLASHMAPH = "TianoR8FlashMap.h";
67
68 public final static String FLASHMAPH = "FlashMap.h";
69
70 public final static String IFNDEF = "#ifndef ";
71
72 public final static String AUTOGENH = "_AUTOGENH_";
73
74
75 ///
76 /// AutoGen.h and AutoGen.c file's header
77 ///
78 public final static String AUTOGENHNOTATION = "/**"
79 + ToolDefinitions.LINE_SEPARATOR
80 + " DO NOT EDIT"
81 + ToolDefinitions.LINE_SEPARATOR
82 + " FILE auto-generated by GenBuild tasks"
83 + ToolDefinitions.LINE_SEPARATOR
84 + " Module name:"
85 + ToolDefinitions.LINE_SEPARATOR
86 + " AutoGen.h"
87 + ToolDefinitions.LINE_SEPARATOR
88 + " Abstract:"
89 + " Auto-generated AutoGen.h for building module or library."
90 + ToolDefinitions.LINE_SEPARATOR
91 + "**/"
92 + ToolDefinitions.LINE_SEPARATOR
93 + ToolDefinitions.LINE_SEPARATOR;
94
95 public final static String AUTOGENCNOTATION = "/**"
96 + ToolDefinitions.LINE_SEPARATOR
97 + " DO NOT EDIT"
98 + ToolDefinitions.LINE_SEPARATOR
99 + " FILE auto-generated by GenBuild tasks"
100 + ToolDefinitions.LINE_SEPARATOR
101 + " Module name:"
102 + ToolDefinitions.LINE_SEPARATOR
103 + " AutoGen.c"
104 + ToolDefinitions.LINE_SEPARATOR
105 + " Abstract:"
106 + " Auto-generated AutoGen.c for building module or library."
107 + ToolDefinitions.LINE_SEPARATOR
108 + "**/"
109 + ToolDefinitions.LINE_SEPARATOR
110 + ToolDefinitions.LINE_SEPARATOR;
111
112 ///
113 /// The defintions for identifying current module
114 /// is PEI Pcd driver or Dxe Pcd driver.
115 ///
116 public static enum PCD_DRIVER_TYPE { NOT_PCD_DRIVER,
117 PEI_PCD_DRIVER,
118 DXE_PCD_DRIVER,
119 UNKNOWN_PCD_DRIVER
120 };
121
122
123 ///
124 /// module type
125 ///
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;
138
139 ///
140 /// Usaged style
141 ///
142 public final static String ALWAYSCONSUMED = "ALWAYS_CONSUMED";
143 public final static String ALWAYSPRODUCED = "ALWAYS_PRODUCED";
144
145
146 public static class MyEnum {
147 String moduleTypeStr;
148 int type;
149
150 MyEnum (String str, int type) {
151 this.type = type;
152 this.moduleTypeStr = str;
153 }
154
155 int ForInt(String str) {
156 if (str.equals(this.moduleTypeStr)) {
157 return this.type;
158 } else
159 return -1;
160 }
161 }
162
163 ///
164 /// Module type
165 ///
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)};
178
179 /**
180 getModuleType
181
182 This function get the module type value according module type string.
183
184 @param moduleTypeStr String of modlue type.
185 @return
186 **/
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) {
192 return returnValue;
193 }
194 }
195 return CommonDefinition.ModuleTypeUnknown;
196 }
197
198 /**
199 formateGuidName
200
201 This function is to formate GUID to ANSI c form.
202
203 @param guidNameCon
204 String of GUID.
205 @return Formated GUID.
206 **/
207 public static String formatGuidName(String guidNameConv) {
208 String[] strList;
209 String guid = "";
210 int index = 0;
211 if (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] + ", ";
217 guid = guid + "{";
218 guid = guid + "0x" + strList[3].substring(0, 2) + ", ";
219 guid = guid + "0x" + strList[3].substring(2, 4);
220
221 while (index < strList[4].length()) {
222 guid = guid + ", ";
223 guid = guid + "0x" + strList[4].substring(index, index + 2);
224 index = index + 2;
225 }
226 guid = guid + "}";
227 return guid;
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(",");
231
232 //
233 // chang Microsoft specific form to ANSI c form
234 //
235 for (int i = 0; i < 3; i++) {
236 guid = guid + strList[i] + ",";
237 }
238 guid = guid + "{";
239
240 for (int i = 3; i < strList.length; i++) {
241 if (i == strList.length - 1) {
242 guid = guid + strList[i];
243 } else {
244 guid = guid + strList[i] + ",";
245 }
246 }
247 guid = guid + "}";
248 return guid;
249 } else {
250 System.out
251 .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");
252 return "0";
253
254 }
255 }
256
257 /**
258 Remove deuplicat string in list
259
260 This function is to duplicat string in list
261
262 @param String[]
263 String list.
264 @return String[] String list which remove the duplicate string.
265 **/
266 public static String[] remDupString (String[] orgList){
267 Set<String> strList = new LinkedHashSet<String>();
268 String[] desList ;
269 if (orgList == null) {
270 return new String[0];
271 }
272 for (int i = 0; i < orgList.length; i++) {
273 strList.add(orgList[i]);
274 }
275 desList = new String[strList.size()];
276 Iterator item = strList.iterator();
277 int index = 0;
278 while (item.hasNext()) {
279 desList[index] = (String)item.next();
280 index++;
281 }
282 return desList;
283 }
284
285 }