From 0fd98b61eb112fe397c67b7735627b7bbdd01e41 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 27 Mar 2007 16:53:31 +0000 Subject: [PATCH] Add basic support for tools (not configurable yet) Fix several uninitialized variables --- source/archive.cpp | 4 +--- source/builder.cpp | 33 ++++++++++++++++++++++++++++++++- source/builder.h | 5 +++-- source/compile.cpp | 10 ++-------- source/link.cpp | 4 +--- source/package.cpp | 4 +++- 6 files changed, 42 insertions(+), 18 deletions(-) diff --git a/source/archive.cpp b/source/archive.cpp index 7da7250..cd25de1 100644 --- a/source/archive.cpp +++ b/source/archive.cpp @@ -14,9 +14,7 @@ Archive::Archive(Builder &b, const StaticLibrary &lib): { const Component &comp=lib.get_component(); - const string &prefix=b.get_arch_prefix(lib.get_package()->get_arch()); - - argv.push_back(prefix+"ar"); + argv.push_back(builder.get_tool("AR", lib.get_package()->get_arch())); argv.push_back("rc"); argv.push_back(lib.get_name()); diff --git a/source/builder.cpp b/source/builder.cpp index f23e85a..31cdd18 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -29,10 +29,15 @@ using namespace Msp; Builder::Builder(int argc, char **argv): analyzer(0), do_build(false), + dry_run(false), + help(false), verbose(1), chrome(false), build_file("Build"), - jobs(1) + jobs(1), + conf_all(false), + conf_only(false), + build_all(false) { string analyze_mode; string work_dir; @@ -100,6 +105,13 @@ Builder::Builder(int argc, char **argv): archs.insert(StringMap::value_type("native", "")); archs.insert(StringMap::value_type("arm", "arm-linux-gnu-")); archs.insert(StringMap::value_type("win32", "i586-mingw32msvc-")); + + 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")); } /** @@ -249,6 +261,25 @@ const string &Builder::get_arch_prefix(const string &arch) const return i->second; } +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; +} + int Builder::main() { if(load_build_file(cwd/build_file)) diff --git a/source/builder.h b/source/builder.h index 98e541d..3e3388d 100644 --- a/source/builder.h +++ b/source/builder.h @@ -30,6 +30,7 @@ public: Target *get_library(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 &); int main(); ~Builder(); @@ -49,7 +50,7 @@ private: typedef std::list PackageList; typedef std::map PackageMap; typedef std::map TargetMap; - typedef std::map ToolMap; + typedef std::map ToolMap; StringList cmdline_targets; RawOptionMap cmdline_options; @@ -65,7 +66,7 @@ private: TargetMap libraries; ToolMap tools; /// Not used yet - StringMap archs; /// arch -> prefix + StringMap archs; //< arch -> prefix Analyzer *analyzer; bool do_build; diff --git a/source/compile.cpp b/source/compile.cpp index 02ae493..5162da6 100644 --- a/source/compile.cpp +++ b/source/compile.cpp @@ -17,20 +17,14 @@ Compile::Compile(Builder &b, const ObjectFile &obj): const TargetList &deps=obj.get_depends(); Path::Path spath=deps.front()->get_name(); - const string &prefix=b.get_arch_prefix(obj.get_package()->get_arch()); - string ext=Path::splitext(spath.str()).ext; const char *tool=0; if(ext==".cpp" || ext==".cc") - { tool="CXX"; - argv.push_back(prefix+"g++"); - } else - { tool="CC"; - argv.push_back(prefix+"gcc"); - } + + argv.push_back(builder.get_tool(tool, obj.get_package()->get_arch())); argv.push_back("-c"); const BuildInfo &binfo=comp.get_build_info(); diff --git a/source/link.cpp b/source/link.cpp index 4a96ff2..2f688be 100644 --- a/source/link.cpp +++ b/source/link.cpp @@ -18,10 +18,8 @@ Link::Link(Builder &b, const Executable &exe): { const Component &comp=exe.get_component(); - const string &prefix=b.get_arch_prefix(exe.get_package()->get_arch()); - //XXX Determine whether to use g++ or gcc - argv.push_back(prefix+"g++"); + argv.push_back(builder.get_tool("LDXX", exe.get_package()->get_arch())); if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE) argv.push_back("-shared"); diff --git a/source/package.cpp b/source/package.cpp index 031ceb5..2e7932c 100644 --- a/source/package.cpp +++ b/source/package.cpp @@ -188,7 +188,8 @@ Package *Package::create(Builder &b, const string &name) Package::Package(Builder &b, const string &n, const vector &info): builder(b), name(n), - buildable(false) + buildable(false), + conf_done(false) { for(vector::const_iterator i=info.begin(); i!=info.end(); ++i) { @@ -273,6 +274,7 @@ void Package::create_build_info() if(lexical_cast(optimize)) { build_info.cflags.push_back("-O"+optimize); + build_info.ldflags.push_back("-O"+optimize); string cpu=config.get_option("cpu").value; if(cpu!="auto") build_info.cflags.push_back("-march="+cpu); -- 2.45.2