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