Skip to content

Commit 29ef2e1

Browse files
author
Mark W. Alexander
committed
Support unified headers in NDK 15+
https://android.googlesource.com/platform/ndk/+/ndk-r15-release/docs/UnifiedHeaders.md - adds --isysroot and -isystem options for unified header includes - changes --sysroot to use the prebuilt NDK /sysroot
1 parent a8248ea commit 29ef2e1

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pythonforandroid/archs.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from os.path import (join, dirname)
1+
from os.path import (exists, join, dirname)
22
from os import environ, uname
33
import sys
44
from distutils.spawn import find_executable
@@ -33,13 +33,27 @@ def include_dirs(self):
3333
def get_env(self, with_flags_in_cc=True):
3434
env = {}
3535

36-
env["CFLAGS"] = " ".join([
37-
"-DANDROID", "-mandroid", "-fomit-frame-pointer",
38-
"--sysroot", self.ctx.ndk_platform])
36+
env['CFLAGS'] = ' '.join([
37+
'-DANDROID', '-mandroid', '-fomit-frame-pointer'
38+
' -D__ANDROID_API__={}'.format(self.ctx._android_api),
39+
])
40+
env['LDFLAGS'] = ' '
41+
42+
sysroot = join(self.ctx._ndk_dir, 'sysroot')
43+
if exists(sysroot):
44+
# post-15 NDK per
45+
# https://android.googlesource.com/platform/ndk/+/ndk-r15-release/docs/UnifiedHeaders.md
46+
env['CFLAGS'] += ' -isystem {}/sysroot/usr/include/{}'.format(
47+
self.ctx.ndk_dir, self.ctx.toolchain_prefix)
48+
else:
49+
sysroot = self.ctx.ndk_platform
50+
env['CFLAGS'] += ' -I{}'.format(self.ctx.ndk_platform)
51+
env['CFLAGS'] += ' -isysroot {} '.format(sysroot)
52+
env['LDFLAGS'] += '--sysroot {} '.format(self.ctx.ndk_platform)
3953

4054
env["CXXFLAGS"] = env["CFLAGS"]
4155

42-
env["LDFLAGS"] = " ".join(['-lm', '-L' + self.ctx.get_libs_dir(self.arch)])
56+
env["LDFLAGS"] += " ".join(['-lm', '-L' + self.ctx.get_libs_dir(self.arch)])
4357

4458
if self.ctx.ndk == 'crystax':
4559
env['LDFLAGS'] += ' -L{}/sources/crystax/libs/{} -lcrystax'.format(self.ctx.ndk_dir, self.arch)

0 commit comments

Comments
 (0)