From 4facd021514ab372c23b1b132d6b4b62baa4efbf Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 9 Jun 2012 01:52:16 +0300 Subject: [PATCH] Make tools capable of reporting a system-wide path used to locate input files --- source/builder.cpp | 16 ++++++++-------- source/gnucompiler.cpp | 9 ++++++++- source/gnucxxcompiler.cpp | 37 ++++++++++++++++++++++++++++++++++++ source/gnulinker.cpp | 13 +++++++++++++ source/tool.h | 3 +++ source/virtualfilesystem.cpp | 24 ----------------------- 6 files changed, 69 insertions(+), 33 deletions(-) diff --git a/source/builder.cpp b/source/builder.cpp index 0cbcb22..e8f8927 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -125,14 +125,6 @@ Builder::Builder(int argc, char **argv): cwd = FS::getcwd(); - toolchain.add_tool(new GnuCCompiler(*this)); - toolchain.add_tool(new GnuCxxCompiler(*this)); - toolchain.add_tool(new GnuLinker(*this)); - toolchain.add_tool(new GnuArchiver(*this)); - toolchain.add_tool(new Copy(*this)); - toolchain.add_tool(new Tar(*this)); - toolchain.add_tool(new PkgConfigGenerator(*this)); - load_build_file((FS::get_sys_data_dir(argv[0], "builder")/"builderrc").str()); load_build_file((FS::get_user_data_dir("builder")/"rc").str()); @@ -151,6 +143,14 @@ Builder::Builder(int argc, char **argv): } } + toolchain.add_tool(new GnuCCompiler(*this)); + toolchain.add_tool(new GnuCxxCompiler(*this)); + toolchain.add_tool(new GnuLinker(*this)); + toolchain.add_tool(new GnuArchiver(*this)); + toolchain.add_tool(new Copy(*this)); + toolchain.add_tool(new Tar(*this)); + toolchain.add_tool(new PkgConfigGenerator(*this)); + if(prfx.empty()) { if(current_arch->is_native()) diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 189e514..6989e2d 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "architecture.h" #include "builder.h" #include "component.h" #include "externaltask.h" @@ -15,7 +16,13 @@ using namespace Msp; GnuCompiler::GnuCompiler(Builder &b, const string &t, const string &n): Tool(b, t), name(n) -{ } +{ + const Architecture &arch = builder.get_current_arch(); + if(arch.is_native()) + system_path.push_back("/usr/include"); + else + system_path.push_back("/usr/"+arch.get_cross_prefix()+"/include"); +} Target *GnuCompiler::create_target(const list &sources, const std::string &) const { diff --git a/source/gnucxxcompiler.cpp b/source/gnucxxcompiler.cpp index fb7fbdc..0601fc2 100644 --- a/source/gnucxxcompiler.cpp +++ b/source/gnucxxcompiler.cpp @@ -1,6 +1,12 @@ +#include +#include +#include +#include "builder.h" #include "csourcefile.h" +#include "externaltask.h" #include "gnucxxcompiler.h" +using namespace std; using namespace Msp; GnuCxxCompiler::GnuCxxCompiler(Builder &b): @@ -9,6 +15,37 @@ GnuCxxCompiler::GnuCxxCompiler(Builder &b): input_suffixes.push_back(".cpp"); input_suffixes.push_back(".cc"); aux_suffixes.push_back(".hpp"); + + ExternalTask::Arguments argv; + argv.push_back(name); + argv.push_back("--version"); + ExternalTask task(argv); + task.set_stdout(ExternalTask::CAPTURE); + task.set_stderr(ExternalTask::IGNORE); + task.start(); + Task::Status status; + while((status=task.check())==Task::RUNNING) ; + if(status==Task::SUCCESS) + if(RegMatch m = Regex("[0-9]\\.[0-9.]+").match(task.get_output())) + { + string cxx_ver = m[0].str; + while(!cxx_ver.empty()) + { + FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver; + if(FS::is_dir(cxx_path)) + { + if(builder.get_verbose()>=5) + IO::print("%s version is %s\n", name, cxx_ver); + system_path.push_back(cxx_path); + break; + } + + string::size_type dot = cxx_ver.rfind('.'); + if(dot==string::npos) + break; + cxx_ver.erase(dot); + } + } } Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 3693e2b..ee4f02d 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -22,6 +22,19 @@ GnuLinker::GnuLinker(Builder &b): { input_suffixes.push_back(".o"); input_suffixes.push_back(".a"); + + const Architecture &arch = builder.get_current_arch(); + if(arch.is_native()) + { + system_path.push_back("/lib"); + system_path.push_back("/usr/lib"); + if(arch.match_name("pc-32-linux")) + system_path.push_back("/usr/lib/i386-linux-gnu"); + else if(arch.match_name("pc-64-linux")) + system_path.push_back("/usr/lib/x86_64-linux-gnu"); + } + else + system_path.push_back("/usr/"+arch.get_cross_prefix()+"/lib"); } Target *GnuLinker::create_target(const list &sources, const std::string &arg) const diff --git a/source/tool.h b/source/tool.h index 22fc3b2..1905555 100644 --- a/source/tool.h +++ b/source/tool.h @@ -13,6 +13,7 @@ class Task; class Tool { public: + typedef std::list SearchPath; typedef std::list SuffixList; protected: @@ -20,6 +21,7 @@ protected: std::string tag; SuffixList input_suffixes; SuffixList aux_suffixes; + SearchPath system_path; Tool(Builder &, const std::string &); public: @@ -29,6 +31,7 @@ public: const SuffixList &get_input_suffixes() const { return input_suffixes; } const SuffixList &get_auxiliary_suffixes() const { return aux_suffixes; } bool accepts_suffix(const std::string &, bool = false) const; + const SearchPath &get_system_path() const { return system_path; } virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; } Target *create_target(Target &, const std::string & = std::string()) const; diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index 75f935d..d5cf909 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -51,30 +51,6 @@ FileTarget *VirtualFileSystem::find_header(const string &name, const SearchPath if(i!=include_cache.end()) return i->second; - static string cxx_ver; - if(cxx_ver.empty()) - { - // XXX This needs to go elsewhere - /*StringList argv; - argv.push_back(current_arch->get_tool("CXX")); - argv.push_back("--version"); - if(RegMatch m = Regex("[0-9]\\.[0-9.]+").match(run_command(argv))) - { - cxx_ver = m[0].str; - while(!cxx_ver.empty() && !FS::is_dir(FS::Path("/usr/include/c++")/cxx_ver)) - { - string::size_type dot = cxx_ver.rfind('.'); - if(dot==string::npos) - break; - cxx_ver.erase(dot); - } - if(verbose>=5) - IO::print("C++ version is %s\n", cxx_ver); - } - else*/ - cxx_ver = "-"; - } - if(builder.get_verbose()>=5) IO::print("Looking for header %s with path %s\n", name, join(path.begin(), path.end())); -- 2.43.0