]> git.tdb.fi Git - builder.git/commitdiff
Make tools architecture-aware and restore cross-compilation functionality
authorMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:07:02 +0000 (00:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:55 +0000 (00:08 +0300)
13 files changed:
source/builder.cpp
source/gnuarchiver.cpp
source/gnuarchiver.h
source/gnuccompiler.cpp
source/gnuccompiler.h
source/gnucompiler.cpp
source/gnucompiler.h
source/gnucxxcompiler.cpp
source/gnucxxcompiler.h
source/gnulinker.cpp
source/gnulinker.h
source/tool.cpp
source/tool.h

index 1787ec17ca05b9cee8ffbf54b4065bef15a2e62e..4ca2e43ec87bdcef8942f49e4fd85aebafd25dcf 100644 (file)
@@ -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));
index 13b2054ff5f26d2ea9006b3513d17e924b28faf9..3f96cbfd9a94135d6c7c6348b3f91b53e358b3a0 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
+#include <msp/strings/format.h>
 #include <stdexcept>
 #include "builder.h"
 #include "component.h"
 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");
 }
index f1a4b635873727273059259555fea6446fb92a15..41386f645f212b4f2e3cf8945086ca4fef4bc0ff 100644 (file)
@@ -6,7 +6,7 @@
 class GnuArchiver: public Tool
 {
 public:
-       GnuArchiver(Builder &);
+       GnuArchiver(Builder &, const Architecture &);
 
        virtual Target *create_target(const std::list<Target *> &, const std::string &) const;
        virtual Task *run(const Target &) const;
index f0d356cbedcdfe7385a0b247fa727d7b4fe8659b..7089a26ec341a1dfe3e0e8c2c5b18a3e5755d4b3 100644 (file)
@@ -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");
index a95f22d6205fec5d333d5da602207f6a2a3ef132..ffb024435566e39812b3be4c96bd81f051d83e03 100644 (file)
@@ -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;
index 5209317dc0fd4b544bfc66b292c6beebd77080d6..8df1a72a92debc7542df10f137f76d29f1f8e18a 100644 (file)
 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<Target *> &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);
 
index d09cb9ad46b398103826ea8268751622b89189b4..9d025edbf791bf326440e49f7e12837973caf016 100644 (file)
@@ -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<Target *> &, const std::string &) const;
index 9045b6c3a369029a48efb39f386ce91a3f4dc978..c3be0bc61272b70b26f463dde447fad109613fc4 100644 (file)
@@ -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");
index 53d2d2ac94df4b2775ab86172340cc13458edd17..45b152f3e76544acca2ba1a703494b11cf404579 100644 (file)
@@ -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;
index df0adbc8eff36944b66053d4e83a371902671d66..719780bb0441c0cc65e8c02f49ee300666cd1c20 100644 (file)
 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();
 
index 2fdaa3a58061f80c8de2c8319d2b79c25ad2d8dd..673056e9c9b878c3d425c8815212d859de97cfcc 100644 (file)
@@ -19,7 +19,7 @@ private:
        Linker *cxx_linker;
 
 public:
-       GnuLinker(Builder &);
+       GnuLinker(Builder &, const Architecture &);
        ~GnuLinker();
 
        virtual Target *create_target(const std::list<Target *> &, const std::string &) const;
index a2c61bf1f24ffa9cd48f4add29e0501c64f47343..cefbb8c3b0188c58d525b87def1a5b694f3a40df 100644 (file)
@@ -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)
 { }
index 7371103213b91f56483f630da8cada940d3fda66..4bbbcf5595a8f3603e85901fb5bdb88503cba6f2 100644 (file)
@@ -5,6 +5,7 @@
 #include <string>
 #include <msp/fs/path.h>
 
+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() { }