3 * Copyright 2001-2004 The Ant-Contrib project
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package net
.sf
.antcontrib
.cpptasks
.gcc
.cross
;
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
;
27 import org
.apache
.tools
.ant
.BuildException
;
29 * Adapter for the 'ld' linker
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() {
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
);
54 protected Object
clone() throws CloneNotSupportedException
{
55 LdLinker clone
= (LdLinker
) super.clone();
58 public Linker
getLinker(LinkType type
) {
59 if (type
.isStaticLibrary()) {
60 return GccLibrarian
.getInstance();
62 if (type
.isSharedLibrary()) {
67 public void link(CCTask task
, File outputFile
, String
[] sourceFiles
,
68 CommandLineLinkerConfiguration config
) throws BuildException
{
70 LdLinker clone
= (LdLinker
) this.clone();
71 LinkerParam param
= config
.getParam("target");
73 clone
.setCommand(param
.getValue() + "-" + this.getCommand());
74 clone
.superlink(task
, outputFile
, sourceFiles
, config
);
75 } catch (CloneNotSupportedException e
) {
76 superlink(task
, outputFile
, sourceFiles
, config
);
79 private void superlink(CCTask task
, File outputFile
, String
[] sourceFiles
,
80 CommandLineLinkerConfiguration config
) throws BuildException
{
81 super.link(task
, outputFile
, sourceFiles
, config
);