@@ -30,13 +30,25 @@ 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+ # '-D__ANDROID_API__={}'.format(self.ctx._android_api)]
41+ if not clang :
42+ cflags += ['-mandroid' ]
43+ else :
44+ cflags += ['-target armv7-none-linux-androideabi' ]
45+ android_host = 'arm-linux-androideabi'
46+ platform_dir = join (self .ctx .ndk_dir , 'platforms' , 'android-{}' .format (self .ctx .ndk_api ), 'arch-arm' )
47+ toolchain = '{android_host}-4.9' .format (android_host = android_host )
48+ toolchain = join (self .ctx .ndk_dir , 'toolchains' , toolchain , 'prebuilt' , 'linux-x86_64' )
49+ cflags += ['-gcc-toolchain {}' .format (toolchain )]
50+
51+ env ['CFLAGS' ] = ' ' .join (cflags )
4052 env ['LDFLAGS' ] = ' '
4153
4254 sysroot = join (self .ctx ._ndk_dir , 'sysroot' )
@@ -82,9 +94,21 @@ def get_env(self, with_flags_in_cc=True):
8294 env ['NDK_CCACHE' ] = self .ctx .ccache
8395 env .update ({k : v for k , v in environ .items () if k .startswith ('CCACHE_' )})
8496
85- cc = find_executable ('{command_prefix}-gcc' .format (
86- command_prefix = command_prefix ), path = environ ['PATH' ])
97+ if clang :
98+ clang_path = join (
99+ self .ctx .ndk_dir , 'toolchains' , 'llvm' , 'prebuilt' ,
100+ 'linux-x86_64' , 'bin' )
101+ environ ['PATH' ] = '{clang_path}:{path}' .format (
102+ clang_path = clang_path , path = environ ['PATH' ])
103+ exe = join (clang_path , 'clang' )
104+ execxx = join (clang_path , 'clang++' )
105+ else :
106+ exe = '{command_prefix}-gcc' .format (command_prefix = command_prefix )
107+ execxx = '{command_prefix}-g++' .format (command_prefix = command_prefix )
108+
109+ cc = find_executable (exe , path = environ ['PATH' ])
87110 if cc is None :
111+ print (environ ['PATH' ])
88112 print ('Searching path are: {!r}' .format (environ ['PATH' ]))
89113 warning ('Couldn\' t find executable for CC. This indicates a '
90114 'problem locating the {} executable in the Android '
@@ -93,20 +117,20 @@ def get_env(self, with_flags_in_cc=True):
93117 exit (1 )
94118
95119 if with_flags_in_cc :
96- env ['CC' ] = '{ccache}{command_prefix}-gcc {cflags}' .format (
97- command_prefix = command_prefix ,
120+ env ['CC' ] = '{ccache}{exe} {cflags}' .format (
121+ exe = exe ,
98122 ccache = ccache ,
99123 cflags = env ['CFLAGS' ])
100- env ['CXX' ] = '{ccache}{command_prefix}-g++ {cxxflags}' .format (
101- command_prefix = command_prefix ,
124+ env ['CXX' ] = '{ccache}{execxx} {cxxflags}' .format (
125+ execxx = execxx ,
102126 ccache = ccache ,
103127 cxxflags = env ['CXXFLAGS' ])
104128 else :
105- env ['CC' ] = '{ccache}{command_prefix}-gcc ' .format (
106- command_prefix = command_prefix ,
129+ env ['CC' ] = '{ccache}{exe} ' .format (
130+ exe = exe ,
107131 ccache = ccache )
108- env ['CXX' ] = '{ccache}{command_prefix}-g++ ' .format (
109- command_prefix = command_prefix ,
132+ env ['CXX' ] = '{ccache}{execxx} ' .format (
133+ execxx = execxx ,
110134 ccache = ccache )
111135
112136 env ['AR' ] = '{}-ar' .format (command_prefix )
@@ -151,8 +175,8 @@ class ArchARM(Arch):
151175class ArchARMv7_a (ArchARM ):
152176 arch = 'armeabi-v7a'
153177
154- def get_env (self , with_flags_in_cc = True ):
155- env = super (ArchARMv7_a , self ).get_env (with_flags_in_cc )
178+ def get_env (self , with_flags_in_cc = True , clang = False ):
179+ env = super (ArchARMv7_a , self ).get_env (with_flags_in_cc , clang = clang )
156180 env ['CFLAGS' ] = (env ['CFLAGS' ] +
157181 (' -march=armv7-a -mfloat-abi=softfp '
158182 '-mfpu=vfp -mthumb' ))
@@ -166,8 +190,8 @@ class Archx86(Arch):
166190 command_prefix = 'i686-linux-android'
167191 platform_dir = 'arch-x86'
168192
169- def get_env (self , with_flags_in_cc = True ):
170- env = super (Archx86 , self ).get_env (with_flags_in_cc )
193+ def get_env (self , with_flags_in_cc = True , clang = False ):
194+ env = super (Archx86 , self ).get_env (with_flags_in_cc , clang = clang )
171195 env ['CFLAGS' ] = (env ['CFLAGS' ] +
172196 ' -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32' )
173197 env ['CXXFLAGS' ] = env ['CFLAGS' ]
@@ -180,8 +204,8 @@ class Archx86_64(Arch):
180204 command_prefix = 'x86_64-linux-android'
181205 platform_dir = 'arch-x86'
182206
183- def get_env (self , with_flags_in_cc = True ):
184- env = super (Archx86_64 , self ).get_env (with_flags_in_cc )
207+ def get_env (self , with_flags_in_cc = True , clang = False ):
208+ env = super (Archx86_64 , self ).get_env (with_flags_in_cc , clang = clang )
185209 env ['CFLAGS' ] = (env ['CFLAGS' ] +
186210 ' -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel' )
187211 env ['CXXFLAGS' ] = env ['CFLAGS' ]
@@ -194,8 +218,8 @@ class ArchAarch_64(Arch):
194218 command_prefix = 'aarch64-linux-android'
195219 platform_dir = 'arch-arm64'
196220
197- def get_env (self , with_flags_in_cc = True ):
198- env = super (ArchAarch_64 , self ).get_env (with_flags_in_cc )
221+ def get_env (self , with_flags_in_cc = True , clang = False ):
222+ env = super (ArchAarch_64 , self ).get_env (with_flags_in_cc , clang = clang )
199223 incpath = ' -I' + join (dirname (__file__ ), 'includes' , 'arm64-v8a' )
200224 env ['EXTRA_CFLAGS' ] = incpath
201225 env ['CFLAGS' ] += incpath
0 commit comments