From: Mikko Rasa Date: Tue, 11 Sep 2007 18:36:03 +0000 (+0000) Subject: Move architecture information from Builder to class Architecture X-Git-Tag: 0.9~22 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=329dc80e392faf7354338621e73dba1880fc767d;p=builder.git Move architecture information from Builder to class Architecture Add problem.h --- diff --git a/builderrc b/builderrc index 6170aec..a39a877 100644 --- a/builderrc +++ b/builderrc @@ -1,3 +1,5 @@ +/* $Id$ */ + binary_package "opengl" { build_info @@ -41,8 +43,15 @@ binary_package "xlib" }; }; -architecture "arm" "arm-linux-gnu"; -architecture "win32" "i586-mingw32msvc"; +architecture "arm" +{ + prefix "arm-linux-gnu"; +}; + +architecture "win32" +{ + prefix "i586-mingw32msvc"; +}; profile "debug" { diff --git a/source/architecture.cpp b/source/architecture.cpp new file mode 100644 index 0000000..50013e8 --- /dev/null +++ b/source/architecture.cpp @@ -0,0 +1,55 @@ +/* $Id$ + +This file is part of builder +Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include "architecture.h" +#include "builder.h" + +using namespace std; +using namespace Msp; + +Architecture::Architecture(Builder &b, const string &n): + builder(b), + name(n) +{ } + +void Architecture::set_tool(const string &t, const string &p) +{ + tools[t]=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; + else + return i->second; + } + + if(name!="native") + { + const Architecture &native=builder.get_architecture("native"); + return prefix+"-"+native.get_tool(t); + } + else + throw KeyError("Unknown tool"); +} + + +Architecture::Loader::Loader(Architecture &a): + arch(a) +{ + add("prefix", &Architecture::prefix); + add("tool", &Loader::tool); +} + +void Architecture::Loader::tool(const string &t, const string &p) +{ + arch.tools[t]=p; +} diff --git a/source/architecture.h b/source/architecture.h new file mode 100644 index 0000000..16ff505 --- /dev/null +++ b/source/architecture.h @@ -0,0 +1,43 @@ +/* $Id$ + +This file is part of builder +Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#ifndef ARCHITECTURE_H_ +#define ARCHITECTURE_H_ + +#include +#include "misc.h" + +class Builder; + +class Architecture +{ +public: + class Loader: public Msp::DataFile::Loader + { + public: + Loader(Architecture &); + Architecture &get_object() { return arch; } + private: + Architecture &arch; + + void tool(const std::string &t, const std::string &p); + }; + + Architecture(Builder &b, const std::string &n); + void set_tool(const std::string &t, const std::string &p); + std::string get_tool(const std::string &t) const; + const std::string &get_prefix() const { return prefix; } +private: + Builder &builder; + std::string name; + std::string prefix; + StringMap tools; +}; + +typedef std::map ArchMap; + +#endif diff --git a/source/archive.cpp b/source/archive.cpp index 4dee508..a7b86c7 100644 --- a/source/archive.cpp +++ b/source/archive.cpp @@ -21,7 +21,8 @@ Archive::Archive(Builder &b, const StaticLibrary &lib): { const Component &comp=lib.get_component(); - argv.push_back(builder.get_tool("AR", comp.get_package().get_arch())); + std::string tool="AR"; + argv.push_back(builder.get_architecture(comp.get_package().get_arch()).get_tool(tool)); argv.push_back("rc"); argv.push_back(lib.get_name()); @@ -34,7 +35,7 @@ Archive::Archive(Builder &b, const StaticLibrary &lib): if(!builder.get_dry_run()) Path::mkpath(lpath.subpath(0, lpath.size()-1), 0755); - announce(comp.get_package().get_name(), "AR ", relative(lpath, comp.get_package().get_source()).str()); + announce(comp.get_package().get_name(), tool, relative(lpath, comp.get_package().get_source()).str()); launch(); } diff --git a/source/builder.cpp b/source/builder.cpp index d466952..ee7eabf 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -115,14 +115,12 @@ Builder::Builder(int argc, char **argv): cwd=Path::getcwd(); - archs.insert(StringMap::value_type("native", "")); - - StringMap &native_tools=tools.insert(ToolMap::value_type("native", StringMap())).first->second; - native_tools.insert(StringMap::value_type("CC", "gcc")); - native_tools.insert(StringMap::value_type("CXX", "g++")); - native_tools.insert(StringMap::value_type("LD", "gcc")); - native_tools.insert(StringMap::value_type("LDXX", "g++")); - native_tools.insert(StringMap::value_type("AR", "ar")); + Architecture &native_arch=archs.insert(ArchMap::value_type("native", Architecture(*this, "native"))).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"); const char *home=getenv("HOME"); if(home) @@ -260,7 +258,7 @@ Target *Builder::get_library(const string &lib, const string &arch, const listsecond; } -string Builder::get_tool(const std::string &tool, const std::string &arch) -{ - ToolMap::iterator i=tools.find(arch); - if(i!=tools.end()) - { - StringMap::iterator j=i->second.find(tool); - if(j!=i->second.end()) - return j->second; - } - - // Either the arch, or the tool within the arch was not found - i=tools.find("native"); - StringMap::iterator j=i->second.find(tool); - if(j==i->second.end()) - throw InvalidParameterValue("Unknown tool"); - - return get_arch_prefix(arch)+"-"+j->second; -} - void Builder::apply_profile_template(Config &config, const string &pt) const { vector parts=split(pt, '-'); @@ -800,9 +779,11 @@ Builder::Loader::Loader(Builder &b, const Path::Path &s): add("package", &Loader::package); } -void Builder::Loader::architecture(const string &a, const string &p) +void Builder::Loader::architecture(const string &n) { - bld.archs.insert(StringMap::value_type(a, p)); + Architecture arch(bld, n); + load_sub(arch); + bld.archs.insert(ArchMap::value_type(n, arch)); } void Builder::Loader::binpkg(const string &n) diff --git a/source/builder.h b/source/builder.h index 4811493..270f816 100644 --- a/source/builder.h +++ b/source/builder.h @@ -14,6 +14,7 @@ Distributed under the LGPL #include #include #include +#include "architecture.h" #include "config.h" #include "misc.h" #include "problem.h" @@ -41,8 +42,7 @@ public: Target *get_header(const std::string &, const std::string &, const std::string &, const StringList &); Target *get_library(const std::string &, const std::string &, const StringList &, LibMode); const Msp::Path::Path &get_cwd() const { return cwd; } - const std::string &get_arch_prefix(const std::string &) const; - std::string get_tool(const std::string &, const std::string &); + const Architecture &get_architecture(const std::string &) const; void apply_profile_template(Config &, const std::string &) const; void add_target(Target *); void problem(const std::string &, const std::string &); @@ -59,7 +59,7 @@ private: Builder &bld; Msp::Path::Path src; - void architecture(const std::string &, const std::string &); + void architecture(const std::string &); void binpkg(const std::string &); void profile(const std::string &); void package(const std::string &); @@ -77,7 +77,6 @@ private: typedef std::list PackageList; typedef std::map PackageMap; - typedef std::map ToolMap; typedef std::map ProfileTemplateMap; StringList cmdline_targets; @@ -92,8 +91,7 @@ private: TargetMap includes; TargetMap libraries; - ToolMap tools; //< arch, tool name -> program name - StringMap archs; //< arch -> prefix + ArchMap archs; ProfileTemplateMap profile_tmpl; ProblemList problems; diff --git a/source/compile.cpp b/source/compile.cpp index d07f3ef..61b17ad 100644 --- a/source/compile.cpp +++ b/source/compile.cpp @@ -31,9 +31,9 @@ Compile::Compile(Builder &b, const ObjectFile &obj): else tool="CC"; - argv.push_back(builder.get_tool(tool, comp.get_package().get_arch())); + argv.push_back(builder.get_architecture(comp.get_package().get_arch()).get_tool(tool)); argv.push_back("-c"); - + const BuildInfo &binfo=comp.get_build_info(); for(list::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i) argv.push_back(*i); @@ -41,7 +41,7 @@ Compile::Compile(Builder &b, const ObjectFile &obj): argv.push_back("-I"+*i); for(list::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i) argv.push_back("-D"+*i); - + Path::Path opath=obj.get_name(); argv.push_back("-o"); argv.push_back(opath.str()); diff --git a/source/link.cpp b/source/link.cpp index a7ea2c5..88ee97a 100644 --- a/source/link.cpp +++ b/source/link.cpp @@ -26,8 +26,9 @@ Link::Link(Builder &b, const Executable &exe): const Component &comp=exe.get_component(); //XXX Determine whether to use g++ or gcc - argv.push_back(builder.get_tool("LDXX", comp.get_package().get_arch())); - + string tool="LXX"; + argv.push_back(builder.get_architecture(comp.get_package().get_arch()).get_tool(tool)); + if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE) argv.push_back("-shared"); else if(comp.get_package().get_library_mode()==ALL_STATIC) @@ -38,7 +39,7 @@ Link::Link(Builder &b, const Executable &exe): argv.push_back(*i); for(list::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i) argv.push_back("-L"+*i); - + argv.push_back("-o"); argv.push_back(exe.get_name()); const TargetList &deps=exe.get_depends(); @@ -62,7 +63,7 @@ Link::Link(Builder &b, const Executable &exe): if(!builder.get_dry_run()) Path::mkpath(epath.subpath(0, epath.size()-1), 0755); - announce(comp.get_package().get_name(), "LINK", relative(epath, comp.get_package().get_source()).str()); + announce(comp.get_package().get_name(), tool, relative(epath, comp.get_package().get_source()).str()); launch(); } diff --git a/source/problem.h b/source/problem.h new file mode 100644 index 0000000..c2af878 --- /dev/null +++ b/source/problem.h @@ -0,0 +1,26 @@ +/* $Id$ + +This file is part of builder +Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#ifndef PROBLEM_H_ +#define PROBLEM_H_ + +#include +#include + +class Package; + +struct Problem +{ + std::string package; + std::string descr; + + Problem(const std::string &p, const std::string &d): package(p), descr(d) { } +}; + +typedef std::list ProblemList; + +#endif