summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorRhody Lugo <rhodylugo@gmail.com>2017-10-31 14:44:25 -0400
committerRhody Lugo <rhodylugo@gmail.com>2017-11-06 07:51:09 -0400
commitec31b23b330404dcd60a537838b039df524e2a98 (patch)
treeae7fdad4cb900d64659a903905ce1314eb2fae09 /platform
parentb8ac700046ee092e6b804c746ae41c3cd9df0b75 (diff)
add support for Android NDK unified headers
Diffstat (limited to 'platform')
-rw-r--r--platform/android/detect.py39
-rw-r--r--platform/android/platform_config.h1
2 files changed, 37 insertions, 3 deletions
diff --git a/platform/android/detect.py b/platform/android/detect.py
index 13fc4ee810..4d5e586faf 100644
--- a/platform/android/detect.py
+++ b/platform/android/detect.py
@@ -26,6 +26,7 @@ def get_opts():
EnumVariable('android_arch', 'Target architecture', "armv7", ('armv7', 'armv6', 'arm64v8', 'x86')),
BoolVariable('android_neon', 'Enable NEON support (armv7 only)', True),
BoolVariable('android_stl', 'Enable Android STL support (for modules)', False),
+ BoolVariable('ndk_unified_headers', 'Enable NDK unified headers', True)
]
@@ -178,12 +179,28 @@ def configure(env):
env['RANLIB'] = tools_path + "/ranlib"
env['AS'] = tools_path + "/as"
- sysroot = env["ANDROID_NDK_ROOT"] + "/platforms/" + env['ndk_platform'] + "/" + env['ARCH']
+ ndk_unified_headers = env['ndk_unified_headers']
+ ndk_version = get_ndk_version(env["ANDROID_NDK_ROOT"])
+
common_opts = ['-fno-integrated-as', '-gcc-toolchain', gcc_toolchain_path]
+ if not ndk_unified_headers and ndk_version != None and ndk_version[0] >= 16:
+ ndk_unified_headers = True
+ print("Turning NDK unified headers on (starting from r16)")
+
+ lib_sysroot = env["ANDROID_NDK_ROOT"] + "/platforms/" + env['ndk_platform'] + "/" + env['ARCH']
+
## Compile flags
- env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include"])
+ if ndk_unified_headers:
+ sysroot = env["ANDROID_NDK_ROOT"] + "/sysroot"
+ env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include"])
+ env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include/" + abi_subpath])
+ # For unified headers this define has to be set manually
+ env.Append(CPPFLAGS=["-D__ANDROID_API__=" + str(int(env['ndk_platform'].split("-")[1]))])
+ else:
+ env.Append(CPPFLAGS=["-isystem", lib_sysroot + "/usr/include"])
+
env.Append(CPPFLAGS='-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -fvisibility=hidden -fno-strict-aliasing'.split())
env.Append(CPPFLAGS='-DNO_STATVFS -DGLES2_ENABLED'.split())
@@ -224,7 +241,7 @@ def configure(env):
## Link flags
- env['LINKFLAGS'] = ['-shared', '--sysroot=' + sysroot, '-Wl,--warn-shared-textrel']
+ env['LINKFLAGS'] = ['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel']
if env["android_arch"] == "armv7":
env.Append(LINKFLAGS='-Wl,--fix-cortex-a8'.split())
env.Append(LINKFLAGS='-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now'.split())
@@ -248,3 +265,19 @@ def configure(env):
if (env["android_arch"] == "armv6" or env["android_arch"] == "armv7"):
env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
env.opus_fixed_point = "yes"
+
+# Return NDK version as [<major>,<minor>,<build>] or None if cannot be figured out (adapted from the Chromium project).
+def get_ndk_version (path):
+ if path == None:
+ return None
+ prop_file_path = os.path.join(path, "source.properties")
+ try:
+ with open(prop_file_path) as prop_file:
+ for line in prop_file:
+ key_value = map(lambda x: string.strip(x), line.split("="))
+ if key_value[0] == "Pkg.Revision":
+ version_parts = key_value[1].split("-")[0].split(".")
+ return map(int, version_parts[0:3])
+ except:
+ print("Could not read source prop file '%s'" % prop_file_path)
+ return None
diff --git a/platform/android/platform_config.h b/platform/android/platform_config.h
index b1c3f027f3..b1f51c9256 100644
--- a/platform/android/platform_config.h
+++ b/platform/android/platform_config.h
@@ -28,3 +28,4 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <alloca.h>
+#include <malloc.h>