]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / borland / BorlandLibrarian.java
1 /*
2 *
3 * Copyright 2002-2004 The Ant-Contrib project
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17 package net.sf.antcontrib.cpptasks.borland;
18 import java.io.File;
19 import java.io.IOException;
20 import java.util.Vector;
21 import org.apache.tools.ant.BuildException;
22
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;
30
31 /**
32 * Adapter for the Borland(r) tlib Librarian
33 *
34 * @author Curt Arnold
35 */
36 public class BorlandLibrarian extends CommandLineLinker {
37 private static final BorlandLibrarian instance = new BorlandLibrarian();
38 public static BorlandLibrarian getInstance() {
39 return instance;
40 }
41 private BorlandLibrarian() {
42 super("tlib", "--version", new String[]{".obj"}, new String[0], ".lib", false,
43 null);
44 }
45 protected void addBase(long base, Vector args) {
46 }
47 protected void addFixed(Boolean fixed, Vector args) {
48 }
49 protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args, Boolean defaultflag) {
50 }
51 protected void addIncremental(boolean incremental, Vector args) {
52 }
53 protected void addMap(boolean map, Vector args) {
54 }
55 protected void addStack(int stack, Vector args) {
56 }
57 /* (non-Javadoc)
58 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)
59 */
60 protected void addEntry(String entry, Vector args) {
61 }
62
63 protected String getCommandFileSwitch(String cmdFile) {
64 return BorlandProcessor.getCommandFileSwitch(cmdFile);
65 }
66 public File[] getLibraryPath() {
67 return CUtil.getPathFromEnvironment("LIB", ";");
68 }
69 public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
70 return BorlandProcessor.getLibraryPatterns(libnames, libType);
71 }
72 public Linker getLinker(LinkType type) {
73 return BorlandLinker.getInstance().getLinker(type);
74 }
75 public int getMaximumCommandLength() {
76 return 1024;
77 }
78 public String[] getOutputFileSwitch(String outFile) {
79 return BorlandProcessor.getOutputFileSwitch(outFile);
80 }
81 public boolean isCaseSensitive() {
82 return BorlandProcessor.isCaseSensitive();
83 }
84 /**
85 * Gets identifier for the linker.
86 *
87 * TLIB will lockup when attempting to get version
88 * information. Since the Librarian version isn't critical
89 * just return a stock response.
90 */
91 public String getIdentifier() {
92 return "TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation";
93 }
94
95 /**
96 * Prepares argument list for exec command.
97 *
98 * @param outputFile
99 * linker output file
100 * @param sourceFiles
101 * linker input files (.obj, .o, .res)
102 * @param args
103 * linker arguments
104 * @return arguments for runTask
105 */
106 protected String[] prepareArguments(
107 CCTask task,
108 String outputDir,
109 String outputName,
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);
117
118 execArgs.addElement(this.getCommand());
119 String outputFileName = new File(outputDir, outputName).toString();
120 execArgs.addElement(quoteFilename(buf, outputFileName));
121
122 for (int i = 0; i < preargs.length; i++) {
123 execArgs.addElement(preargs[i]);
124 }
125
126 //
127 // add a place-holder for page size
128 //
129 int pageSizeIndex = execArgs.size();
130 execArgs.addElement(null);
131
132 int objBytes = 0;
133
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")) {
138 } else {
139 if (last4.equals(".res")) {
140 } else {
141 if (last4.equals(".lib")) {
142 } else {
143 execArgs.addElement("+" + quoteFilename(buf, sourceFiles[i]));
144 objBytes += new File(sourceFiles[i]).length();
145 }
146 }
147 }
148 }
149
150 for (int i = 0; i < endargs.length; i++) {
151 execArgs.addElement(endargs[i]);
152 }
153
154 String[] execArguments = new String[execArgs.size()];
155 execArgs.copyInto(execArguments);
156
157 int minPageSize = objBytes >> 16;
158 int pageSize = 0;
159 for(int i = 4; i <= 15; i++) {
160 pageSize = 1 << i;
161 if (pageSize > minPageSize) break;
162 }
163 execArguments[pageSizeIndex] = "/P" + Integer.toString(pageSize);
164
165 return execArguments;
166 }
167
168 /**
169 * Prepares argument list to execute the linker using a response file.
170 *
171 * @param outputFile
172 * linker output file
173 * @param args
174 * output of prepareArguments
175 * @return arguments for runTask
176 */
177 protected String[] prepareResponseFile(File outputFile, String[] args)
178 throws IOException {
179 return BorlandProcessor.prepareResponseFile(outputFile, args, " & \n");
180 }
181
182 /**
183 * Builds a library
184 *
185 */
186 public void link(CCTask task,
187 File outputFile,
188 String[] sourceFiles,
189 CommandLineLinkerConfiguration config)
190 throws BuildException
191 {
192 //
193 // delete any existing library
194 outputFile.delete();
195 //
196 // build a new library
197 super.link(task, outputFile, sourceFiles, config);
198 }
199
200 }