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
.sun
;
19 import java
.util
.Vector
;
21 import net
.sf
.antcontrib
.cpptasks
.CUtil
;
22 import net
.sf
.antcontrib
.cpptasks
.compiler
.AbstractCompiler
;
23 import net
.sf
.antcontrib
.cpptasks
.compiler
.CommandLineCCompiler
;
24 import net
.sf
.antcontrib
.cpptasks
.compiler
.LinkType
;
25 import net
.sf
.antcontrib
.cpptasks
.compiler
.Linker
;
26 import net
.sf
.antcontrib
.cpptasks
.compiler
.Processor
;
27 import net
.sf
.antcontrib
.cpptasks
.OptimizationEnum
;
30 import org
.apache
.tools
.ant
.types
.Environment
;
32 * Adapter for the Sun C89 C++ Compiler
34 * @author Hiram Chirino (cojonudo14@hotmail.com)
36 public class C89CCompiler
extends CommandLineCCompiler
{
37 private static final AbstractCompiler instance
= new C89CCompiler(false,
39 public static AbstractCompiler
getInstance() {
42 private C89CCompiler(boolean newEnvironment
, Environment env
) {
43 super("c89", null, new String
[]{".c", ".cc", ".cpp", ".cxx", ".c++"},
44 new String
[]{".h", ".hpp"}, ".o", false, null, newEnvironment
,
47 protected void addImpliedArgs(
50 final boolean multithreaded
,
51 final boolean exceptions
,
52 final LinkType linkType
,
54 final OptimizationEnum optimization
,
55 final Boolean defaultflag
) {
56 // Specifies that only compilations and assemblies be done.
57 args
.addElement("-c");
59 * if (exceptions) { args.addElement("/GX"); }
62 args
.addElement("-g");
63 args
.addElement("-D_DEBUG");
65 * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
66 * args.addElement("/MTd"); } else { args.addElement("/MDd");
67 * args.addElement("/D_DLL"); } } else { args.addElement("/MLd"); }
70 args
.addElement("-DNDEBUG");
72 * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
73 * args.addElement("/MT"); } else { args.addElement("/MD");
74 * args.addElement("/D_DLL"); } } else { args.addElement("/ML"); }
78 protected void addWarningSwitch(Vector args
, int level
) {
79 C89Processor
.addWarningSwitch(args
, level
);
81 public Processor
changeEnvironment(boolean newEnvironment
, Environment env
) {
82 if (newEnvironment
|| env
!= null) {
83 return new C89CCompiler(newEnvironment
, env
);
87 protected void getDefineSwitch(StringBuffer buf
, String define
, String value
) {
88 C89Processor
.getDefineSwitch(buf
, define
, value
);
90 protected File
[] getEnvironmentIncludePath() {
91 return CUtil
.getPathFromEnvironment("INCLUDE", ":");
93 protected String
getIncludeDirSwitch(String includeDir
) {
94 return C89Processor
.getIncludeDirSwitch(includeDir
);
96 public Linker
getLinker(LinkType type
) {
97 return C89Linker
.getInstance().getLinker(type
);
99 public int getMaximumCommandLength() {
100 return Integer
.MAX_VALUE
;
102 /* Only compile one file at time for now */
103 protected int getMaximumInputFilesPerCommand() {
106 protected void getUndefineSwitch(StringBuffer buf
, String define
) {
107 C89Processor
.getUndefineSwitch(buf
, define
);