3 #include <sys/utsname.h>
5 #include <msp/strings/format.h>
6 #include <msp/strings/utils.h>
7 #include "architecture.h"
41 const char *systems[] =
51 const char *aliases[] =
58 "power macintosh", "ppc",
64 Architecture::Architecture(Builder &b, const string &spec):
77 system = tolower(un.sysname);
78 parse_specification(tolower(un.machine));
79 // We really only want to set type for the default arch
83 bits = sizeof(void *)*numeric_limits<unsigned char>::digits;
88 parse_specification(spec);
89 const Architecture &native_arch = builder.get_native_arch();
91 type = native_arch.type;
93 system = native_arch.system;
96 if(type==native_arch.type)
97 bits = native_arch.bits;
102 if(type!=native_arch.type || system!=native_arch.system)
103 cross_prefix = format("%s-%s", type, system);
104 else if(bits==native_arch.bits)
109 name += format("-%s", cpu);
110 name += format("-%d-%s", bits, system);
112 if(system=="windows")
114 sharedlib_patterns.push_back(Pattern("%.dll"));
115 sharedlib_patterns.push_back(Pattern("lib%.dll"));
116 /* XXX Hack: Consider import libraries (*.dll.a) as dynamic libraries,
117 even though technically they are linked statically. */
118 sharedlib_patterns.push_back(Pattern("lib%.dll.a"));
119 staticlib_patterns.push_back(Pattern("lib%.a"));
120 executable_patterns.push_back(Pattern("%.exe"));
125 sharedlib_patterns.push_back(Pattern("lib%.dylib"));
127 sharedlib_patterns.push_back(Pattern("lib%.so"));
128 staticlib_patterns.push_back(Pattern("lib%.a"));
129 executable_patterns.push_back(Pattern("%"));
133 bool Architecture::match_name(const string &pattern) const
135 bool negate = (pattern[0]=='!');
136 vector<string> parts = split(pattern.substr(negate), "-");
137 for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
139 string part = resolve_alias(*i);
140 if((part=="32" && bits==32) || (part=="64" && bits==64))
142 else if(part!=type && part!=cpu && part!=system)
148 string Architecture::resolve_alias(const string &part) const
150 for(unsigned j=0; aliases[j]; j+=2)
157 void Architecture::parse_specification(const string &spec)
159 vector<string> parts = split(spec, "-");
160 for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
162 string part = resolve_alias(*i);
166 for(unsigned j=0; (!ok && types[j]); ++j)
169 if(!type.empty() && part!=type)
170 throw invalid_argument("Conflicting type specification");
175 for(unsigned j=0; (!ok && cpus[j]); j+=2)
180 else if(cpus[j+1]!=type)
181 throw invalid_argument("Conflicting CPU specification");
186 for(unsigned j=0; (!ok && systems[j]); ++j)
193 if(!ok && (part=="32" || part=="64"))
195 bits = lexical_cast<unsigned>(part);
200 throw invalid_argument("Unrecognized part in arch specification: "+*i);
205 Architecture::Loader::Loader(Architecture &a):
206 DataFile::ObjectLoader<Architecture>(a)
208 add("prefix", &Architecture::cross_prefix);