]> git.tdb.fi Git - builder.git/blob - source/androidcompiler.cpp
Initialize AndroidCompiler's build info in do_prepare
[builder.git] / source / androidcompiler.cpp
1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include <msp/fs/utils.h>
4 #include <msp/strings/format.h>
5 #include <msp/strings/utils.h>
6 #include "androidcompiler.h"
7 #include "androidtools.h"
8 #include "builder.h"
9 #include "externaltask.h"
10 #include "filetarget.h"
11
12 using namespace std;
13 using namespace Msp;
14
15 AndroidCompiler::AndroidCompiler(Builder &b, const Architecture &a, const string &t, const AndroidNdk &n):
16         CustomizedTool(b, t, a),
17         ndk(n)
18 {
19         set_command((tag=="CXX" ? "g++" : "gcc"), true);
20         if(ndk.get_root_dir().empty())
21                 problems.push_back("Android NDK not found");
22         else if(ndk.get_bin_dir().empty())
23                 problems.push_back("Android NDK toolchain not found");
24         else
25                 set_command((ndk.get_bin_dir()/command).str());
26
27         if(ndk.get_platform_sysroot().empty())
28                 problems.push_back("Android platform not found");
29         else if(!ndk.get_common_sysroot().empty())
30         {
31                 build_info.sysroot = ndk.get_common_sysroot();
32                 /* The common sysroot has asm headers in arch directories and the
33                 compiler doesn't pick them up automatically */
34                 build_info.incpath.push_back(ndk.get_common_sysroot()/"usr/include"/architecture->get_cross_prefix());
35         }
36         else
37                 build_info.sysroot = ndk.get_platform_sysroot();
38 }
39
40 void AndroidCompiler::do_prepare(ToolData &tool) const
41 {
42         const Architecture &arch = *static_cast<const Tool &>(tool).get_architecture();
43
44         CustomizedTool::do_prepare(tool);
45         if(tag=="CXX")
46         {
47                 tool.build_info.libs.push_back("gnustl_static");
48
49                 unsigned version = tool.extra_data;
50                 string version_str = format("%d.%d.%d", version>>16, (version>>8)&0xFF, version&0xFF);
51                 FS::Path libstdcxx_dir = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++";
52                 FS::Path libstdcxx_path;
53                 while(1)
54                 {
55                         libstdcxx_path = libstdcxx_dir/version_str;
56                         if(FS::exists(libstdcxx_path))
57                                 break;
58
59                         string::size_type dot = version_str.rfind('.');
60                         if(dot==string::npos)
61                         {
62                                 tool.problems.push_back("C++ standard library not found");
63                                 return;
64                         }
65
66                         version_str = version_str.substr(0, dot);
67                 }
68
69                 builder.get_logger().log("tools", "Found GNU libstdc++ in %s", libstdcxx_path);
70
71                 FS::Path public_dir = libstdcxx_path/"include";
72                 tool.system_path.push_back(public_dir);
73                 tool.build_info.incpath.push_back(public_dir);
74
75                 FS::Path arch_path = libstdcxx_path/"libs";
76                 builder.get_logger().log("files", "Traversing %s", arch_path.str());
77                 string arch_dir = arch.best_match(list_files(arch_path));
78                 if(!arch_dir.empty())
79                 {
80                         tool.build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
81                         tool.build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
82                 }
83         }
84 }