+string FileTarget::generate_name(Builder &builder, const SourcePackage *pkg, const FS::Path &path)
+{
+ if(pkg && FS::descendant_depth(path, pkg->get_source_directory())>=0)
+ {
+ FS::Path relpath = FS::relative(path, pkg->get_source_directory());
+ return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
+ }
+ else if(FS::descendant_depth(path, builder.get_prefix())>=0)
+ {
+ FS::Path relpath = FS::relative(path, builder.get_prefix());
+ return "<prefix>"+relpath.str().substr(1);
+ }
+
+ return path.str();
+}
+
+void FileTarget::touch()
+{
+ mtime = Time::now();
+ modified();
+ signal_bubble_rebuild.emit();
+}
+
+void FileTarget::check_rebuild()
+{
+ if(!tool)
+ return;
+
+ if(!mtime)
+ mark_rebuild("Does not exist");
+ else
+ {
+ for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
+ {
+ FileTarget *ft = dynamic_cast<FileTarget *>(*i);
+ if(ft && ft->get_mtime()>mtime)
+ mark_rebuild((*i)->get_name()+" has changed");
+ else if((*i)->needs_rebuild())
+ mark_rebuild((*i)->get_name()+" needs rebuilding");
+ }
+ }
+
+ if(!needs_rebuild() && package)
+ {
+ if(package->get_config().get_mtime()>mtime)
+ mark_rebuild("Package options changed");
+
+ string build_sig = create_build_signature();
+ if(package->get_cache().has_key(this, "build_sig"))
+ {
+ if(package->get_cache().get_value(this, "build_sig")!=build_sig)
+ mark_rebuild("Build signature changed");
+ }
+ }
+}
+
+string FileTarget::create_build_signature() const
+{
+ if(!package)
+ return string();
+
+ const BuildInfo &binfo = (component ? component->get_build_info() : package->get_build_info());
+ return tool->create_build_signature(binfo);
+}
+
+Task *FileTarget::build()
+{
+ Task *task = Target::build();
+ task->set_file(path);
+ task->set_unlink(true);
+ return task;
+}
+
+void FileTarget::build_finished(bool success)
+{
+ if(success)
+ {
+ stat();
+ if(package)
+ {
+ string build_sig = create_build_signature();
+ if(!build_sig.empty())
+ package->get_cache().set_value(this, "build_sig", build_sig);
+ }
+ }
+
+ Target::build_finished(success);
+}
+
+void FileTarget::clean()
+{
+ if(mtime)