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
.io
.IOException
;
20 import java
.util
.Vector
;
21 import org
.apache
.tools
.ant
.BuildException
;
23 import net
.sf
.antcontrib
.cpptasks
.CUtil
;
24 import net
.sf
.antcontrib
.cpptasks
.compiler
.CommandLineLinker
;
25 import net
.sf
.antcontrib
.cpptasks
.compiler
.LinkType
;
26 import net
.sf
.antcontrib
.cpptasks
.compiler
.Linker
;
27 import net
.sf
.antcontrib
.cpptasks
.CCTask
;
28 import net
.sf
.antcontrib
.cpptasks
.compiler
.CommandLineLinkerConfiguration
;
29 import net
.sf
.antcontrib
.cpptasks
.types
.LibraryTypeEnum
;
32 * Adapter for the Borland(r) tlib Librarian
36 public class BorlandLibrarian
extends CommandLineLinker
{
37 private static final BorlandLibrarian instance
= new BorlandLibrarian();
38 public static BorlandLibrarian
getInstance() {
41 private BorlandLibrarian() {
42 super("tlib", "--version", new String
[]{".obj"}, new String
[0], ".lib", false,
45 protected void addBase(long base
, Vector args
) {
47 protected void addFixed(Boolean fixed
, Vector args
) {
49 protected void addImpliedArgs(boolean debug
, LinkType linkType
, Vector args
, Boolean defaultflag
) {
51 protected void addIncremental(boolean incremental
, Vector args
) {
53 protected void addMap(boolean map
, Vector args
) {
55 protected void addStack(int stack
, Vector args
) {
58 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)
60 protected void addEntry(String entry
, Vector args
) {
63 protected String
getCommandFileSwitch(String cmdFile
) {
64 return BorlandProcessor
.getCommandFileSwitch(cmdFile
);
66 public File
[] getLibraryPath() {
67 return CUtil
.getPathFromEnvironment("LIB", ";");
69 public String
[] getLibraryPatterns(String
[] libnames
, LibraryTypeEnum libType
) {
70 return BorlandProcessor
.getLibraryPatterns(libnames
, libType
);
72 public Linker
getLinker(LinkType type
) {
73 return BorlandLinker
.getInstance().getLinker(type
);
75 public int getMaximumCommandLength() {
78 public String
[] getOutputFileSwitch(String outFile
) {
79 return BorlandProcessor
.getOutputFileSwitch(outFile
);
81 public boolean isCaseSensitive() {
82 return BorlandProcessor
.isCaseSensitive();
85 * Gets identifier for the linker.
87 * TLIB will lockup when attempting to get version
88 * information. Since the Librarian version isn't critical
89 * just return a stock response.
91 public String
getIdentifier() {
92 return "TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation";
96 * Prepares argument list for exec command.
101 * linker input files (.obj, .o, .res)
104 * @return arguments for runTask
106 protected String
[] prepareArguments(
110 String
[] sourceFiles
,
111 CommandLineLinkerConfiguration config
) {
112 String
[] preargs
= config
.getPreArguments();
113 String
[] endargs
= config
.getEndArguments();
114 StringBuffer buf
= new StringBuffer();
115 Vector execArgs
= new Vector(preargs
.length
+ endargs
.length
+ 10
116 + sourceFiles
.length
);
118 execArgs
.addElement(this.getCommand());
119 String outputFileName
= new File(outputDir
, outputName
).toString();
120 execArgs
.addElement(quoteFilename(buf
, outputFileName
));
122 for (int i
= 0; i
< preargs
.length
; i
++) {
123 execArgs
.addElement(preargs
[i
]);
127 // add a place-holder for page size
129 int pageSizeIndex
= execArgs
.size();
130 execArgs
.addElement(null);
134 for (int i
= 0; i
< sourceFiles
.length
; i
++) {
135 String last4
= sourceFiles
[i
]
136 .substring(sourceFiles
[i
].length() - 4).toLowerCase();
137 if (last4
.equals(".def")) {
139 if (last4
.equals(".res")) {
141 if (last4
.equals(".lib")) {
143 execArgs
.addElement("+" + quoteFilename(buf
, sourceFiles
[i
]));
144 objBytes
+= new File(sourceFiles
[i
]).length();
150 for (int i
= 0; i
< endargs
.length
; i
++) {
151 execArgs
.addElement(endargs
[i
]);
154 String
[] execArguments
= new String
[execArgs
.size()];
155 execArgs
.copyInto(execArguments
);
157 int minPageSize
= objBytes
>> 16;
159 for(int i
= 4; i
<= 15; i
++) {
161 if (pageSize
> minPageSize
) break;
163 execArguments
[pageSizeIndex
] = "/P" + Integer
.toString(pageSize
);
165 return execArguments
;
169 * Prepares argument list to execute the linker using a response file.
174 * output of prepareArguments
175 * @return arguments for runTask
177 protected String
[] prepareResponseFile(File outputFile
, String
[] args
)
179 return BorlandProcessor
.prepareResponseFile(outputFile
, args
, " & \n");
186 public void link(CCTask task
,
188 String
[] sourceFiles
,
189 CommandLineLinkerConfiguration config
)
190 throws BuildException
193 // delete any existing library
196 // build a new library
197 super.link(task
, outputFile
, sourceFiles
, config
);