1 #include <msp/path/utils.h>
2 #include <msp/time/utils.h>
12 Tries to locate a target that will help getting this target built. If all
13 dependencies are up-to-date, returns this target. If there are no targets
14 ready to be built (maybe because they are being built right now), returns 0.
16 Target *Target::get_buildable_target()
19 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
21 Target *tgt=(*i)->get_buildable_target();
24 else if((*i)->get_rebuild())
28 if(self_ok && rebuild && !building)
34 void Target::add_depend(Target *dep)
36 depends.push_back(dep);
37 dep->rdepends.push_back(this);
41 Prepares the target by recursively preparing dependencies, then checking
42 whether rebuilding is needed. A flag is used to prevent unnecessary
45 void Target::prepare()
51 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
59 Returns the number of targets that need to be rebuilt in order to get this
62 unsigned Target::count_rebuild()
68 unsigned count=rebuild;
69 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
70 count+=(*i)->count_rebuild();
75 Changes the mtime of the target to the current time.
82 Target::Target(Builder &b, const Package *p, const string &n):
94 if(!Path::stat(name, st))
95 mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
98 void Target::mark_rebuild(const std::string &reason)
101 rebuild_reason=reason;
105 Checks if this target needs to be rebuilt and why.
107 void Target::check_rebuild()
112 if(builder.get_build_all())
113 mark_rebuild("Rebuilding everything");
115 mark_rebuild("Does not exist");
118 for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
120 if((*i)->get_mtime()>mtime)
121 mark_rebuild(Path::basename((*i)->get_name())+" has changed");
122 else if((*i)->get_rebuild())
123 mark_rebuild(Path::basename((*i)->get_name())+" needs rebuilding");
126 if(!rebuild && package && package->get_config().get_mtime()>mtime)
127 mark_rebuild("Package options changed");
131 Hooks the target up with the given action, then returns it. This should be
132 called from the public build() function of buildable targets.
134 Action *Target::build(Action *action)
137 action->signal_done.connect(sigc::mem_fun(this, &Target::build_done));
142 Handles for the build_done signal of Action.
144 void Target::build_done()