]> git.tdb.fi Git - builder.git/blob - source/target.h
Include libmode in library lookup hash
[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 <map>
13 #include <string>
14 #include <msp/time/timestamp.h>
15
16 class Action;
17 class Builder;
18 class Package;
19
20 class Target;
21 typedef std::list<Target *> TargetList;
22
23 /**
24 Targets make up the build graph.  This class is a base for all target types and
25 handles many common tasks.  Most targets are associated with a file.
26 */
27 class Target
28 {
29 public:
30         const std::string  &get_name() const           { return name; }
31         Target             *get_buildable_target();
32         bool               get_buildable() const       { return buildable; }
33         bool               get_rebuild() const         { return rebuild; }
34         const std::string  &get_rebuild_reason() const { return rebuild_reason; }
35         const Msp::Time::TimeStamp &get_mtime() const  { return mtime; }
36         virtual const char *get_type() const=0;
37         const TargetList   &get_depends() const        { return depends; }
38         const Package      *get_package() const        { return package; }
39         bool               get_depends_ready() const   { return deps_ready; }
40         void               add_depend(Target *);
41         virtual void       prepare();
42
43         /**
44         Finds dependencies for the target.  When all dependencies have been found,
45         the function should set deps_ready to true.
46         */
47         virtual void       find_depends()              { deps_ready=true; }
48
49         /**
50         Creates and returns an Action suitable for building this target.
51         */
52         Action             *build();
53
54         void               reset_count()               { counted=false; }
55         virtual unsigned   count_rebuild();
56         void               touch();
57         virtual ~Target() { }
58 protected:
59         Builder       &builder;
60         const Package *package;
61         std::string   name;
62         Msp::Time::TimeStamp mtime;
63
64         bool          buildable;
65         bool          building;
66         bool          rebuild;
67         std::string   rebuild_reason;
68
69         TargetList    depends;
70         TargetList    rdepends;
71         bool          deps_ready;
72
73         bool          prepared;
74         bool          counted;
75
76         Target(Builder &, const Package *, const std::string &);
77         void         mark_rebuild(const std::string &);
78         virtual void check_rebuild();
79         virtual Action *create_action() =0;
80         virtual void build_done();
81 };
82
83 typedef std::map<std::string, Target *> TargetMap;
84
85 #endif