diff options
Diffstat (limited to 'src/main/java/net/sf/antcontrib/cpptasks/gcc')
5 files changed, 145 insertions, 39 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 75ddcc7..f1eb2d7 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java @@ -55,11 +55,17 @@ public abstract class AbstractLdLinker extends CommandLineLinker { args.addElement("-g"); } if (isDarwin()) { - if (linkType.isPluginModule()) { + if (linkType.isPluginModule()) { + args.addElement("-bundle"); +// BEGINFREEHEP + } else if (linkType.isJNIModule()) { + args.addElement("-dynamic"); args.addElement("-bundle"); +// ENDFREEHEP } else { if (linkType.isSharedLibrary()) { - args.addElement("-prebind"); +// FREEHEP no longer needed for 10.4+ +// args.addElement("-prebind"); args.addElement("-dynamiclib"); } } @@ -121,11 +127,16 @@ public abstract class AbstractLdLinker extends CommandLineLinker { // if (set.getType() != previousLibraryType) { if (set.getType() != null && "static".equals(set.getType().getValue())) { +// BEGINFREEHEP not on MacOS X + if (!isDarwin()) { endargs.addElement(getStaticLibFlag()); previousLibraryType = set.getType(); + } +//ENDFREEHEP } else { +// FREEHEP not on MacOS X, recheck this! if (set.getType() == null || - !"framework".equals(set.getType().getValue()) || + !"framework".equals(set.getType().getValue()) && !isDarwin()) { endargs.addElement(getDynamicLibFlag()); previousLibraryType = set.getType(); @@ -137,7 +148,8 @@ public abstract class AbstractLdLinker extends CommandLineLinker { "framework".equals(set.getType().getValue()) && isDarwin()) { buf.setLength(0); - buf.append("-framework "); +// FREEHEP, added as endarg w/o trailing space to avoid quoting! + endargs.addElement("-framework"); } int initialLength = buf.length(); for (int j = 0; j < libs.length; j++) { @@ -154,6 +166,13 @@ public abstract class AbstractLdLinker extends CommandLineLinker { endargs.addElement(buf.toString()); } } + +// BEGINFREEHEP if last was -Bstatic reset it to -Bdynamic so that libc and libm can be found as shareables + if ((previousLibraryType != null) && previousLibraryType.getValue().equals("static") && !isDarwin()) { + endargs.addElement(getDynamicLibFlag()); + } +// ENDFREEHEP + String rc[] = new String[libnames.size()]; for (int i = 0; i < libnames.size(); i++) { rc[i] = (String) libnames.elementAt(i); @@ -239,7 +258,8 @@ public abstract class AbstractLdLinker extends CommandLineLinker { return patterns; } public int getMaximumCommandLength() { - return Integer.MAX_VALUE; +// FREEHEP + return isWindows() ? 20000 : Integer.MAX_VALUE; } public String[] getOutputFileNames(String baseName, VersionInfo versionInfo) { String[] baseNames = super.getOutputFileNames(baseName, versionInfo); 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 999ccf7..f9e4c0b 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCCompiler.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCCompiler.java @@ -59,6 +59,11 @@ public final class GccCCompiler extends GccCompatibleCCompiler { sourceExtensions, headerExtensions, false, new GccCCompiler("g77", sourceExtensions, headerExtensions, true, null, false, null), false, null); +// FREEHEP + private static final GccCCompiler gfortranInstance = new GccCCompiler("gfortran", + sourceExtensions, headerExtensions, false, + new GccCCompiler("gfortran", sourceExtensions, headerExtensions, true, + null, false, null), false, null); private static final GccCCompiler gppInstance = new GccCCompiler("g++", sourceExtensions, headerExtensions, false, new GccCCompiler("g++", sourceExtensions, headerExtensions, true, @@ -80,6 +85,14 @@ public final class GccCCompiler extends GccCompatibleCCompiler { return g77Instance; } /** + * Gets g77 adapter + */ +// FREEHEPBEGIN + public static GccCCompiler getGFortranInstance() { + return gfortranInstance; + } +// FREEHEPEND + /** * Gets gpp adapter */ public static GccCCompiler getGppInstance() { @@ -118,6 +131,12 @@ public final class GccCCompiler extends GccCompatibleCCompiler { if (isPICMeaningful && linkType.isSharedLibrary()) { args.addElement("-fPIC"); } +// BEGINFREEHEP + // Add -fno_rtti only for g++ and c++ + if (!getCommand().equals("g77") && !getCommand().equals("gcc") && (rtti != null) && (!rtti.booleanValue())) { + args.addElement("-fno_rtti"); + } +// ENDFREEHEP } public Processor changeEnvironment(boolean newEnvironment, Environment env) { if (newEnvironment || env != null) { @@ -237,6 +256,6 @@ public final class GccCCompiler extends GccCompatibleCCompiler { return GccLinker.getInstance().getLinker(linkType); } public int getMaximumCommandLength() { - return Integer.MAX_VALUE; + return isWindows() ? 20000 : Integer.MAX_VALUE; } } 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..fc7bbfc 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java @@ -98,10 +98,16 @@ public abstract class GccCompatibleCCompiler extends CommandLineCCompiler { args.addElement("-mwindows"); } } - if (rtti != null && !rtti.booleanValue()) { - args.addElement("-fno-rtti"); +// BEGINFREEHEP, tests have been modified + if (!exceptions) { + args.addElement("-fno-exceptions"); } - +// ENDFREEHEP +// BEGINFREEHEP moved to GccCCompiler +// if (rtti != null && !rtti.booleanValue()) { +// args.addElement("-fno-rtti"); +// } +// ENDFREEHEP } /** * Adds an include path to the command. 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 c4720c8..a551bfa 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java @@ -33,10 +33,13 @@ public class GccLinker extends AbstractLdLinker { private static final String[] libtoolObjFiles = new String[]{".fo", ".a", ".lib", ".dll", ".so", ".sl"}; private static String[] linkerOptions = new String[]{"-bundle", +// FREEHEP + "-dynamic", "-dynamiclib", "-nostartfiles", "-nostdlib", "-prebind", "-s", "-static", "-shared", "-symbolic", "-Xlinker", "--export-all-symbols", "-static-libgcc",}; - private static final GccLinker dllLinker = new GccLinker("gcc", objFiles, +// FREEHEP refactored dllLinker to soLinker + private static final GccLinker soLinker = new GccLinker("gcc", objFiles, discardFiles, "lib", ".so", false, new GccLinker("gcc", objFiles, discardFiles, "lib", ".so", true, null)); private static final GccLinker instance = new GccLinker("gcc", objFiles, @@ -45,6 +48,11 @@ public class GccLinker extends AbstractLdLinker { objFiles, discardFiles, "lib", ".bundle", false, null); private static final GccLinker machDllLinker = new GccLinker("gcc", objFiles, discardFiles, "lib", ".dylib", false, null); + private static final GccLinker machJNILinker = new GccLinker("gcc", + objFiles, discardFiles, "lib", ".jnilib", false, null); +// FREEHEP added dllLinker for windows + private static final GccLinker dllLinker = new GccLinker("gcc", + objFiles, discardFiles, "", ".dll", false, null); public static GccLinker getInstance() { return instance; } @@ -191,20 +199,17 @@ public class GccLinker extends AbstractLdLinker { if (type.isStaticLibrary()) { return GccLibrarian.getInstance(); } +// BEGINFREEHEP + if (type.isJNIModule()) { + return isDarwin() ? machJNILinker : isWindows() ? dllLinker : soLinker; + } if (type.isPluginModule()) { - if (isDarwin()) { - return machBundleLinker; - } else { - return dllLinker; - } + return isDarwin() ? machBundleLinker : isWindows() ? dllLinker : soLinker; } if (type.isSharedLibrary()) { - if (isDarwin()) { - return machDllLinker; - } else { - return dllLinker; - } + return isDarwin() ? machDllLinker : isWindows() ? dllLinker : soLinker; } +// ENDFREEHEP return instance; } } 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 f3bc174..043720d 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java @@ -33,7 +33,8 @@ 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 dllLinker = new GppLinker("gcc", objFiles, + // FREEHEP refactored dllLinker into soLinker + private static final GppLinker soLinker = new GppLinker("gcc", objFiles, discardFiles, "lib", ".so", false, new GppLinker("gcc", objFiles, discardFiles, "lib", ".so", true, null)); private final static String libPrefix = "libraries: ="; @@ -41,18 +42,29 @@ public class GppLinker extends AbstractLdLinker { ".lib", ".dll", ".so", ".sl"}; private static String[] linkerOptions = new String[]{"-bundle", "-dylib", "-dynamic", "-dynamiclib", "-nostartfiles", "-nostdlib", - "-prebind", "-s", "-static", "-shared", "-symbolic", "-Xlinker"}; + "-prebind", "-s", "-static", "-shared", "-symbolic", "-Xlinker", + // FREEHEP + "-static-libgcc", "-shared-libgcc" }; private static final GppLinker instance = new GppLinker("gcc", objFiles, discardFiles, "", "", false, null); 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); + // FREEHEP + private static final GppLinker machJNILinker = new GppLinker("gcc", + objFiles, discardFiles, "lib", ".jnilib", false, null); + // FREEHEP added dllLinker for windows + private static final GppLinker dllLinker = new GppLinker("gcc", objFiles, + discardFiles, "", ".dll", false, null); public static GppLinker getInstance() { return instance; } private File[] libDirs; private String runtimeLibrary; + // FREEEHEP + private String gccLibrary, gfortranLibrary; + protected GppLinker(String command, String[] extensions, String[] ignoredExtensions, String outputPrefix, String outputSuffix, boolean isLibtool, GppLinker libtoolLinker) { @@ -69,22 +81,66 @@ public class GppLinker extends AbstractLdLinker { args.addElement("-mwindows"); } } - if (linkType.isStaticRuntime()) { - String[] cmdin = new String[]{"g++", "-print-file-name=libstdc++.a"}; - String[] cmdout = CaptureStreamHandler.run(cmdin); - if (cmdout.length > 0) { - runtimeLibrary = cmdout[0]; + // BEGINFREEHEP link or not with libstdc++ + // for MacOS X see: + // http://developer.apple.com/documentation/DeveloperTools/Conceptual/CppRuntimeEnv/Articles/LibCPPDeployment.html + gfortranLibrary = null; + if (linkType.linkFortran()) { + if (linkType.isStaticRuntime()) { + String[] cmdin = new String[] { "gfortran", + "-print-file-name=libgfortran.a" }; + String[] cmdout = CaptureStreamHandler.run(cmdin); + if ((cmdout.length > 0) && (cmdout[0].indexOf('/') >= 0)) { + gfortranLibrary = cmdout[0]; + } + } else { + gfortranLibrary = "-lgfortran"; + } + } + + runtimeLibrary = null; + if (linkType.linkCPP()) { + if (linkType.isStaticRuntime()) { + if (isDarwin()) { + runtimeLibrary = "-lstdc++-static"; + } else { + String[] cmdin = new String[] { "g++", + "-print-file-name=libstdc++.a" }; + String[] cmdout = CaptureStreamHandler.run(cmdin); + if ((cmdout.length > 0) && (cmdout[0].indexOf('/') >= 0)) { + runtimeLibrary = cmdout[0]; + } + } } else { - runtimeLibrary = null; + runtimeLibrary = "-lstdc++"; } + } + + gccLibrary = null; + if (linkType.isStaticRuntime()) { + gccLibrary = "-static-libgcc"; } else { - runtimeLibrary = "-lstdc++"; + if (linkType.linkCPP()) { + // NOTE: added -fexceptions here for MacOS X + gccLibrary = "-fexceptions"; + } else { + gccLibrary = "-shared-libgcc"; + } } + // ENDFREEHEP } public String[] addLibrarySets(CCTask task, LibrarySet[] libsets, Vector preargs, Vector midargs, Vector endargs) { String[] rs = super.addLibrarySets(task, libsets, preargs, midargs, endargs); + // BEGINFREEHEP + if (gfortranLibrary != null) { + endargs.addElement(gfortranLibrary); + } + if (gccLibrary != null) { + endargs.addElement(gccLibrary); + } + // ENDFREEHEP if (runtimeLibrary != null) { endargs.addElement(runtimeLibrary); } @@ -184,20 +240,20 @@ public class GppLinker extends AbstractLdLinker { if (type.isStaticLibrary()) { return GccLibrarian.getInstance(); } + // BEGINFREEHEP + if (type.isJNIModule()) { + return isDarwin() ? machJNILinker : isWindows() ? dllLinker + : soLinker; + } if (type.isPluginModule()) { - if (GccProcessor.getMachine().indexOf("darwin") >= 0) { - return machPluginLinker; - } else { - return dllLinker; - } + return isDarwin() ? machPluginLinker : isWindows() ? dllLinker + : soLinker; } if (type.isSharedLibrary()) { - if (GccProcessor.getMachine().indexOf("darwin") >= 0) { - return machDllLinker; - } else { - return dllLinker; - } + return isDarwin() ? machDllLinker : isWindows() ? dllLinker + : soLinker; } + // ENDFREEHEP return instance; } } |