3 #include <sys/utsname.h>
5 #include <msp/strings/format.h>
6 #include <msp/strings/utils.h>
7 #include "architecture.h"
40 const char *systems[] =
48 const char *aliases[] =
59 Architecture::Architecture(Builder &b, const string &spec):
72 system = tolower(un.sysname);
73 parse_specification(tolower(un.machine));
74 // We really only want to set type for the default arch
78 bits = sizeof(void *)*numeric_limits<unsigned char>::digits;
83 parse_specification(spec);
84 const Architecture &native_arch = builder.get_native_arch();
86 type = native_arch.type;
88 system = native_arch.system;
91 if(type==native_arch.type)
92 bits = native_arch.bits;
97 if(type!=native_arch.type || system!=native_arch.system)
98 cross_prefix = format("%s-%s", type, system);
99 else if(bits==native_arch.bits)
104 name += format("-%s", cpu);
105 name += format("-%d-%s", bits, system);
107 if(system=="windows")
109 sharedlib_patterns.push_back(Pattern("%.dll"));
110 sharedlib_patterns.push_back(Pattern("lib%.dll"));
111 staticlib_patterns.push_back(Pattern("lib%.a"));
112 staticlib_patterns.push_back(Pattern("lib%.dll.a"));
113 executable_patterns.push_back(Pattern("%.exe"));
117 sharedlib_patterns.push_back(Pattern("lib%.so"));
118 staticlib_patterns.push_back(Pattern("lib%.a"));
119 executable_patterns.push_back(Pattern("%"));
123 void Architecture::set_cross_prefix(const string &p)
128 bool Architecture::match_name(const string &pattern) const
130 vector<string> parts = split(pattern, "-");
131 for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
133 string part = resolve_alias(*i);
134 if((part=="32" && bits==32) || (part=="64" && bits==64))
136 else if(part!=type && part!=cpu && part!=system)
142 string Architecture::resolve_alias(const string &part) const
144 for(unsigned j=0; aliases[j]; j+=2)
151 void Architecture::parse_specification(const string &spec)
153 vector<string> parts = split(spec, "-");
154 for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
156 string part = resolve_alias(*i);
160 for(unsigned j=0; (!ok && types[j]); ++j)
163 if(!type.empty() && part!=type)
164 throw invalid_argument("Conflicting type specification");
169 for(unsigned j=0; (!ok && cpus[j]); j+=2)
174 else if(cpus[j+1]!=type)
175 throw invalid_argument("Conflicting CPU specification");
180 for(unsigned j=0; (!ok && systems[j]); ++j)
187 if(!ok && (part=="32" || part=="64"))
189 bits = lexical_cast<unsigned>(part);
194 throw invalid_argument("Unrecognized part in arch specification: "+*i);
199 Architecture::Loader::Loader(Architecture &a):
200 DataFile::ObjectLoader<Architecture>(a)
202 add("prefix", &Architecture::cross_prefix);