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