3 This file is part of builder
4 Copyright © 2006-2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/fs/utils.h>
9 #include <msp/strings/formatter.h>
12 #include "component.h"
15 #include "objectfile.h"
17 #include "sharedlibrary.h"
18 #include "staticlibrary.h"
23 Binary::Binary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
24 FileTarget(b, &c.get_package(), generate_target_path(c)),
28 for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
32 void Binary::find_depends()
34 LibMode libmode = comp.get_package().get_library_mode();
35 if(dynamic_cast<SharedLibrary *>(this))
38 list<const Component *> queue;
39 list<Target *> dep_libs;
40 queue.push_back(&comp);
43 const Component *c = queue.front();
44 queue.erase(queue.begin());
46 const StringList &libpath = c->get_build_info().libpath;
48 const list<string> &libs = c->get_build_info().libs;
49 for(StringList::const_iterator i=libs.begin(); i!=libs.end(); ++i)
51 Target *lib = builder.get_library(*i, libpath, libmode);
54 dep_libs.push_back(lib);
56 lib = lib->get_real_target();
57 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
58 queue.push_back(&stlib->get_component());
61 builder.problem(comp.get_package().get_name(), format("Couldn't find library %s for %s", *i, name));
65 /* Add only the last occurrence of each library to the actual dependencies.
66 This ensures that static library ordering is correct. */
67 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
70 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
71 last = (j==i || *j!=*i);
79 Action *Binary::create_action()
81 return new Link(builder, *this);
84 FS::Path Binary::generate_target_path(const Component &c)
86 const SourcePackage &pkg = c.get_package();
87 string prefix, suffix;
88 const string &sys = pkg.get_builder().get_current_arch().get_system();
90 if(c.get_type()==Component::LIBRARY)
98 else if(c.get_type()==Component::MODULE)
100 else if(c.get_type()==Component::PROGRAM)
106 return pkg.get_out_dir()/(prefix+c.get_name()+suffix);