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