]> git.tdb.fi Git - builder.git/blob - source/target.h
Add Id tag to all files
[builder.git] / source / target.h
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef TARGET_H_
9 #define TARGET_H_
10
11 #include <list>
12 #include <string>
13 #include <msp/time/timestamp.h>
14
15 class Action;
16 class Builder;
17 class Package;
18
19 class Target;
20 typedef std::list<Target *> TargetList;
21
22 /**
23 Targets make up the build graph.  This class is a base for all target types and
24 handles many common tasks.  Most targets are associated with a file.
25 */
26 class Target
27 {
28 public:
29         const std::string  &get_name() const           { return name; }
30         Target             *get_buildable_target();
31         bool               get_buildable() const       { return buildable; }
32         bool               get_rebuild() const         { return rebuild; }
33         const std::string  &get_rebuild_reason() const { return rebuild_reason; }
34         const Msp::Time::TimeStamp &get_mtime() const  { return mtime; }
35         virtual const char *get_type() const=0;
36         const TargetList   &get_depends() const        { return depends; }
37         const Package      *get_package() const        { return package; }
38         bool               get_depends_ready() const   { return deps_ready; }
39         void               add_depend(Target *);
40         virtual void       find_depends()              { deps_ready=true; }
41         virtual void       prepare();
42
43         /**
44         Creates and returns an Action suitable for building this target.
45         */
46         virtual Action     *build()=0;
47
48         void               reset_count()               { counted=false; }
49         virtual unsigned   count_rebuild();
50         void               touch();
51         virtual ~Target() { }
52 protected:
53         Builder       &builder;
54         const Package *package;
55         std::string   name;
56         Msp::Time::TimeStamp mtime;
57
58         bool          buildable;
59         bool          building;
60         bool          rebuild;
61         std::string   rebuild_reason;
62
63         TargetList    depends;
64         TargetList    rdepends;
65         bool          deps_ready;
66
67         bool          prepared;
68         bool          counted;
69
70         Target(Builder &, const Package *, const std::string &);
71         void         mark_rebuild(const std::string &);
72         virtual void check_rebuild();
73         Action       *build(Action *);
74         virtual void build_done();
75 };
76
77 #endif