X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgnucompiler.cpp;h=3236631d756d69b10a0fc0172b4f580972d0a863;hb=edd4771292a2273080fbcbac266c6831834b0b86;hp=0ec9222a2d28587f8127f01cbaa1e01008496459;hpb=1ed833343bc83b83c5f61cbfd74423bbba677a04;p=builder.git diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 0ec9222..3236631 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -6,7 +6,6 @@ #include "builder.h" #include "component.h" #include "csourcefile.h" -#include "externaltask.h" #include "gnucompiler.h" #include "objcsourcefile.h" #include "objectfile.h" @@ -28,8 +27,7 @@ const char *cpus[] = } GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t): - Tool(b, a, t), - version(0) + Tool(b, &a, t) { if(tag=="CC") { @@ -51,7 +49,7 @@ GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t): throw invalid_argument("GnuCompiler::GnuCompiler"); set_command((tag=="CXX" ? "g++" : "gcc"), true); - set_run(_run); + set_run_external(_run); } Target *GnuCompiler::create_source(const Component &comp, const FS::Path &path) const @@ -103,22 +101,27 @@ string GnuCompiler::create_build_signature(const BuildInfo &binfo) const return result; } -void GnuCompiler::do_prepare() +void GnuCompiler::do_prepare(ToolData &tool) const { - executable = builder.get_vfs().find_binary(command); - prepare_syspath(); - prepare_version(); + tool.extra_data = 0U; + prepare_syspath(tool); + prepare_version(tool); + + if(tag=="CXX") + tool.build_info.libs.push_back("stdc++"); } -void GnuCompiler::prepare_syspath() +void GnuCompiler::prepare_syspath(ToolData &tool) const { bool path_found = false; - const FS::Path &sysroot = build_info.sysroot; + const FS::Path &sysroot = tool.build_info.sysroot; + const std::string &tool_tag = static_cast(tool).get_tag(); - if(executable) + const FileTarget *exe = static_cast(tool).get_executable(); + if(exe) { ExternalTask::Arguments argv; - argv.push_back(executable->get_path().str()); + argv.push_back(exe->get_path().str()); argv.push_back("-Wp,-v"); argv.push_back("-E"); if(tag=="CXX") @@ -146,8 +149,8 @@ void GnuCompiler::prepare_syspath() else if(record_path) { FS::Path path = strip(output.substr(start, newline-start)); - builder.get_logger().log("tools", "Got %s system path: %s", tag, path); - system_path.push_back(path); + builder.get_logger().log("tools", "Got %s system path: %s", tool_tag, path); + tool.system_path.push_back(path); } start = newline+1; } @@ -158,50 +161,60 @@ void GnuCompiler::prepare_syspath() if(!path_found) { - builder.get_logger().log("tools", "No %s system path found, using defaults", tag); + builder.get_logger().log("tools", "No %s system path found, using defaults", tool_tag); + const Architecture &arch = *static_cast(tool).get_architecture(); if(!sysroot.empty()) - system_path.push_back(sysroot/"usr/include"); - else if(architecture->is_native()) - system_path.push_back("/usr/include"); + tool.system_path.push_back(sysroot/"usr/include"); + else if(arch.is_native()) + tool.system_path.push_back("/usr/include"); else - system_path.push_back(format("/usr/%s/include", architecture->get_cross_prefix())); + tool.system_path.push_back(format("/usr/%s/include", arch.get_cross_prefix())); } } -void GnuCompiler::prepare_version() +void GnuCompiler::prepare_version(ToolData &tool) const { - if(!executable) + const FileTarget *exe = static_cast(tool).get_executable(); + if(!exe) return; - prepare_version("-dumpversion"); + string exe_path = exe->get_path().str(); + unsigned version = query_version(exe_path, "-dumpversion"); if(version>=0x70000) - prepare_version("-dumpfullversion"); - builder.get_logger().log("tools", "%s version is %d.%d.%d", FS::basename(executable->get_path()), version>>16, (version>>8)&0xFF, version&0xFF); + { + unsigned v = query_version(exe_path, "-dumpfullversion"); + if(v) + version = v; + } + tool.extra_data = version; + builder.get_logger().log("tools", "%s version is %d.%d.%d", FS::basename(exe->get_path()), version>>16, (version>>8)&0xFF, version&0xFF); } -void GnuCompiler::prepare_version(const string &arg) +unsigned GnuCompiler::query_version(const string &exe_path, const string &arg) const { ExternalTask::Arguments argv; - argv.push_back(executable->get_path().str()); + argv.push_back(exe_path); argv.push_back(arg); builder.get_logger().log("auxcommands", "Running %s", join(argv.begin(), argv.end())); + unsigned ver = 0; try { string version_str = strip(ExternalTask::run_and_capture_output(argv)); vector version_parts = split(version_str, '.'); - version = 0; for(unsigned i=0; (i<3 && i(version_parts[i])<<(16-8*i); + ver |= lexical_cast(version_parts[i])<<(16-8*i); } catch(const runtime_error &) { } + + return ver; } -Task *GnuCompiler::_run(const ObjectFile &object) +ExternalTask::Arguments GnuCompiler::_run(const ObjectFile &object, FS::Path &work_dir) { - const GnuCompiler &tool = dynamic_cast(*object.get_tool()); + const Tool &tool = *object.get_tool(); const Architecture &arch = *tool.get_architecture(); ExternalTask::Arguments argv; @@ -225,7 +238,8 @@ Task *GnuCompiler::_run(const ObjectFile &object) { argv.push_back("-Wextra"); argv.push_back("-Wundef"); - if(tool.version>=0x80000) + unsigned version = tool.get_extra_data(); + if(version>=0x80000) argv.push_back("-Wno-cast-function-type"); } if(binfo.warning_level>=3) @@ -330,11 +344,10 @@ Task *GnuCompiler::_run(const ObjectFile &object) FS::Path obj_path = object.get_path(); FS::Path src_path = object.get_source().get_path(); - FS::Path work_dir = object.get_component()->get_package().get_source_directory(); argv.push_back("-o"); argv.push_back(relative(obj_path, work_dir).str()); argv.push_back(relative(src_path, work_dir).str()); - return new ExternalTask(argv, work_dir); + return argv; }