+ bool path_found = false;
+ const FS::Path &sysroot = tool.build_info.sysroot;
+ const std::string &tool_tag = static_cast<Tool &>(tool).get_tag();
+
+ const FileTarget *exe = static_cast<Tool &>(tool).get_executable();
+ if(exe)
+ {
+ 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())
+ argv.push_back("--sysroot="+sysroot.str());
+
+ builder.get_logger().log("auxcommands", "Running %s", join(argv.begin(), argv.end()));
+ 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())
+ {
+ string::size_type search_dir = output.find("SEARCH_DIR(\"", start);
+ if(search_dir==string::npos)
+ break;
+
+ search_dir += 12;
+ string::size_type end = output.find("\");", search_dir);
+ if(end==string::npos)
+ break;
+
+ FS::Path path;
+ if(!output.compare(search_dir, 2, "=/"))
+ {
+ search_dir += 2;
+ if(sysroot.empty())
+ path = "/";
+ else
+ path = sysroot;
+ }
+
+ path /= output.substr(search_dir, end-search_dir);
+ 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;
+ }
+ }
+ catch(...)
+ { }
+ }
+
+ if(!path_found)