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
;
20 import net
.sf
.antcontrib
.cpptasks
.CCTask
;
21 import net
.sf
.antcontrib
.cpptasks
.compiler
.CommandLineCompiler
;
22 import net
.sf
.antcontrib
.cpptasks
.compiler
.CommandLineCompilerConfiguration
;
23 import net
.sf
.antcontrib
.cpptasks
.compiler
.LinkType
;
24 import net
.sf
.antcontrib
.cpptasks
.compiler
.Linker
;
25 import net
.sf
.antcontrib
.cpptasks
.compiler
.Processor
;
26 import net
.sf
.antcontrib
.cpptasks
.compiler
.ProgressMonitor
;
27 import net
.sf
.antcontrib
.cpptasks
.parser
.CParser
;
28 import net
.sf
.antcontrib
.cpptasks
.parser
.Parser
;
29 import net
.sf
.antcontrib
.cpptasks
.OptimizationEnum
;
31 import org
.apache
.tools
.ant
.BuildException
;
32 import org
.apache
.tools
.ant
.types
.Environment
;
34 * Adapter for the Borland(r) brc32 Resource compiler.
38 public class BorlandResourceCompiler
extends CommandLineCompiler
{
39 private static final BorlandResourceCompiler instance
= new BorlandResourceCompiler(
41 public static BorlandResourceCompiler
getInstance() {
44 private BorlandResourceCompiler(boolean newEnvironment
, Environment env
) {
45 super("brc32", "c:\\__bogus\\__bogus.rc", new String
[]{".rc"},
46 new String
[]{".h", ".hpp", ".inl"}, ".res", false, null,
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
) {
60 args
.addElement("-r");
62 protected void addWarningSwitch(Vector args
, int level
) {
64 public Processor
changeEnvironment(boolean newEnvironment
, Environment env
) {
65 if (newEnvironment
|| env
!= null) {
66 return new BorlandResourceCompiler(newEnvironment
, env
);
70 public void compile(CCTask task
, File outputDir
, String
[] sourceFiles
,
71 String
[] args
, String
[] endArgs
, boolean relentless
,
72 CommandLineCompilerConfiguration config
, ProgressMonitor monitor
)
73 throws BuildException
{
74 super.compile(task
, outputDir
, sourceFiles
, args
, endArgs
, relentless
,
78 * The include parser for C will work just fine, but we didn't want to
79 * inherit from CommandLineCCompiler
81 protected Parser
createParser(File source
) {
84 protected int getArgumentCountPerInputFile() {
87 protected void getDefineSwitch(StringBuffer buffer
, String define
,
90 buffer
.append(define
);
91 if (value
!= null && value
.length() > 0) {
96 protected File
[] getEnvironmentIncludePath() {
97 return BorlandProcessor
.getEnvironmentPath("brc32", 'i',
98 new String
[]{"..\\include"});
100 protected String
getIncludeDirSwitch(String includeDir
) {
101 return BorlandProcessor
.getIncludeDirSwitch("-i", includeDir
);
103 protected String
getInputFileArgument(File outputDir
, String filename
,
106 String outputFileName
= getOutputFileName(filename
);
107 String fullOutputName
= new File(outputDir
, outputFileName
)
109 return "-fo" + fullOutputName
;
113 public Linker
getLinker(LinkType type
) {
114 return BorlandLinker
.getInstance().getLinker(type
);
116 public int getMaximumCommandLength() {
119 protected int getMaximumInputFilesPerCommand() {
122 protected int getTotalArgumentLengthForInputFile(File outputDir
,
124 String arg1
= getInputFileArgument(outputDir
, inputFile
, 0);
125 String arg2
= getInputFileArgument(outputDir
, inputFile
, 1);
126 return arg1
.length() + arg2
.length() + 2;
128 protected void getUndefineSwitch(StringBuffer buffer
, String define
) {