]> git.tdb.fi Git - builder.git/commitdiff
Add build info to tools and use it to pass runtime libs
authorMikko Rasa <tdb@tdb.fi>
Fri, 3 Oct 2014 21:42:20 +0000 (00:42 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 3 Oct 2014 21:42:20 +0000 (00:42 +0300)
This is more flexible and removes the need for the linker to know about
all compilers.

source/binary.cpp
source/binary.h
source/gnulinker.cpp
source/gnuobjccompiler.cpp
source/target.cpp
source/tool.h

index 6efe77a6475b5ce74fc18d9c2435910b3734f5a8..079ae84995843d669f632789030e4bbb24bde69d 100644 (file)
@@ -29,6 +29,15 @@ Binary::Binary(Builder &b, const Component &c, const string &p, const list<Objec
        arch_in_build_sig = true;
 }
 
+void Binary::collect_build_info(BuildInfo &binfo) const
+{
+       for(list<ObjectFile *>::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)
index b4357581fc905fde0b5110cac788f4149306196e..7581541bd3d9d1a726e273460ecbbd02d56e47fd 100644 (file)
@@ -18,6 +18,10 @@ protected:
        Binary(Builder &, const Msp::FS::Path &);
        Binary(Builder &, const Component &, const std::string &, const std::list<ObjectFile *> &);
 
+public:
+       virtual void collect_build_info(BuildInfo &) const;
+
+protected:
        virtual void find_dependencies();
 };
 
index 6a2fcd54cdfd17d90f330f53f75b66b5bbe625e8..2d7438d61b547e01f137c0905c049ed7f1f7d89d 100644 (file)
@@ -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<ObjectFile *>(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<StaticLibrary *>(tgt))
                        argv.push_back((file?file:stlib)->get_path().str());
                else if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(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")
index eddca5ff9a5de66b88fe6f40d90cbc8831d0f0b0..228eecb5249a91452ff76cb1f17147ef409f4365 100644 (file)
@@ -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
index 7c5532f9f8200daca4859cedaa51682a138a9a10..cb44b1322d19cad25e8c392077d3e6ea79925485 100644 (file)
@@ -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)
index 7531bbf86b945e82638ea0044a106001b4a45931..ad89e47431b3b47eee53c8d7a747ef98cce2707c 100644 (file)
@@ -4,6 +4,7 @@
 #include <list>
 #include <string>
 #include <msp/fs/path.h>
+#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<std::string> 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; }