]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / gcc / GccCompatibleCCompiler.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.gcc;
18 import java.io.File;
19 import java.util.Vector;
20 import net.sf.antcontrib.cpptasks.CUtil;
21 import net.sf.antcontrib.cpptasks.compiler.CommandLineCCompiler;
22 import net.sf.antcontrib.cpptasks.compiler.LinkType;
23 import org.apache.tools.ant.types.Environment;
24 import net.sf.antcontrib.cpptasks.OptimizationEnum;
25
26 /**
27 * Abstract base class for compilers that attempt to be command line compatible
28 * with GCC
29 *
30 * @author Adam Murdoch
31 * @author Curt Arnold
32 */
33 public abstract class GccCompatibleCCompiler extends CommandLineCCompiler {
34 private final static String[] headerExtensions = new String[]{".h", ".hpp",
35 ".inl"};
36 private final static String[] sourceExtensions = new String[]{".c", ".cc",
37 ".cpp", ".cxx", ".c++", ".i", ".f", ".for"};
38 private final static String[] defaultflags = new String[]{"-c"};
39 /**
40 * Private constructor. Use GccCCompiler.getInstance() to get singleton
41 * instance of this class.
42 */
43 protected GccCompatibleCCompiler(String command, String identifierArg,
44 boolean libtool, GccCompatibleCCompiler libtoolCompiler,
45 boolean newEnvironment, Environment env) {
46 super(command, identifierArg, sourceExtensions, headerExtensions,
47 libtool ? ".fo" : ".o", libtool, libtoolCompiler,
48 newEnvironment, env);
49 }
50 /**
51 * Private constructor. Use GccCCompiler.getInstance() to get singleton
52 * instance of this class.
53 */
54 protected GccCompatibleCCompiler(String command, String identifierArg,
55 String[] sourceExtensions, String[] headerExtensions,
56 boolean libtool, GccCompatibleCCompiler libtoolCompiler,
57 boolean newEnvironment, Environment env) {
58 super(command, identifierArg, sourceExtensions, headerExtensions,
59 libtool ? ".fo" : ".o", libtool, libtoolCompiler,
60 newEnvironment, env);
61 }
62 public void addImpliedArgs(final Vector args,
63 final boolean debug,
64 final boolean multithreaded,
65 final boolean exceptions,
66 final LinkType linkType,
67 final Boolean rtti,
68 final OptimizationEnum optimization,
69 final Boolean defaultflag) {
70 //
71 // -fPIC is too much trouble
72 // users have to manually add it for
73 // operating systems that make sense
74 //
75 if (defaultflag != null && defaultflag.booleanValue()) {
76 for (int i = 0; i < defaultflags.length; i++) {
77 args.addElement(defaultflags[i]);
78 }
79 }
80 if (debug) {
81 args.addElement("-g");
82 } else {
83 if (optimization != null) {
84 if (optimization.isSize()) {
85 args.addElement("-Os");
86 } else if (optimization.isSpeed()) {
87 if ("full".equals(optimization.getValue())) {
88 args.addElement("-O2");
89 } else {
90 if ("speed".equals(optimization.getValue())) {
91 args.addElement("-O1");
92 } else {
93 args.addElement("-O3");
94 }
95 }
96 }
97 }
98 }
99 if (getIdentifier().indexOf("mingw") >= 0) {
100 if (linkType.isSubsystemConsole()) {
101 args.addElement("-mconsole");
102 }
103 if (linkType.isSubsystemGUI()) {
104 args.addElement("-mwindows");
105 }
106 }
107 if (rtti != null && !rtti.booleanValue()) {
108 args.addElement("-fno-rtti");
109 }
110
111 }
112 /**
113 * Adds an include path to the command.
114 */
115 public void addIncludePath(String path, Vector cmd) {
116 cmd.addElement("-I" + path);
117 }
118 public void addWarningSwitch(Vector args, int level) {
119 switch (level) {
120 case 0 :
121 args.addElement("-w");
122 break;
123 case 5 :
124 args.addElement("-Werror");
125 /* nobreak */
126 case 4 :
127 args.addElement("-W");
128 /* nobreak */
129 case 3 :
130 args.addElement("-Wall");
131 break;
132 }
133 }
134 public void getDefineSwitch(StringBuffer buffer, String define, String value) {
135 buffer.append("-D");
136 buffer.append(define);
137 if (value != null && value.length() > 0) {
138 buffer.append('=');
139 buffer.append(value);
140 }
141 }
142 protected File[] getEnvironmentIncludePath() {
143 return CUtil.getPathFromEnvironment("INCLUDE", ":");
144 }
145 public String getIncludeDirSwitch(String includeDir) {
146 return "-I" + includeDir;
147 }
148 public void getUndefineSwitch(StringBuffer buffer, String define) {
149 buffer.append("-U");
150 buffer.append(define);
151 }
152 }