]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/devstudio/DevStudioCompatibleCCompiler.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / devstudio / DevStudioCompatibleCCompiler.java
1 /*
2 *
3 * Copyright 2002-2004 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.devstudio;
18 import java.io.File;
19 import java.util.Vector;
20 import net.sf.antcontrib.cpptasks.CUtil;
21 import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration;
22 import net.sf.antcontrib.cpptasks.compiler.CompilerConfiguration;
23 import net.sf.antcontrib.cpptasks.compiler.LinkType;
24 import net.sf.antcontrib.cpptasks.compiler.PrecompilingCommandLineCCompiler;
25 import org.apache.tools.ant.BuildException;
26 import org.apache.tools.ant.types.Environment;
27 import net.sf.antcontrib.cpptasks.OptimizationEnum;
28
29 /**
30 * An abstract base class for compilers that are basically command line
31 * compatible with Microsoft(r) C/C++ Optimizing Compiler
32 *
33 * @author Curt Arnold
34 */
35 public abstract class DevStudioCompatibleCCompiler
36 extends
37 PrecompilingCommandLineCCompiler {
38 private static String[] mflags = new String[]{
39 //
40 // first four are single-threaded
41 // (runtime=static,debug=false), (..,debug=true),
42 // (runtime=dynamic,debug=true), (..,debug=false), (not supported)
43 // next four are multi-threaded, same sequence
44 "/ML", "/MLd", null, null, "/MT", "/MTd", "/MD", "/MDd"};
45 private static String[] defaultflags = new String[]{"/nologo", "/c"};
46 protected DevStudioCompatibleCCompiler(String command,
47 String identifierArg, boolean newEnvironment, Environment env) {
48 super(command, identifierArg, new String[]{".c", ".cc", ".cpp", ".cxx",
49 ".c++"}, new String[]{".h", ".hpp", ".inl"}, ".obj", false,
50 null, newEnvironment, env);
51 }
52 protected void addImpliedArgs(final Vector args,
53 final boolean debug,
54 final boolean multithreaded,
55 final boolean exceptions,
56 final LinkType linkType,
57 final Boolean rtti,
58 final OptimizationEnum optimization,
59 final Boolean defaultflag) {
60 if (defaultflag != null && defaultflag.booleanValue()) {
61 for (int i = 0; i < defaultflags.length; i++) {
62 args.addElement(defaultflags[i]);
63 }
64 }
65 if (exceptions) {
66 args.addElement("/GX");
67 }
68 int mindex = 0;
69 if (multithreaded) {
70 mindex += 4;
71 }
72 boolean staticRuntime = linkType.isStaticRuntime();
73 if (!staticRuntime) {
74 mindex += 2;
75 }
76 if (debug) {
77 mindex += 1;
78 args.addElement("/Zi");
79 args.addElement("/Od");
80 args.addElement("/GZ");
81 args.addElement("/D_DEBUG");
82 } else {
83 if (optimization != null) {
84 if (optimization.isSize()) {
85 args.addElement("/O1");
86 }
87 if (optimization.isSpeed()) {
88 args.addElement("/O2");
89 }
90 }
91 args.addElement("/DNDEBUG");
92 }
93 String mflag = mflags[mindex];
94 if (mflag == null) {
95 throw new BuildException(
96 "multithread='false' and runtime='dynamic' not supported");
97 }
98 args.addElement(mflag);
99 if (rtti != null && rtti.booleanValue()) {
100 args.addElement("/GR");
101 }
102 }
103 protected void addWarningSwitch(Vector args, int level) {
104 DevStudioProcessor.addWarningSwitch(args, level);
105 }
106 protected CompilerConfiguration createPrecompileGeneratingConfig(
107 CommandLineCompilerConfiguration baseConfig, File prototype,
108 String lastInclude) {
109 String[] additionalArgs = new String[]{
110 "/Fp" + CUtil.getBasename(prototype) + ".pch", "/Yc"};
111 return new CommandLineCompilerConfiguration(baseConfig, additionalArgs,
112 null, true);
113 }
114 protected CompilerConfiguration createPrecompileUsingConfig(
115 CommandLineCompilerConfiguration baseConfig, File prototype,
116 String lastInclude, String[] exceptFiles) {
117 String[] additionalArgs = new String[]{
118 "/Fp" + CUtil.getBasename(prototype) + ".pch",
119 "/Yu" + lastInclude};
120 return new CommandLineCompilerConfiguration(baseConfig, additionalArgs,
121 exceptFiles, false);
122 }
123 protected void getDefineSwitch(StringBuffer buffer, String define,
124 String value) {
125 DevStudioProcessor.getDefineSwitch(buffer, define, value);
126 }
127 protected File[] getEnvironmentIncludePath() {
128 return CUtil.getPathFromEnvironment("INCLUDE", ";");
129 }
130 protected String getIncludeDirSwitch(String includeDir) {
131 return DevStudioProcessor.getIncludeDirSwitch(includeDir);
132 }
133 protected void getUndefineSwitch(StringBuffer buffer, String define) {
134 DevStudioProcessor.getUndefineSwitch(buffer, define);
135 }
136 }