summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/sf/antcontrib/cpptasks/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/sf/antcontrib/cpptasks/gcc')
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractArLibrarian.java2
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java14
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCCompiler.java74
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java23
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java191
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java139
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java183
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/LdLinker.java2
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/WindresResourceCompiler.java12
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccCCompiler.java4
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccLinker.java2
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GppLinker.java2
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/LdLinker.java2
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccCCompiler.java4
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccLinker.java2
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GppLinker.java2
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/LdLinker.java2
17 files changed, 402 insertions, 258 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractArLibrarian.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractArLibrarian.java
index 2e8d4af..3b496b9 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractArLibrarian.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractArLibrarian.java
@@ -40,7 +40,7 @@ public abstract class AbstractArLibrarian extends CommandLineLinker {
String outputPrefix, String outputExtension, boolean isLibtool,
AbstractArLibrarian libtoolLibrarian) {
super(command, identificationArg, inputExtensions, ignoredExtensions,
- outputExtension, isLibtool, libtoolLibrarian);
+ outputExtension, false, isLibtool, libtoolLibrarian);
this.outputPrefix = outputPrefix;
}
public void addBase(long base, Vector args) {
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 0a0f5ff..3ee7f8e 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java
@@ -33,15 +33,19 @@ import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
* @author Curt Arnold
*/
public abstract class AbstractLdLinker extends CommandLineLinker {
- private String outputPrefix;
+ private final String outputPrefix;
protected AbstractLdLinker(String command, String identifierArg,
String[] extensions, String[] ignoredExtensions,
- String outputPrefix, String outputSuffix, boolean isLibtool,
- AbstractLdLinker libtoolLinker) {
+ String outputPrefix, String outputSuffix, boolean isXCoderun,
+ boolean isLibtool, AbstractLdLinker libtoolLinker) {
super(command, identifierArg, extensions, ignoredExtensions,
- outputSuffix, isLibtool, libtoolLinker);
+ outputSuffix, isXCoderun, isLibtool, libtoolLinker);
this.outputPrefix = outputPrefix;
}
+ protected AbstractLdLinker(AbstractLdLinker ld, boolean isXCoderun) {
+ super(ld, isXCoderun);
+ this.outputPrefix = ld.outputPrefix;
+ }
public void addBase(long base, Vector args) {
if (base >= 0) {
args.addElement("--image-base");
@@ -292,7 +296,7 @@ public abstract class AbstractLdLinker extends CommandLineLinker {
//
// null out any sources that correspond to library names
//
- String[] localSources = (String[]) sourceFiles.clone();
+ String[] localSources = sourceFiles.clone();
int extra = 0;
for (int i = 0; i < libnames.length; i++) {
String libname = libnames[i];
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCCompiler.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCCompiler.java
index fb831e1..da6de52 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCCompiler.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCCompiler.java
@@ -53,28 +53,28 @@ public final class GccCCompiler extends GccCompatibleCCompiler {
".inl"};
private static final GccCCompiler cppInstance = new GccCCompiler("c++",
sourceExtensions, headerExtensions, false,
- new GccCCompiler("c++", sourceExtensions, headerExtensions, true,
- null, false, null), false, null);
+ false, new GccCCompiler("c++", sourceExtensions, headerExtensions, false,
+ true, null, false, null), false, null);
private static final GccCCompiler g77Instance = new GccCCompiler("g77",
sourceExtensions, headerExtensions, false,
- new GccCCompiler("g77", sourceExtensions, headerExtensions, true,
- null, false, null), false, null);
+ false, new GccCCompiler("g77", sourceExtensions, headerExtensions, false,
+ true, null, false, null), false, null);
private static final GccCCompiler gppInstance = new GccCCompiler("g++",
sourceExtensions, headerExtensions, false,
- new GccCCompiler("g++", sourceExtensions, headerExtensions, true,
- null, false, null), false, null);
+ false, new GccCCompiler("g++", sourceExtensions, headerExtensions, false,
+ true, null, false, null), false, null);
private static final GccCCompiler instance = new GccCCompiler("gcc",
sourceExtensions, headerExtensions, false,
- new GccCCompiler("gcc", sourceExtensions, headerExtensions, true,
- null, false, null), false, null);
+ false, new GccCCompiler("gcc", sourceExtensions, headerExtensions, false,
+ true, null, false, null), false, null);
private static final GccCCompiler clangInstance = new GccCCompiler("clang",
sourceExtensions, headerExtensions, false,
- new GccCCompiler("clang", sourceExtensions, headerExtensions, true,
- null, false, null), false, null);
+ false, new GccCCompiler("clang", sourceExtensions, headerExtensions, false,
+ true, null, false, null), false, null);
private static final GccCCompiler cpplangInstance = new GccCCompiler("clang++",
sourceExtensions, headerExtensions, false,
- new GccCCompiler("clang++", sourceExtensions, headerExtensions, true,
- null, false, null), false, null);
+ false, new GccCCompiler("clang++", sourceExtensions, headerExtensions, false,
+ true, null, false, null), false, null);
/**
* Gets c++ adapter
*/
@@ -111,21 +111,53 @@ public final class GccCCompiler extends GccCompatibleCCompiler {
public static GccCCompiler getCPPLangInstance() {
return cpplangInstance;
}
+ /**
+ * Gets XCode clang adapter
+ */
+ public static GccCCompiler getXCodeCLangInstance() {
+ return createXCodeRun(clangInstance);
+ }
+ /**
+ * Gets clang++ adapter
+ */
+ public static GccCCompiler getXCodeCPPLangInstance() {
+ return createXCodeRun(cpplangInstance);
+ }
private String identifier;
private File[] includePath;
private boolean isPICMeaningful = true;
/**
* Private constructor. Use GccCCompiler.getInstance() to get singleton
* instance of this class.
+ * @param isXCoderun TODO
*/
private GccCCompiler(String command, String[] sourceExtensions,
- String[] headerExtensions, boolean isLibtool,
- GccCCompiler libtoolCompiler, boolean newEnvironment,
- Environment env) {
- super(command, null, sourceExtensions, headerExtensions, isLibtool,
- libtoolCompiler, newEnvironment, env);
+ String[] headerExtensions, boolean isXCoderun,
+ boolean isLibtool, GccCCompiler libtoolCompiler,
+ boolean newEnvironment, Environment env) {
+ super(command, null, sourceExtensions, headerExtensions, isXCoderun,
+ isLibtool, libtoolCompiler, newEnvironment, env);
isPICMeaningful = System.getProperty("os.name").indexOf("Windows") < 0;
}
+ private GccCCompiler(GccCCompiler cc, boolean isXcoderun) {
+ super(cc, isXcoderun);
+ isPICMeaningful = cc.isPICMeaningful;
+ }
+ private static GccCCompiler createXCodeRun(GccCCompiler cc) {
+ /**
+ super(command, null, sourceExtensions, headerExtensions, isXCoderun,
+ isLibtool, libtoolCompiler, newEnvironment, env);
+ */
+ final GccCCompiler libtoolCC = (GccCCompiler)cc.getLibtoolCompiler();
+ final GccCCompiler libtoolCCXCR;
+ if( null != libtoolCC ) {
+ libtoolCCXCR = new GccCCompiler(libtoolCC, true /* isXCoderun */);
+ } else {
+ libtoolCCXCR = null;
+ }
+ return new GccCCompiler(cc, true /* isXCoderun */);
+ }
+
public void addImpliedArgs(final Vector args,
final boolean debug,
final boolean multithreaded,
@@ -142,9 +174,9 @@ public final class GccCCompiler extends GccCompatibleCCompiler {
public Processor changeEnvironment(boolean newEnvironment, Environment env) {
if (newEnvironment || env != null) {
return new GccCCompiler(getCommand(), this.getSourceExtensions(),
- this.getHeaderExtensions(), this.getLibtool(),
- (GccCCompiler) this.getLibtoolCompiler(), newEnvironment,
- env);
+ this.getHeaderExtensions(), false,
+ this.getLibtool(), (GccCCompiler) this.getLibtoolCompiler(),
+ newEnvironment, env);
}
return this;
}
@@ -234,7 +266,7 @@ public final class GccCCompiler extends GccCompatibleCCompiler {
}
}
}
- return (File[]) includePath.clone();
+ return includePath.clone();
}
public String getIdentifier() throws BuildException {
if (identifier == null) {
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java
index 0485fba..1a698c1 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java
@@ -35,29 +35,32 @@ public abstract class GccCompatibleCCompiler extends CommandLineCCompiler {
".inl"};
private final static String[] sourceExtensions = new String[]{".c", ".cc",
".cpp", ".cxx", ".c++", ".i", ".f", ".for"};
+
+ protected GccCompatibleCCompiler(GccCompatibleCCompiler cc, boolean isXcoderun) {
+ super(cc, isXcoderun);
+ }
/**
* Private constructor. Use GccCCompiler.getInstance() to get singleton
* instance of this class.
+ * @param isXcoderun TODO
*/
protected GccCompatibleCCompiler(String command, String identifierArg,
- boolean libtool, GccCompatibleCCompiler libtoolCompiler,
+ boolean isXcoderun, boolean libtool, GccCompatibleCCompiler libtoolCompiler,
boolean newEnvironment, Environment env) {
super(command, identifierArg, sourceExtensions, headerExtensions,
- libtool ? ".fo" : ".o", libtool, libtoolCompiler,
- newEnvironment, env);
+ libtool ? ".fo" : ".o", isXcoderun, libtool,
+ libtoolCompiler, newEnvironment, env);
}
- /**
- * Private constructor. Use GccCCompiler.getInstance() to get singleton
- * instance of this class.
- */
+
protected GccCompatibleCCompiler(String command, String identifierArg,
String[] sourceExtensions, String[] headerExtensions,
- boolean libtool, GccCompatibleCCompiler libtoolCompiler,
+ boolean isXcoderun, boolean libtool, GccCompatibleCCompiler libtoolCompiler,
boolean newEnvironment, Environment env) {
- super(command, identifierArg, sourceExtensions, headerExtensions,
- libtool ? ".fo" : ".o", libtool, libtoolCompiler,
+ super(command, identifierArg, sourceExtensions, headerExtensions,
+ libtool ? ".fo" : ".o", isXcoderun, libtool, libtoolCompiler,
newEnvironment, env);
}
+
public void addImpliedArgs(final Vector args,
final boolean debug,
final boolean multithreaded,
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java
index 52a5473..4f3d7f0 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java
@@ -1,5 +1,5 @@
/*
- *
+ *
* Copyright 2002-2004 The Ant-Contrib project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,136 +15,123 @@
* limitations under the License.
*/
package net.sf.antcontrib.cpptasks.gcc;
+
import java.io.File;
-import java.util.Vector;
-import java.util.HashSet;
-import java.util.Arrays;
import net.sf.antcontrib.cpptasks.CUtil;
-import net.sf.antcontrib.cpptasks.compiler.LinkType;
-import net.sf.antcontrib.cpptasks.compiler.Linker;
+
/**
* Adapter for the GCC linker
- *
+ *
* @author Adam Murdoch, et.al.
*/
-public class GccLinker extends AbstractLdLinker {
+public class GccLinker extends GnuLinker {
private static final String[] discardFiles = new String[0];
private static final String[] objFiles = new String[]{".o", ".a", ".lib",
".dll", ".so", ".sl"};
private static final String[] libtoolObjFiles = new String[]{".fo", ".a",
".lib", ".dll", ".so", ".sl"};
- private static String[] linkerOptions = new String[]{"-bundle",
+ private static final String[] linkerOptions = new String[]{"-bundle",
"-dynamiclib", "-nostartfiles", "-nostdlib", "-prebind", "-noprebind", "-s",
"-static", "-shared", "-symbolic", "-Xlinker",
- "--export-all-symbols", "-static-libgcc",};
- private static String[] darwinLinkerOptions = new String[]{"-arch", "-weak_framework", "-lazy_framework", "-weak_library" };
-
- private static final GccLinker dllLinker = new GccLinker("gcc", objFiles,
+ "--export-all-symbols", "-static-libgcc",};
+
+ private static final GccLinker dllLinker = new GccLinker("gcc", objFiles,
discardFiles, "lib", ".so", false, new GccLinker("gcc", objFiles, discardFiles, "lib", ".so", true, null));
- private static final GccLinker dllCLangLinker = new GccLinker("clang", objFiles,
+ private static final GccLinker dllClangLinker = new GccLinker("clang", objFiles,
discardFiles, "lib", ".so", false, new GccLinker("clang", objFiles, discardFiles, "lib", ".so", true, null));
-
+
private static final GccLinker instance = new GccLinker("gcc", objFiles,
discardFiles, "", "", false, null);
private static final GccLinker clangInstance = new GccLinker("clang", objFiles,
discardFiles, "", "", false, null);
-
+ private static final GccLinker xcodeClangInstance = new GccLinker(clangInstance, true);
+
private static final GccLinker machBundleLinker = new GccLinker("gcc",
objFiles, discardFiles, "lib", ".bundle", false, null);
- private static final GccLinker machCLangBundleLinker = new GccLinker("clang",
+ private static final GccLinker machClangBundleLinker = new GccLinker("clang",
objFiles, discardFiles, "lib", ".bundle", false, null);
-
+ private static final GccLinker xcodeMachClangBundleLinker = new GccLinker(machClangBundleLinker, true);
+
private static final GccLinker machDllLinker = new GccLinker("gcc",
objFiles, discardFiles, "lib", ".dylib", false, null);
- private static final GccLinker machDllCLangLinker = new GccLinker("clang",
+ private static final GccLinker machDllClangLinker = new GccLinker("clang",
objFiles, discardFiles, "lib", ".dylib", false, null);
-
+ private static final GccLinker xcodeMachDllClangLinker = new GccLinker(machDllClangLinker, true);
+
public static GccLinker getInstance() {
return instance;
}
- public static GccLinker getCLangInstance() {
+ public static GccLinker getClangInstance() {
return clangInstance;
}
- private final boolean isGCC;
- private File[] libDirs;
+ public static GccLinker getXcodeClangInstance() {
+ return xcodeClangInstance;
+ }
+
protected GccLinker(String command, String[] extensions,
String[] ignoredExtensions, String outputPrefix,
String outputSuffix, boolean isLibtool, GccLinker libtoolLinker) {
super(command, "-dumpversion", extensions, ignoredExtensions,
- outputPrefix, outputSuffix, isLibtool, libtoolLinker);
- isGCC = "gcc".equals(command);
- }
- protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
- super.addImpliedArgs(debug, linkType, args);
- if (getIdentifier().indexOf("mingw") >= 0) {
- if (linkType.isSubsystemConsole()) {
- args.addElement("-mconsole");
- }
- if (linkType.isSubsystemGUI()) {
- args.addElement("-mwindows");
- }
- }
+ outputPrefix, outputSuffix, false, isLibtool, libtoolLinker);
+ }
+ protected GccLinker(GccLinker ld, boolean isXCoderun) {
+ super(ld, isXCoderun);
}
- /**
- * Allows drived linker to decorate linker option. Override by GccLinker to
- * prepend a "-Wl," to pass option to through gcc to linker.
- *
- * @param buf
- * buffer that may be used and abused in the decoration process,
- * must not be null.
- * @param arg
- * linker argument
- */
- public String decorateLinkerOption(StringBuffer buf, String arg) {
- String decoratedArg = arg;
- if (arg.startsWith("--sysroot")) {
- return arg;
- }
- if (arg.startsWith("-nostdlib")) {
- return arg;
- }
- if (arg.length() > 1 && arg.charAt(0) == '-') {
- switch (arg.charAt(1)) {
- //
- // passed automatically by GCC
- //
- case 'g' :
- case 'f' :
- case 'F' :
- /* Darwin */
- case 'm' :
- case 'O' :
- case 'W' :
- case 'l' :
- case 'L' :
- case 'u' :
- case 'v' :
- break;
- default :
- boolean known = false;
- HashSet allLinkerOptions = new HashSet();
- allLinkerOptions.addAll(Arrays.asList(linkerOptions));
- if (isDarwin()) {
- allLinkerOptions.addAll(Arrays.asList(darwinLinkerOptions));
- }
- known = allLinkerOptions.contains(arg);
- if (!known) {
- buf.setLength(0);
- buf.append("-Wl,");
- buf.append(arg);
- decoratedArg = buf.toString();
- }
- break;
- }
- }
- return decoratedArg;
+ @Override
+ protected final String[] getStaticLinkerOptions() { return linkerOptions; }
+
+ @Override
+ protected final GnuLinker getStaticDllLinker() {
+ return dllLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticDllClangLinker() {
+ return dllClangLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticClangInstance() {
+ return clangInstance;
+ }
+ @Override
+ protected final GnuLinker getStaticXcodeClangInstance() {
+ return xcodeClangInstance;
+ }
+ @Override
+ protected final GnuLinker getStaticMachBundleLinker() {
+ return machBundleLinker;
}
+ @Override
+ protected final GnuLinker getStaticMachClangBundleLinker() {
+ return machClangBundleLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticXcodeMachClangBundleLinker() {
+ return xcodeMachClangBundleLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticMachDllLinker() {
+ return machDllLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticMachDllClangLinker() {
+ return machDllClangLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticXcodeMachDllClangLinker() {
+ return xcodeMachDllClangLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticInstance() {
+ return instance;
+ }
+
/**
* Returns library path.
- *
+ *
*/
+ @Override
public File[] getLibraryPath() {
if (libDirs == null) {
//
@@ -157,8 +144,8 @@ public class GccLinker extends AbstractLdLinker {
//
// build default path from gcc and system /lib and /lib/w32api
//
- String[] impliedLibPath = new String[]{buf.toString(),
- "/lib/w32api", "/lib"};
+ // String[] impliedLibPath = new String[]{buf.toString(), "/lib/w32api", "/lib"};
+
//
// read gcc specs file for other library paths
//
@@ -214,24 +201,4 @@ public class GccLinker extends AbstractLdLinker {
}
return libDirs;
}
- public Linker getLinker(LinkType type) {
- if (type.isStaticLibrary()) {
- return GccLibrarian.getInstance(); // uses 'ar', which is 'gcc' agnostic
- }
- if (type.isPluginModule()) {
- if (isDarwin()) {
- return isGCC ? machBundleLinker : machCLangBundleLinker;
- } else {
- return isGCC ? dllLinker : dllCLangLinker;
- }
- }
- if (type.isSharedLibrary()) {
- if (isDarwin()) {
- return isGCC ? machDllLinker : machDllCLangLinker;
- } else {
- return isGCC ? dllLinker : dllCLangLinker;
- }
- }
- return isGCC ? instance : clangInstance;
- }
}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java
new file mode 100644
index 0000000..cbd30ea
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java
@@ -0,0 +1,139 @@
+package net.sf.antcontrib.cpptasks.gcc;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+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" };
+
+ protected final boolean isGCC;
+ protected File[] libDirs;
+
+ public GnuLinker(String command, String identifierArg, String[] extensions,
+ String[] ignoredExtensions, String outputPrefix,
+ String outputSuffix, boolean isXCoderun, boolean isLibtool,
+ AbstractLdLinker libtoolLinker) {
+ super(command, identifierArg, extensions, ignoredExtensions,
+ outputPrefix, outputSuffix, isXCoderun, isLibtool,
+ libtoolLinker);
+ isGCC = "gcc".equals(command);
+ }
+
+ public GnuLinker(AbstractLdLinker ld, boolean isXCoderun) {
+ super(ld, isXCoderun);
+ isGCC = "gcc".equals(getCommand());
+ }
+
+ protected abstract String[] getStaticLinkerOptions();
+ protected abstract GnuLinker getStaticDllLinker();
+ protected abstract GnuLinker getStaticDllClangLinker();
+ protected abstract GnuLinker getStaticClangInstance();
+ protected abstract GnuLinker getStaticXcodeClangInstance();
+ protected abstract GnuLinker getStaticMachBundleLinker();
+ protected abstract GnuLinker getStaticMachClangBundleLinker();
+ protected abstract GnuLinker getStaticXcodeMachClangBundleLinker();
+ protected abstract GnuLinker getStaticMachDllLinker();
+ protected abstract GnuLinker getStaticMachDllClangLinker();
+ protected abstract GnuLinker getStaticXcodeMachDllClangLinker();
+ protected abstract GnuLinker getStaticInstance();
+
+ @Override
+ protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
+ super.addImpliedArgs(debug, linkType, args);
+ if (getIdentifier().indexOf("mingw") >= 0) {
+ if (linkType.isSubsystemConsole()) {
+ args.addElement("-mconsole");
+ }
+ if (linkType.isSubsystemGUI()) {
+ args.addElement("-mwindows");
+ }
+ }
+ }
+
+ /**
+ * Allows drived linker to decorate linker option. Override by GccLinker to
+ * prepend a "-Wl," to pass option to through gcc to linker.
+ *
+ * @param buf
+ * buffer that may be used and abused in the decoration process,
+ * must not be null.
+ * @param arg
+ * linker argument
+ */
+ @Override
+ public String decorateLinkerOption(StringBuffer buf, String arg) {
+ if (arg.startsWith("--sysroot")) {
+ return arg;
+ }
+ if (arg.startsWith("-nostdlib")) {
+ return arg;
+ }
+ String decoratedArg = arg;
+ if (arg.length() > 1 && arg.charAt(0) == '-') {
+ switch (arg.charAt(1)) {
+ //
+ // passed automatically by GCC
+ //
+ case 'g' :
+ case 'f' :
+ case 'F' :
+ /* Darwin */
+ case 'm' :
+ case 'O' :
+ case 'W' :
+ case 'l' :
+ case 'L' :
+ case 'u' :
+ case 'v' :
+ break;
+ default :
+ boolean known = false;
+ HashSet<String> allLinkerOptions = new HashSet<String>();
+ allLinkerOptions.addAll(Arrays.asList(getStaticLinkerOptions()));
+ if (isDarwin()) {
+ allLinkerOptions.addAll(Arrays.asList(darwinLinkerOptions));
+ }
+ known = allLinkerOptions.contains(arg);
+
+ if (!known) {
+ buf.setLength(0);
+ buf.append("-Wl,");
+ buf.append(arg);
+ decoratedArg = buf.toString();
+ }
+ break;
+ }
+ }
+ return decoratedArg;
+ }
+
+ @Override
+ public Linker getLinker(LinkType type) {
+ if (type.isStaticLibrary()) {
+ return GccLibrarian.getInstance(); // uses 'ar', which is 'gcc' agnostic
+ }
+ if (type.isPluginModule()) {
+ if (isDarwin()) {
+ return isGCC ? getStaticMachBundleLinker() : ( getXcodeRun() ? getStaticXcodeMachClangBundleLinker() : getStaticMachClangBundleLinker() );
+ } else {
+ return isGCC ? getStaticDllLinker() : getStaticDllClangLinker();
+ }
+ }
+ if (type.isSharedLibrary()) {
+ if (isDarwin()) {
+ return isGCC ? getStaticMachDllLinker() : ( getXcodeRun() ? getStaticXcodeMachDllClangLinker() : getStaticMachDllClangLinker() );
+ } else {
+ return isGCC ? getStaticDllLinker() : getStaticDllClangLinker();
+ }
+ }
+ return isGCC ? getStaticInstance() : ( getXcodeRun() ? getStaticXcodeClangInstance() : getStaticClangInstance() ) ;
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java
index 4dfe771..1ca34b5 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java
@@ -1,5 +1,5 @@
/*
- *
+ *
* Copyright 2003-2004 The Ant-Contrib project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +16,8 @@
*/
package net.sf.antcontrib.cpptasks.gcc;
import java.io.File;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Vector;
import net.sf.antcontrib.cpptasks.CCTask;
@@ -26,54 +28,116 @@ import net.sf.antcontrib.cpptasks.compiler.Linker;
import net.sf.antcontrib.cpptasks.types.LibrarySet;
/**
* Adapter for the g++ variant of the GCC linker
- *
+ *
* @author Stephen M. Webb <[email protected]>, et.al.
*/
-public class GppLinker extends AbstractLdLinker {
+public class GppLinker extends GnuLinker {
protected static final String[] discardFiles = new String[0];
protected static final String[] objFiles = new String[]{".o", ".a", ".lib",
".dll", ".so", ".sl"};
- private static final GppLinker dllLinker = new GppLinker("gcc", objFiles,
- discardFiles, "lib", ".so", false, new GppLinker("gcc", objFiles,
- discardFiles, "lib", ".so", true, null));
private final static String libPrefix = "libraries: =";
- protected static final String[] libtoolObjFiles = new String[]{".fo", ".a",
+ private static final String[] libtoolObjFiles = new String[]{".fo", ".a",
".lib", ".dll", ".so", ".sl"};
private static String[] linkerOptions = new String[]{"-bundle", "-dylib",
"-dynamic", "-dynamiclib", "-nostartfiles", "-nostdlib",
"-prebind", "-s", "-static", "-shared", "-symbolic", "-Xlinker"};
+
+ private static final GppLinker dllLinker = new GppLinker("gcc", objFiles,
+ discardFiles, "lib", ".so", false, false, new GppLinker("gcc", objFiles,
+ discardFiles, "lib", ".so", false, true, null));
+ private static final GppLinker dllClangLinker = new GppLinker("clang", objFiles,
+ discardFiles, "lib", ".so", false, false, new GppLinker("clang", objFiles,
+ discardFiles, "lib", ".so", false, true, null));
+
private static final GppLinker instance = new GppLinker("gcc", objFiles,
- discardFiles, "", "", false, null);
+ discardFiles, "", "", false, false, null);
private static final GppLinker clangInstance = new GppLinker("clang", objFiles,
- discardFiles, "", "", false, null);
+ discardFiles, "", "", false, false, null);
+ private static final GppLinker xcodeClangInstance = new GppLinker(clangInstance, true);
+
+ private static final GppLinker machBundleLinker = new GppLinker("gcc",
+ objFiles, discardFiles, "lib", ".bundle", false, false, null);
+ private static final GppLinker machClangBundleLinker = new GppLinker("clang",
+ objFiles, discardFiles, "lib", ".bundle", false, false, null);
+ private static final GppLinker xcodeMachClangBundleLinker = new GppLinker(machClangBundleLinker, true);
+
private static final GppLinker machDllLinker = new GppLinker("gcc",
- objFiles, discardFiles, "lib", ".dylib", false, null);
- private static final GppLinker machPluginLinker = new GppLinker("gcc",
- objFiles, discardFiles, "lib", ".bundle", false, null);
+ objFiles, discardFiles, "lib", ".dylib", false, false, null);
+ private static final GppLinker machDllClangLinker = new GppLinker("clang",
+ objFiles, discardFiles, "lib", ".dylib", false, false, null);
+ private static final GppLinker xcodeMachDllClangLinker = new GppLinker(machDllClangLinker, true);
+
public static GppLinker getInstance() {
return instance;
}
- public static GppLinker getCLangInstance() {
+ public static GppLinker getClangInstance() {
return clangInstance;
}
- private File[] libDirs;
+ public static GppLinker getXcodeClangInstance() {
+ return xcodeClangInstance;
+ }
private String runtimeLibrary;
protected GppLinker(String command, String[] extensions,
String[] ignoredExtensions, String outputPrefix,
- String outputSuffix, boolean isLibtool, GppLinker libtoolLinker) {
+ String outputSuffix, boolean isXCoderun, boolean isLibtool, GppLinker libtoolLinker) {
super(command, "-dumpversion", extensions, ignoredExtensions,
- outputPrefix, outputSuffix, isLibtool, libtoolLinker);
+ outputPrefix, outputSuffix, false, isLibtool, libtoolLinker);
+ }
+ protected GppLinker(GppLinker ld, boolean isXCoderun) {
+ super(ld, isXCoderun);
+ }
+
+ @Override
+ protected final String[] getStaticLinkerOptions() { return linkerOptions; }
+
+ @Override
+ protected final GnuLinker getStaticDllLinker() {
+ return dllLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticDllClangLinker() {
+ return dllClangLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticClangInstance() {
+ return clangInstance;
+ }
+ @Override
+ protected final GnuLinker getStaticXcodeClangInstance() {
+ return xcodeClangInstance;
+ }
+ @Override
+ protected final GnuLinker getStaticMachBundleLinker() {
+ return machBundleLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticMachClangBundleLinker() {
+ return machClangBundleLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticXcodeMachClangBundleLinker() {
+ return xcodeMachClangBundleLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticMachDllLinker() {
+ return machDllLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticMachDllClangLinker() {
+ return machDllClangLinker;
}
+ @Override
+ protected final GnuLinker getStaticXcodeMachDllClangLinker() {
+ return xcodeMachDllClangLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticInstance() {
+ return instance;
+ }
+
+ @Override
protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
super.addImpliedArgs(debug, linkType, args);
- if (getIdentifier().indexOf("mingw") >= 0) {
- if (linkType.isSubsystemConsole()) {
- args.addElement("-mconsole");
- }
- if (linkType.isSubsystemGUI()) {
- args.addElement("-mwindows");
- }
- }
if (linkType.isStaticRuntime()) {
String[] cmdin = new String[]{"g++", "-print-file-name=libstdc++.a"};
String[] cmdout = CaptureStreamHandler.run(cmdin);
@@ -86,6 +150,7 @@ public class GppLinker extends AbstractLdLinker {
runtimeLibrary = "-lstdc++";
}
}
+ @Override
public String[] addLibrarySets(CCTask task, LibrarySet[] libsets,
Vector preargs, Vector midargs, Vector endargs) {
String[] rs = super.addLibrarySets(task, libsets, preargs, midargs,
@@ -96,56 +161,10 @@ public class GppLinker extends AbstractLdLinker {
return rs;
}
/**
- * Allows drived linker to decorate linker option. Override by GppLinker to
- * prepend a "-Wl," to pass option to through gcc to linker.
- *
- * @param buf
- * buffer that may be used and abused in the decoration process,
- * must not be null.
- * @param arg
- * linker argument
- */
- public String decorateLinkerOption(StringBuffer buf, String arg) {
- String decoratedArg = arg;
- if (arg.length() > 1 && arg.charAt(0) == '-') {
- switch (arg.charAt(1)) {
- //
- // passed automatically by GCC
- //
- case 'g' :
- case 'f' :
- case 'F' :
- /* Darwin */
- case 'm' :
- case 'O' :
- case 'W' :
- case 'l' :
- case 'L' :
- case 'u' :
- break;
- default :
- boolean known = false;
- for (int i = 0; i < linkerOptions.length; i++) {
- if (linkerOptions[i].equals(arg)) {
- known = true;
- break;
- }
- }
- if (!known) {
- buf.setLength(0);
- buf.append("-Wl,");
- buf.append(arg);
- decoratedArg = buf.toString();
- }
- break;
- }
- }
- return decoratedArg;
- }
- /**
* Returns library path.
- *
+ *
*/
+ @Override
public File[] getLibraryPath() {
if (libDirs == null) {
Vector dirs = new Vector();
@@ -185,24 +204,4 @@ public class GppLinker extends AbstractLdLinker {
}
return libDirs;
}
- public Linker getLinker(LinkType type) {
- if (type.isStaticLibrary()) {
- return GccLibrarian.getInstance();
- }
- if (type.isPluginModule()) {
- if (GccProcessor.getMachine().indexOf("darwin") >= 0) {
- return machPluginLinker;
- } else {
- return dllLinker;
- }
- }
- if (type.isSharedLibrary()) {
- if (GccProcessor.getMachine().indexOf("darwin") >= 0) {
- return machDllLinker;
- } else {
- return dllLinker;
- }
- }
- return instance;
- }
}
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 2104e34..aaab5c7 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/LdLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/LdLinker.java
@@ -43,7 +43,7 @@ public final class LdLinker extends AbstractLdLinker {
String[] ignoredExtensions, String outputPrefix,
String outputSuffix, boolean isLibtool, LdLinker libtoolLinker) {
super(command, "-version", extensions, ignoredExtensions, outputPrefix,
- outputSuffix, isLibtool, libtoolLinker);
+ outputSuffix, false, isLibtool, libtoolLinker);
}
public Linker getLinker(LinkType type) {
if (type.isStaticLibrary()) {
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/WindresResourceCompiler.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/WindresResourceCompiler.java
index a617024..24b3948 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/WindresResourceCompiler.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/WindresResourceCompiler.java
@@ -1,5 +1,5 @@
/*
- *
+ *
* Copyright 2008 The Ant-Contrib project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +29,7 @@ import net.sf.antcontrib.cpptasks.OptimizationEnum;
import org.apache.tools.ant.types.Environment;
/**
* Adapter for the GNU windres resource compiler.
- *
+ *
* @author Curt Arnold
*/
public final class WindresResourceCompiler extends CommandLineCompiler {
@@ -40,12 +40,12 @@ public final class WindresResourceCompiler extends CommandLineCompiler {
}
private WindresResourceCompiler(boolean newEnvironment, Environment env) {
super("windres", null, new String[]{".rc"}, new String[]{".h", ".hpp",
- ".inl"}, ".o", false, null, newEnvironment, env);
+ ".inl"}, ".o", false, false, null, newEnvironment, env);
}
- protected void addImpliedArgs(final Vector args,
+ protected void addImpliedArgs(final Vector args,
final boolean debug,
- final boolean multithreaded,
- final boolean exceptions,
+ final boolean multithreaded,
+ final boolean exceptions,
final LinkType linkType,
final Boolean rtti,
final OptimizationEnum optimization) {
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccCCompiler.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccCCompiler.java
index 86a8ac7..0662c3f 100755
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccCCompiler.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccCCompiler.java
@@ -105,8 +105,8 @@ public final class GccCCompiler extends GccCompatibleCCompiler {
String[] headerExtensions, boolean isLibtool,
GccCCompiler libtoolCompiler, boolean newEnvironment,
Environment env) {
- super(command, null, sourceExtensions, headerExtensions, isLibtool,
- libtoolCompiler, newEnvironment, env);
+ super(command, null, sourceExtensions, headerExtensions, false,
+ isLibtool, libtoolCompiler, newEnvironment, env);
isPICMeaningful = System.getProperty("os.name").indexOf("Windows") < 0;
}
public void addImpliedArgs(final Vector args,
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccLinker.java
index 4347211..fa2daff 100755
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccLinker.java
@@ -57,7 +57,7 @@ public class GccLinker extends AbstractLdLinker {
String[] ignoredExtensions, String outputPrefix,
String outputSuffix, boolean isLibtool, GccLinker libtoolLinker) {
super(command, "-dumpversion", extensions, ignoredExtensions,
- outputPrefix, outputSuffix, isLibtool, libtoolLinker);
+ outputPrefix, outputSuffix, false, isLibtool, libtoolLinker);
}
protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
super.addImpliedArgs(debug, linkType, args);
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GppLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GppLinker.java
index b332c64..319668b 100755
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GppLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GppLinker.java
@@ -62,7 +62,7 @@ public class GppLinker extends AbstractLdLinker {
String[] ignoredExtensions, String outputPrefix,
String outputSuffix, boolean isLibtool, GppLinker libtoolLinker) {
super(command, "-dumpversion", extensions, ignoredExtensions,
- outputPrefix, outputSuffix, isLibtool, libtoolLinker);
+ outputPrefix, outputSuffix, false, isLibtool, libtoolLinker);
}
protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
super.addImpliedArgs(debug, linkType, args);
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 26abf8c..6a844e6 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
@@ -49,7 +49,7 @@ public final class LdLinker extends AbstractLdLinker {
String[] ignoredExtensions, String outputPrefix,
String outputSuffix, boolean isLibtool, LdLinker libtoolLinker) {
super(command, "-version", extensions, ignoredExtensions, outputPrefix,
- outputSuffix, isLibtool, libtoolLinker);
+ outputSuffix, false, isLibtool, libtoolLinker);
}
protected Object clone() throws CloneNotSupportedException {
LdLinker clone = (LdLinker) super.clone();
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccCCompiler.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccCCompiler.java
index 44dd968..4e1568e 100755
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccCCompiler.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccCCompiler.java
@@ -104,8 +104,8 @@ public final class GccCCompiler extends GccCompatibleCCompiler {
String[] headerExtensions, boolean isLibtool,
GccCCompiler libtoolCompiler, boolean newEnvironment,
Environment env) {
- super(command, null, sourceExtensions, headerExtensions, isLibtool,
- libtoolCompiler, newEnvironment, env);
+ super(command, null, sourceExtensions, headerExtensions, false,
+ isLibtool, libtoolCompiler, newEnvironment, env);
isPICMeaningful = System.getProperty("os.name").indexOf("Windows") < 0;
}
public void addImpliedArgs(final Vector args,
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccLinker.java
index d7dd3db..89897dc 100755
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccLinker.java
@@ -58,7 +58,7 @@ public class GccLinker extends AbstractLdLinker {
String[] ignoredExtensions, String outputPrefix,
String outputSuffix, boolean isLibtool, GccLinker libtoolLinker) {
super(command, "-dumpversion", extensions, ignoredExtensions,
- outputPrefix, outputSuffix, isLibtool, libtoolLinker);
+ outputPrefix, outputSuffix, false, isLibtool, libtoolLinker);
}
protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
super.addImpliedArgs(debug, linkType, args);
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GppLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GppLinker.java
index 45bbea9..1404e6b 100755
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GppLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GppLinker.java
@@ -62,7 +62,7 @@ public class GppLinker extends AbstractLdLinker {
String[] ignoredExtensions, String outputPrefix,
String outputSuffix, boolean isLibtool, GppLinker libtoolLinker) {
super(command, "-dumpversion", extensions, ignoredExtensions,
- outputPrefix, outputSuffix, isLibtool, libtoolLinker);
+ outputPrefix, outputSuffix, false, isLibtool, libtoolLinker);
}
protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
super.addImpliedArgs(debug, linkType, args);
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/LdLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/LdLinker.java
index 0cc5fbf..c6370c7 100755
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/LdLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/LdLinker.java
@@ -46,7 +46,7 @@ public final class LdLinker extends AbstractLdLinker {
String[] ignoredExtensions, String outputPrefix,
String outputSuffix, boolean isLibtool, LdLinker libtoolLinker) {
super(command, "-version", extensions, ignoredExtensions, outputPrefix,
- outputSuffix, isLibtool, libtoolLinker);
+ outputSuffix, false, isLibtool, libtoolLinker);
}
public Linker getLinker(LinkType type) {
if (type.isStaticLibrary()) {