]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/borland/BorlandLinker.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / borland / BorlandLinker.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.Enumeration;\r
21import java.util.Vector;\r
22\r
23import net.sf.antcontrib.cpptasks.CCTask;\r
24import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker;\r
25import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;\r
26import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
27import net.sf.antcontrib.cpptasks.compiler.Linker;\r
28import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;\r
29\r
30/**\r
31 * Adapter for the Borland(r) ilink32 linker\r
32 * \r
33 * @author Curt Arnold\r
34 */\r
35public final class BorlandLinker extends CommandLineLinker {\r
36 private static final BorlandLinker dllLinker = new BorlandLinker(".dll");\r
37 private static final BorlandLinker instance = new BorlandLinker(".exe");\r
38 public static BorlandLinker getInstance() {\r
39 return instance;\r
40 }\r
41 private BorlandLinker(String outputSuffix) {\r
42 super("ilink32", "-r", new String[]{".obj", ".lib", ".res"},\r
43 new String[]{".map", ".pdb", ".lnk"}, outputSuffix, false, null);\r
44 }\r
45 protected void addBase(long base, Vector args) {\r
46 if (base >= 0) {\r
47 String baseAddr = Long.toHexString(base);\r
48 args.addElement("-b:" + baseAddr);\r
49 }\r
50 }\r
51 protected void addFixed(Boolean fixed, Vector args) {\r
52 }\r
53 protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args, Boolean defaultflag) {\r
54 if (linkType.isExecutable()) {\r
55 if (linkType.isSubsystemConsole()) {\r
56 args.addElement("/ap");\r
57 } else {\r
58 if (linkType.isSubsystemGUI()) {\r
59 args.addElement("/Tpe");\r
60 }\r
61 }\r
62 }\r
63 if (linkType.isSharedLibrary()) {\r
64 args.addElement("/Tpd");\r
65 args.addElement("/Gi");\r
66 }\r
67 }\r
68 protected void addIncremental(boolean incremental, Vector args) {\r
69 }\r
70 protected void addMap(boolean map, Vector args) {\r
71 if (!map) {\r
72 args.addElement("-x");\r
73 }\r
74 }\r
75 protected void addStack(int stack, Vector args) {\r
76 if (stack >= 0) {\r
77 String stackStr = Integer.toHexString(stack);\r
78 args.addElement("-S:" + stackStr);\r
79 }\r
80 }\r
81 /* (non-Javadoc)\r
82 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)\r
83 */\r
84 protected void addEntry(String entry, Vector args) {\r
85 }\r
86 \r
87 public String getCommandFileSwitch(String commandFile) {\r
88 return "@" + commandFile;\r
89 }\r
90 public String getIdentifier() {\r
91 return "Borland Linker";\r
92 }\r
93 public File[] getLibraryPath() {\r
94 return BorlandProcessor.getEnvironmentPath("ilink32", 'L',\r
95 new String[]{"..\\lib"});\r
96 }\r
97 public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {\r
98 return BorlandProcessor.getLibraryPatterns(libnames, libType);\r
99 }\r
100 public Linker getLinker(LinkType type) {\r
101 if (type.isStaticLibrary()) {\r
102 return BorlandLibrarian.getInstance();\r
103 }\r
104 if (type.isSharedLibrary()) {\r
105 return dllLinker;\r
106 }\r
107 return instance;\r
108 }\r
109 public int getMaximumCommandLength() {\r
110 return 1024;\r
111 }\r
112 public String[] getOutputFileSwitch(String outFile) {\r
113 return BorlandProcessor.getOutputFileSwitch(outFile);\r
114 }\r
115 protected String getStartupObject(LinkType linkType) {\r
116 if (linkType.isSharedLibrary()) {\r
117 return "c0d32.obj";\r
118 }\r
119 if (linkType.isSubsystemGUI()) {\r
120 return "c0w32.obj";\r
121 }\r
122 if (linkType.isSubsystemConsole()) {\r
123 return "c0x32.obj";\r
124 }\r
125 return null;\r
126 }\r
127 public boolean isCaseSensitive() {\r
128 return BorlandProcessor.isCaseSensitive();\r
129 }\r
130 /**\r
131 * Prepares argument list for exec command.\r
132 * \r
133 * @param outputFile\r
134 * linker output file\r
135 * @param sourceFiles\r
136 * linker input files (.obj, .o, .res)\r
137 * @param args\r
138 * linker arguments\r
139 * @return arguments for runTask\r
140 */\r
141 protected String[] prepareArguments(\r
142 CCTask task,\r
143 String outputDir, \r
144 String outputName,\r
145 String[] sourceFiles, \r
146 CommandLineLinkerConfiguration config) {\r
147 String[] preargs = config.getPreArguments();\r
148 String[] endargs = config.getEndArguments();\r
149 Vector execArgs = new Vector(preargs.length + endargs.length + 10\r
150 + sourceFiles.length);\r
151 execArgs.addElement(this.getCommand());\r
152 for (int i = 0; i < preargs.length; i++) {\r
153 execArgs.addElement(preargs[i]);\r
154 }\r
155 for (int i = 0; i < endargs.length; i++) {\r
156 execArgs.addElement(endargs[i]);\r
157 }\r
158 //\r
159 // see if the input files have any known startup obj files\r
160 //\r
161 String startup = null;\r
162 for (int i = 0; i < sourceFiles.length; i++) {\r
163 String filename = new File(sourceFiles[i]).getName().toLowerCase();\r
164 if (startup != null && filename.substring(0, 2).equals("c0")\r
165 && filename.substring(3, 5).equals("32")\r
166 && filename.substring(filename.length() - 4).equals(".obj")) {\r
167 startup = sourceFiles[i];\r
168 }\r
169 }\r
170 //\r
171 // c0w32.obj, c0x32.obj or c0d32.obj depending on\r
172 // link type\r
173 if (startup == null) {\r
174 startup = config.getStartupObject();\r
175 }\r
176 execArgs.addElement(startup);\r
177 Vector resFiles = new Vector();\r
178 Vector libFiles = new Vector();\r
179 String defFile = null;\r
180 StringBuffer buf = new StringBuffer();\r
181 for (int i = 0; i < sourceFiles.length; i++) {\r
182 String last4 = sourceFiles[i]\r
183 .substring(sourceFiles[i].length() - 4).toLowerCase();\r
184 if (last4.equals(".def")) {\r
185 defFile = quoteFilename(buf, sourceFiles[i]);\r
186 } else {\r
187 if (last4.equals(".res")) {\r
188 resFiles.addElement(quoteFilename(buf, sourceFiles[i]));\r
189 } else {\r
190 if (last4.equals(".lib")) {\r
191 libFiles.addElement(quoteFilename(buf, sourceFiles[i]));\r
192 } else {\r
193 execArgs.addElement(quoteFilename(buf, sourceFiles[i]));\r
194 }\r
195 }\r
196 }\r
197 }\r
198 //\r
199 // output file name\r
200 //\r
201 String outputFileName = new File(outputDir, outputName).toString();\r
202 execArgs.addElement("," + quoteFilename(buf, outputFileName));\r
203 if (config.getMap()) {\r
204 int lastPeriod = outputFileName.lastIndexOf('.');\r
205 String mapName;\r
206 if (lastPeriod < outputFileName.length() - 4) {\r
207 mapName = outputFileName + ".map";\r
208 } else {\r
209 mapName = outputFileName.substring(0, lastPeriod) + ".map";\r
210 }\r
211 execArgs.addElement("," + quoteFilename(buf, mapName) + ",");\r
212 } else {\r
213 execArgs.addElement(",,");\r
214 }\r
215 //\r
216 // add all the libraries\r
217 //\r
218 Enumeration libEnum = libFiles.elements();\r
219 boolean hasImport32 = false;\r
220 boolean hasCw32 = false;\r
221 while (libEnum.hasMoreElements()) {\r
222 String libName = (String) libEnum.nextElement();\r
223 if (libName.equalsIgnoreCase("import32.lib")) {\r
224 hasImport32 = true;\r
225 }\r
226 if (libName.equalsIgnoreCase("cw32.lib")) {\r
227 hasImport32 = true;\r
228 }\r
229 execArgs.addElement(quoteFilename(buf, libName));\r
230 }\r
231 if (!hasCw32) {\r
232 execArgs.addElement(quoteFilename(buf, "cw32.lib"));\r
233 }\r
234 if (!hasImport32) {\r
235 execArgs.addElement(quoteFilename(buf, "import32.lib"));\r
236 }\r
237 if (defFile == null) {\r
238 execArgs.addElement(",,");\r
239 } else {\r
240 execArgs.addElement("," + quoteFilename(buf, defFile) + ",");\r
241 }\r
242 Enumeration resEnum = resFiles.elements();\r
243 while (resEnum.hasMoreElements()) {\r
244 String resName = (String) resEnum.nextElement();\r
245 execArgs.addElement(quoteFilename(buf, resName));\r
246 }\r
247 String[] execArguments = new String[execArgs.size()];\r
248 execArgs.copyInto(execArguments);\r
249 return execArguments;\r
250 }\r
251 /**\r
252 * Prepares argument list to execute the linker using a response file.\r
253 * \r
254 * @param outputFile\r
255 * linker output file\r
256 * @param args\r
257 * output of prepareArguments\r
258 * @return arguments for runTask\r
259 */\r
260 protected String[] prepareResponseFile(File outputFile, String[] args)\r
261 throws IOException {\r
262 return BorlandProcessor.prepareResponseFile(outputFile, args, " + \n");\r
263 }\r
264}\r