4 #include "executable.h"
7 #include "objectfile.h"
9 #include "staticlibrary.h"
14 Executable::Executable(Builder &b, const Component &c, const list<ObjectFile *> &objs):
15 Target(b, &c.get_package(), generate_target_name(c)),
19 for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
24 Finds and adds any required libraries to the dependencies.
26 void Executable::find_depends()
28 LibMode libmode=package->get_library_mode();
30 list<const Component *> queue;
31 list<Target *> dep_libs;
32 queue.push_back(&comp);
35 const Component *c=queue.front();
36 queue.erase(queue.begin());
38 const StringList &libpath=c->get_build_info().libpath;
39 const string &arch=c->get_package().get_arch();
41 const list<string> &libs=c->get_build_info().libs;
42 for(StringList::const_iterator i=libs.begin(); i!=libs.end(); ++i)
44 Target *lib=builder.get_library(*i, arch, libpath, libmode);
47 dep_libs.push_back(lib);
49 if(dynamic_cast<Install *>(lib))
50 lib=lib->get_depends().front();
51 if(StaticLibrary *stlib=dynamic_cast<StaticLibrary *>(lib))
52 queue.push_back(&stlib->get_component());
55 cout<<"Couldn't find library "<<*i<<" for "<<name<<'\n';
56 //XXX Throw an exception here or something
60 /* Add only the last occurrence of each library to the actual dependencies.
61 This ensures that static library ordering is correct. */
62 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
65 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
66 last=(j==i || *j!=*i);
74 Action *Executable::build()
76 return Target::build(new Link(builder, *this));;
80 Returns the name for the executable. We can't do this in the constructor since
81 we need to pass the value to the Target c'tor.
83 string Executable::generate_target_name(const Component &c)
86 const string &arch=c.get_package().get_arch();
88 if(c.get_type()==Component::LIBRARY)
96 else if(c.get_type()==Component::MODULE)
98 else if(c.get_type()==Component::PROGRAM)
104 return (c.get_package().get_out_dir()/(prefix+c.get_name()+suffix)).str();