From 74dddb20753ad9f4addc54597674041d5fc40412 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 3 Dec 2017 13:08:24 +0200 Subject: [PATCH] Also get the linker system path from the actual linker program --- source/gnulinker.cpp | 97 +++++++++++++++++++++++++++++++++++++------- source/gnulinker.h | 3 ++ 2 files changed, 86 insertions(+), 14 deletions(-) diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index a93f809..adc3efc 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -30,21 +30,7 @@ GnuLinker::GnuLinker(Builder &b, const Architecture &a, const FS::Path &sysroot) processing_unit = COMPONENT; if(!sysroot.empty()) - { build_info.sysroot = sysroot; - system_path.push_back(sysroot/"usr"/"lib"); - } - else if(architecture->is_native()) - { - system_path.push_back("/lib"); - system_path.push_back("/usr/lib"); - if(architecture->match_name("pc-32-linux")) - system_path.push_back("/usr/lib/i386-linux-gnu"); - else if(architecture->match_name("pc-64-linux")) - system_path.push_back("/usr/lib/x86_64-linux-gnu"); - } - else - system_path.push_back("/usr/"+architecture->get_cross_prefix()+"/lib"); default_linker = new Linker(*this, "CC"); cxx_linker = new Linker(*this, "CXX"); @@ -113,6 +99,89 @@ Target *GnuLinker::create_install(Target &target) const return 0; } +void GnuLinker::do_prepare() +{ + bool path_found = false; + const FS::Path &sysroot = build_info.sysroot; + + Tool &compiler = builder.get_toolchain().get_tool("CC"); + if(dynamic_cast(&compiler)) + { + compiler.prepare(); + FileTarget *compiler_exe = compiler.get_executable(); + if(compiler_exe) + { + ExternalTask::Arguments argv; + argv.push_back(compiler_exe->get_path().str()); + argv.push_back("-Wl,--verbose"); + argv.push_back("-nostdlib"); + if(!sysroot.empty()) + argv.push_back("--sysroot="+sysroot.str()); + + builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end()))); + try + { + string output = ExternalTask::run_and_capture_output(argv, FS::Path(), true); + string::size_type start = 0; + while(startis_native()) + { + system_path.push_back("/lib"); + 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"); + } + 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"); + } + } + else + system_path.push_back("/usr/"+architecture->get_cross_prefix()+"/lib"); + } +} + Task *GnuLinker::run(const Target &) const { throw logic_error("GnuLinker should not be run directly"); diff --git a/source/gnulinker.h b/source/gnulinker.h index 872234a..7841700 100644 --- a/source/gnulinker.h +++ b/source/gnulinker.h @@ -37,6 +37,9 @@ public: virtual Target *create_target(const std::list &, const std::string &); virtual Target *create_install(Target &) const; +protected: + virtual void do_prepare(); +public: virtual Task *run(const Target &) const; }; -- 2.43.0