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)
40 throw InvalidParameterValue("A target can't depend on itself");
41 depends.push_back(dep);
42 dep->rdepends.push_back(this);
46 Prepares the target by recursively preparing dependencies, then checking
47 whether rebuilding is needed. A flag is used to prevent unnecessary
50 void Target::prepare()
56 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
64 Returns the number of targets that need to be rebuilt in order to get this
67 unsigned Target::count_rebuild()
73 unsigned count=rebuild;
74 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
75 count+=(*i)->count_rebuild();
80 Changes the mtime of the target to the current time.
87 Target::Target(Builder &b, const Package *p, const string &n):
99 if(!Path::stat(name, st))
100 mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
103 void Target::mark_rebuild(const std::string &reason)
106 rebuild_reason=reason;
110 Checks if this target needs to be rebuilt and why.
112 void Target::check_rebuild()
117 if(builder.get_build_all())
118 mark_rebuild("Rebuilding everything");
120 mark_rebuild("Does not exist");
123 for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
125 if((*i)->get_mtime()>mtime)
126 mark_rebuild(Path::basename((*i)->get_name())+" has changed");
127 else if((*i)->get_rebuild())
128 mark_rebuild(Path::basename((*i)->get_name())+" needs rebuilding");
131 if(!rebuild && package && package->get_config().get_mtime()>mtime)
132 mark_rebuild("Package options changed");
136 Hooks the target up with the given action, then returns it. This should be
137 called from the public build() function of buildable targets.
139 Action *Target::build(Action *action)
142 action->signal_done.connect(sigc::mem_fun(this, &Target::build_done));
147 Handles for the build_done signal of Action.
149 void Target::build_done()