@@ -30,13 +30,24 @@ def include_dirs(self):
3030 d .format (arch = self ))
3131 for d in self .ctx .include_dirs ]
3232
33- def get_env (self , with_flags_in_cc = True ):
33+ def get_env (self , with_flags_in_cc = True , clang = False ):
3434 env = {}
3535
36- env ['CFLAGS' ] = ' ' .join ([
37- '-DANDROID' , '-mandroid' , '-fomit-frame-pointer'
38- ' -D__ANDROID_API__={}' .format (self .ctx .ndk_api ),
39- ])
36+ cflags = [
37+ '-DANDROID' ,
38+ '-fomit-frame-pointer' ,
39+ '-D__ANDROID_API__={}' .format (self .ctx .ndk_api )]
40+ if not clang :
41+ cflags += ['-mandroid' ]
42+ else :
43+ cflags += ['-target armv7-none-linux-androideabi' ]
44+ android_host = 'arm-linux-androideabi'
45+ platform_dir = join (self .ctx .ndk_dir , 'platforms' , 'android-{}' .format (self .ctx .ndk_api ), 'arch-arm' )
46+ toolchain = '{android_host}-4.9' .format (android_host = android_host )
47+ toolchain = join (self .ctx .ndk_dir , 'toolchains' , toolchain , 'prebuilt' , 'linux-x86_64' )
48+ cflags += ['-gcc-toolchain {}' .format (toolchain )]
49+
50+ env ['CFLAGS' ] = ' ' .join (cflags )
4051 env ['LDFLAGS' ] = ' '
4152
4253 sysroot = join (self .ctx ._ndk_dir , 'sysroot' )
@@ -82,9 +93,21 @@ def get_env(self, with_flags_in_cc=True):
8293 env ['NDK_CCACHE' ] = self .ctx .ccache
8394 env .update ({k : v for k , v in environ .items () if k .startswith ('CCACHE_' )})
8495
85- cc = find_executable ('{command_prefix}-gcc' .format (
86- command_prefix = command_prefix ), path = environ ['PATH' ])
96+ if clang :
97+ clang_path = join (
98+ self .ctx .ndk_dir , 'toolchains' , 'llvm' , 'prebuilt' ,
99+ 'linux-x86_64' , 'bin' )
100+ environ ['PATH' ] = '{clang_path}:{path}' .format (
101+ clang_path = clang_path , path = environ ['PATH' ])
102+ exe = join (clang_path , 'clang' )
103+ execxx = join (clang_path , 'clang++' )
104+ else :
105+ exe = '{command_prefix}-gcc' .format (command_prefix = command_prefix )
106+ execxx = '{command_prefix}-g++' .format (command_prefix = command_prefix )
107+
108+ cc = find_executable (exe , path = environ ['PATH' ])
87109 if cc is None :
110+ print (environ ['PATH' ])
88111 print ('Searching path are: {!r}' .format (environ ['PATH' ]))
89112 warning ('Couldn\' t find executable for CC. This indicates a '
90113 'problem locating the {} executable in the Android '
@@ -93,20 +116,20 @@ def get_env(self, with_flags_in_cc=True):
93116 exit (1 )
94117
95118 if with_flags_in_cc :
96- env ['CC' ] = '{ccache}{command_prefix}-gcc {cflags}' .format (
97- command_prefix = command_prefix ,
119+ env ['CC' ] = '{ccache}{exe} {cflags}' .format (
120+ exe = exe ,
98121 ccache = ccache ,
99122 cflags = env ['CFLAGS' ])
100- env ['CXX' ] = '{ccache}{command_prefix}-g++ {cxxflags}' .format (
101- command_prefix = command_prefix ,
123+ env ['CXX' ] = '{ccache}{execxx} {cxxflags}' .format (
124+ execxx = execxx ,
102125 ccache = ccache ,
103126 cxxflags = env ['CXXFLAGS' ])
104127 else :
105- env ['CC' ] = '{ccache}{command_prefix}-gcc ' .format (
106- command_prefix = command_prefix ,
128+ env ['CC' ] = '{ccache}{exe} ' .format (
129+ exe = exe ,
107130 ccache = ccache )
108- env ['CXX' ] = '{ccache}{command_prefix}-g++ ' .format (
109- command_prefix = command_prefix ,
131+ env ['CXX' ] = '{ccache}{execxx} ' .format (
132+ execxx = execxx ,
110133 ccache = ccache )
111134
112135 env ['AR' ] = '{}-ar' .format (command_prefix )
@@ -151,8 +174,8 @@ class ArchARM(Arch):
151174class ArchARMv7_a (ArchARM ):
152175 arch = 'armeabi-v7a'
153176
154- def get_env (self , with_flags_in_cc = True ):
155- env = super (ArchARMv7_a , self ).get_env (with_flags_in_cc )
177+ def get_env (self , with_flags_in_cc = True , clang = False ):
178+ env = super (ArchARMv7_a , self ).get_env (with_flags_in_cc , clang = clang )
156179 env ['CFLAGS' ] = (env ['CFLAGS' ] +
157180 (' -march=armv7-a -mfloat-abi=softfp '
158181 '-mfpu=vfp -mthumb' ))
@@ -166,8 +189,8 @@ class Archx86(Arch):
166189 command_prefix = 'i686-linux-android'
167190 platform_dir = 'arch-x86'
168191
169- def get_env (self , with_flags_in_cc = True ):
170- env = super (Archx86 , self ).get_env (with_flags_in_cc )
192+ def get_env (self , with_flags_in_cc = True , clang = False ):
193+ env = super (Archx86 , self ).get_env (with_flags_in_cc , clang = clang )
171194 env ['CFLAGS' ] = (env ['CFLAGS' ] +
172195 ' -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32' )
173196 env ['CXXFLAGS' ] = env ['CFLAGS' ]
@@ -180,8 +203,8 @@ class Archx86_64(Arch):
180203 command_prefix = 'x86_64-linux-android'
181204 platform_dir = 'arch-x86_64'
182205
183- def get_env (self , with_flags_in_cc = True ):
184- env = super (Archx86_64 , self ).get_env (with_flags_in_cc )
206+ def get_env (self , with_flags_in_cc = True , clang = False ):
207+ env = super (Archx86_64 , self ).get_env (with_flags_in_cc , clang = clang )
185208 env ['CFLAGS' ] = (env ['CFLAGS' ] +
186209 ' -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel' )
187210 env ['CXXFLAGS' ] = env ['CFLAGS' ]
@@ -194,8 +217,8 @@ class ArchAarch_64(Arch):
194217 command_prefix = 'aarch64-linux-android'
195218 platform_dir = 'arch-arm64'
196219
197- def get_env (self , with_flags_in_cc = True ):
198- env = super (ArchAarch_64 , self ).get_env (with_flags_in_cc )
220+ def get_env (self , with_flags_in_cc = True , clang = False ):
221+ env = super (ArchAarch_64 , self ).get_env (with_flags_in_cc , clang = clang )
199222 incpath = ' -I' + join (dirname (__file__ ), 'includes' , 'arm64-v8a' )
200223 env ['EXTRA_CFLAGS' ] = incpath
201224 env ['CFLAGS' ] += incpath
0 commit comments