]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/devstudio/DevStudioCompatibleCCompiler.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / devstudio / DevStudioCompatibleCCompiler.java
CommitLineData
878ddf1f 1/*\r
2 *\r
3 * Copyright 2002-2004 The Ant-Contrib project\r
4 *\r
5 * Licensed under the Apache License, Version 2.0 (the "License");\r
6 * you may not use this file except in compliance with the License.\r
7 * You may obtain a copy of the License at\r
8 *\r
9 * http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 * Unless required by applicable law or agreed to in writing, software\r
12 * distributed under the License is distributed on an "AS IS" BASIS,\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 * See the License for the specific language governing permissions and\r
15 * limitations under the License.\r
16 */\r
17package net.sf.antcontrib.cpptasks.devstudio;\r
18import java.io.File;\r
19import java.util.Vector;\r
20import net.sf.antcontrib.cpptasks.CUtil;\r
21import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration;\r
22import net.sf.antcontrib.cpptasks.compiler.CompilerConfiguration;\r
23import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
24import net.sf.antcontrib.cpptasks.compiler.PrecompilingCommandLineCCompiler;\r
25import org.apache.tools.ant.BuildException;\r
26import org.apache.tools.ant.types.Environment;\r
27import net.sf.antcontrib.cpptasks.OptimizationEnum;\r
28\r
29/**\r
30 * An abstract base class for compilers that are basically command line\r
31 * compatible with Microsoft(r) C/C++ Optimizing Compiler\r
32 *\r
33 * @author Curt Arnold\r
34 */\r
35public abstract class DevStudioCompatibleCCompiler\r
36 extends\r
37 PrecompilingCommandLineCCompiler {\r
38 private static String[] mflags = new String[]{\r
39 //\r
40 // first four are single-threaded\r
41 // (runtime=static,debug=false), (..,debug=true),\r
42 // (runtime=dynamic,debug=true), (..,debug=false), (not supported)\r
43 // next four are multi-threaded, same sequence\r
44 "/ML", "/MLd", null, null, "/MT", "/MTd", "/MD", "/MDd"};\r
45 private static String[] defaultflags = new String[]{"/nologo", "/c"};\r
46 protected DevStudioCompatibleCCompiler(String command,\r
47 String identifierArg, boolean newEnvironment, Environment env) {\r
48 super(command, identifierArg, new String[]{".c", ".cc", ".cpp", ".cxx",\r
49 ".c++"}, new String[]{".h", ".hpp", ".inl"}, ".obj", false,\r
50 null, newEnvironment, env);\r
51 }\r
52 protected void addImpliedArgs(final Vector args,\r
53 final boolean debug,\r
54 final boolean multithreaded,\r
55 final boolean exceptions,\r
56 final LinkType linkType,\r
57 final Boolean rtti,\r
58 final OptimizationEnum optimization,\r
59 final Boolean defaultflag) {\r
60 if (defaultflag != null && defaultflag.booleanValue()) {\r
61 for (int i = 0; i < defaultflags.length; i++) {\r
62 args.addElement(defaultflags[i]);\r
63 }\r
64 }\r
65 if (exceptions) {\r
66 args.addElement("/GX");\r
67 }\r
68 int mindex = 0;\r
69 if (multithreaded) {\r
70 mindex += 4;\r
71 }\r
72 boolean staticRuntime = linkType.isStaticRuntime();\r
73 if (!staticRuntime) {\r
74 mindex += 2;\r
75 }\r
76 if (debug) {\r
77 mindex += 1;\r
78 args.addElement("/Zi");\r
79 args.addElement("/Od");\r
80 args.addElement("/GZ");\r
81 args.addElement("/D_DEBUG");\r
82 } else {\r
83 if (optimization != null) {\r
84 if (optimization.isSize()) {\r
85 args.addElement("/O1");\r
86 }\r
87 if (optimization.isSpeed()) {\r
88 args.addElement("/O2");\r
89 }\r
90 }\r
91 args.addElement("/DNDEBUG");\r
92 }\r
93 String mflag = mflags[mindex];\r
94 if (mflag == null) {\r
95 throw new BuildException(\r
96 "multithread='false' and runtime='dynamic' not supported");\r
97 }\r
98 args.addElement(mflag);\r
99 if (rtti != null && rtti.booleanValue()) {\r
100 args.addElement("/GR");\r
101 }\r
102 }\r
103 protected void addWarningSwitch(Vector args, int level) {\r
104 DevStudioProcessor.addWarningSwitch(args, level);\r
105 }\r
106 protected CompilerConfiguration createPrecompileGeneratingConfig(\r
107 CommandLineCompilerConfiguration baseConfig, File prototype,\r
108 String lastInclude) {\r
109 String[] additionalArgs = new String[]{\r
110 "/Fp" + CUtil.getBasename(prototype) + ".pch", "/Yc"};\r
111 return new CommandLineCompilerConfiguration(baseConfig, additionalArgs,\r
112 null, true);\r
113 }\r
114 protected CompilerConfiguration createPrecompileUsingConfig(\r
115 CommandLineCompilerConfiguration baseConfig, File prototype,\r
116 String lastInclude, String[] exceptFiles) {\r
117 String[] additionalArgs = new String[]{\r
118 "/Fp" + CUtil.getBasename(prototype) + ".pch",\r
119 "/Yu" + lastInclude};\r
120 return new CommandLineCompilerConfiguration(baseConfig, additionalArgs,\r
121 exceptFiles, false);\r
122 }\r
123 protected void getDefineSwitch(StringBuffer buffer, String define,\r
124 String value) {\r
125 DevStudioProcessor.getDefineSwitch(buffer, define, value);\r
126 }\r
127 protected File[] getEnvironmentIncludePath() {\r
128 return CUtil.getPathFromEnvironment("INCLUDE", ";");\r
129 }\r
130 protected String getIncludeDirSwitch(String includeDir) {\r
131 return DevStudioProcessor.getIncludeDirSwitch(includeDir);\r
132 }\r
133 protected void getUndefineSwitch(StringBuffer buffer, String define) {\r
134 DevStudioProcessor.getUndefineSwitch(buffer, define);\r
135 }\r
136}\r