]> git.tdb.fi Git - builder.git/blobdiff - source/gnulinker.cpp
Gather more system path information for GnuLinker
[builder.git] / source / gnulinker.cpp
index 2416449d63c5654a6f6dce62d6a620a6af1420c7..591c80be20db9aefc4d7b7d9713c455313e14665 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>
@@ -29,7 +30,7 @@ GnuLinker::GnuLinker(Builder &b, const Architecture &a):
 
        processing_unit = COMPONENT;
 
-       set_command("gcc");
+       set_command("gcc", true);
        set_run(_run);
 }
 
@@ -98,15 +99,18 @@ string GnuLinker::create_build_signature(const BuildInfo &binfo) const
        return result;
 }
 
-void GnuLinker::do_prepare()
+void GnuLinker::do_prepare(ToolData &tool) const
 {
        bool path_found = false;
-       const FS::Path &sysroot = build_info.sysroot;
+       const FS::Path &sysroot = tool.build_info.sysroot;
+       const std::string &tool_tag = static_cast<Tool &>(tool).get_tag();
 
-       if(executable)
+       const FileTarget *exe = static_cast<Tool &>(tool).get_executable();
+       if(exe)
        {
                ExternalTask::Arguments argv;
-               argv.push_back(executable->get_path().str());
+               argv.push_back(exe->get_path().str());
+               argv.push_back("-v");
                argv.push_back("-Wl,--verbose");
                argv.push_back("-nostdlib");
                if(!sysroot.empty())
@@ -116,6 +120,23 @@ void GnuLinker::do_prepare()
                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())
                        {
@@ -139,8 +160,11 @@ void GnuLinker::do_prepare()
                                }
 
                                path /= output.substr(search_dir, end-search_dir);
-                               builder.get_logger().log("tools", "Got %s system path: %s", tag, path);
-                               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;
@@ -152,26 +176,26 @@ void GnuLinker::do_prepare()
 
        if(!path_found)
        {
-               builder.get_logger().log("tools", "No %s system path found, using defaults", tag);
+               builder.get_logger().log("tools", "No %s system path found, using defaults", tool_tag);
                if(!sysroot.empty())
-                       system_path.push_back(sysroot/"usr/lib");
+                       tool.system_path.push_back(sysroot/"usr/lib");
                else if(architecture->is_native())
                {
-                       system_path.push_back("/lib");
-                       system_path.push_back("/usr/lib");
+                       tool.system_path.push_back("/lib");
+                       tool.system_path.push_back("/usr/lib");
                        if(architecture->match_name("pc-32-linux"))
                        {
-                               system_path.push_back("/lib/i386-linux-gnu");
-                               system_path.push_back("/usr/lib/i386-linux-gnu");
+                               tool.system_path.push_back("/lib/i386-linux-gnu");
+                               tool.system_path.push_back("/usr/lib/i386-linux-gnu");
                        }
                        else if(architecture->match_name("pc-64-linux"))
                        {
-                               system_path.push_back("/lib/x86_64-linux-gnu");
-                               system_path.push_back("/usr/lib/x86_64-linux-gnu");
+                               tool.system_path.push_back("/lib/x86_64-linux-gnu");
+                               tool.system_path.push_back("/usr/lib/x86_64-linux-gnu");
                        }
                }
                else
-                       system_path.push_back(format("/usr/%s/lib", architecture->get_cross_prefix()));
+                       tool.system_path.push_back(format("/usr/%s/lib", architecture->get_cross_prefix()));
        }
 }