]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/autogen/CommonDefinition.java
Change module build sequence. 1. Get FvImageName list according to their declaration...
[mirror_edk2.git] / Tools / 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
21\r
878ddf1f 22/**\r
23 CommonDefinition\r
24 \r
25 This class is to define some common marcos, which used by AutoGen.\r
26 \r
27**/\r
28public class CommonDefinition {\r
4b5f5549 29\r
878ddf1f 30 public final static String LibraryStr = "LIBRARY";\r
31 public final static String autoGenHbegin = "extern int __make_me_compile_correctly;\r\n";\r
32 public final static String include = "#include";\r
33 public final static String autoGenCLine1 = "\r\n";\r
5f907e4a 34\r
878ddf1f 35 public final static String autoGenCLine2 = "const UINT8 _gDebugPropertyMask "\r
5f907e4a 36 + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"\r
37 + " | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"\r
38 + " | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;\r\n";\r
878ddf1f 39\r
40 public final static String autoGenCLine3 = "const UINTN _gModuleDefaultErrorLevel"\r
5f907e4a 41 + " = EFI_D_ERROR | EFI_D_LOAD;\r\n";\r
42\r
878ddf1f 43 public final static String autoGenHLine1 = "#define EFI_SPECIFICATION_VERSION 0x00020000\r\n";\r
44 public final static String autoGenHVersionDefault = "#define EFI_SPECIFICATION_VERSION 0x00000000\r\n";\r
45 public final static String autoGenHLine2 = "#define EDK_RELEASE_VERSION 0x00090000\r\n";\r
46 public final static String autoGenHReleaseDefault = "#define EDK_RELEASE_VERSION 0x00000000\r\n";\r
47\r
48 public final static String includeAutogenH = "#include <AutoGen.h>\r\n" ;\r
a29c47e0 49 public final static String marcDefineStr = "#define ";\r
878ddf1f 50\r
51 public final static String gEfi = "gEfi";\r
52 public final static String protocolGuid = "ProtocolGuid";\r
53 public final static String ppiGuid = "PpiGuid";\r
54 public final static String guidGuid = "Guid";\r
73b4e31a 55\r
5f907e4a 56 public final static String tianoR8FlashMapH = "TianoR8FlashMap.h";\r
57 public final static String flashMapH = "FlashMap.h";\r
58\r
4b5f5549 59 ///\r
60 /// The defintions for identifying current module\r
61 /// is PEI Pcd driver or Dxe Pcd driver.\r
62 /// \r
5f907e4a 63 public static enum PCD_DRIVER_TYPE { NOT_PCD_DRIVER,\r
64 PEI_PCD_DRIVER, \r
65 DXE_PCD_DRIVER,\r
66 UNKNOWN_PCD_DRIVER};\r
67\r
4b5f5549 68 ///\r
69 /// AutoGen.h and AutoGen.c file's header\r
70 ///\r
878ddf1f 71 public final static String autogenHNotation = \r
5f907e4a 72 "/**\r\n" +\r
73 " DO NOT EDIT\r\n" +\r
74 " FILE auto-generated by GenBuild tasks\r\n" +\r
75 " Module name:\r\n" +\r
76 " AutoGen.h\r\n" +\r
77 " Abstract:" +\r
78 " Auto-generated AutoGen.h for building module or library.\r\n" +\r
79 "**/\r\n\r\n";\r
80\r
878ddf1f 81 public final static String autogenCNotation = \r
5f907e4a 82 "/**\r\n" +\r
83 " DO NOT EDIT\r\n" +\r
84 " FILE auto-generated by GenBuild tasks\r\n" +\r
85 " Module name:\r\n" +\r
86 " AutoGen.c\r\n" +\r
87 " Abstract:" +\r
88 " Auto-generated AutoGen.c for building module or library.\r\n" +\r
89 "**/\r\n\r\n";\r
90\r
4b5f5549 91 ///\r
92 /// module type\r
93 ///\r
878ddf1f 94 public final static int ModuleTypeBase = 0;\r
95 public final static int ModuleTypeSec = 1;\r
96 public final static int ModuleTypePeiCore = 2;\r
97 public final static int ModuleTypePeim = 3;\r
98 public final static int ModuleTypeDxeCore = 4;\r
99 public final static int ModuleTypeDxeDriver = 5;\r
100 public final static int ModuleTypeDxeRuntimeDriver = 6;\r
101 public final static int ModuleTypeDxeSmmDriver = 7;\r
102 public final static int ModuleTypeDxeSalDriver = 8;\r
103 public final static int ModuleTypeUefiDriver = 9;\r
104 public final static int ModuleTypeUefiApplication = 10;\r
105 public final static int ModuleTypeUnknown = 11;\r
5f907e4a 106\r
4b5f5549 107 ///\r
108 /// Usaged style\r
109 ///\r
878ddf1f 110 public final static String AlwaysConsumed = "ALWAYS_CONSUMED";\r
111 public final static String AlwaysProduced = "ALWAYS_PRODUCED";\r
5f907e4a 112\r
878ddf1f 113\r
114 public static class MyEnum {\r
115 String moduleTypeStr;\r
116 int type;\r
117\r
118 MyEnum (String str, int type) {\r
119 this.type = type;\r
120 this.moduleTypeStr = str;\r
121 }\r
122\r
123 int ForInt(String str) {\r
124 if (str.equals(this.moduleTypeStr)) {\r
125 return this.type;\r
126 } else\r
127 return -1;\r
128 }\r
129 }\r
5f907e4a 130\r
4b5f5549 131 ///\r
132 /// Module type\r
133 ///\r
878ddf1f 134 public static final MyEnum[] moduleEnum = new MyEnum[] {\r
5f907e4a 135 new MyEnum("BASE", ModuleTypeBase),\r
136 new MyEnum("SEC", ModuleTypeSec),\r
137 new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
138 new MyEnum("PEIM", ModuleTypePeim),\r
139 new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
140 new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),\r
141 new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
142 new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
143 new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
144 new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),\r
145 new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication)};\r
146\r
878ddf1f 147 /**\r
148 getModuleType\r
149 \r
150 This function get the module type value according module type string.\r
151 \r
152 @param moduleTypeStr String of modlue type.\r
153 @return \r
154 **/\r
155 static public int getModuleType(String moduleTypeStr) {\r
156 int returnValue = -1;\r
157 for (int i = 0; i < CommonDefinition.moduleEnum.length; i++) {\r
158 returnValue = CommonDefinition.moduleEnum[i].ForInt(moduleTypeStr);\r
159 if (returnValue != -1) {\r
160 return returnValue;\r
161 }\r
162 }\r
163 return CommonDefinition.ModuleTypeUnknown;\r
164 }\r
165\r
166 /**\r
4b5f5549 167 formateGuidName\r
878ddf1f 168 \r
4b5f5549 169 This function is to formate GUID to ANSI c form.\r
878ddf1f 170 \r
4b5f5549 171 @param guidNameCon\r
172 String of GUID.\r
173 @return Formated GUID.\r
878ddf1f 174 **/\r
a29c47e0 175 public static String formatGuidName(String guidNameConv) {\r
176 String[] strList;\r
177 String guid = "";\r
178 int index = 0;\r
179 if (guidNameConv\r
5f907e4a 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}")) {\r
a29c47e0 181 strList = guidNameConv.split("-");\r
182 guid = "0x" + strList[0] + ", ";\r
183 guid = guid + "0x" + strList[1] + ", ";\r
184 guid = guid + "0x" + strList[2] + ", ";\r
185 guid = guid + "{";\r
186 guid = guid + "0x" + strList[3].substring(0, 2) + ", ";\r
187 guid = guid + "0x" + strList[3].substring(2, 4);\r
99d2c3c4 188\r
a29c47e0 189 while (index < strList[4].length()) {\r
190 guid = guid + ", ";\r
191 guid = guid + "0x" + strList[4].substring(index, index + 2);\r
192 index = index + 2;\r
193 }\r
194 guid = guid + "}";\r
195 return guid;\r
196 } else if (guidNameConv\r
5f907e4a 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}( )*(\\})?")) {\r
a29c47e0 198 strList = guidNameConv.split(",");\r
99d2c3c4 199\r
a29c47e0 200 //\r
201 // chang Microsoft specific form to ANSI c form\r
202 //\r
203 for (int i = 0; i < 3; i++) {\r
204 guid = guid + strList[i] + ",";\r
205 }\r
206 guid = guid + "{";\r
99d2c3c4 207\r
a29c47e0 208 for (int i = 3; i < strList.length; i++) {\r
209 if (i == strList.length - 1) {\r
210 guid = guid + strList[i];\r
211 } else {\r
212 guid = guid + strList[i] + ",";\r
213 }\r
214 }\r
215 guid = guid + "}";\r
216 return guid;\r
217 } else {\r
218 System.out\r
5f907e4a 219 .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");\r
a29c47e0 220 return "0";\r
221\r
222 }\r
223 }\r
5f907e4a 224\r
136adffc 225 /**\r
4b5f5549 226 Remove deuplicat string in list\r
227 \r
228 This function is to duplicat string in list\r
229 \r
230 @param String[]\r
231 String list.\r
232 @return String[] String list which remove the duplicate string.\r
233 **/\r
136adffc 234 public static String[] remDupString (String[] orgList){\r
58c5839f 235 Set<String> strList = new LinkedHashSet<String>();\r
136adffc 236 String[] desList ;\r
5f907e4a 237 if (orgList == null) {\r
136adffc 238 return new String[0];\r
239 }\r
5f907e4a 240 for (int i = 0; i < orgList.length; i++) {\r
136adffc 241 strList.add(orgList[i]);\r
242 }\r
243 desList = new String[strList.size()];\r
244 Iterator item = strList.iterator();\r
245 int index = 0;\r
5f907e4a 246 while (item.hasNext()) {\r
136adffc 247 desList[index] = (String)item.next();\r
248 index++;\r
249 }\r
250 return desList;\r
251 }\r
5f907e4a 252\r
391dbbb1 253}\r