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_out_dir()/p),
25 for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
29 void Binary::find_dependencies()
34 BuildInfo::LibraryMode libmode = component->get_build_info().libmode;
36 list<const Component *> queue;
37 list<Target *> dep_libs;
38 queue.push_back(component);
41 const Component *c = queue.front();
42 queue.erase(queue.begin());
44 const BuildInfo &binfo = c->get_build_info();
45 for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
47 Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
50 dep_libs.push_back(lib);
52 lib = lib->get_real_target();
53 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
54 if(stlib->get_component())
55 queue.push_back(stlib->get_component());
58 builder.problem(package->get_name(), format("Couldn't find library %s for %s", *i, name));
62 /* Add only the last occurrence of each library to the actual dependencies.
63 This ensures that static library ordering is correct. */
64 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
67 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
68 last = (j==i || *j!=*i);
74 string Binary::create_build_signature() const
76 set<const Tool *> object_tools;
77 for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
78 object_tools.insert((*i)->get_tool());
81 sigs.push_back(tool->create_build_signature(component->get_build_info()));
82 for(set<const Tool *>::const_iterator i=object_tools.begin(); i!=object_tools.end(); ++i)
83 sigs.push_back((*i)->create_build_signature(component->get_build_info()));
86 return join(sigs.begin(), sigs.end(), ";");