2 #include <msp/fs/utils.h>
5 #include "objectfile.h"
6 #include "sourcefile.h"
7 #include "sourcepackage.h"
12 ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s):
13 FileTarget(b, c.get_package(), generate_target_path(c, FS::relative(s.get_path(), c.get_package().get_source()).str())),
20 FS::Path ObjectFile::generate_target_path(const Component &comp, const string &src)
22 const SourcePackage &pkg = comp.get_package();
23 string fn = FS::basepart(src)+".o";
24 if(!fn.compare(0, 2, "./"))
26 for(string::iterator i=fn.begin(); i!=fn.end(); ++i)
29 return pkg.get_temp_dir()/comp.get_name()/fn;
32 void ObjectFile::find_depends()
34 for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
37 find_depends(dynamic_cast<FileTarget *>(*i));
41 void ObjectFile::find_depends(FileTarget *tgt)
43 FileTarget *rtgt = dynamic_cast<FileTarget *>(tgt->get_real_target());
44 const Dependencies &tdeps = rtgt->get_depends();
45 Dependencies deps_to_add;
48 /* We are using the target from its original location, so dependencies
54 /* The target has been displaced by installing it. Displace any
55 dependencies that come from the same package as well. */
56 const SourcePackage *tpkg = rtgt->get_package();
57 for(Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i)
59 FileTarget *file = dynamic_cast<FileTarget *>(*i);
60 if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source())>=0)
62 FS::Path displaced = tgt->get_path()/FS::relative(file->get_path(), rtgt->get_path());
63 if(Target *ddep = builder.get_vfs().get_target(displaced))
64 deps_to_add.push_back(ddep);
67 deps_to_add.push_back(*i);
71 for(Dependencies::const_iterator i=deps_to_add.begin(); i!=deps_to_add.end(); ++i)
72 if(find(depends.begin(), depends.end(), *i)==depends.end())