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
CommitLineData
878ddf1f 1/** @file\r
2 CommonDefinition class.\r
3\r
4 This class is to define some common marcos and funcions, which used by AutoGen.\r
5 \r
6 Copyright (c) 2006, Intel Corporation\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11 \r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15 **/\r
16package org.tianocore.build.autogen;\r
17\r
136adffc 18import java.util.Iterator;\r
58c5839f 19import java.util.LinkedHashSet;\r
136adffc 20import java.util.Set;\r
cb4d97bd 21import org.tianocore.common.definitions.EdkDefinitions;\r
22import org.tianocore.common.definitions.ToolDefinitions;\r
878ddf1f 23/**\r
24 CommonDefinition\r
25 \r
26 This class is to define some common marcos, which used by AutoGen.\r
27 \r
28**/\r
29public class CommonDefinition {\r
4b5f5549 30\r
cb4d97bd 31 ///\r
32 /// final static string\r
33 /// \r
34 public final static String LIBRARY = "LIBRARY";\r
35\r
36 public final static String AUTOGENHBEGIN = "extern int __make_me_compile_correctly;"\r
37 + ToolDefinitions.LINE_SEPARATOR;\r
38\r
39 public final static String INCLUDE = "#include";\r
40\r
41 //public final static String DEBUGPROPERYMASK = "const UINT8 _gDebugPropertyMask "\r
42 // + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"\r
43 // + " | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"\r
44 // + " | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;" \r
45 // + ToolDefinitions.LINE_SEPARATOR;\r
46\r
47 //public final static String DEFAULERROLEVEL = "const UINTN _gModuleDefaultErrorLevel"\r
48 // + " = EFI_D_ERROR | EFI_D_LOAD;"\r
49 // + ToolDefinitions.LINE_SEPARATOR;\r
50\r
51\r
52 public final static String INCLUDEAUTOGENH = INCLUDE \r
53 + " <AutoGen.h>"\r
54 + ToolDefinitions.LINE_SEPARATOR;\r
55\r
56 public final static String DEFINE = "#define ";\r
57\r
58 public final static String GEFI = "gEfi";\r
5f907e4a 59\r
cb4d97bd 60 public final static String PRTOCOLGUID = "ProtocolGuid";\r
878ddf1f 61\r
cb4d97bd 62 public final static String PPIGUID = "PpiGuid";\r
5f907e4a 63\r
cb4d97bd 64 public final static String GUID = "Guid";\r
878ddf1f 65\r
cb4d97bd 66 public final static String TIANOR8PLASHMAPH = "TianoR8FlashMap.h";\r
878ddf1f 67\r
cb4d97bd 68 public final static String FLASHMAPH = "FlashMap.h";\r
73b4e31a 69\r
cb4d97bd 70 public final static String IFNDEF = "#ifndef ";\r
71\r
72 public final static String AUTOGENH = "_AUTOGENH_";\r
73\r
74 \r
75 ///\r
76 /// AutoGen.h and AutoGen.c file's header\r
77 ///\r
78 public final static String AUTOGENHNOTATION = "/**"\r
79 + ToolDefinitions.LINE_SEPARATOR\r
80 + " DO NOT EDIT"\r
81 + ToolDefinitions.LINE_SEPARATOR\r
82 + " FILE auto-generated by GenBuild tasks"\r
83 + ToolDefinitions.LINE_SEPARATOR \r
84 + " Module name:"\r
85 + ToolDefinitions.LINE_SEPARATOR\r
86 + " AutoGen.h"\r
87 + ToolDefinitions.LINE_SEPARATOR \r
88 + " Abstract:" \r
89 + " Auto-generated AutoGen.h for building module or library."\r
90 + ToolDefinitions.LINE_SEPARATOR\r
91 + "**/"\r
92 + ToolDefinitions.LINE_SEPARATOR \r
93 + ToolDefinitions.LINE_SEPARATOR;\r
94\r
95 public final static String AUTOGENCNOTATION = "/**"\r
96 + ToolDefinitions.LINE_SEPARATOR\r
97 + " DO NOT EDIT"\r
98 + ToolDefinitions.LINE_SEPARATOR\r
99 + " FILE auto-generated by GenBuild tasks"\r
100 + ToolDefinitions.LINE_SEPARATOR \r
101 + " Module name:"\r
102 + ToolDefinitions.LINE_SEPARATOR \r
103 + " AutoGen.c"\r
104 + ToolDefinitions.LINE_SEPARATOR \r
105 + " Abstract:" \r
106 + " Auto-generated AutoGen.c for building module or library."\r
107 + ToolDefinitions.LINE_SEPARATOR \r
108 + "**/"\r
109 + ToolDefinitions.LINE_SEPARATOR\r
110 + ToolDefinitions.LINE_SEPARATOR;\r
5f907e4a 111\r
4b5f5549 112 ///\r
113 /// The defintions for identifying current module\r
114 /// is PEI Pcd driver or Dxe Pcd driver.\r
115 /// \r
5f907e4a 116 public static enum PCD_DRIVER_TYPE { NOT_PCD_DRIVER,\r
cb4d97bd 117 PEI_PCD_DRIVER, \r
118 DXE_PCD_DRIVER,\r
119 UNKNOWN_PCD_DRIVER\r
120 };\r
5f907e4a 121\r
5f907e4a 122\r
4b5f5549 123 ///\r
124 /// module type\r
125 ///\r
cb4d97bd 126 public final static int ModuleTypeBase = 0;\r
127 public final static int ModuleTypeSec = 1;\r
128 public final static int ModuleTypePeiCore = 2;\r
129 public final static int ModuleTypePeim = 3;\r
130 public final static int ModuleTypeDxeCore = 4;\r
131 public final static int ModuleTypeDxeDriver = 5;\r
878ddf1f 132 public final static int ModuleTypeDxeRuntimeDriver = 6;\r
cb4d97bd 133 public final static int ModuleTypeDxeSmmDriver = 7;\r
134 public final static int ModuleTypeDxeSalDriver = 8;\r
135 public final static int ModuleTypeUefiDriver = 9;\r
136 public final static int ModuleTypeUefiApplication = 10;\r
137 public final static int ModuleTypeUnknown = 11;\r
5f907e4a 138\r
4b5f5549 139 ///\r
140 /// Usaged style\r
141 ///\r
cb4d97bd 142 public final static String ALWAYSCONSUMED = "ALWAYS_CONSUMED";\r
143 public final static String ALWAYSPRODUCED = "ALWAYS_PRODUCED";\r
5f907e4a 144\r
878ddf1f 145\r
146 public static class MyEnum {\r
147 String moduleTypeStr;\r
148 int type;\r
149\r
150 MyEnum (String str, int type) {\r
151 this.type = type;\r
152 this.moduleTypeStr = str;\r
153 }\r
154\r
155 int ForInt(String str) {\r
156 if (str.equals(this.moduleTypeStr)) {\r
157 return this.type;\r
158 } else\r
159 return -1;\r
160 }\r
161 }\r
5f907e4a 162\r
4b5f5549 163 ///\r
164 /// Module type\r
165 ///\r
878ddf1f 166 public static final MyEnum[] moduleEnum = new MyEnum[] {\r
cb4d97bd 167 new MyEnum(EdkDefinitions.MODULE_TYPE_BASE, ModuleTypeBase),\r
168 new MyEnum(EdkDefinitions.MODULE_TYPE_SEC, ModuleTypeSec),\r
169 new MyEnum(EdkDefinitions.MODULE_TYPE_PEI_CORE, ModuleTypePeiCore),\r
170 new MyEnum(EdkDefinitions.MODULE_TYPE_PEIM, ModuleTypePeim),\r
171 new MyEnum(EdkDefinitions.MODULE_TYPE_DXE_CORE, ModuleTypeDxeCore),\r
172 new MyEnum(EdkDefinitions.MODULE_TYPE_DXE_DRIVER, ModuleTypeDxeDriver),\r
173 new MyEnum(EdkDefinitions.MODULE_TYPE_DXE_RUNTIME_DRIVER, ModuleTypeDxeRuntimeDriver),\r
174 new MyEnum(EdkDefinitions.MODULE_TYPE_DXE_SAL_DRIVER, ModuleTypeDxeSalDriver),\r
175 new MyEnum(EdkDefinitions.MODULE_TYPE_DXE_SMM_DRIVER, ModuleTypeDxeSmmDriver),\r
176 new MyEnum(EdkDefinitions.MODULE_TYPE_UEFI_DRIVER, ModuleTypeUefiDriver),\r
177 new MyEnum(EdkDefinitions.MODULE_TYPE_UEFI_APPLICATION, ModuleTypeUefiApplication)};\r
5f907e4a 178\r
878ddf1f 179 /**\r
180 getModuleType\r
181 \r
182 This function get the module type value according module type string.\r
183 \r
184 @param moduleTypeStr String of modlue type.\r
185 @return \r
186 **/\r
cb4d97bd 187 public static int getModuleType(String moduleTypeStr) {\r
878ddf1f 188 int returnValue = -1;\r
189 for (int i = 0; i < CommonDefinition.moduleEnum.length; i++) {\r
190 returnValue = CommonDefinition.moduleEnum[i].ForInt(moduleTypeStr);\r
191 if (returnValue != -1) {\r
192 return returnValue;\r
193 }\r
194 }\r
195 return CommonDefinition.ModuleTypeUnknown;\r
196 }\r
197\r
198 /**\r
4b5f5549 199 formateGuidName\r
878ddf1f 200 \r
4b5f5549 201 This function is to formate GUID to ANSI c form.\r
878ddf1f 202 \r
4b5f5549 203 @param guidNameCon\r
204 String of GUID.\r
205 @return Formated GUID.\r
878ddf1f 206 **/\r
a29c47e0 207 public static String formatGuidName(String guidNameConv) {\r
208 String[] strList;\r
209 String guid = "";\r
210 int index = 0;\r
211 if (guidNameConv\r
5f907e4a 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}")) {\r
a29c47e0 213 strList = guidNameConv.split("-");\r
214 guid = "0x" + strList[0] + ", ";\r
215 guid = guid + "0x" + strList[1] + ", ";\r
216 guid = guid + "0x" + strList[2] + ", ";\r
217 guid = guid + "{";\r
218 guid = guid + "0x" + strList[3].substring(0, 2) + ", ";\r
219 guid = guid + "0x" + strList[3].substring(2, 4);\r
99d2c3c4 220\r
a29c47e0 221 while (index < strList[4].length()) {\r
222 guid = guid + ", ";\r
223 guid = guid + "0x" + strList[4].substring(index, index + 2);\r
224 index = index + 2;\r
225 }\r
226 guid = guid + "}";\r
227 return guid;\r
228 } else if (guidNameConv\r
5f907e4a 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}( )*(\\})?")) {\r
a29c47e0 230 strList = guidNameConv.split(",");\r
99d2c3c4 231\r
a29c47e0 232 //\r
233 // chang Microsoft specific form to ANSI c form\r
234 //\r
235 for (int i = 0; i < 3; i++) {\r
236 guid = guid + strList[i] + ",";\r
237 }\r
238 guid = guid + "{";\r
99d2c3c4 239\r
a29c47e0 240 for (int i = 3; i < strList.length; i++) {\r
241 if (i == strList.length - 1) {\r
242 guid = guid + strList[i];\r
243 } else {\r
244 guid = guid + strList[i] + ",";\r
245 }\r
246 }\r
247 guid = guid + "}";\r
248 return guid;\r
249 } else {\r
250 System.out\r
5f907e4a 251 .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");\r
a29c47e0 252 return "0";\r
253\r
254 }\r
255 }\r
5f907e4a 256\r
136adffc 257 /**\r
4b5f5549 258 Remove deuplicat string in list\r
259 \r
260 This function is to duplicat string in list\r
261 \r
262 @param String[]\r
263 String list.\r
264 @return String[] String list which remove the duplicate string.\r
265 **/\r
136adffc 266 public static String[] remDupString (String[] orgList){\r
58c5839f 267 Set<String> strList = new LinkedHashSet<String>();\r
136adffc 268 String[] desList ;\r
5f907e4a 269 if (orgList == null) {\r
136adffc 270 return new String[0];\r
271 }\r
5f907e4a 272 for (int i = 0; i < orgList.length; i++) {\r
136adffc 273 strList.add(orgList[i]);\r
274 }\r
275 desList = new String[strList.size()];\r
276 Iterator item = strList.iterator();\r
277 int index = 0;\r
5f907e4a 278 while (item.hasNext()) {\r
136adffc 279 desList[index] = (String)item.next();\r
280 index++;\r
281 }\r
282 return desList;\r
283 }\r
5f907e4a 284\r
391dbbb1 285}\r