]> git.tdb.fi Git - builder.git/blob - source/architecture.cpp
Refactor arch handling a bit
[builder.git] / source / architecture.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "architecture.h"
9 #include "builder.h"
10
11 using namespace std;
12 using namespace Msp;
13
14 Architecture::Architecture(Builder &b, const string &n, bool a):
15         builder(b),
16         name(n),
17         native(a)
18 { }
19
20 void Architecture::set_tool(const string &t, const string &p)
21 {
22         tools[t]=p;
23 }
24
25 std::string Architecture::get_tool(const string &t) const
26 {
27         StringMap::const_iterator i=tools.find(t);
28         if(i!=tools.end())
29         {
30                 if(i->second[0]=='-')
31                         return prefix+i->second;
32                 else
33                         return i->second;
34         }
35
36         if(!native)
37         {
38                 const Architecture &native_arch=builder.get_native_arch();
39                 return prefix+"-"+native_arch.get_tool(t);
40         }
41         else
42                 throw KeyError("Unknown tool");
43 }
44
45
46 Architecture::Loader::Loader(Architecture &a):
47         arch(a)
48 {
49         add("prefix", &Architecture::prefix);
50         add("tool",   &Loader::tool);
51 }
52
53 void Architecture::Loader::tool(const string &t, const string &p)
54 {
55         arch.tools[t]=p;
56 }