1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
3 #include <msp/strings/utils.h>
7 #include "objectfile.h"
8 #include "sharedlibrary.h"
9 #include "sourcepackage.h"
10 #include "staticlibrary.h"
16 Binary::Binary(Builder &b, const FS::Path &p):
20 Binary::Binary(Builder &b, const Component &c, const string &p, const list<ObjectFile *> &objs):
21 FileTarget(b, c.get_package(), c.get_package().get_output_directory()/p),
25 for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
29 void Binary::find_dependencies()
34 list<const Component *> queue;
35 list<Target *> dep_libs;
36 queue.push_back(component);
39 const Component *c = queue.front();
40 queue.erase(queue.begin());
42 const BuildInfo &binfo = c->get_build_info();
43 for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
45 BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(*i);
46 Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
49 Target *real = lib->get_real_target();
50 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(real))
52 dep_libs.push_back(stlib);
53 if(stlib->get_component())
54 queue.push_back(stlib->get_component());
57 dep_libs.push_back(lib);
60 builder.problem(package->get_name(), format("Couldn't find library %s for %s", *i, name));
64 /* Add only the last occurrence of each library to the actual dependencies.
65 This ensures that static library ordering is correct. */
66 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
69 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
70 last = (j==i || *j!=*i);
76 string Binary::create_build_signature() const
78 set<const Tool *> object_tools;
79 for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
80 object_tools.insert((*i)->get_tool());
83 sigs.push_back(tool->create_build_signature(component->get_build_info()));
84 for(set<const Tool *>::const_iterator i=object_tools.begin(); i!=object_tools.end(); ++i)
85 sigs.push_back((*i)->create_build_signature(component->get_build_info()));
88 return join(sigs.begin(), sigs.end(), ";");