3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
10 #include "component.h"
11 #include "executable.h"
14 #include "objectfile.h"
16 #include "staticlibrary.h"
21 Executable::Executable(Builder &b, const Component &c, const list<ObjectFile *> &objs):
22 Target(b, &c.get_package(), generate_target_name(c)),
26 for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
31 Finds and adds any required libraries to the dependencies.
33 void Executable::find_depends()
35 LibMode libmode=comp.get_package().get_library_mode();
37 list<const Component *> queue;
38 list<Target *> dep_libs;
39 queue.push_back(&comp);
42 const Component *c=queue.front();
43 queue.erase(queue.begin());
45 const StringList &libpath=c->get_build_info().libpath;
46 const string &arch=c->get_package().get_arch();
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, arch, libpath, libmode);
54 dep_libs.push_back(lib);
56 if(dynamic_cast<Install *>(lib))
57 lib=lib->get_depends().front();
58 if(StaticLibrary *stlib=dynamic_cast<StaticLibrary *>(lib))
59 queue.push_back(&stlib->get_component());
62 cout<<"Couldn't find library "<<*i<<" for "<<name<<'\n';
63 //XXX Throw an exception here or something
67 /* Add only the last occurrence of each library to the actual dependencies.
68 This ensures that static library ordering is correct. */
69 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
72 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
73 last=(j==i || *j!=*i);
81 Action *Executable::build()
83 return Target::build(new Link(builder, *this));;
87 Returns the name for the executable. We can't do this in the constructor since
88 we need to pass the value to the Target c'tor.
90 string Executable::generate_target_name(const Component &c)
93 const string &arch=c.get_package().get_arch();
95 if(c.get_type()==Component::LIBRARY)
103 else if(c.get_type()==Component::MODULE)
105 else if(c.get_type()==Component::PROGRAM)
111 return (c.get_package().get_out_dir()/(prefix+c.get_name()+suffix)).str();