}
else
system_path.push_back("/usr/"+arch.get_cross_prefix()+"/lib");
+
+ default_linker = new Linker(*this, "CC");
+ cxx_linker = new Linker(*this, "CXX");
+}
+
+GnuLinker::~GnuLinker()
+{
+ delete default_linker;
+ delete cxx_linker;
}
Target *GnuLinker::create_target(const list<Target *> &sources, const std::string &arg) const
if(sources.empty())
throw invalid_argument("GnuLinker::create_target");
list<ObjectFile *> objs;
+ Linker *linker = default_linker;
for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
{
if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+ {
objs.push_back(obj);
+ if(obj->get_tool()->get_tag()=="CXX")
+ linker = cxx_linker;
+ }
else
throw invalid_argument("GnuLinker::create_target");
}
bin = new SharedLibrary(builder, comp, objs);
else
bin = new Executable(builder, comp, objs);
- bin->set_tool(*this);
+ bin->set_tool(*linker);
return bin;
}
-Task *GnuLinker::run(const Target &target) const
+Task *GnuLinker::run(const Target &) const
{
- const Binary &bin = dynamic_cast<const Binary &>(target);
+ throw logic_error("GnuLinker should not be run directly");
+}
- string command = "gcc";
- const Target::Dependencies &depends = target.get_depends();
- for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
- {
- const Tool *tool = obj->get_tool();
- if(tool->get_tag()=="CXX")
- command = "g++";
- }
+GnuLinker::Linker::Linker(GnuLinker &p, const string &compiler_tag):
+ SubTool(p)
+{
+ if(compiler_tag=="CC")
+ command = "gcc";
+ else if(compiler_tag=="CXX")
+ command = "g++";
+ else
+ throw invalid_argument("GnuLinker::Linker::Linker");
+}
+
+Target *GnuLinker::Linker::create_target(const list<Target *> &sources, const string &arg) const
+{
+ return parent.create_target(sources, arg);
+}
+
+Task *GnuLinker::Linker::run(const Target &target) const
+{
+ const Binary &bin = dynamic_cast<const Binary &>(target);
vector<string> argv;
argv.push_back(command);
argv.push_back("-o");
argv.push_back(relative(bin.get_path(), work_dir).str());
+
+ const Target::Dependencies &depends = target.get_depends();
for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
{
Target *tgt = (*i)->get_real_target();
class GnuLinker: public Tool
{
+private:
+ class Linker: public SubTool
+ {
+ private:
+ std::string command;
+
+ public:
+ Linker(GnuLinker &, const std::string &);
+
+ virtual Target *create_target(const std::list<Target *> &, const std::string &) const;
+ virtual Task *run(const Target &) const;
+ };
+
+ Linker *default_linker;
+ Linker *cxx_linker;
+
public:
GnuLinker(Builder &);
+ ~GnuLinker();
virtual Target *create_target(const std::list<Target *> &, const std::string &) const;
virtual Task *run(const Target &) const;