diff options
Diffstat (limited to 'src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java')
-rw-r--r-- | src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java | 94 |
1 files changed, 75 insertions, 19 deletions
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; } } |