3 * Copyright 2002-2004 The Ant-Contrib project
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package net
.sf
.antcontrib
.cpptasks
.gcc
;
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
;
27 * Abstract base class for compilers that attempt to be command line compatible
30 * @author Adam Murdoch
33 public abstract class GccCompatibleCCompiler
extends CommandLineCCompiler
{
34 private final static String
[] headerExtensions
= new String
[]{".h", ".hpp",
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"};
40 * Private constructor. Use GccCCompiler.getInstance() to get singleton
41 * instance of this class.
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
,
51 * Private constructor. Use GccCCompiler.getInstance() to get singleton
52 * instance of this class.
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
,
62 public void addImpliedArgs(final Vector args
,
64 final boolean multithreaded
,
65 final boolean exceptions
,
66 final LinkType linkType
,
68 final OptimizationEnum optimization
,
69 final Boolean defaultflag
) {
71 // -fPIC is too much trouble
72 // users have to manually add it for
73 // operating systems that make sense
75 if (defaultflag
!= null && defaultflag
.booleanValue()) {
76 for (int i
= 0; i
< defaultflags
.length
; i
++) {
77 args
.addElement(defaultflags
[i
]);
81 args
.addElement("-g");
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");
90 if ("speed".equals(optimization
.getValue())) {
91 args
.addElement("-O1");
93 args
.addElement("-O3");
99 if (getIdentifier().indexOf("mingw") >= 0) {
100 if (linkType
.isSubsystemConsole()) {
101 args
.addElement("-mconsole");
103 if (linkType
.isSubsystemGUI()) {
104 args
.addElement("-mwindows");
107 if (rtti
!= null && !rtti
.booleanValue()) {
108 args
.addElement("-fno-rtti");
113 * Adds an include path to the command.
115 public void addIncludePath(String path
, Vector cmd
) {
116 cmd
.addElement("-I" + path
);
118 public void addWarningSwitch(Vector args
, int level
) {
121 args
.addElement("-w");
124 args
.addElement("-Werror");
127 args
.addElement("-W");
130 args
.addElement("-Wall");
134 public void getDefineSwitch(StringBuffer buffer
, String define
, String value
) {
136 buffer
.append(define
);
137 if (value
!= null && value
.length() > 0) {
139 buffer
.append(value
);
142 protected File
[] getEnvironmentIncludePath() {
143 return CUtil
.getPathFromEnvironment("INCLUDE", ":");
145 public String
getIncludeDirSwitch(String includeDir
) {
146 return "-I" + includeDir
;
148 public void getUndefineSwitch(StringBuffer buffer
, String define
) {
150 buffer
.append(define
);