+
+/**
+Checks if this target needs to be rebuilt and why.
+*/
+void Target::check_rebuild()
+{
+ if(!buildable)
+ return;
+
+ if(builder.get_build_all())
+ mark_rebuild("Rebuilding everything");
+ else if(!mtime)
+ mark_rebuild("Does not exist");
+ else
+ {
+ for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
+ {
+ if((*i)->get_mtime()>mtime)
+ mark_rebuild(basename((*i)->get_name())+" has changed");
+ else if((*i)->get_rebuild())
+ mark_rebuild(basename((*i)->get_name())+" needs rebuilding");
+ }
+ }
+
+ const SourcePackage *spkg=dynamic_cast<const SourcePackage *>(package);
+ if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
+ mark_rebuild("Package options changed");
+}
+
+/**
+Hooks the target up with the given action, then returns it. This should be
+called from the public build() function of buildable targets.
+*/
+Action *Target::build(Action *action)
+{
+ building=true;
+ action->signal_done.connect(sigc::mem_fun(this, &Target::build_done));
+ return action;
+}
+
+/**
+Handles for the build_done signal of Action.
+*/
+void Target::build_done()
+{
+ building=false;
+ rebuild=false;
+}