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
.borland
;
19 import java
.util
.Vector
;
21 import net
.sf
.antcontrib
.cpptasks
.compiler
.CommandLineCompilerConfiguration
;
22 import net
.sf
.antcontrib
.cpptasks
.compiler
.CompilerConfiguration
;
23 import net
.sf
.antcontrib
.cpptasks
.compiler
.LinkType
;
24 import net
.sf
.antcontrib
.cpptasks
.compiler
.Linker
;
25 import net
.sf
.antcontrib
.cpptasks
.compiler
.PrecompilingCommandLineCCompiler
;
26 import net
.sf
.antcontrib
.cpptasks
.compiler
.Processor
;
27 import net
.sf
.antcontrib
.cpptasks
.OptimizationEnum
;
29 import org
.apache
.tools
.ant
.types
.Environment
;
31 * Adapter for the Borland(r) C/C++ compiler.
35 public class BorlandCCompiler
extends PrecompilingCommandLineCCompiler
{
36 private static final String
[] headerExtensions
= new String
[]{".h", ".hpp",
38 private static final String
[] sourceExtensions
= new String
[]{".c", ".cc",
39 ".cpp", ".cxx", ".c++"};
40 private static final BorlandCCompiler instance
= new BorlandCCompiler(
42 public static BorlandCCompiler
getInstance() {
45 private BorlandCCompiler(boolean newEnvironment
, Environment env
) {
46 super("bcc32", "--version", sourceExtensions
, headerExtensions
, ".obj", false,
47 null, newEnvironment
, env
);
49 protected void addImpliedArgs(final Vector args
,
51 final boolean multithreaded
,
52 final boolean exceptions
,
53 final LinkType linkType
,
55 final OptimizationEnum optimization
,
56 final Boolean defaultflag
) {
57 args
.addElement("-c");
59 // turn off compiler autodependency since
61 args
.addElement("-X");
63 args
.addElement("-x");
65 args
.addElement("-x-");
68 args
.addElement("-tWM");
71 args
.addElement("-Od");
72 args
.addElement("-v");
74 if (optimization
!= null) {
75 if (optimization
.isSpeed()) {
76 args
.addElement("-O1");
78 if (optimization
.isSpeed()) {
79 args
.addElement("-O2");
81 if (optimization
.isNoOptimization()) {
82 args
.addElement("-Od");
88 if (rtti
!= null && !rtti
.booleanValue()) {
89 args
.addElement("-RT-");
92 protected void addWarningSwitch(Vector args
, int level
) {
93 BorlandProcessor
.addWarningSwitch(args
, level
);
95 public Processor
changeEnvironment(boolean newEnvironment
, Environment env
) {
96 if (newEnvironment
|| env
!= null) {
97 return new BorlandCCompiler(newEnvironment
, env
);
101 protected CompilerConfiguration
createPrecompileGeneratingConfig(
102 CommandLineCompilerConfiguration baseConfig
, File prototype
,
103 String lastInclude
) {
104 String
[] additionalArgs
= new String
[]{"-H=" + lastInclude
, "-Hc"};
105 return new CommandLineCompilerConfiguration(baseConfig
, additionalArgs
,
108 protected CompilerConfiguration
createPrecompileUsingConfig(
109 CommandLineCompilerConfiguration baseConfig
, File prototype
,
110 String lastInclude
, String
[] exceptFiles
) {
111 String
[] additionalArgs
= new String
[]{"-Hu"};
112 return new CommandLineCompilerConfiguration(baseConfig
, additionalArgs
,
115 protected void getDefineSwitch(StringBuffer buffer
, String define
,
117 BorlandProcessor
.getDefineSwitch(buffer
, define
, value
);
119 protected File
[] getEnvironmentIncludePath() {
120 return BorlandProcessor
.getEnvironmentPath("bcc32", 'I',
121 new String
[]{"..\\include"});
123 protected String
getIncludeDirSwitch(String includeDir
) {
124 return BorlandProcessor
.getIncludeDirSwitch("-I", includeDir
);
126 public Linker
getLinker(LinkType type
) {
127 return BorlandLinker
.getInstance().getLinker(type
);
129 public int getMaximumCommandLength() {
132 protected void getUndefineSwitch(StringBuffer buffer
, String define
) {
133 BorlandProcessor
.getUndefineSwitch(buffer
, define
);