-#include <msp/fs/utils.h>
-#include <msp/strings/format.h>
-#include <msp/strings/utils.h>
-#include "binary.h"
-#include "builder.h"
-#include "component.h"
-#include "objectfile.h"
-#include "sharedlibrary.h"
-#include "sourcepackage.h"
-#include "staticlibrary.h"
-#include "tool.h"
-
-using namespace std;
-using namespace Msp;
-
-Binary::Binary(Builder &b, const FS::Path &p):
- FileTarget(b, p)
-{ }
-
-Binary::Binary(Builder &b, const Component &c, const string &p, const list<ObjectFile *> &objs):
- FileTarget(b, c.get_package(), c.get_package().get_out_dir()/p),
- objects(objs)
-{
- component = &c;
- for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
- add_dependency(**i);
-}
-
-void Binary::find_dependencies()
-{
- if(!component)
- return;
-
- list<const Component *> queue;
- list<Target *> dep_libs;
- queue.push_back(component);
- while(!queue.empty())
- {
- const Component *c = queue.front();
- queue.erase(queue.begin());
-
- const BuildInfo &binfo = c->get_build_info();
- for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
- {
- BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(*i);
- Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
- if(lib)
- {
- dep_libs.push_back(lib);
-
- lib = lib->get_real_target();
- if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
- if(stlib->get_component())
- queue.push_back(stlib->get_component());
- }
- else
- builder.problem(package->get_name(), format("Couldn't find library %s for %s", *i, name));
- }
- }
-
- /* Add only the last occurrence of each library to the actual dependencies.
- This ensures that static library ordering is correct. */
- for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
- {
- bool last = true;
- for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
- last = (j==i || *j!=*i);
- if(last)
- add_dependency(**i);
- }
-}
-
-string Binary::create_build_signature() const
-{
- set<const Tool *> object_tools;
- for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
- object_tools.insert((*i)->get_tool());
-
- list<string> sigs;
- sigs.push_back(tool->create_build_signature(component->get_build_info()));
- for(set<const Tool *>::const_iterator i=object_tools.begin(); i!=object_tools.end(); ++i)
- sigs.push_back((*i)->create_build_signature(component->get_build_info()));
- sigs.sort();
-
- return join(sigs.begin(), sigs.end(), ";");
-}