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