};
};
-binary_package "opengl/win32"
+binary_package "opengl/windows"
{
build_info
{
};
};
-binary_package "devil/win32"
+binary_package "devil/windows"
{
build_info
{
};
};
-binary_package "openal/win32"
+binary_package "openal/windows"
{
build_info
{
};
};
-architecture "arm"
-{
- prefix "arm-linux-gnueabi";
-};
-
-architecture "win32"
-{
- prefix "i586-mingw32msvc";
-};
+cross_prefix "arm" "arm-linux-gnueabi";
+cross_prefix "windows" "i586-mingw32msvc";
profile "debug"
{
/* $Id$
This file is part of builder
-Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
+#include <limits>
+#ifndef WIN32
+#include <sys/utsname.h>
+#endif
+#include <msp/strings/formatter.h>
+#include <msp/strings/utils.h>
#include "architecture.h"
#include "builder.h"
using namespace std;
using namespace Msp;
-Architecture::Architecture(Builder &b, const string &n, bool a):
+namespace {
+
+const char *types[] =
+{
+ "pc",
+ "arm",
+ 0
+};
+
+const char *cpus[] =
+{
+ "i386", "pc", 0,
+ "i486", "pc", 0,
+ "pentium", "pc", 0,
+ "i586", "pc", "pentium",
+ "pentiumpro", "pc", 0,
+ "i686", "pc", "pentiumpro",
+ "pentium2", "pc", 0,
+ "pentium3", "pc", 0,
+ "pentium4", "pc", 0,
+ "core2", "pc", 0,
+ "k6", "pc", 0,
+ "athlon", "pc", 0,
+ "athlonxp", "pc", 0,
+ "athlon64", "pc", 0,
+ "armv5", "arm", 0,
+ 0
+};
+
+const char *systems[] =
+{
+ "linux",
+ "freebsd",
+ "windows",
+ 0
+};
+
+}
+
+Architecture::Architecture(Builder &b, const string &spec):
builder(b),
- name(n),
- native(a)
-{ }
+ bits(0),
+ native(false)
+{
+ if(spec.empty())
+ {
+#ifdef WIN32
+ system = "windows";
+#else
+ utsname un;
+ if(uname(&un)==0)
+ {
+ system = tolower(un.sysname);
+ parse_specification(tolower(un.machine));
+ // We really only want to set type for the default arch
+ cpu.clear();
+ }
+#endif
+ bits = sizeof(void *)*numeric_limits<unsigned char>::digits;
+ native = true;
+ }
+ else
+ {
+ parse_specification(spec);
+ const Architecture &native_arch = builder.get_native_arch();
+ if(type.empty())
+ type = native_arch.type;
+ if(cpu.empty())
+ cpu = native_arch.cpu;
+ if(system.empty())
+ system = native_arch.system;
+ if(!bits)
+ {
+ if(type==native_arch.type)
+ bits = native_arch.bits;
+ else
+ bits = 32;
+ }
+
+ if(type!=native_arch.type || system!=native_arch.system)
+ cross_prefix = format("%s-%s", type, system);
+ else if(bits!=native_arch.bits)
+ {
+ build_info.cflags.push_back(format("-m%d", bits));
+ build_info.ldflags.push_back(format("-m%d", bits));
+ }
+ else
+ native = true;
+
+ if(!cpu.empty())
+ build_info.cflags.push_back(format("-march=%s", cpu));
+ }
+ name = type;
+ if(!cpu.empty())
+ name += format("-%s", cpu);
+ name += format("-%d-%s", bits, system);
+}
void Architecture::set_tool(const string &t, const string &p)
{
tools[t] = p;
}
+void Architecture::set_cross_prefix(const string &p)
+{
+ cross_prefix = p;
+}
+
std::string Architecture::get_tool(const string &t) const
{
StringMap::const_iterator i = tools.find(t);
if(i!=tools.end())
{
if(i->second[0]=='-')
- return prefix+i->second;
+ return cross_prefix+i->second;
else
return i->second;
}
- if(!native)
+ const Architecture &native_arch = builder.get_native_arch();
+ if(this!=&native_arch)
{
- const Architecture &native_arch = builder.get_native_arch();
- return prefix+"-"+native_arch.get_tool(t);
+ if(!cross_prefix.empty())
+ return cross_prefix+"-"+native_arch.get_tool(t);
+ else
+ return native_arch.get_tool(t);
}
else
- throw KeyError("Unknown tool");
+ throw KeyError("Unknown tool", t);
+}
+
+bool Architecture::match_name(const string &pattern) const
+{
+ vector<string> parts = split(pattern, "-");
+ for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ {
+ if(*i!=type && *i!=cpu && *i!=system)
+ return false;
+ }
+ return true;
+}
+
+void Architecture::parse_specification(const string &spec)
+{
+ vector<string> parts = split(spec, "-");
+ for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ {
+ bool ok = false;
+ for(unsigned j=0; (!ok && types[j]); ++j)
+ if(*i==types[j])
+ {
+ if(!type.empty() && *i!=type)
+ throw InvalidParameterValue("Conflicting type specification");
+ type = *i;
+ ok = true;
+ }
+ for(unsigned j=0; (!ok && cpus[j]); j+=3)
+ if(*i==cpus[j])
+ {
+ if(type.empty())
+ type = cpus[j+1];
+ else if(cpus[j+1]!=type)
+ throw InvalidParameterValue("Conflicting CPU specification");
+ cpu = (cpus[j+2] ? cpus[j+2] : *i);
+ ok = true;
+ }
+ for(unsigned j=0; (!ok && systems[j]); ++j)
+ if(*i==systems[j])
+ {
+ system = *i;
+ ok = true;
+ }
+ if(!ok && (*i=="32" || *i=="64"))
+ {
+ bits = lexical_cast<unsigned>(*i);
+ ok = true;
+ }
+ if(!ok)
+ throw InvalidParameterValue("Unrecognized part in arch specification: "+*i);
+ }
}
Architecture::Loader::Loader(Architecture &a):
arch(a)
{
- add("prefix", &Architecture::prefix);
+ add("prefix", &Architecture::cross_prefix);
add("tool", &Loader::tool);
}
/* $Id$
This file is part of builder
-Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#define ARCHITECTURE_H_
#include <msp/datafile/loader.h>
+#include "buildinfo.h"
#include "misc.h"
class Builder;
private:
Builder &builder;
+ std::string type;
+ std::string cpu;
+ std::string system;
+ unsigned bits;
std::string name;
bool native;
- std::string prefix;
+ std::string cross_prefix;
StringMap tools;
+ BuildInfo build_info;
public:
- Architecture(Builder &b, const std::string &n, bool a = false);
- void set_tool(const std::string &t, const std::string &p);
- std::string get_tool(const std::string &t) const;
+ Architecture(Builder &b, const std::string &spec);
+
const std::string &get_name() const { return name; }
+ const std::string &get_system() const { return system; }
+ bool match_name(const std::string &) const;
bool is_native() const { return native; }
- const std::string &get_prefix() const { return prefix; }
+
+ void set_tool(const std::string &t, const std::string &p);
+ void set_cross_prefix(const std::string &);
+ std::string get_tool(const std::string &t) const;
+ const std::string &get_cross_prefix() const { return cross_prefix; }
+
+ const BuildInfo &get_build_info() const { return build_info; }
+
+private:
+ void parse_specification(const std::string &);
};
typedef std::map<std::string, Architecture> ArchMap;
/* $Id$
This file is part of builder
-Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2010 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
{
const SourcePackage &pkg = c.get_package();
string prefix, suffix;
- const string &arch = pkg.get_builder().get_current_arch().get_name();
+ const string &sys = pkg.get_builder().get_current_arch().get_system();
if(c.get_type()==Component::LIBRARY)
{
prefix = "lib";
- if(arch=="win32")
+ if(sys=="windows")
suffix = ".dll";
else
suffix = ".so";
suffix = ".m";
else if(c.get_type()==Component::PROGRAM)
{
- if(arch=="win32")
+ if(sys=="windows")
suffix = ".exe";
}
/* $Id$
This file is part of builder
-Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2010 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#include <set>
#include <cstdlib>
-#include <sys/utsname.h>
#include <msp/core/except.h>
#include <msp/core/getopt.h>
#include <msp/datafile/parser.h>
Builder::Builder(int argc, char **argv):
main_pkg(0),
+ native_arch(*this, string()),
analyzer(0),
build(false),
clean(0),
cwd = FS::getcwd();
- utsname un;
- string sysname = "native";
- if(uname(&un)==0)
- sysname = tolower(un.sysname);
-
- native_arch = &archs.insert(ArchMap::value_type(sysname, Architecture(*this, sysname, true))).first->second;
- native_arch->set_tool("CC", "gcc");
- native_arch->set_tool("CXX", "g++");
- native_arch->set_tool("LD", "gcc");
- native_arch->set_tool("LXX", "g++");
- native_arch->set_tool("AR", "ar");
+ native_arch.set_tool("CC", "gcc");
+ native_arch.set_tool("CXX", "g++");
+ native_arch.set_tool("LD", "gcc");
+ native_arch.set_tool("LXX", "g++");
+ native_arch.set_tool("AR", "ar");
load_build_file((FS::get_sys_data_dir(argv[0], "builder")/"builderrc").str());
load_build_file((FS::get_user_data_dir("builder")/"rc").str());
if(arch.empty())
- current_arch = native_arch;
+ current_arch = &native_arch;
else
- current_arch = &get_architecture(arch);
+ current_arch = new Architecture(*this, arch);
+
+ if(!current_arch->is_native())
+ {
+ for(StringMap::const_iterator i=cross_prefixes.begin(); i!=cross_prefixes.end(); ++i)
+ if(current_arch->match_name(i->first))
+ {
+ current_arch->set_cross_prefix(i->second);
+ break;
+ }
+ }
if(prfx.empty())
{
return 0;
if(verbose>=2)
- IO::print("Building on %s, for %s\n", native_arch->get_name(), current_arch->get_name());
+ {
+ IO::print("Building on %s, for %s%s\n", native_arch.get_name(),
+ current_arch->get_name(), (current_arch->is_native() ? " (native)" : ""));
+ IO::print("Prefix is %s\n", prefix);
+ }
if(verbose>=1)
IO::print("%d active packages, %d targets\n", all_reqs.size(), targets.size());
if(verbose>=2)
Package *Builder::get_package(const string &name)
{
- PackageMap::iterator i = packages.find(format("%s/%s", name, current_arch->get_name()));
+ PackageMap::iterator i = packages.find(format("%s/%s", name, current_arch->get_system()));
if(i==packages.end())
i = packages.find(name);
if(i!=packages.end())
if(current_arch->is_native())
syspath.push_back("/usr/include");
else
- syspath.push_back("/usr/"+current_arch->get_prefix()+"/include");
+ syspath.push_back("/usr/"+current_arch->get_cross_prefix()+"/include");
if(cxx_ver!="-")
syspath.push_back((FS::Path("/usr/include/c++/")/cxx_ver).str());
syspath.push_back("/usr/lib");
}
else
- syspath.push_back("/usr/"+current_arch->get_prefix()+"/lib");
+ syspath.push_back("/usr/"+current_arch->get_cross_prefix()+"/lib");
if(verbose>=5)
IO::print("Looking for library %s with path %s\n", lib, join(path.begin(), path.end()));
return tgt;
}
-const Architecture &Builder::get_architecture(const string &arch) const
-{
- ArchMap::const_iterator i = archs.find(arch);
- if(i==archs.end())
- throw KeyError("Unknown architecture", arch);
-
- return i->second;
-}
-
void Builder::apply_profile_template(Config &config, const string &pt) const
{
vector<string> parts = split(pt, '-');
if(mode!=ALL_STATIC)
{
- if(current_arch->get_name()=="win32")
+ // XXX Should probably let the Architecture populate the list
+ if(current_arch->get_system()=="windows")
{
candidates.push_back("lib"+lib+".dll");
candidates.push_back(lib+".dll");
/* Static libraries are always considered, since sometimes shared versions
may not be available */
candidates.push_back("lib"+lib+".a");
- if(current_arch->get_name()=="win32")
+ if(current_arch->get_system()=="windows")
candidates.push_back("lib"+lib+".dll.a");
for(StringList::iterator i=candidates.begin(); i!=candidates.end(); ++i)
bld(b),
src(s)
{
- add("architecture", &Loader::architecture);
add("binary_package", &Loader::binpkg);
+ add("cross_prefix", &Loader::cross_prefix);
add("profile", &Loader::profile);
add("package", &Loader::package);
}
-void Builder::Loader::architecture(const string &n)
-{
- Architecture arch(bld, n);
- load_sub(arch);
- bld.archs.insert(ArchMap::value_type(n, arch));
-}
-
void Builder::Loader::binpkg(const string &n)
{
BinaryPackage *pkg = new BinaryPackage(bld, n);
bld.packages.insert(PackageMap::value_type(n, pkg));
}
+void Builder::Loader::cross_prefix(const string &a, const string &p)
+{
+ bld.cross_prefixes[a] = p;
+}
+
void Builder::Loader::profile(const string &n)
{
StringMap prf;
/* $Id$
This file is part of builder
-Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2010 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
public:
Loader(Builder &, const Msp::FS::Path &);
private:
- void architecture(const std::string &);
void binpkg(const std::string &);
+ void cross_prefix(const std::string &, const std::string &);
void profile(const std::string &);
void package(const std::string &);
};
TargetMap includes;
TargetMap libraries;
- ArchMap archs;
- Architecture *native_arch;
- const Architecture *current_arch;
+ Architecture native_arch;
+ Architecture *current_arch;
+ StringMap cross_prefixes;
ProfileTemplateMap profile_tmpl;
ProblemList problems;
Target *get_library(const std::string &, const StringList &, LibMode);
const Msp::FS::Path &get_cwd() const { return cwd; }
- const Architecture &get_architecture(const std::string &) const;
const Architecture &get_current_arch() const { return *current_arch; }
- const Architecture &get_native_arch() const { return *native_arch; }
+ const Architecture &get_native_arch() const { return native_arch; }
const Msp::FS::Path &get_prefix() const { return prefix; }
const StringList &get_warnings() const { return warnings; }
void apply_profile_template(Config &, const std::string &) const;
/* $Id$
This file is part of builder
-Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
unsigned start = 1;
if(i->second[1]=='=')
++start;
+ string value = i->second.substr(start);
- string value;
+ bool match = false;
if(conf.is_option(i->first))
- value = conf.get_option(i->first).value;
+ match = (conf.get_option(i->first).value==value);
else if(i->first=="arch")
- value = pkg.get_builder().get_current_arch().get_name();
+ match = pkg.get_builder().get_current_arch().match_name(value);
- if((value==i->second.substr(start))==neg)
+ if(match==neg)
result = false;
}
/* $Id$
This file is part of builder
-Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
FS::Path SourcePackage::get_temp_dir() const
{
- return source/config.get_option("tempdir").value/builder.get_current_arch().get_name()/config.get_option("profile").value;
+ string subdir = format("%s.%s", builder.get_current_arch().get_name(), config.get_option("profile").value);
+ return source/config.get_option("tempdir").value/subdir;
}
FS::Path SourcePackage::get_out_dir() const
config.add_option("optimize", "0", "Apply compiler optimizations");
config.add_option("strip", "no", "Strip symbols from programs");
config.add_option("debug", "no", "Produce debugging symbols");
- config.add_option("cpu", "none", "CPU type to optimize for");
config.add_option("staticlibs", "local", "Use static libraries");
for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i)
void SourcePackage::create_build_info()
{
+ build_info.add(builder.get_current_arch().get_build_info());
+
for(PackageList::iterator i=base_reqs.begin(); i!=base_reqs.end(); ++i)
{
const BuildInfo &ebi = (*i)->get_exported_binfo();
{
build_info.cflags.push_back("-O"+optimize);
build_info.ldflags.push_back("-O"+optimize);
- string cpu = config.get_option("cpu").value;
- if(cpu!="none")
- build_info.cflags.push_back("-march="+cpu);
}
if(lexical_cast<bool>(config.get_option("debug").value))