]> git.tdb.fi Git - builder.git/blob - source/tool.h
Track build options to rebuild primary targets when build type changes
[builder.git] / source / tool.h
1 #ifndef TOOL_H_
2 #define TOOL_H_
3
4 #include <list>
5 #include <string>
6 #include <msp/fs/path.h>
7
8 class Architecture;
9 class Builder;
10 class BuildInfo;
11 class Component;
12 class FileTarget;
13 class Target;
14 class Task;
15
16 /**
17 Base class for tools.  Tools are used to turn targets into other targets.
18 Examples include compilers and linkers.
19 */
20 class Tool
21 {
22 public:
23         typedef std::list<Msp::FS::Path> SearchPath;
24         typedef std::list<std::string> SuffixList;
25
26 protected:
27         Builder &builder;
28         const Architecture *architecture;
29         std::string tag;
30         FileTarget *executable;
31         SuffixList input_suffixes;
32         SuffixList aux_suffixes;
33         SearchPath system_path;
34
35         Tool(Builder &, const std::string &);
36         Tool(Builder &, const Architecture &, const std::string &);
37 public:
38         virtual ~Tool() { }
39
40         const std::string &get_tag() const { return tag; }
41
42         /** Returns a target for the tool's own executable.  If the tool does not
43         use an external program, returns null. */
44         // XXX The executable target should be retrieved when first needed
45         FileTarget *get_executable() const { return executable; }
46
47         /// Returns a list of suffixes that can be processed with this tool.
48         const SuffixList &get_input_suffixes() const { return input_suffixes; }
49
50         /** Returns a list of suffixes that are associated with this tool, but can't
51         be processed directly.  For example C and C++ headers. */
52         const SuffixList &get_auxiliary_suffixes() const { return aux_suffixes; }
53
54         /** Indicates whether the tool can accept a suffix.  If aux is true,
55         auxiliary suffixes are considered as well */
56         bool accepts_suffix(const std::string &, bool aux = false) const;
57
58         /// Returns the systemwide search path for source files.
59         const SearchPath &get_system_path() const { return system_path; }
60
61         /// Creates a source file appropriate for this tool.
62         virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }
63
64         /** Creates a package-less source file appropriate for this too.  This is
65         called during dependency discovery when no package has created a target for
66         the file. */
67         virtual Target *create_source(const Msp::FS::Path &) const { return 0; }
68
69         /// Convenience function to create a target from a single source.
70         Target *create_target(Target &, const std::string & = std::string()) const;
71
72         /** Creates a target from sources.  The exact types of accepted sources
73         depends on the tool.  The optional second argument can be used to select an
74         alternative target type for tools that can create multiple kinds of targets. */ 
75         virtual Target *create_target(const std::list<Target *> &, const std::string & = std::string()) const = 0;
76
77         virtual std::string create_build_signature(const BuildInfo &) const { return std::string(); }
78
79         /** Invokes the tool to build a target.  This should not be called directly;
80         use Target::build() instead. */
81         virtual Task *run(const Target &) const = 0;
82 };
83
84 /**
85 Intermediate base class for tool facets.  For example, a linker may need to
86 use different commands depending on whether C++ source files are present or
87 not, but their presence can't be directly determined from the object files.
88 */
89 class SubTool: public Tool
90 {
91 protected:
92         Tool &parent;
93
94         SubTool(Tool &);
95 };
96
97 #endif