From e1933c74b9c256332cd12c9a1094e4687b535112 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 10 Dec 2019 18:40:13 +0100 Subject: Bug 1417 Android clang support: Introduce clangLinkerOption '-target ' Also move isGCC and new isCLANG to CommandLineLinker --- .../cpptasks/compiler/CommandLineLinker.java | 14 +++++++++++++- .../net/sf/antcontrib/cpptasks/gcc/GnuLinker.java | 21 +++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java index 8b8ff89..321bd29 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java @@ -53,6 +53,8 @@ public abstract class CommandLineLinker extends AbstractLinker private final CommandLineLinker libtoolLinker; private final boolean newEnvironment = false; private final String outputSuffix; + private final boolean isGCC; + private final boolean isCLANG; /** Creates a comand line linker invocation @@ -70,6 +72,8 @@ public abstract class CommandLineLinker extends AbstractLinker this.isLibtool = isLibtool; this.isXcoderun = isXCoderun; this.libtoolLinker = libtoolLinker; + isGCC = "gcc".equals(command); + isCLANG = "clang".equals(command); } public CommandLineLinker(final CommandLineLinker ld, final boolean isXCoderun) { super(ld); @@ -79,6 +83,8 @@ public abstract class CommandLineLinker extends AbstractLinker this.isLibtool = ld.isLibtool; this.isXcoderun = isXCoderun; this.libtoolLinker = ld.libtoolLinker; + isGCC = "gcc".equals(command); + isCLANG = "clang".equals(command); } protected abstract void addBase(long base, Vector args); @@ -243,9 +249,15 @@ public abstract class CommandLineLinker extends AbstractLinker protected final boolean getLibtool() { return isLibtool; } - protected final boolean getXcodeRun() { + protected final boolean isXcodeRun() { return isXcoderun; } + protected final boolean isGCC() { + return isGCC; + } + protected final boolean isCLANG() { + return isCLANG; + } /** * Performs a link using a command line linker * diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java index 7307d74..2e4e29b 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java @@ -12,8 +12,8 @@ import net.sf.antcontrib.cpptasks.compiler.Linker; public abstract class GnuLinker extends AbstractLdLinker { static String[] darwinLinkerOptions = new String[]{"-arch", "-weak_framework", "-lazy_framework", "-weak_library" }; + static String[] clangLinkerOptions = new String[]{"-target" }; - protected final boolean isGCC; protected File[] libDirs; public GnuLinker(final String command, final String identifierArg, final String[] extensions, @@ -23,12 +23,10 @@ public abstract class GnuLinker extends AbstractLdLinker { super(command, identifierArg, extensions, ignoredExtensions, outputPrefix, outputSuffix, isXCoderun, isLibtool, libtoolLinker); - isGCC = "gcc".equals(command); } public GnuLinker(final AbstractLdLinker ld, final boolean isXCoderun) { super(ld, isXCoderun); - isGCC = "gcc".equals(getCommand()); } protected abstract String[] getStaticLinkerOptions(); @@ -102,6 +100,9 @@ public abstract class GnuLinker extends AbstractLdLinker { boolean known = false; final HashSet allLinkerOptions = new HashSet(); allLinkerOptions.addAll(Arrays.asList(getStaticLinkerOptions())); + if( isCLANG() ) { + allLinkerOptions.addAll(Arrays.asList(clangLinkerOptions)); + } if (isDarwin()) { allLinkerOptions.addAll(Arrays.asList(darwinLinkerOptions)); } @@ -126,26 +127,26 @@ public abstract class GnuLinker extends AbstractLdLinker { } if (type.isStaticLibrary()) { if (isDarwin()) { - return isGCC ? getStaticMachArLinker() : ( getXcodeRun() ? getStaticXcodeMachArClangLinker() : getStaticMachArClangLinker() ); + return isGCC() ? getStaticMachArLinker() : ( isXcodeRun() ? getStaticXcodeMachArClangLinker() : getStaticMachArClangLinker() ); } else { - return isGCC ? getStaticArLinker() : getStaticArClangLinker(); + return isGCC() ? getStaticArLinker() : getStaticArClangLinker(); } } if (type.isPluginModule()) { if (isDarwin()) { - return isGCC ? getStaticMachBundleLinker() : ( getXcodeRun() ? getStaticXcodeMachClangBundleLinker() : getStaticMachClangBundleLinker() ); + return isGCC() ? getStaticMachBundleLinker() : ( isXcodeRun() ? getStaticXcodeMachClangBundleLinker() : getStaticMachClangBundleLinker() ); } else { - return isGCC ? getStaticDllLinker() : getStaticDllClangLinker(); + return isGCC() ? getStaticDllLinker() : getStaticDllClangLinker(); } } if (type.isSharedLibrary()) { if (isDarwin()) { - return isGCC ? getStaticMachDllLinker() : ( getXcodeRun() ? getStaticXcodeMachDllClangLinker() : getStaticMachDllClangLinker() ); + return isGCC() ? getStaticMachDllLinker() : ( isXcodeRun() ? getStaticXcodeMachDllClangLinker() : getStaticMachDllClangLinker() ); } else { - return isGCC ? getStaticDllLinker() : getStaticDllClangLinker(); + return isGCC() ? getStaticDllLinker() : getStaticDllClangLinker(); } } - return isGCC ? getStaticInstance() : ( getXcodeRun() ? getStaticXcodeClangInstance() : getStaticClangInstance() ) ; + return isGCC() ? getStaticInstance() : ( isXcodeRun() ? getStaticXcodeClangInstance() : getStaticClangInstance() ) ; } } \ No newline at end of file -- cgit v1.2.3