3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/path/utils.h>
9 #include <msp/time/utils.h>
13 #include "sourcepackage.h"
20 Tries to locate a target that will help getting this target built. If all
21 dependencies are up-to-date, returns this target. If there are no targets
22 ready to be built (maybe because they are being built right now), returns 0.
24 Target *Target::get_buildable_target()
29 bool self_ok=!building;
30 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
32 Target *tgt=(*i)->get_buildable_target();
35 else if((*i)->get_rebuild())
45 void Target::add_depend(Target *dep)
48 throw InvalidParameterValue("A target can't depend on itself");
49 depends.push_back(dep);
50 dep->rdepends.push_back(this);
54 Prepares the target by recursively preparing dependencies, then checking
55 whether rebuilding is needed. A flag is used to prevent unnecessary
58 void Target::prepare()
64 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
72 Returns the number of targets that need to be rebuilt in order to get this
75 unsigned Target::count_rebuild()
81 unsigned count=rebuild;
82 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
83 count+=(*i)->count_rebuild();
88 Changes the mtime of the target to the current time.
95 Target::Target(Builder &b, const Package *p, const string &n):
106 builder.add_target(this);
109 if(!Path::stat(name, st))
110 mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
113 void Target::mark_rebuild(const std::string &reason)
116 rebuild_reason=reason;
120 Checks if this target needs to be rebuilt and why.
122 void Target::check_rebuild()
127 if(builder.get_build_all())
128 mark_rebuild("Rebuilding everything");
130 mark_rebuild("Does not exist");
133 for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
135 if((*i)->get_mtime()>mtime)
136 mark_rebuild(Path::basename((*i)->get_name())+" has changed");
137 else if((*i)->get_rebuild())
138 mark_rebuild(Path::basename((*i)->get_name())+" needs rebuilding");
142 const SourcePackage *spkg=dynamic_cast<const SourcePackage *>(package);
143 if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
144 mark_rebuild("Package options changed");
148 Hooks the target up with the given action, then returns it. This should be
149 called from the public build() function of buildable targets.
151 Action *Target::build(Action *action)
154 action->signal_done.connect(sigc::mem_fun(this, &Target::build_done));
159 Handles for the build_done signal of Action.
161 void Target::build_done()