From: Mikko Rasa Date: Fri, 3 Oct 2014 21:42:20 +0000 (+0300) Subject: Add build info to tools and use it to pass runtime libs X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c51411c4b3ed4e6a0d8343b848db3dc736bc7857;p=builder.git Add build info to tools and use it to pass runtime libs This is more flexible and removes the need for the linker to know about all compilers. --- diff --git a/source/binary.cpp b/source/binary.cpp index 6efe77a..079ae84 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -29,6 +29,15 @@ Binary::Binary(Builder &b, const Component &c, const string &p, const list::const_iterator i=objects.begin(); i!=objects.end(); ++i) + if(const Tool *obj_tool = (*i)->get_tool()) + binfo.update_from(obj_tool->get_build_info()); + + Target::collect_build_info(binfo); +} + void Binary::find_dependencies() { if(!component) diff --git a/source/binary.h b/source/binary.h index b435758..7581541 100644 --- a/source/binary.h +++ b/source/binary.h @@ -18,6 +18,10 @@ protected: Binary(Builder &, const Msp::FS::Path &); Binary(Builder &, const Component &, const std::string &, const std::list &); +public: + virtual void collect_build_info(BuildInfo &) const; + +protected: virtual void find_dependencies(); }; diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 6a2fcd5..2d7438d 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -216,7 +216,6 @@ Task *GnuLinker::Linker::run(const Target &target) const argv.push_back(relative(bin.get_path(), work_dir).str()); bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC); - bool need_l_objc = false; const Target::Dependencies &depends = target.get_dependencies(); for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) @@ -225,13 +224,7 @@ Task *GnuLinker::Linker::run(const Target &target) const Target *tgt = (*i)->get_real_target(); if(ObjectFile *obj = dynamic_cast(tgt)) - { argv.push_back(relative(obj->get_path(), work_dir).str()); - /* XXX This is a hack. A more generic way is needed for tools to pass - information down the chain. */ - if(obj->get_tool()->get_tag()=="OBJC") - need_l_objc = true; - } else if(StaticLibrary *stlib = dynamic_cast(tgt)) argv.push_back((file?file:stlib)->get_path().str()); else if(SharedLibrary *shlib = dynamic_cast(tgt)) @@ -257,8 +250,6 @@ Task *GnuLinker::Linker::run(const Target &target) const argv.push_back(i->substr(0, i->size()-10)); } - if(need_l_objc) - argv.push_back("-lobjc"); if(static_link_ok) argv.push_back("-static"); else if(architecture->get_system()=="windows") diff --git a/source/gnuobjccompiler.cpp b/source/gnuobjccompiler.cpp index eddca5f..228eecb 100644 --- a/source/gnuobjccompiler.cpp +++ b/source/gnuobjccompiler.cpp @@ -8,6 +8,7 @@ GnuObjCCompiler::GnuObjCCompiler(Builder &b, const Architecture &a): { set_command("gcc", true); input_suffixes.push_back(".m"); + build_info.libs.push_back("objc"); } Target *GnuObjCCompiler::create_source(const Component &comp, const FS::Path &path) const diff --git a/source/target.cpp b/source/target.cpp index 7c5532f..cb44b13 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -87,6 +87,8 @@ void Target::set_tool(Tool &t) void Target::collect_build_info(BuildInfo &binfo) const { + if(tool) + binfo.update_from(tool->get_build_info()); if(component) binfo.update_from(component->get_build_info()); else if(package) diff --git a/source/tool.h b/source/tool.h index 7531bbf..ad89e47 100644 --- a/source/tool.h +++ b/source/tool.h @@ -4,6 +4,7 @@ #include #include #include +#include "buildinfo.h" class Architecture; class Builder; @@ -32,6 +33,7 @@ protected: SuffixList input_suffixes; SuffixList aux_suffixes; SearchPath system_path; + BuildInfo build_info; bool prepared; std::list problems; @@ -71,6 +73,10 @@ public: /// Returns the systemwide search path for source files. const SearchPath &get_system_path() const { return system_path; } + /** Returns tool-specific build info. This can be used by other tools down + the chain. */ + const BuildInfo &get_build_info() const { return build_info; } + /// Creates a source file appropriate for this tool. virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }