]> git.tdb.fi Git - builder.git/blobdiff - source/gnulinker.cpp
Add gcc's private library directory to ClangLinker's system path
[builder.git] / source / gnulinker.cpp
index 19313336473a2ac92b6f26e80e05824f94371347..b726dd5846cb6ed228955adfe3d7a73510d0ff96 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdexcept>
 #include <vector>
+#include <msp/core/algorithm.h>
 #include <msp/fs/dir.h>
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
@@ -8,7 +9,6 @@
 #include "component.h"
 #include "executable.h"
 #include "exportdefinitions.h"
-#include "externaltask.h"
 #include "gnucompiler.h"
 #include "gnulinker.h"
 #include "importlibrary.h"
@@ -30,7 +30,7 @@ GnuLinker::GnuLinker(Builder &b, const Architecture &a):
        processing_unit = COMPONENT;
 
        set_command("gcc", true);
-       set_run(_run);
+       set_run_external(_run);
 }
 
 Target *GnuLinker::create_target(const vector<Target *> &sources, const string &arg)
@@ -109,6 +109,7 @@ void GnuLinker::do_prepare(ToolData &tool) const
        {
                ExternalTask::Arguments argv;
                argv.push_back(exe->get_path().str());
+               argv.push_back("-v");
                argv.push_back("-Wl,--verbose");
                argv.push_back("-nostdlib");
                if(!sysroot.empty())
@@ -118,6 +119,23 @@ void GnuLinker::do_prepare(ToolData &tool) const
                try
                {
                        string output = ExternalTask::run_and_capture_output(argv, FS::Path(), true);
+
+                       string::size_type lib_path = output.find("LIBRARY_PATH=");
+                       if(lib_path!=string::npos)
+                       {
+                               string::size_type newline = output.find('\n', lib_path);
+                               for(const string &p: split(output.substr(lib_path+13, newline-lib_path-13), ':'))
+                               {
+                                       FS::Path path = strip(p);
+                                       if(!any_equals(tool.system_path, path))
+                                       {
+                                               builder.get_logger().log("tools", "Got %s frontend system path: %s", tool_tag, path);
+                                               tool.system_path.push_back(path);
+                                       }
+                                       path_found = true;
+                               }
+                       }
+
                        string::size_type start = 0;
                        while(start<output.size())
                        {
@@ -141,8 +159,11 @@ void GnuLinker::do_prepare(ToolData &tool) const
                                }
 
                                path /= output.substr(search_dir, end-search_dir);
-                               builder.get_logger().log("tools", "Got %s system path: %s", tool_tag, path);
-                               tool.system_path.push_back(path);
+                               if(!any_equals(tool.system_path, path))
+                               {
+                                       builder.get_logger().log("tools", "Got %s implicit system path: %s", tool_tag, path);
+                                       tool.system_path.push_back(path);
+                               }
                                path_found = true;
 
                                start = end+3;
@@ -177,7 +198,7 @@ void GnuLinker::do_prepare(ToolData &tool) const
        }
 }
 
-Task *GnuLinker::_run(const Binary &bin)
+ExternalTask::Arguments GnuLinker::_run(const Binary &bin, FS::Path &work_dir)
 {
        const Tool &tool = *bin.get_tool();
        const Builder &builder = tool.get_builder();
@@ -186,8 +207,6 @@ Task *GnuLinker::_run(const Binary &bin)
        ExternalTask::Arguments argv;
        argv.push_back(tool.get_executable()->get_path().str());
 
-       FS::Path work_dir = bin.get_component()->get_package().get_source_directory();
-
        if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&bin))
        {
                argv.push_back("-shared");
@@ -287,9 +306,6 @@ Task *GnuLinker::_run(const Binary &bin)
                        argv.push_back(l.substr(0, l.size()-10));
                }
 
-       if(has_cplusplus)
-               argv.push_back("-lstdc++");
-
        if(static_link_ok)
                argv.push_back("-static");
        else
@@ -305,5 +321,5 @@ Task *GnuLinker::_run(const Binary &bin)
                        argv.push_back("-Wl,--enable-auto-import");
        }
 
-       return new ExternalTask(argv, work_dir);
+       return argv;
 }