3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/fs/stat.h>
9 #include <msp/fs/utils.h>
10 #include <msp/time/utils.h>
13 #include "filetarget.h"
15 #include "sourcepackage.h"
21 Target::Target(Builder &b, const Package *p, const string &n):
32 builder.add_target(this);
35 Target *Target::get_buildable_target()
40 bool self_ok = !building;
41 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
43 Target *tgt = (*i)->get_buildable_target();
46 else if((*i)->get_rebuild())
56 void Target::add_depend(Target *dep)
59 throw InvalidParameterValue("A target can't depend on itself");
60 depends.push_back(dep);
61 dep->rdepends.push_back(this);
64 void Target::prepare()
70 builder.problem((package ? package->get_name() : string()), "Dependency cycle detected at "+name);
75 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
83 Action *Target::build()
91 if(FileTarget *ft = dynamic_cast<FileTarget *>(this))
92 if(!builder.get_dry_run() && FS::exists(ft->get_path()))
93 FS::unlink(ft->get_path());
95 Action *action = create_action();
98 action->signal_done.connect(sigc::mem_fun(this, &Target::build_done));
111 void Target::mark_rebuild(const std::string &reason)
114 rebuild_reason = reason;
117 void Target::check_rebuild()
122 if(builder.get_build_all())
123 mark_rebuild("Rebuilding everything");
125 mark_rebuild("Does not exist");
128 for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
130 if((*i)->get_mtime()>mtime)
131 mark_rebuild(FS::basename((*i)->get_name())+" has changed");
132 else if((*i)->get_rebuild())
133 mark_rebuild(FS::basename((*i)->get_name())+" needs rebuilding");
137 const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(package);
138 if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
139 mark_rebuild("Package options changed");
142 void Target::build_done()