From: Mikko Rasa Date: Sun, 8 Jul 2012 21:07:02 +0000 (+0300) Subject: Make tools architecture-aware and restore cross-compilation functionality X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=25a315f3cb5805614c513ac762ea1bd512ce82cb;p=builder.git Make tools architecture-aware and restore cross-compilation functionality --- diff --git a/source/builder.cpp b/source/builder.cpp index 1787ec1..4ca2e43 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -183,10 +183,10 @@ 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 GnuCCompiler(*this, *current_arch)); + toolchain.add_tool(new GnuCxxCompiler(*this, *current_arch)); + toolchain.add_tool(new GnuLinker(*this, *current_arch)); + toolchain.add_tool(new GnuArchiver(*this, *current_arch)); toolchain.add_tool(new Copy(*this)); toolchain.add_tool(new Tar(*this)); toolchain.add_tool(new PkgConfigGenerator(*this)); diff --git a/source/gnuarchiver.cpp b/source/gnuarchiver.cpp index 13b2054..3f96cbf 100644 --- a/source/gnuarchiver.cpp +++ b/source/gnuarchiver.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "builder.h" #include "component.h" @@ -13,10 +14,13 @@ using namespace std; using namespace Msp; -GnuArchiver::GnuArchiver(Builder &b): - Tool(b, "AR") +GnuArchiver::GnuArchiver(Builder &b, const Architecture &a): + Tool(b, a, "AR") { - executable = builder.get_vfs().find_binary("ar"); + string command = "ar"; + if(architecture->is_cross()) + command = format("%s-%s", architecture->get_cross_prefix(), command); + executable = builder.get_vfs().find_binary(command); input_suffixes.push_back(".o"); } diff --git a/source/gnuarchiver.h b/source/gnuarchiver.h index f1a4b63..41386f6 100644 --- a/source/gnuarchiver.h +++ b/source/gnuarchiver.h @@ -6,7 +6,7 @@ class GnuArchiver: public Tool { public: - GnuArchiver(Builder &); + GnuArchiver(Builder &, const Architecture &); virtual Target *create_target(const std::list &, const std::string &) const; virtual Task *run(const Target &) const; diff --git a/source/gnuccompiler.cpp b/source/gnuccompiler.cpp index f0d356c..7089a26 100644 --- a/source/gnuccompiler.cpp +++ b/source/gnuccompiler.cpp @@ -4,8 +4,8 @@ using namespace std; using namespace Msp; -GnuCCompiler::GnuCCompiler(Builder &b): - GnuCompiler(b, "CC", "gcc") +GnuCCompiler::GnuCCompiler(Builder &b, const Architecture &a): + GnuCompiler(b, a, "CC", "gcc") { input_suffixes.push_back(".c"); aux_suffixes.push_back(".h"); diff --git a/source/gnuccompiler.h b/source/gnuccompiler.h index a95f22d..ffb0244 100644 --- a/source/gnuccompiler.h +++ b/source/gnuccompiler.h @@ -6,7 +6,7 @@ class GnuCCompiler: public GnuCompiler { public: - GnuCCompiler(Builder &); + GnuCCompiler(Builder &, const Architecture &); virtual Target *create_source(const Component &, const Msp::FS::Path &) const; virtual Target *create_source(const Msp::FS::Path &) const; diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 5209317..8df1a72 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -13,16 +13,18 @@ using namespace std; using namespace Msp; -GnuCompiler::GnuCompiler(Builder &b, const string &t, const string &n): - Tool(b, t) +GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t, const string &c): + Tool(b, a, t) { - executable = builder.get_vfs().find_binary(n); + string command = c; + if(architecture->is_cross()) + command = format("%s-%s", architecture->get_cross_prefix(), command); + executable = builder.get_vfs().find_binary(command); - const Architecture &arch = builder.get_current_arch(); - if(arch.is_native()) + if(architecture->is_native()) system_path.push_back("/usr/include"); else - system_path.push_back("/usr/"+arch.get_cross_prefix()+"/include"); + system_path.push_back("/usr/"+architecture->get_cross_prefix()+"/include"); } Target *GnuCompiler::create_target(const list &sources, const string &) const @@ -70,12 +72,11 @@ Task *GnuCompiler::run(const Target &target) const if(comp.get_type()==Component::LIBRARY) argv.push_back("-fPIC"); - const Architecture &arch = builder.get_current_arch(); const Architecture &native_arch = builder.get_native_arch(); - if(arch.get_bits()!=native_arch.get_bits()) - argv.push_back(format("-m%d", arch.get_bits())); + if(architecture->get_bits()!=native_arch.get_bits()) + argv.push_back(format("-m%d", architecture->get_bits())); - const string &cpu = arch.get_cpu(); + const string &cpu = architecture->get_cpu(); if(!cpu.empty()) argv.push_back("-march="+cpu); diff --git a/source/gnucompiler.h b/source/gnucompiler.h index d09cb9a..9d025ed 100644 --- a/source/gnucompiler.h +++ b/source/gnucompiler.h @@ -6,7 +6,7 @@ class GnuCompiler: public Tool { protected: - GnuCompiler(Builder &, const std::string &, const std::string &); + GnuCompiler(Builder &, const Architecture &, const std::string &, const std::string &); public: virtual Target *create_target(const std::list &, const std::string &) const; diff --git a/source/gnucxxcompiler.cpp b/source/gnucxxcompiler.cpp index 9045b6c..c3be0bc 100644 --- a/source/gnucxxcompiler.cpp +++ b/source/gnucxxcompiler.cpp @@ -11,8 +11,8 @@ using namespace std; using namespace Msp; -GnuCxxCompiler::GnuCxxCompiler(Builder &b): - GnuCompiler(b, "CXX", "g++") +GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a): + GnuCompiler(b, a, "CXX", "g++") { input_suffixes.push_back(".cpp"); input_suffixes.push_back(".cc"); diff --git a/source/gnucxxcompiler.h b/source/gnucxxcompiler.h index 53d2d2a..45b152f 100644 --- a/source/gnucxxcompiler.h +++ b/source/gnucxxcompiler.h @@ -6,7 +6,7 @@ class GnuCxxCompiler: public GnuCompiler { public: - GnuCxxCompiler(Builder &); + GnuCxxCompiler(Builder &, const Architecture &); virtual Target *create_source(const Component &, const Msp::FS::Path &) const; virtual Target *create_source(const Msp::FS::Path &) const; diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index df0adbc..719780b 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -17,24 +17,23 @@ using namespace std; using namespace Msp; -GnuLinker::GnuLinker(Builder &b): - Tool(b, "LINK") +GnuLinker::GnuLinker(Builder &b, const Architecture &a): + Tool(b, a, "LINK") { input_suffixes.push_back(".o"); input_suffixes.push_back(".a"); - const Architecture &arch = builder.get_current_arch(); - if(arch.is_native()) + if(architecture->is_native()) { system_path.push_back("/lib"); system_path.push_back("/usr/lib"); - if(arch.match_name("pc-32-linux")) + if(architecture->match_name("pc-32-linux")) system_path.push_back("/usr/lib/i386-linux-gnu"); - else if(arch.match_name("pc-64-linux")) + else if(architecture->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"); + system_path.push_back("/usr/"+architecture->get_cross_prefix()+"/lib"); default_linker = new Linker(*this, "CC"); cxx_linker = new Linker(*this, "CXX"); @@ -95,6 +94,8 @@ GnuLinker::Linker::Linker(GnuLinker &p, const string &compiler_tag): command = "g++"; else throw invalid_argument("GnuLinker::Linker::Linker"); + if(architecture->is_cross()) + command = format("%s-%s", architecture->get_cross_prefix(), command); executable = builder.get_vfs().find_binary(command); } } @@ -131,10 +132,9 @@ Task *GnuLinker::Linker::run(const Target &target) const if(binfo.threads) argv.push_back("-pthread"); - const Architecture &arch = builder.get_current_arch(); const Architecture &native_arch = builder.get_native_arch(); - if(arch.get_bits()!=native_arch.get_bits()) - argv.push_back(format("-m%d", arch.get_bits())); + if(architecture->get_bits()!=native_arch.get_bits()) + argv.push_back(format("-m%d", architecture->get_bits())); FS::Path work_dir = comp.get_package().get_source(); diff --git a/source/gnulinker.h b/source/gnulinker.h index 2fdaa3a..673056e 100644 --- a/source/gnulinker.h +++ b/source/gnulinker.h @@ -19,7 +19,7 @@ private: Linker *cxx_linker; public: - GnuLinker(Builder &); + GnuLinker(Builder &, const Architecture &); ~GnuLinker(); virtual Target *create_target(const std::list &, const std::string &) const; diff --git a/source/tool.cpp b/source/tool.cpp index a2c61bf..cefbb8c 100644 --- a/source/tool.cpp +++ b/source/tool.cpp @@ -5,6 +5,14 @@ using namespace std; Tool::Tool(Builder &b, const string &t): builder(b), + architecture(0), + tag(t), + executable(0) +{ } + +Tool::Tool(Builder &b, const Architecture &a, const string &t): + builder(b), + architecture(&a), tag(t), executable(0) { } diff --git a/source/tool.h b/source/tool.h index 7371103..4bbbcf5 100644 --- a/source/tool.h +++ b/source/tool.h @@ -5,6 +5,7 @@ #include #include +class Architecture; class Builder; class Component; class FileTarget; @@ -23,6 +24,7 @@ public: protected: Builder &builder; + const Architecture *architecture; std::string tag; FileTarget *executable; SuffixList input_suffixes; @@ -30,6 +32,7 @@ protected: SearchPath system_path; Tool(Builder &, const std::string &); + Tool(Builder &, const Architecture &, const std::string &); public: virtual ~Tool() { }