]> git.tdb.fi Git - builder.git/blob - source/binary.cpp
Remove the buildable flag and instead check for tool being non-null
[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 "link.h"
7 #include "objectfile.h"
8 #include "sharedlibrary.h"
9 #include "sourcepackage.h"
10 #include "staticlibrary.h"
11
12 using namespace std;
13 using namespace Msp;
14
15 Binary::Binary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
16         FileTarget(b, &c.get_package(), generate_target_path(c)),
17         comp(c)
18 {
19         for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
20                 add_depend(*i);
21
22         if(c.get_type()==Component::LIBRARY)
23                 install_location = "lib";
24         else if(c.get_type()==Component::MODULE)
25                 install_location = "lib/"+package->get_name();
26         else if(c.get_type()==Component::PROGRAM)
27                 install_location = "bin";
28 }
29
30 void Binary::find_depends()
31 {
32         LibMode libmode = comp.get_package().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(&comp);
39         while(!queue.empty())
40         {
41                 const Component *c = queue.front();
42                 queue.erase(queue.begin());
43
44                 const StringList &libpath = c->get_build_info().libpath;
45
46                 const list<string> &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(comp.get_package().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
74         deps_ready = true;
75 }
76
77 FS::Path Binary::generate_target_path(const Component &c)
78 {
79         const SourcePackage &pkg = c.get_package();
80         string prefix, suffix;
81         const string &sys = pkg.get_builder().get_current_arch().get_system();
82
83         if(c.get_type()==Component::LIBRARY)
84         {
85                 prefix = "lib";
86                 if(sys=="windows")
87                         suffix = ".dll";
88                 else
89                         suffix = ".so";
90         }
91         else if(c.get_type()==Component::MODULE)
92                 suffix = ".m";
93         else if(c.get_type()==Component::PROGRAM)
94         {
95                 if(sys=="windows")
96                         suffix = ".exe";
97         }
98
99         return pkg.get_out_dir()/(prefix+c.get_name()+suffix);
100 }