]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/gcc/cross/LdLinker.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / gcc / cross / LdLinker.java
CommitLineData
878ddf1f 1/*\r
2 * \r
3 * Copyright 2001-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.gcc.cross;\r
18import java.io.File;\r
19\r
20import net.sf.antcontrib.cpptasks.CCTask;\r
21import net.sf.antcontrib.cpptasks.LinkerParam;\r
22import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;\r
23import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
24import net.sf.antcontrib.cpptasks.compiler.Linker;\r
25import net.sf.antcontrib.cpptasks.gcc.AbstractLdLinker;\r
26\r
27import org.apache.tools.ant.BuildException;\r
28/**\r
29 * Adapter for the 'ld' linker\r
30 * \r
31 * @author Curt Arnold\r
32 */\r
33public final class LdLinker extends AbstractLdLinker {\r
34 private static final String[] libtoolObjFiles = new String[]{".fo", ".a",\r
35 ".lib", ".dll", ".so", ".sl"};\r
36 private static final String[] objFiles = new String[]{".o", ".a", ".lib",\r
37 ".dll", ".so", ".sl"};\r
38 private static final String[] discardFiles = new String[0];\r
39 private static final LdLinker dllLinker = new LdLinker("ld", objFiles,\r
40 discardFiles, "lib", ".so", false, new LdLinker("ld", objFiles,\r
41 discardFiles, "lib", ".so", true, null));\r
42 private static final LdLinker instance = new LdLinker("ld", objFiles,\r
43 discardFiles, "", "", false, null);\r
44 public static LdLinker getInstance() {\r
45 return instance;\r
46 }\r
47 private File[] libDirs;\r
48 private LdLinker(String command, String[] extensions,\r
49 String[] ignoredExtensions, String outputPrefix,\r
50 String outputSuffix, boolean isLibtool, LdLinker libtoolLinker) {\r
51 super(command, "-version", extensions, ignoredExtensions, outputPrefix,\r
52 outputSuffix, isLibtool, libtoolLinker);\r
53 }\r
54 protected Object clone() throws CloneNotSupportedException {\r
55 LdLinker clone = (LdLinker) super.clone();\r
56 return clone;\r
57 }\r
58 public Linker getLinker(LinkType type) {\r
59 if (type.isStaticLibrary()) {\r
60 return GccLibrarian.getInstance();\r
61 }\r
62 if (type.isSharedLibrary()) {\r
63 return dllLinker;\r
64 }\r
65 return instance;\r
66 }\r
67 public void link(CCTask task, File outputFile, String[] sourceFiles,\r
68 CommandLineLinkerConfiguration config) throws BuildException {\r
69 try {\r
70 LdLinker clone = (LdLinker) this.clone();\r
71 LinkerParam param = config.getParam("target");\r
72 if (param != null)\r
73 clone.setCommand(param.getValue() + "-" + this.getCommand());\r
74 clone.superlink(task, outputFile, sourceFiles, config);\r
75 } catch (CloneNotSupportedException e) {\r
76 superlink(task, outputFile, sourceFiles, config);\r
77 }\r
78 }\r
79 private void superlink(CCTask task, File outputFile, String[] sourceFiles,\r
80 CommandLineLinkerConfiguration config) throws BuildException {\r
81 super.link(task, outputFile, sourceFiles, config);\r
82 }\r
83}\r