#include <msp/fs/dir.h>
#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
#include <msp/strings/format.h>
+#include <msp/strings/utils.h>
#include "androidcompiler.h"
#include "androidtools.h"
#include "builder.h"
+#include "externaltask.h"
+#include "filetarget.h"
using namespace std;
using namespace Msp;
AndroidCompiler::AndroidCompiler(Builder &b, const Architecture &a, const string &t, const AndroidNdk &n):
- GnuCompiler(b, a, t, n.get_platform_sysroot()),
+ GnuCompiler(b, a, t),
ndk(n)
{
- set_command((ndk.get_bin_dir()/command).str());
- build_info.incpath.insert(build_info.incpath.end(), system_path.begin(), system_path.end());
+ if(ndk.get_root_dir().empty())
+ problems.push_back("Android NDK not found");
+ else if(ndk.get_bin_dir().empty())
+ problems.push_back("Android NDK toolchain not found");
+ else
+ set_command((ndk.get_bin_dir()/command).str());
+
+ if(ndk.get_platform_sysroot().empty())
+ problems.push_back("Android platform not found");
+ else if(!ndk.get_common_sysroot().empty())
+ {
+ build_info.sysroot = ndk.get_common_sysroot();
+ /* The common sysroot has asm headers in arch directories and the
+ compiler doesn't pick them up automatically */
+ build_info.incpath.push_back(ndk.get_common_sysroot()/"usr/include"/architecture->get_cross_prefix());
+ }
+ else
+ build_info.sysroot = ndk.get_platform_sysroot();
+
if(tag=="CXX")
build_info.libs.push_back("gnustl_static");
}
void AndroidCompiler::do_prepare()
{
GnuCompiler::do_prepare();
- if(executable && tag=="CXX")
+ if(tag=="CXX")
{
- FS::Path libstdcxx_path = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++"/version;
+ string version_str = format("%d.%d.%d", version>>16, (version>>8)&0xFF, version&0xFF);
+ FS::Path libstdcxx_dir = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++";
+ FS::Path libstdcxx_path;
+ while(1)
+ {
+ libstdcxx_path = libstdcxx_dir/version_str;
+ if(FS::exists(libstdcxx_path))
+ break;
+
+ string::size_type dot = version_str.rfind('.');
+ if(dot==string::npos)
+ {
+ problems.push_back("C++ standard library not found");
+ return;
+ }
+
+ version_str = version_str.substr(0, dot);
+ }
FS::Path public_dir = libstdcxx_path/"include";
system_path.push_back(public_dir);