5 #include "executable.h"
8 #include "objectfile.h"
10 #include "staticlibrary.h"
15 Executable::Executable(Builder &b, const Component &c, const list<ObjectFile *> &objs):
16 Target(b, &c.get_package(), generate_target_name(c)),
20 for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
25 Finds and adds any required libraries to the dependencies.
27 void Executable::find_depends()
29 LibMode libmode=package->get_library_mode();
31 list<const Component *> queue;
32 list<Target *> dep_libs;
33 queue.push_back(&comp);
36 const Component *c=queue.front();
37 queue.erase(queue.begin());
39 const list<string> &libs=c->get_build_info().libs;
40 for(StringList::const_iterator i=libs.begin(); i!=libs.end(); ++i)
42 Target *lib=builder.get_library(*i, c->get_build_info().libpath, libmode);
45 if(contains(depends, lib))
48 dep_libs.push_front(lib);
50 if(dynamic_cast<Install *>(lib))
51 lib=lib->get_depends().front();
52 if(StaticLibrary *stlib=dynamic_cast<StaticLibrary *>(lib))
53 queue.push_back(&stlib->get_component());
56 cout<<"Couldn't find library "<<*i<<" for "<<name<<'\n';
57 //XXX Throw an exception here or something
61 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
67 Action *Executable::build()
69 return Target::build(new Link(builder, *this));;
73 Returns the name for the executable. We can't do this in the constructor since
74 we need to pass the value to the Target c'tor.
76 string Executable::generate_target_name(const Component &c)
79 const string &arch=c.get_package().get_arch();
81 if(c.get_type()==Component::LIBRARY)
89 else if(c.get_type()==Component::MODULE)
91 else if(c.get_type()==Component::PROGRAM)
97 return (c.get_package().get_out_dir()/(prefix+c.get_name()+suffix)).str();