]> git.tdb.fi Git - builder.git/blob - source/binary.cpp
Don't copy cpu from a potentially incompatible architecture
[builder.git] / source / binary.cpp
1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
3 #include "binary.h"
4 #include "builder.h"
5 #include "component.h"
6 #include "objectfile.h"
7 #include "sharedlibrary.h"
8 #include "sourcepackage.h"
9 #include "staticlibrary.h"
10
11 using namespace std;
12 using namespace Msp;
13
14 Binary::Binary(Builder &b, const FS::Path &p):
15         FileTarget(b, 0, p)
16 { }
17
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)
20 {
21         component = &c;
22         for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
23                 add_depend(*i);
24 }
25
26 void Binary::find_depends()
27 {
28         if(!component)
29                 return;
30
31         const SourcePackage &spkg = component->get_package();
32         LibMode libmode = spkg.get_library_mode();
33         if(dynamic_cast<SharedLibrary *>(this))
34                 libmode = DYNAMIC;
35
36         list<const Component *> queue;
37         list<Target *> dep_libs;
38         queue.push_back(component);
39         while(!queue.empty())
40         {
41                 const Component *c = queue.front();
42                 queue.erase(queue.begin());
43
44                 const BuildInfo::PathList &libpath = c->get_build_info().libpath;
45
46                 const BuildInfo::WordList &libs = c->get_build_info().libs;
47                 for(StringList::const_iterator i=libs.begin(); i!=libs.end(); ++i)
48                 {
49                         Target *lib = builder.get_vfs().find_library(*i, libpath, libmode);
50                         if(lib)
51                         {
52                                 dep_libs.push_back(lib);
53
54                                 lib = lib->get_real_target();
55                                 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
56                                         queue.push_back(stlib->get_component());
57                         }
58                         else
59                                 builder.problem(spkg.get_name(), format("Couldn't find library %s for %s", *i, name));
60                 }
61         }
62
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)
66         {
67                 bool last = true;
68                 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
69                         last = (j==i || *j!=*i);
70                 if(last)
71                         add_depend(*i);
72         }
73 }