]> git.tdb.fi Git - builder.git/blob - source/androidcompiler.cpp
Clean up compiler and linker constructors
[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
29                 build_info.sysroot = ndk.get_platform_sysroot();
30
31         if(tag=="CXX")
32                 build_info.libs.push_back("gnustl_static");
33 }
34
35 void AndroidCompiler::do_prepare()
36 {
37         GnuCompiler::do_prepare();
38         if(executable && tag=="CXX")
39         {
40                 ExternalTask::Arguments argv;
41                 argv.push_back(executable->get_path().str());
42                 argv.push_back("-dumpversion");
43
44                 builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
45                 string version;
46                 try
47                 {
48                         version = strip(ExternalTask::run_and_capture_output(argv));
49                         builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), version));
50                 }
51                 catch(const runtime_error &)
52                 { }
53
54                 FS::Path libstdcxx_dir = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++";
55                 FS::Path libstdcxx_path;
56                 while(1)
57                 {
58                         libstdcxx_path = libstdcxx_dir/version;
59                         if(FS::exists(libstdcxx_path))
60                                 break;
61
62                         string::size_type dot = version.rfind('.');
63                         if(dot==string::npos)
64                         {
65                                 problems.push_back("C++ standard library not found");
66                                 return;
67                         }
68
69                         version = version.substr(0, dot);
70                 }
71
72                 FS::Path public_dir = libstdcxx_path/"include";
73                 system_path.push_back(public_dir);
74                 build_info.incpath.push_back(public_dir);
75
76                 FS::Path arch_path = libstdcxx_path/"libs";
77                 builder.get_logger().log("files", format("Traversing %s", arch_path.str()));
78                 string arch_dir = architecture->best_match(list_files(arch_path));
79                 if(!arch_dir.empty())
80                 {
81                         build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
82                         build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
83                 }
84         }
85 }