]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/autogen/CommonDefinition.java
3d0bf7ab3437a30c32d457348cac98ef5c2418c2
[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.Iterator;
19 import java.util.LinkedHashSet;
20 import java.util.Set;
21
22 /**
23 CommonDefinition
24
25 This class is to define some common marcos, which used by AutoGen.
26
27 **/
28 public class CommonDefinition {
29
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";
34
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";
39
40 public final static String autoGenCLine3 = "const UINTN _gModuleDefaultErrorLevel"
41 + " = EFI_D_ERROR | EFI_D_LOAD;\r\n";
42
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";
47
48 public final static String includeAutogenH = "#include <AutoGen.h>\r\n" ;
49 public final static String marcDefineStr = "#define ";
50
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";
55
56 public final static String tianoR8FlashMapH = "TianoR8FlashMap.h";
57 public final static String flashMapH = "FlashMap.h";
58
59 ///
60 /// The defintions for identifying current module
61 /// is PEI Pcd driver or Dxe Pcd driver.
62 ///
63 public static enum PCD_DRIVER_TYPE { NOT_PCD_DRIVER,
64 PEI_PCD_DRIVER,
65 DXE_PCD_DRIVER,
66 UNKNOWN_PCD_DRIVER};
67
68 ///
69 /// AutoGen.h and AutoGen.c file's header
70 ///
71 public final static String autogenHNotation =
72 "/**\r\n" +
73 " DO NOT EDIT\r\n" +
74 " FILE auto-generated by GenBuild tasks\r\n" +
75 " Module name:\r\n" +
76 " AutoGen.h\r\n" +
77 " Abstract:" +
78 " Auto-generated AutoGen.h for building module or library.\r\n" +
79 "**/\r\n\r\n";
80
81 public final static String autogenCNotation =
82 "/**\r\n" +
83 " DO NOT EDIT\r\n" +
84 " FILE auto-generated by GenBuild tasks\r\n" +
85 " Module name:\r\n" +
86 " AutoGen.c\r\n" +
87 " Abstract:" +
88 " Auto-generated AutoGen.c for building module or library.\r\n" +
89 "**/\r\n\r\n";
90
91 ///
92 /// module type
93 ///
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;
106
107 ///
108 /// Usaged style
109 ///
110 public final static String AlwaysConsumed = "ALWAYS_CONSUMED";
111 public final static String AlwaysProduced = "ALWAYS_PRODUCED";
112
113
114 public static class MyEnum {
115 String moduleTypeStr;
116 int type;
117
118 MyEnum (String str, int type) {
119 this.type = type;
120 this.moduleTypeStr = str;
121 }
122
123 int ForInt(String str) {
124 if (str.equals(this.moduleTypeStr)) {
125 return this.type;
126 } else
127 return -1;
128 }
129 }
130
131 ///
132 /// Module type
133 ///
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)};
146
147 /**
148 getModuleType
149
150 This function get the module type value according module type string.
151
152 @param moduleTypeStr String of modlue type.
153 @return
154 **/
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) {
160 return returnValue;
161 }
162 }
163 return CommonDefinition.ModuleTypeUnknown;
164 }
165
166 /**
167 formateGuidName
168
169 This function is to formate GUID to ANSI c form.
170
171 @param guidNameCon
172 String of GUID.
173 @return Formated GUID.
174 **/
175 public static String formatGuidName(String guidNameConv) {
176 String[] strList;
177 String guid = "";
178 int index = 0;
179 if (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] + ", ";
185 guid = guid + "{";
186 guid = guid + "0x" + strList[3].substring(0, 2) + ", ";
187 guid = guid + "0x" + strList[3].substring(2, 4);
188
189 while (index < strList[4].length()) {
190 guid = guid + ", ";
191 guid = guid + "0x" + strList[4].substring(index, index + 2);
192 index = index + 2;
193 }
194 guid = guid + "}";
195 return guid;
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(",");
199
200 //
201 // chang Microsoft specific form to ANSI c form
202 //
203 for (int i = 0; i < 3; i++) {
204 guid = guid + strList[i] + ",";
205 }
206 guid = guid + "{";
207
208 for (int i = 3; i < strList.length; i++) {
209 if (i == strList.length - 1) {
210 guid = guid + strList[i];
211 } else {
212 guid = guid + strList[i] + ",";
213 }
214 }
215 guid = guid + "}";
216 return guid;
217 } else {
218 System.out
219 .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");
220 return "0";
221
222 }
223 }
224
225 /**
226 Remove deuplicat string in list
227
228 This function is to duplicat string in list
229
230 @param String[]
231 String list.
232 @return String[] String list which remove the duplicate string.
233 **/
234 public static String[] remDupString (String[] orgList){
235 Set<String> strList = new LinkedHashSet<String>();
236 String[] desList ;
237 if (orgList == null) {
238 return new String[0];
239 }
240 for (int i = 0; i < orgList.length; i++) {
241 strList.add(orgList[i]);
242 }
243 desList = new String[strList.size()];
244 Iterator item = strList.iterator();
245 int index = 0;
246 while (item.hasNext()) {
247 desList[index] = (String)item.next();
248 index++;
249 }
250 return desList;
251 }
252
253 }