diff options
author | Sven Gothel <[email protected]> | 2019-06-15 18:14:16 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-06-15 18:14:16 +0200 |
commit | 757192655df20cc6a68affe8cbb4d7de387c9c67 (patch) | |
tree | d3a829ebced8d74e1b80a051fd9c53ca78aca9a2 | |
parent | 241e6e391a99e95b9d9e89e3d4b4973b17033b02 (diff) |
Refine option 'usehighleveltool' implementation
continuation of commit 6523322893a0f18cef7b45e693249e147721990e
- Fix AbstractLdLinker implied args:
-- reverse '-static' usage for isStaticRuntime (misunderstood)
-- use '-r' for reloctable for isStaticLibrary
- Adding feature to LdLinker (cross and native)
3 files changed, 43 insertions, 24 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java index d70feaf..9b17bbb 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java @@ -59,8 +59,11 @@ public abstract class AbstractLdLinker extends CommandLineLinker { args.addElement("-g"); } if (isDarwin()) { - if (linkType.isStaticRuntime() || linkType.isStaticLibrary()) { + if (linkType.isStaticRuntime() ) { args.addElement("-static"); + } + if (linkType.isStaticLibrary()) { + args.addElement("-r"); // reloctable or incremental linker } else if (linkType.isPluginModule()) { args.addElement("-bundle"); } else if (linkType.isSharedLibrary()) { @@ -68,8 +71,11 @@ public abstract class AbstractLdLinker extends CommandLineLinker { args.addElement("-dynamic"); } } else { - if (linkType.isStaticRuntime() || linkType.isStaticLibrary()) { + if (linkType.isStaticRuntime() ) { args.addElement("-static"); + } + if (linkType.isStaticLibrary()) { + args.addElement("-r"); // reloctable or incremental linker } else if (linkType.isPluginModule()) { args.addElement("-shared"); } else if (linkType.isSharedLibrary()) { diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/LdLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/LdLinker.java index aaab5c7..c653f9f 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/LdLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/LdLinker.java @@ -1,5 +1,5 @@ /* - * + * * Copyright 2001-2004 The Ant-Contrib project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,10 @@ import java.io.File; import net.sf.antcontrib.cpptasks.compiler.LinkType; import net.sf.antcontrib.cpptasks.compiler.Linker; +import net.sf.antcontrib.cpptasks.gcc.cross.GccLibrarian; /** * Adapter for the 'ld' linker - * + * * @author Curt Arnold */ public final class LdLinker extends AbstractLdLinker { @@ -31,6 +32,9 @@ public final class LdLinker extends AbstractLdLinker { private static final LdLinker dllLinker = new LdLinker("ld", objFiles, discardFiles, "lib", ".so", false, new LdLinker("ld", objFiles, discardFiles, "lib", ".so", true, null)); + private static final LdLinker arLinker = new LdLinker("ld", objFiles, + discardFiles, "lib", ".a", false, new LdLinker("ld", objFiles, + discardFiles, "lib", ".a", true, null)); private static final LdLinker instance = new LdLinker("ld", objFiles, discardFiles, "", "", false, null); private static final String[] libtoolObjFiles = new String[]{".fo", ".a", @@ -39,16 +43,19 @@ public final class LdLinker extends AbstractLdLinker { return instance; } private File[] libDirs; - private LdLinker(String command, String[] extensions, - String[] ignoredExtensions, String outputPrefix, - String outputSuffix, boolean isLibtool, LdLinker libtoolLinker) { + private LdLinker(final String command, final String[] extensions, + final String[] ignoredExtensions, final String outputPrefix, + final String outputSuffix, final boolean isLibtool, final LdLinker libtoolLinker) { super(command, "-version", extensions, ignoredExtensions, outputPrefix, outputSuffix, false, isLibtool, libtoolLinker); } - public Linker getLinker(LinkType type) { - if (type.isStaticLibrary()) { + public Linker getLinker(final LinkType type) { + if ( type.isStaticLibrary() && !type.getUseHighlevelTool() ) { return GccLibrarian.getInstance(); } + if (type.isStaticLibrary()) { + return arLinker; + } if (type.isSharedLibrary()) { return dllLinker; } diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/LdLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/LdLinker.java index 6a844e6..ba6deef 100755 --- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/LdLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/LdLinker.java @@ -1,5 +1,5 @@ /* - * + * * Copyright 2001-2004 The Ant-Contrib project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +27,7 @@ import net.sf.antcontrib.cpptasks.gcc.AbstractLdLinker; import org.apache.tools.ant.BuildException; /** * Adapter for the 'ld' linker - * + * * @author Curt Arnold */ public final class LdLinker extends AbstractLdLinker { @@ -36,6 +36,9 @@ public final class LdLinker extends AbstractLdLinker { private static final String[] objFiles = new String[]{".o", ".a", ".lib", ".dll", ".so", ".sl"}; private static final String[] discardFiles = new String[0]; + private static final LdLinker arLinker = new LdLinker("ld", objFiles, + discardFiles, "lib", ".a", false, new LdLinker("ld", objFiles, + discardFiles, "lib", ".a", true, null)); private static final LdLinker dllLinker = new LdLinker("ld", objFiles, discardFiles, "lib", ".so", false, new LdLinker("ld", objFiles, discardFiles, "lib", ".so", true, null)); @@ -45,39 +48,42 @@ public final class LdLinker extends AbstractLdLinker { return instance; } private File[] libDirs; - private LdLinker(String command, String[] extensions, - String[] ignoredExtensions, String outputPrefix, - String outputSuffix, boolean isLibtool, LdLinker libtoolLinker) { + private LdLinker(final String command, final String[] extensions, + final String[] ignoredExtensions, final String outputPrefix, + final String outputSuffix, final boolean isLibtool, final LdLinker libtoolLinker) { super(command, "-version", extensions, ignoredExtensions, outputPrefix, outputSuffix, false, isLibtool, libtoolLinker); } protected Object clone() throws CloneNotSupportedException { - LdLinker clone = (LdLinker) super.clone(); + final LdLinker clone = (LdLinker) super.clone(); return clone; } - public Linker getLinker(LinkType type) { - if (type.isStaticLibrary()) { + public Linker getLinker(final LinkType type) { + if ( type.isStaticLibrary() && !type.getUseHighlevelTool() ) { return GccLibrarian.getInstance(); } + if (type.isStaticLibrary()) { + return arLinker; + } if (type.isSharedLibrary()) { return dllLinker; } return instance; } - public void link(CCTask task, File outputFile, String[] sourceFiles, - CommandLineLinkerConfiguration config) throws BuildException { + public void link(final CCTask task, final File outputFile, final String[] sourceFiles, + final CommandLineLinkerConfiguration config) throws BuildException { try { - LdLinker clone = (LdLinker) this.clone(); - LinkerParam param = config.getParam("target"); + final LdLinker clone = (LdLinker) this.clone(); + final LinkerParam param = config.getParam("target"); if (param != null) clone.setCommand(param.getValue() + "-" + this.getCommand()); clone.superlink(task, outputFile, sourceFiles, config); - } catch (CloneNotSupportedException e) { + } catch (final CloneNotSupportedException e) { superlink(task, outputFile, sourceFiles, config); } } - private void superlink(CCTask task, File outputFile, String[] sourceFiles, - CommandLineLinkerConfiguration config) throws BuildException { + private void superlink(final CCTask task, final File outputFile, final String[] sourceFiles, + final CommandLineLinkerConfiguration config) throws BuildException { super.link(task, outputFile, sourceFiles, config); } } |