]> git.tdb.fi Git - builder.git/blob - source/androidcompiler.cpp
Refactor transitive dependencies to work on all targets
[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         GnuCompiler(b, a, t),
17         ndk(n)
18 {
19         if(ndk.get_root_dir().empty())
20                 problems.push_back("Android NDK not found");
21         else if(ndk.get_bin_dir().empty())
22                 problems.push_back("Android NDK toolchain not found");
23         else
24                 set_command((ndk.get_bin_dir()/command).str());
25
26         if(ndk.get_platform_sysroot().empty())
27                 problems.push_back("Android platform not found");
28         else if(!ndk.get_common_sysroot().empty())
29         {
30                 build_info.sysroot = ndk.get_common_sysroot();
31                 /* The common sysroot has asm headers in arch directories and the
32                 compiler doesn't pick them up automatically */
33                 build_info.incpath.push_back(ndk.get_common_sysroot()/"usr/include"/architecture->get_cross_prefix());
34         }
35         else
36                 build_info.sysroot = ndk.get_platform_sysroot();
37
38         if(tag=="CXX")
39                 build_info.libs.push_back("gnustl_static");
40 }
41
42 void AndroidCompiler::do_prepare()
43 {
44         GnuCompiler::do_prepare();
45         if(tag=="CXX")
46         {
47                 string version_str = format("%d.%d.%d", version>>16, (version>>8)&0xFF, version&0xFF);
48                 FS::Path libstdcxx_dir = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++";
49                 FS::Path libstdcxx_path;
50                 while(1)
51                 {
52                         libstdcxx_path = libstdcxx_dir/version_str;
53                         if(FS::exists(libstdcxx_path))
54                                 break;
55
56                         string::size_type dot = version_str.rfind('.');
57                         if(dot==string::npos)
58                         {
59                                 problems.push_back("C++ standard library not found");
60                                 return;
61                         }
62
63                         version_str = version_str.substr(0, dot);
64                 }
65
66                 FS::Path public_dir = libstdcxx_path/"include";
67                 system_path.push_back(public_dir);
68                 build_info.incpath.push_back(public_dir);
69
70                 FS::Path arch_path = libstdcxx_path/"libs";
71                 builder.get_logger().log("files", format("Traversing %s", arch_path.str()));
72                 string arch_dir = architecture->best_match(list_files(arch_path));
73                 if(!arch_dir.empty())
74                 {
75                         build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
76                         build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
77                 }
78         }
79 }