1 #include <msp/builder/builder.h>
2 #include <msp/builder/externaltask.h>
3 #include <msp/builder/filetarget.h>
4 #include <msp/core/algorithm.h>
5 #include <msp/fs/dir.h>
6 #include <msp/fs/stat.h>
7 #include <msp/fs/utils.h>
8 #include <msp/strings/format.h>
9 #include <msp/strings/utils.h>
10 #include "androidcompiler.h"
11 #include "androidtools.h"
16 AndroidCompiler::AndroidCompiler(Builder &b, const Architecture &a, const string &t, const AndroidNdk &n):
17 CustomizedTool(b, t, a),
20 set_command((tag=="CXX" ? "g++" : "gcc"), true);
21 if(ndk.get_root_dir().empty())
22 problems.push_back("Android NDK not found");
23 else if(ndk.get_bin_dir().empty())
24 problems.push_back("Android NDK toolchain not found");
26 set_command((ndk.get_bin_dir()/command).str());
28 if(ndk.get_platform_sysroot().empty())
29 problems.push_back("Android platform not found");
30 else if(!ndk.get_common_sysroot().empty())
32 build_info.sysroot = ndk.get_common_sysroot();
33 /* The common sysroot has asm headers in arch directories and the
34 compiler doesn't pick them up automatically */
35 build_info.incpath.push_back(ndk.get_common_sysroot()/"usr/include"/architecture->get_cross_prefix());
38 build_info.sysroot = ndk.get_platform_sysroot();
41 void AndroidCompiler::do_prepare(ToolData &tool) const
43 const Architecture &arch = *static_cast<const Tool &>(tool).get_architecture();
45 CustomizedTool::do_prepare(tool);
48 auto i = find(tool.build_info.libs, "stdc++");
49 if(i!=tool.build_info.libs.end())
52 tool.build_info.libs.push_back("gnustl_static");
54 unsigned version = tool.extra_data;
55 string version_str = format("%d.%d.%d", version>>16, (version>>8)&0xFF, version&0xFF);
56 FS::Path libstdcxx_dir = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++";
57 FS::Path libstdcxx_path;
60 libstdcxx_path = libstdcxx_dir/version_str;
61 if(FS::exists(libstdcxx_path))
64 string::size_type dot = version_str.rfind('.');
67 tool.problems.push_back("C++ standard library not found");
71 version_str = version_str.substr(0, dot);
74 builder.get_logger().log("tools", "Found GNU libstdc++ in %s", libstdcxx_path);
76 FS::Path public_dir = libstdcxx_path/"include";
77 tool.system_path.push_back(public_dir);
78 tool.build_info.incpath.push_back(public_dir);
80 FS::Path arch_path = libstdcxx_path/"libs";
81 builder.get_logger().log("files", "Traversing %s", arch_path.str());
82 string arch_dir = arch.best_match(list_files(arch_path));
85 tool.build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
86 tool.build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);