6 #include <msp/fs/path.h>
18 Base class for tools. Tools are used to turn targets into other targets.
19 Examples include compilers and linkers.
24 typedef std::list<Msp::FS::Path> SearchPath;
25 typedef std::list<std::string> SuffixList;
29 const Architecture *architecture;
32 FileTarget *executable;
33 SuffixList input_suffixes;
34 SuffixList aux_suffixes;
35 SearchPath system_path;
38 std::list<std::string> problems;
40 Tool(Builder &, const std::string &);
41 Tool(Builder &, const Architecture &, const std::string &);
45 const std::string &get_tag() const { return tag; }
47 /** Returns the architecture this tool build for. May return null if the
48 tool is architecture-agnostic. */
49 const Architecture *get_architecture() const { return architecture; }
51 /** Overrides the command used by the tool. The new command should accept
52 the same command line arguments. Only works on tools that use an external
53 command. If cross is true and the architecture is not native, a cross
54 prefix is added to the command. May have no effect after prepare() has been
56 void set_command(const std::string &cmd, bool cross = false);
58 /** Returns a target for the tool's own executable. If the tool does not
59 use an external program, returns null. The tool must be prepared first. */
60 FileTarget *get_executable() const { return executable; }
62 /// Returns a list of suffixes that can be processed with this tool.
63 const SuffixList &get_input_suffixes() const { return input_suffixes; }
65 /** Returns a list of suffixes that are associated with this tool, but can't
66 be processed directly. For example C and C++ headers. */
67 const SuffixList &get_auxiliary_suffixes() const { return aux_suffixes; }
69 /** Indicates whether the tool can accept a suffix. If aux is true,
70 auxiliary suffixes are considered as well */
71 bool accepts_suffix(const std::string &, bool aux = false) const;
73 /// Returns the systemwide search path for source files.
74 const SearchPath &get_system_path() const { return system_path; }
76 /** Returns tool-specific build info. This can be used by other tools down
78 const BuildInfo &get_build_info() const { return build_info; }
80 /// Creates a source file appropriate for this tool.
81 virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }
83 /** Creates a package-less source file appropriate for this tool. This is
84 called during dependency discovery when no package has created a target for
86 virtual Target *create_source(const Msp::FS::Path &) const { return 0; }
88 /// Convenience function to create a target from a single source.
89 Target *create_target(Target &, const std::string & = std::string());
91 /** Creates a target from sources. The exact types of accepted sources
92 depends on the tool. The optional second argument can be used to select an
93 alternative target type for tools that can create multiple kinds of targets. */
94 virtual Target *create_target(const std::list<Target *> &, const std::string & = std::string()) = 0;
96 /** Creates an install target for a target created by this tool. Can return
97 null if the tool does not want to handle installing in a special way. */
98 virtual Target *create_install(Target &) const { return 0; }
100 virtual std::string create_build_signature(const BuildInfo &) const { return std::string(); }
105 virtual void do_prepare() { }
108 const std::list<std::string> &get_problems() const { return problems; }
110 /** Invokes the tool to build a target. This should not be called directly;
111 use Target::build() instead. */
112 virtual Task *run(const Target &) const = 0;
116 Intermediate base class for tool facets. For example, a linker may need to
117 use different commands depending on whether C++ source files are present or
118 not, but their presence can't be directly determined from the object files.
120 class SubTool: public Tool