]> git.tdb.fi Git - builder.git/blob - source/tool.h
Store a target representing the executable in each tool
[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 Builder;
9 class Component;
10 class FileTarget;
11 class Target;
12 class Task;
13
14 /**
15 Base class for tools.  Tools are used to turn targets into other targets.
16 Examples include compilers and linkers.
17 */
18 class Tool
19 {
20 public:
21         typedef std::list<Msp::FS::Path> SearchPath;
22         typedef std::list<std::string> SuffixList;
23
24 protected:
25         Builder &builder;
26         std::string tag;
27         FileTarget *executable;
28         SuffixList input_suffixes;
29         SuffixList aux_suffixes;
30         SearchPath system_path;
31
32         Tool(Builder &, const std::string &);
33 public:
34         virtual ~Tool() { }
35
36         const std::string &get_tag() const { return tag; }
37         // XXX The executable target should be retrieved when first needed
38         FileTarget *get_executable() const { return executable; }
39         const SuffixList &get_input_suffixes() const { return input_suffixes; }
40         const SuffixList &get_auxiliary_suffixes() const { return aux_suffixes; }
41         bool accepts_suffix(const std::string &, bool = false) const;
42         const SearchPath &get_system_path() const { return system_path; }
43
44         virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }
45         virtual Target *create_source(const Msp::FS::Path &) const { return 0; }
46         Target *create_target(Target &, const std::string & = std::string()) const;
47         virtual Target *create_target(const std::list<Target *> &, const std::string & = std::string()) const = 0;
48         virtual Task *run(const Target &) const = 0;
49 };
50
51 /**
52 Intermediate base class for tool facets.  For example, a linker may need to
53 use different commands depending on whether C++ source files are present or
54 not, but their presence can't be directly determined from the object files.
55 */
56 class SubTool: public Tool
57 {
58 protected:
59         Tool &parent;
60
61         SubTool(Tool &);
62 };
63
64 #endif