]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/userdefine/UserDefineCompiler.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / userdefine / UserDefineCompiler.java
1 /*
2 *
3 * Copyright 2002-2006 The Ant-Contrib project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package net.sf.antcontrib.cpptasks.userdefine;
18
19 import org.apache.tools.ant.Project;
20
21 import net.sf.antcontrib.cpptasks.CCTask;
22 import org.tianocore.build.toolchain.*;
23
24 public class UserDefineCompiler extends CommandLineUserDefine {
25
26 public UserDefineCompiler(CCTask cctask, UserDefineDef userdefineDef) {
27 String arch = null;
28 String os = null;
29 String vendor = null;
30 String commandType = null;
31 Project project = cctask.getProject();
32 // get command string
33 if (cctask.getArch() == null) {
34 arch = project.getProperty("ARCH");
35 if (arch == null) {
36 arch = System.getProperty("os.arch");
37 }
38 } else {
39 arch = cctask.getArch();
40 }
41 arch = arch.toUpperCase();
42 if (cctask.getOs() == null) {
43 os = project.getProperty("OS");
44 if (os == null) {
45 os = System.getProperty("os.name");
46 }
47 } else {
48 os = cctask.getOs();
49 }
50
51 commandType = userdefineDef.getType();
52
53 if (commandType != null) {
54 if (ToolChainFactory.getValue(arch + "_" + commandType + "_VENDOR") != null
55 && ToolChainFactory.getValue(
56 arch + "_" + commandType + "_VENDOR").trim()
57 .length() > 0) {
58 vendor = ToolChainFactory.getValue(arch + "_" + commandType
59 + "_VENDOR");
60 } else if (ToolChainFactory.getValue(arch + "_VENDOR") != null) {
61 vendor = ToolChainFactory.getValue(arch + "_VENDOR");
62 }
63 }
64
65 // look if ARCH_VENDOR_OS_COMMANDTYPE is existed
66 if (arch != null && vendor != null && os != null && commandType != null) {
67 command = project.getProperty(arch + "_" + vendor + "_" + os + "_"
68 + commandType);
69 }
70 // look if ARCH_VENDOR_COMMANDTYPE is existed
71 if (command == null) {
72 if (arch != null && vendor != null && commandType != null) {
73 command = project.getProperty(arch + "_" + vendor + "_"
74 + commandType);
75 }
76 }
77 // look if ARCH_COMMANDTYPE is existed
78 if (command == null) {
79 if (arch != null && commandType != null) {
80 command = project.getProperty(arch + "_" + commandType);
81 }
82 }
83 // look if COMMANDTYPE is existed
84 if (command == null) {
85 if (commandType != null) {
86 command = project.getProperty(commandType);
87 }
88 }
89 // using the default value from VENDOR_OS_COMMANDTYPE or
90 // VENDOR_COMMANDTYPE
91 if (command == null) {
92 if (vendor != null && os != null && commandType != null) {
93 String str = vendor + "_" + os + "_" + commandType;
94 command = UserDefineMapping.getDefaultCommand(str);
95 }
96 }
97 // VENDOR_COMMANDTYPE
98 if (command == null) {
99 if (vendor != null && commandType != null) {
100 String str = vendor + "_" + commandType;
101 command = UserDefineMapping.getDefaultCommand(str);
102 }
103 }
104 // just give the name whatever
105 if (command == null) {
106 command = "cl";
107 }
108
109 // initialize the includePathDelimiter
110 if (userdefineDef.getIncludepathDelimiter() != null) {
111 includePathDelimiter = userdefineDef.getIncludepathDelimiter();
112 }
113 // else find VENDOR
114 else {
115 if (vendor != null) {
116 includePathDelimiter = UserDefineMapping
117 .getIncludePathDelimiter(vendor, commandType);
118 }
119 }
120 if (includePathDelimiter == null) {
121 includePathDelimiter = "-I";
122 }
123 /*
124 * Set libSet.
125 */
126 if (userdefineDef.getLibSet() != null
127 && userdefineDef.getLibSet().size() > 0) {
128 String[] libList;
129 if (vendor.equalsIgnoreCase("GCC")) {
130 libSetList.add("-(");
131 for (int i = 0; i < userdefineDef.getLibSet().size(); i++) {
132 libList = userdefineDef.getLibSet().get(i).getLibs();
133 for (int j = 0; j < libList.length; j++) {
134 libSetList.add(libList[j]);
135 }
136 }
137 libSetList.add("-)");
138 } else {
139 for (int i = 0; i < userdefineDef.getLibSet().size(); i++) {
140 libList = userdefineDef.getLibSet().get(i).getLibs();
141 for (int j = 0; j < libList.length; j++) {
142 libSetList.add(libList[j]);
143 }
144 }
145 }
146 }
147 /*
148 * set includeFileFlag
149 */
150 if (userdefineDef.getIncludeFile() != null) {
151 if (userdefineDef.getIncludeFileFlag() != null) {
152 includeFileFlag = userdefineDef.getIncludeFileFlag();
153 } else {
154 includeFileFlag = UserDefineMapping.getCompellingIncFileFlag(
155 vendor, commandType);
156 }
157 }
158 /*
159 * set entryPointFlag
160 */
161 if (userdefineDef.getEntryPointvalue() != null) {
162 if (userdefineDef.getEntryPointFlag() != null) {
163 entryPointFlag = userdefineDef.getEntryPointFlag();
164 } else {
165 entryPointFlag = UserDefineMapping.getEntryPointFlag(vendor,
166 commandType);
167 }
168 }
169 /*
170 * set subSystemFlag
171 */
172 if (userdefineDef.getSubSystemvalue() != null) {
173 if (userdefineDef.getSubSystemFlag() != null) {
174 subSystemFlag = userdefineDef.getSubSystemFlag();
175 } else {
176 subSystemFlag = UserDefineMapping.getSubSystemFlag(vendor,
177 commandType);
178 }
179 }
180 /*
181 * set mapFlag
182 */
183 if (userdefineDef.getMapvalue() != null) {
184 if (userdefineDef.getMapFlag() != null) {
185 mapFlag = userdefineDef.getMapFlag();
186 } else {
187 mapFlag = UserDefineMapping.getMapFlag(vendor, commandType);
188 }
189 }
190 /*
191 * set pdbFlag
192 */
193 if (userdefineDef.getPdbvalue() != null) {
194 if (userdefineDef.getPdbFlag() != null) {
195 pdbFlag = userdefineDef.getPdbFlag();
196 } else {
197 pdbFlag = UserDefineMapping.getPdbFlag(vendor, commandType);
198 }
199 }
200 /*
201 * set outputFileFlag
202 */
203 if (userdefineDef.getOutputFile() != null) {
204 if (userdefineDef.getOutPutFlag() != null) {
205 outputFileFlag = userdefineDef.getOutPutFlag();
206 } else {
207 outputFileFlag = UserDefineMapping.getOutputFileFlag(vendor,
208 arch, commandType);
209 }
210 }
211
212 /*
213 * set fileList
214 */
215 if (userdefineDef.getFileList() != null) {
216 fileList = userdefineDef.getFileList();
217 }
218 }
219 }