- Target::add_depend(tgt);
- new_deps.push_back(tgt);
-}
-
-Action *ObjectFile::create_action()
-{
- return new Compile(builder, *this);
-}
+ FileTarget *rtgt = dynamic_cast<FileTarget *>(tgt->get_real_target());
+ const Dependencies &tdeps = rtgt->get_dependencies();
+ 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_directory())>=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
+ {
+ const Component *tcomp = file->get_component();
+ const Component::OverlayList &overlays = tcomp->get_overlays();
+ string last_dir = FS::basename(FS::dirname(displaced));
+ for(Component::OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
+ if(last_dir==*j)
+ {
+ displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path());
+ if((ddep = builder.get_vfs().get_target(displaced)))
+ deps_to_add.push_back(ddep);
+ }
+ }
+ }
+ else
+ deps_to_add.push_back(*i);
+ }
+ }