]> git.tdb.fi Git - builder.git/blob - source/tool.cpp
3aa2db3c713716ba7d90bcafa715afe368a37302
[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 void Tool::set_command(const string &cmd, bool cross)
27 {
28         if(cmd.empty())
29                 throw invalid_argument("Tool::set_command");
30
31         if(cross && architecture->is_cross() && !FS::Path(cmd).is_absolute())
32                 command = format("%s-%s", architecture->get_cross_prefix(), cmd);
33         else
34                 command = cmd;
35 }
36
37 bool Tool::accepts_suffix(const string &suffix, bool aux) const
38 {
39         if(find(input_suffixes.begin(), input_suffixes.end(), suffix)!=input_suffixes.end())
40                 return true;
41         else if(aux)
42                 return find(aux_suffixes.begin(), aux_suffixes.end(), suffix)!=aux_suffixes.end();
43         else
44                 return false;
45 }
46
47 Target *Tool::create_target(Target &source, const string &arg)
48 {
49         list<Target *> sources;
50         sources.push_back(&source);
51         return create_target(sources, arg);
52 }
53
54 void Tool::prepare()
55 {
56         if(prepared)
57                 return;
58
59         prepared = true;
60         do_prepare();
61         if(!executable && !command.empty())
62         {
63                 executable = builder.get_vfs().find_binary(command);
64                 if(!executable)
65                         problems.push_back(format("Can't find executable %s", command));
66         }
67 }
68
69
70 SubTool::SubTool(Tool &p):
71         Tool(p),
72         parent(p)
73 { }