]> git.tdb.fi Git - builder.git/blob - source/tool.cpp
Add a utility function for setting the executable for a Tool
[builder.git] / source / tool.cpp
1 #include <algorithm>
2 #include <msp/strings/format.h>
3 #include "architecture.h"
4 #include "builder.h"
5 #include "tool.h"
6
7 using namespace std;
8 using namespace Msp;
9
10 Tool::Tool(Builder &b, const string &t):
11         builder(b),
12         architecture(0),
13         tag(t),
14         executable(0),
15         prepared(false)
16 { }
17
18 Tool::Tool(Builder &b, const Architecture &a, const string &t):
19         builder(b),
20         architecture(&a),
21         tag(t),
22         executable(0),
23         prepared(false)
24 { }
25
26 bool Tool::accepts_suffix(const string &suffix, bool aux) const
27 {
28         if(find(input_suffixes.begin(), input_suffixes.end(), suffix)!=input_suffixes.end())
29                 return true;
30         else if(aux)
31                 return find(aux_suffixes.begin(), aux_suffixes.end(), suffix)!=aux_suffixes.end();
32         else
33                 return false;
34 }
35
36 Target *Tool::create_target(Target &source, const string &arg)
37 {
38         list<Target *> sources;
39         sources.push_back(&source);
40         return create_target(sources, arg);
41 }
42
43 void Tool::prepare()
44 {
45         if(prepared)
46                 return;
47
48         prepared = true;
49         do_prepare();
50 }
51
52 void Tool::set_executable(const string &command, bool cross)
53 {
54         if(cross && architecture->is_cross())
55                 return set_executable(format("%s-%s", architecture->get_cross_prefix(), command), false);
56
57         executable = builder.get_vfs().find_binary(command);
58         if(!executable)
59                 builder.problem(string(), format("Can't find executable %s for tool %s", command, tag));
60 }
61
62
63 SubTool::SubTool(Tool &p):
64         Tool(p),
65         parent(p)
66 { }