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()
21 bool self_ok=!building;
22 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
24 Target *tgt=(*i)->get_buildable_target();
27 else if((*i)->get_rebuild())
37 void Target::add_depend(Target *dep)
39 depends.push_back(dep);
40 dep->rdepends.push_back(this);
44 Prepares the target by recursively preparing dependencies, then checking
45 whether rebuilding is needed. A flag is used to prevent unnecessary
48 void Target::prepare()
54 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
62 Returns the number of targets that need to be rebuilt in order to get this
65 unsigned Target::count_rebuild()
71 unsigned count=rebuild;
72 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
73 count+=(*i)->count_rebuild();
78 Changes the mtime of the target to the current time.
85 Target::Target(Builder &b, const Package *p, const string &n):
97 if(!Path::stat(name, st))
98 mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
101 void Target::mark_rebuild(const std::string &reason)
104 rebuild_reason=reason;
108 Checks if this target needs to be rebuilt and why.
110 void Target::check_rebuild()
115 if(builder.get_build_all())
116 mark_rebuild("Rebuilding everything");
118 mark_rebuild("Does not exist");
121 for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
123 if((*i)->get_mtime()>mtime)
124 mark_rebuild(Path::basename((*i)->get_name())+" has changed");
125 else if((*i)->get_rebuild())
126 mark_rebuild(Path::basename((*i)->get_name())+" needs rebuilding");
129 if(!rebuild && package && package->get_config().get_mtime()>mtime)
130 mark_rebuild("Package options changed");
134 Hooks the target up with the given action, then returns it. This should be
135 called from the public build() function of buildable targets.
137 Action *Target::build(Action *action)
140 action->signal_done.connect(sigc::mem_fun(this, &Target::build_done));
145 Handles for the build_done signal of Action.
147 void Target::build_done()