1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
6 #include "objectfile.h"
7 #include "sharedlibrary.h"
8 #include "sourcepackage.h"
9 #include "staticlibrary.h"
14 Binary::Binary(Builder &b, const FS::Path &p):
18 Binary::Binary(Builder &b, const Component &c, const std::string &p, const list<ObjectFile *> &objs):
19 FileTarget(b, &c.get_package(), c.get_package().get_out_dir()/p)
22 for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
26 void Binary::find_depends()
31 const SourcePackage &spkg = component->get_package();
32 LibMode libmode = spkg.get_library_mode();
33 if(dynamic_cast<SharedLibrary *>(this))
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::PathList &libpath = c->get_build_info().libpath;
46 const BuildInfo::WordList &libs = c->get_build_info().libs;
47 for(StringList::const_iterator i=libs.begin(); i!=libs.end(); ++i)
49 Target *lib = builder.get_vfs().find_library(*i, libpath, libmode);
52 dep_libs.push_back(lib);
54 lib = lib->get_real_target();
55 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
56 queue.push_back(stlib->get_component());
59 builder.problem(spkg.get_name(), format("Couldn't find library %s for %s", *i, name));
63 /* Add only the last occurrence of each library to the actual dependencies.
64 This ensures that static library ordering is correct. */
65 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
68 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
69 last = (j==i || *j!=*i);