+++ /dev/null
-/*\r
- *\r
- * Copyright 2002-2004 The Ant-Contrib project\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package net.sf.antcontrib.cpptasks.gcc;\r
-import java.io.File;\r
-import java.util.Vector;\r
-import net.sf.antcontrib.cpptasks.CUtil;\r
-import net.sf.antcontrib.cpptasks.compiler.CommandLineCCompiler;\r
-import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
-import org.apache.tools.ant.types.Environment;\r
-import net.sf.antcontrib.cpptasks.OptimizationEnum;\r
-\r
-/**\r
- * Abstract base class for compilers that attempt to be command line compatible\r
- * with GCC\r
- *\r
- * @author Adam Murdoch\r
- * @author Curt Arnold\r
- */\r
-public abstract class GccCompatibleCCompiler extends CommandLineCCompiler {\r
- private final static String[] headerExtensions = new String[]{".h", ".hpp",\r
- ".inl"};\r
- private final static String[] sourceExtensions = new String[]{".c", ".cc",\r
- ".cpp", ".cxx", ".c++", ".i", ".f", ".for"};\r
- private final static String[] defaultflags = new String[]{"-c"};\r
- /**\r
- * Private constructor. Use GccCCompiler.getInstance() to get singleton\r
- * instance of this class.\r
- */\r
- protected GccCompatibleCCompiler(String command, String identifierArg,\r
- boolean libtool, GccCompatibleCCompiler libtoolCompiler,\r
- boolean newEnvironment, Environment env) {\r
- super(command, identifierArg, sourceExtensions, headerExtensions,\r
- libtool ? ".fo" : ".o", libtool, libtoolCompiler,\r
- newEnvironment, env);\r
- }\r
- /**\r
- * Private constructor. Use GccCCompiler.getInstance() to get singleton\r
- * instance of this class.\r
- */\r
- protected GccCompatibleCCompiler(String command, String identifierArg,\r
- String[] sourceExtensions, String[] headerExtensions,\r
- boolean libtool, GccCompatibleCCompiler libtoolCompiler,\r
- boolean newEnvironment, Environment env) {\r
- super(command, identifierArg, sourceExtensions, headerExtensions,\r
- libtool ? ".fo" : ".o", libtool, libtoolCompiler,\r
- newEnvironment, env);\r
- }\r
- public void addImpliedArgs(final Vector args,\r
- final boolean debug,\r
- final boolean multithreaded,\r
- final boolean exceptions,\r
- final LinkType linkType,\r
- final Boolean rtti,\r
- final OptimizationEnum optimization,\r
- final Boolean defaultflag) {\r
- //\r
- // -fPIC is too much trouble\r
- // users have to manually add it for\r
- // operating systems that make sense\r
- //\r
- if (defaultflag != null && defaultflag.booleanValue()) {\r
- for (int i = 0; i < defaultflags.length; i++) {\r
- args.addElement(defaultflags[i]);\r
- }\r
- }\r
- if (debug) {\r
- args.addElement("-g");\r
- } else {\r
- if (optimization != null) {\r
- if (optimization.isSize()) {\r
- args.addElement("-Os");\r
- } else if (optimization.isSpeed()) {\r
- if ("full".equals(optimization.getValue())) {\r
- args.addElement("-O2");\r
- } else {\r
- if ("speed".equals(optimization.getValue())) {\r
- args.addElement("-O1");\r
- } else {\r
- args.addElement("-O3");\r
- }\r
- }\r
- }\r
- }\r
- }\r
- if (getIdentifier().indexOf("mingw") >= 0) {\r
- if (linkType.isSubsystemConsole()) {\r
- args.addElement("-mconsole");\r
- }\r
- if (linkType.isSubsystemGUI()) {\r
- args.addElement("-mwindows");\r
- }\r
- }\r
- if (rtti != null && !rtti.booleanValue()) {\r
- args.addElement("-fno-rtti");\r
- }\r
-\r
- }\r
- /**\r
- * Adds an include path to the command.\r
- */\r
- public void addIncludePath(String path, Vector cmd) {\r
- cmd.addElement("-I" + path);\r
- }\r
- public void addWarningSwitch(Vector args, int level) {\r
- switch (level) {\r
- case 0 :\r
- args.addElement("-w");\r
- break;\r
- case 5 :\r
- args.addElement("-Werror");\r
- /* nobreak */\r
- case 4 :\r
- args.addElement("-W");\r
- /* nobreak */\r
- case 3 :\r
- args.addElement("-Wall");\r
- break;\r
- }\r
- }\r
- public void getDefineSwitch(StringBuffer buffer, String define, String value) {\r
- buffer.append("-D");\r
- buffer.append(define);\r
- if (value != null && value.length() > 0) {\r
- buffer.append('=');\r
- buffer.append(value);\r
- }\r
- }\r
- protected File[] getEnvironmentIncludePath() {\r
- return CUtil.getPathFromEnvironment("INCLUDE", ":");\r
- }\r
- public String getIncludeDirSwitch(String includeDir) {\r
- return "-I" + includeDir;\r
- }\r
- public void getUndefineSwitch(StringBuffer buffer, String define) {\r
- buffer.append("-U");\r
- buffer.append(define);\r
- }\r
-}\r