-#include <algorithm>
-#include <msp/fs/utils.h>
-#include "builder.h"
-#include "component.h"
-#include "objectfile.h"
-#include "sourcefile.h"
-#include "sourcepackage.h"
-
-using namespace std;
-using namespace Msp;
-
-ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s):
- FileTarget(b, &c.get_package(), generate_target_path(c, FS::relative(s.get_path(), c.get_package().get_source()).str())),
- comp(c),
- source(s)
-{
- add_depend(&source);
-}
-
-void ObjectFile::find_depends()
-{
- for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
- {
- (*i)->prepare();
- find_depends(dynamic_cast<FileTarget *>(*i));
- }
-}
-
-
-void ObjectFile::find_depends(FileTarget *tgt)
-{
- FileTarget *rtgt = dynamic_cast<FileTarget *>(tgt->get_real_target());
- const Dependencies &tdeps = rtgt->get_depends();
- Dependencies deps_to_add;
- if(rtgt==tgt)
- {
- /* We are using the target from its original location, so dependencies
- apply directly */
- deps_to_add = tdeps;
- }
- else
- {
- /* The target has been displaced by installing it. Displace any
- dependencies that come from the same package as well. */
- const SourcePackage *tpkg = rtgt->get_package();
- for(Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i)
- {
- FileTarget *file = dynamic_cast<FileTarget *>(*i);
- if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source())>=0)
- {
- FS::Path displaced = tgt->get_path()/FS::relative(file->get_path(), rtgt->get_path());
- if(Target *ddep = builder.get_vfs().get_target(displaced))
- deps_to_add.push_back(ddep);
- }
- else
- deps_to_add.push_back(*i);
- }
- }
-
- for(Dependencies::const_iterator i=deps_to_add.begin(); i!=deps_to_add.end(); ++i)
- if(find(depends.begin(), depends.end(), *i)==depends.end())
- add_depend(*i);
-}
-
-FS::Path ObjectFile::generate_target_path(const Component &comp, const string &src)
-{
- const SourcePackage &pkg = comp.get_package();
- string fn = FS::basepart(src)+".o";
- if(!fn.compare(0, 2, "./"))
- fn.erase(0, 2);
- for(string::iterator i=fn.begin(); i!=fn.end(); ++i)
- if(*i=='/')
- *i = '_';
- return pkg.get_temp_dir()/comp.get_name()/fn;
-}