}
}
- 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));
#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");
}
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;
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");
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;
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
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);
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;
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");
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;
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");
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);
}
}
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();
Linker *cxx_linker;
public:
- GnuLinker(Builder &);
+ GnuLinker(Builder &, const Architecture &);
~GnuLinker();
virtual Target *create_target(const std::list<Target *> &, const std::string &) const;
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)
{ }
#include <string>
#include <msp/fs/path.h>
+class Architecture;
class Builder;
class Component;
class FileTarget;
protected:
Builder &builder;
+ const Architecture *architecture;
std::string tag;
FileTarget *executable;
SuffixList input_suffixes;
SearchPath system_path;
Tool(Builder &, const std::string &);
+ Tool(Builder &, const Architecture &, const std::string &);
public:
virtual ~Tool() { }