summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2019-06-15 14:18:22 +0200
committerSven Gothel <[email protected]>2019-06-15 14:18:22 +0200
commit6523322893a0f18cef7b45e693249e147721990e (patch)
tree9b35d616d0952eb814b53e4406da908b38a65289
parentbd21aded190bb92261e4a01acdfa8e1be2158474 (diff)
Adding option 'usehighleveltool'
Adding option 'usehighleveltool', which gives preference to the higher level tool selection. Default is false. Currently 'usehighleveltool' is implemented for LinkType operation to build a static library, i.e. 'outtype' target is 'static'. If set to false (default), the default low level 'ar' librarian tool is being used. If set to true, the high-level tool gcc, g++ or clang (w/ or w/o xcode's xcrun) will be used to process the command. This might have some advantages where xcode's clang may validate consistency of the result, i.e. missing symbols etc.
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/CCTask.java22
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkType.java30
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java23
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java42
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java16
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java43
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GccLinker.java16
-rwxr-xr-xsrc/main/java/net/sf/antcontrib/cpptasks/gcc/cross/GppLinker.java16
8 files changed, 179 insertions, 29 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/CCTask.java b/src/main/java/net/sf/antcontrib/cpptasks/CCTask.java
index 2e6adab..95af2a9 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/CCTask.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/CCTask.java
@@ -1291,6 +1291,28 @@ public class CCTask extends Task {
return linkType.getOutputType();
}
+
+ /**
+ * User preference whether to use a high-level-tool for
+ * linker operations, e.g. gcc instead of ar to build static libraries.
+ * <p>
+ * Default is false.
+ * </p>
+ * @param useHighlevelTool user preference, default is false
+ */
+ public void setUseHighlevelTool(final boolean useHighlevelTool) {
+ linkType.setUseHighlevelTool(useHighlevelTool);
+ }
+
+ /**
+ * Gets the usehighleveltool flag.
+ * @return the usehighleveltool flag
+ * @see #setUseHighlevelTool(boolean)
+ */
+ public boolean getUseHighlevelTool() {
+ return linkType.getUseHighlevelTool();
+ }
+
/**
* Sets the project.
*/
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkType.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkType.java
index 70ee93f..ad4a1e0 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkType.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkType.java
@@ -28,6 +28,15 @@ public class LinkType {
private boolean staticRuntime = false;
private SubsystemEnum subsystem = new SubsystemEnum();
/**
+ * User preference whether to use a high-level-tool for
+ * linker operations, e.g. gcc instead of ar to build static libraries.
+ * <p>
+ * Default is false.
+ * </p>
+ */
+ private boolean useHighlevelTool = false;
+
+ /**
* Constructor
*
* By default, an gui executable with a dynamically linked runtime
@@ -147,4 +156,25 @@ public class LinkType {
public String getSubsystem() {
return subsystem.getValue();
}
+
+ /**
+ * User preference whether to use a high-level-tool for
+ * linker operations, e.g. gcc instead of ar to build static libraries.
+ * <p>
+ * Default is false.
+ * </p>
+ * @param useHighlevelTool user preference, default is false
+ */
+ public void setUseHighlevelTool(final boolean useHighlevelTool) {
+ this.useHighlevelTool = useHighlevelTool;
+ }
+
+ /**
+ * Gets the usehighleveltool flag.
+ * @return the usehighleveltool flag
+ * @see #setUseHighlevelTool(boolean)
+ */
+ public boolean getUseHighlevelTool() {
+ return useHighlevelTool;
+ }
}
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 3ee7f8e..f264cd9 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java
@@ -59,24 +59,21 @@ public abstract class AbstractLdLinker extends CommandLineLinker {
args.addElement("-g");
}
if (isDarwin()) {
- if (linkType.isPluginModule()) {
+ if (linkType.isStaticRuntime() || linkType.isStaticLibrary()) {
+ args.addElement("-static");
+ } else if (linkType.isPluginModule()) {
args.addElement("-bundle");
- } else {
- if (linkType.isSharedLibrary()) {
- // args.addElement("-prebind"); // Only required for OSX 10.3 and earlier, no auto-add (can add manually though)
- args.addElement("-dynamiclib");
- }
+ } else if (linkType.isSharedLibrary()) {
+ // args.addElement("-prebind"); // Only required for OSX 10.3 and earlier, no auto-add (can add manually though)
+ args.addElement("-dynamic");
}
} else {
- if (linkType.isStaticRuntime()) {
+ if (linkType.isStaticRuntime() || linkType.isStaticLibrary()) {
args.addElement("-static");
- }
- if (linkType.isPluginModule()) {
+ } else if (linkType.isPluginModule()) {
+ args.addElement("-shared");
+ } else if (linkType.isSharedLibrary()) {
args.addElement("-shared");
- } else {
- if (linkType.isSharedLibrary()) {
- args.addElement("-shared");
- }
}
}
}
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 88a3bed..30d9ce6 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java
@@ -36,17 +36,22 @@ public class GccLinker extends GnuLinker {
"-static", "-shared", "-symbolic", "-Xlinker",
"--export-all-symbols", "-static-libgcc", "-static-libstdc++",};
- 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,
- 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 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,
+ discardFiles, "lib", ".so", false, new GccLinker("clang", objFiles, discardFiles, "lib", ".so", true, null));
+
+ private static final GccLinker arLinker = new GccLinker("gcc", objFiles,
+ discardFiles, "lib", ".a", false, new GccLinker("gcc", objFiles, discardFiles, "lib", ".a", true, null));
+ private static final GccLinker arClangLinker = new GccLinker("clang", objFiles,
+ discardFiles, "lib", ".a", false, new GccLinker("clang", objFiles, discardFiles, "lib", ".a", true, null));
+
private static final GccLinker machBundleLinker = new GccLinker("gcc",
objFiles, discardFiles, "lib", ".bundle", false, null);
private static final GccLinker machClangBundleLinker = new GccLinker("clang",
@@ -59,6 +64,12 @@ public class GccLinker extends GnuLinker {
objFiles, discardFiles, "lib", ".dylib", false, null);
private static final GccLinker xcodeMachDllClangLinker = new GccLinker(machDllClangLinker, true);
+ private static final GccLinker machArLinker = new GccLinker("gcc",
+ objFiles, discardFiles, "lib", ".a", false, null);
+ private static final GccLinker machArClangLinker = new GccLinker("clang",
+ objFiles, discardFiles, "lib", ".a", false, null);
+ private static final GccLinker xcodeMachArClangLinker = new GccLinker(machArClangLinker, true);
+
public static GccLinker getInstance() {
return instance;
}
@@ -91,6 +102,14 @@ public class GccLinker extends GnuLinker {
return dllClangLinker;
}
@Override
+ protected final GnuLinker getStaticArLinker() {
+ return arLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticArClangLinker() {
+ return arClangLinker;
+ }
+ @Override
protected final GnuLinker getStaticClangInstance() {
return clangInstance;
}
@@ -123,6 +142,19 @@ public class GccLinker extends GnuLinker {
return xcodeMachDllClangLinker;
}
@Override
+ protected final GnuLinker getStaticMachArLinker() {
+ return machArLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticMachArClangLinker() {
+ return machArClangLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticXcodeMachArClangLinker() {
+ return xcodeMachArClangLinker;
+ }
+
+ @Override
protected final GnuLinker getStaticInstance() {
return instance;
}
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 cbd30ea..02a1bee 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GnuLinker.java
@@ -34,6 +34,8 @@ public abstract class GnuLinker extends AbstractLdLinker {
protected abstract String[] getStaticLinkerOptions();
protected abstract GnuLinker getStaticDllLinker();
protected abstract GnuLinker getStaticDllClangLinker();
+ protected abstract GnuLinker getStaticArLinker();
+ protected abstract GnuLinker getStaticArClangLinker();
protected abstract GnuLinker getStaticClangInstance();
protected abstract GnuLinker getStaticXcodeClangInstance();
protected abstract GnuLinker getStaticMachBundleLinker();
@@ -42,6 +44,9 @@ public abstract class GnuLinker extends AbstractLdLinker {
protected abstract GnuLinker getStaticMachDllLinker();
protected abstract GnuLinker getStaticMachDllClangLinker();
protected abstract GnuLinker getStaticXcodeMachDllClangLinker();
+ protected abstract GnuLinker getStaticMachArLinker();
+ protected abstract GnuLinker getStaticMachArClangLinker();
+ protected abstract GnuLinker getStaticXcodeMachArClangLinker();
protected abstract GnuLinker getStaticInstance();
@Override
@@ -115,10 +120,17 @@ public abstract class GnuLinker extends AbstractLdLinker {
}
@Override
- public Linker getLinker(LinkType type) {
- if (type.isStaticLibrary()) {
+ public Linker getLinker(final LinkType type) {
+ if ( type.isStaticLibrary() && !type.getUseHighlevelTool() ) {
return GccLibrarian.getInstance(); // uses 'ar', which is 'gcc' agnostic
}
+ if (type.isStaticLibrary()) {
+ if (isDarwin()) {
+ return isGCC ? getStaticMachArLinker() : ( getXcodeRun() ? getStaticXcodeMachArClangLinker() : getStaticMachArClangLinker() );
+ } else {
+ return isGCC ? getStaticArLinker() : getStaticArClangLinker();
+ }
+ }
if (type.isPluginModule()) {
if (isDarwin()) {
return isGCC ? getStaticMachBundleLinker() : ( getXcodeRun() ? getStaticXcodeMachClangBundleLinker() : getStaticMachClangBundleLinker() );
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 1ca34b5..5bdc2eb 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java
@@ -42,6 +42,12 @@ public class GppLinker extends GnuLinker {
"-dynamic", "-dynamiclib", "-nostartfiles", "-nostdlib",
"-prebind", "-s", "-static", "-shared", "-symbolic", "-Xlinker"};
+ private static final GppLinker instance = new GppLinker("gcc", objFiles,
+ discardFiles, "", "", false, false, null);
+ private static final GppLinker clangInstance = new GppLinker("clang", objFiles,
+ discardFiles, "", "", false, false, null);
+ private static final GppLinker xcodeClangInstance = new GppLinker(clangInstance, true);
+
private static final GppLinker dllLinker = new GppLinker("gcc", objFiles,
discardFiles, "lib", ".so", false, false, new GppLinker("gcc", objFiles,
discardFiles, "lib", ".so", false, true, null));
@@ -49,11 +55,12 @@ public class GppLinker extends GnuLinker {
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, false, null);
- private static final GppLinker clangInstance = new GppLinker("clang", objFiles,
- discardFiles, "", "", false, false, null);
- private static final GppLinker xcodeClangInstance = new GppLinker(clangInstance, true);
+ private static final GppLinker arLinker = new GppLinker("gcc", objFiles,
+ discardFiles, "lib", ".a", false, false, new GppLinker("gcc", objFiles,
+ discardFiles, "lib", ".a", false, true, null));
+ private static final GppLinker arClangLinker = new GppLinker("clang", objFiles,
+ discardFiles, "lib", ".a", false, false, new GppLinker("clang", objFiles,
+ discardFiles, "lib", ".a", false, true, null));
private static final GppLinker machBundleLinker = new GppLinker("gcc",
objFiles, discardFiles, "lib", ".bundle", false, false, null);
@@ -67,6 +74,12 @@ public class GppLinker extends GnuLinker {
objFiles, discardFiles, "lib", ".dylib", false, false, null);
private static final GppLinker xcodeMachDllClangLinker = new GppLinker(machDllClangLinker, true);
+ private static final GppLinker machArLinker = new GppLinker("gcc",
+ objFiles, discardFiles, "lib", ".a", false, false, null);
+ private static final GppLinker machArClangLinker = new GppLinker("clang",
+ objFiles, discardFiles, "lib", ".a", false, false, null);
+ private static final GppLinker xcodeMachArClangLinker = new GppLinker(machArClangLinker, true);
+
public static GppLinker getInstance() {
return instance;
}
@@ -99,6 +112,14 @@ public class GppLinker extends GnuLinker {
return dllClangLinker;
}
@Override
+ protected final GnuLinker getStaticArLinker() {
+ return arLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticArClangLinker() {
+ return arClangLinker;
+ }
+ @Override
protected final GnuLinker getStaticClangInstance() {
return clangInstance;
}
@@ -131,6 +152,18 @@ public class GppLinker extends GnuLinker {
return xcodeMachDllClangLinker;
}
@Override
+ protected final GnuLinker getStaticMachArLinker() {
+ return machArLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticMachArClangLinker() {
+ return machArClangLinker;
+ }
+ @Override
+ protected final GnuLinker getStaticXcodeMachArClangLinker() {
+ return xcodeMachArClangLinker;
+ }
+ @Override
protected final GnuLinker getStaticInstance() {
return instance;
}
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 3bdcf82..27774a1 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
@@ -34,6 +34,9 @@ public class GccLinker extends AbstractLdLinker {
private static final String[] discardFiles = new String[0];
private static final String[] objFiles = new String[]{".o", ".a", ".lib",
".dll", ".so", ".sl"};
+ private static final GccLinker arLinker = new GccLinker("gcc", objFiles,
+ discardFiles, "lib", ".a", false, new GccLinker("gcc", objFiles,
+ discardFiles, "lib", ".a", true, null));
private static final GccLinker dllLinker = new GccLinker("gcc", objFiles,
discardFiles, "lib", ".so", false, new GccLinker("gcc", objFiles,
discardFiles, "lib", ".so", true, null));
@@ -45,6 +48,8 @@ public class GccLinker extends AbstractLdLinker {
"-dynamiclib", "-nostartfiles", "-nostdlib", "-prebind", "-s",
"-static", "-shared", "-symbolic", "-Xlinker",
"--export-all-symbols", "-static-libgcc", "-static-libstdc++",};
+ private static final GccLinker machArLinker = new GccLinker("gcc",
+ objFiles, discardFiles, "lib", ".a", false, null);
private static final GccLinker machBundleLinker = new GccLinker("gcc",
objFiles, discardFiles, "lib", ".bundle", false, null);
private static final GccLinker machDllLinker = new GccLinker("gcc",
@@ -195,10 +200,17 @@ public class GccLinker extends AbstractLdLinker {
}
return libDirs;
}
- 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()) {
+ if (isDarwin()) {
+ return machArLinker;
+ } else {
+ return arLinker;
+ }
+ }
if (type.isPluginModule()) {
if (isDarwin()) {
return machBundleLinker;
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 319668b..afcedd5 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
@@ -38,6 +38,9 @@ public class GppLinker extends AbstractLdLinker {
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 arLinker = new GppLinker("gcc", objFiles,
+ discardFiles, "lib", ".a", false, new GppLinker("gcc", objFiles,
+ discardFiles, "lib", ".a", true, null));
private static final GppLinker dllLinker = new GppLinker("gcc", objFiles,
discardFiles, "lib", ".so", false, new GppLinker("gcc", objFiles,
discardFiles, "lib", ".so", true, null));
@@ -49,6 +52,8 @@ public class GppLinker extends AbstractLdLinker {
"-prebind", "-s", "-static", "-shared", "-symbolic", "-Xlinker"};
private static final GppLinker instance = new GppLinker("gcc", objFiles,
discardFiles, "", "", false, null);
+ private static final GppLinker machArLinker = new GppLinker("gcc",
+ objFiles, discardFiles, "lib", ".a", false, null);
private static final GppLinker machDllLinker = new GppLinker("gcc",
objFiles, discardFiles, "lib", ".dylib", false, null);
private static final GppLinker machPluginLinker = new GppLinker("gcc",
@@ -189,10 +194,17 @@ public class GppLinker extends AbstractLdLinker {
}
return libDirs;
}
- 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()) {
+ if (isDarwin()) {
+ return machArLinker;
+ } else {
+ return arLinker;
+ }
+ }
if (type.isPluginModule()) {
if (GccProcessor.getMachine().indexOf("darwin") >= 0) {
return machPluginLinker;