]> git.tdb.fi Git - builder.git/blob - source/tool.h
Make tools architecture-aware and restore cross-compilation functionality
[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         // XXX The executable target should be retrieved when first needed
41         FileTarget *get_executable() const { return executable; }
42         const SuffixList &get_input_suffixes() const { return input_suffixes; }
43         const SuffixList &get_auxiliary_suffixes() const { return aux_suffixes; }
44         bool accepts_suffix(const std::string &, bool = false) const;
45         const SearchPath &get_system_path() const { return system_path; }
46
47         virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }
48         virtual Target *create_source(const Msp::FS::Path &) const { return 0; }
49         Target *create_target(Target &, const std::string & = std::string()) const;
50         virtual Target *create_target(const std::list<Target *> &, const std::string & = std::string()) const = 0;
51         virtual Task *run(const Target &) const = 0;
52 };
53
54 /**
55 Intermediate base class for tool facets.  For example, a linker may need to
56 use different commands depending on whether C++ source files are present or
57 not, but their presence can't be directly determined from the object files.
58 */
59 class SubTool: public Tool
60 {
61 protected:
62         Tool &parent;
63
64         SubTool(Tool &);
65 };
66
67 #endif