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):
33 Target *Target::get_buildable_target()
38 bool self_ok = !building;
39 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
41 Target *tgt = (*i)->get_buildable_target();
44 else if((*i)->get_rebuild())
54 void Target::add_depend(Target *dep)
57 throw InvalidParameterValue("A target can't depend on itself");
58 depends.push_back(dep);
61 void Target::prepare()
67 builder.problem((package ? package->get_name() : string()), "Dependency cycle detected at "+name);
72 for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
80 Action *Target::build()
88 if(FileTarget *ft = dynamic_cast<FileTarget *>(this))
89 if(!builder.get_dry_run() && FS::exists(ft->get_path()))
90 FS::unlink(ft->get_path());
92 Action *action = create_action();
95 action->signal_done.connect(sigc::mem_fun(this, &Target::build_done));
108 void Target::mark_rebuild(const std::string &reason)
111 rebuild_reason = reason;
114 void Target::check_rebuild()
119 if(builder.get_build_all())
120 mark_rebuild("Rebuilding everything");
122 mark_rebuild("Does not exist");
125 for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
127 if((*i)->get_mtime()>mtime)
128 mark_rebuild((*i)->get_name()+" has changed");
129 else if((*i)->get_rebuild())
130 mark_rebuild((*i)->get_name()+" needs rebuilding");
134 const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(package);
135 if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
136 mark_rebuild("Package options changed");
139 void Target::build_done()