1
1
from distutils .spawn import find_executable
2
2
from os import environ
3
- from os .path import join , split , exists
3
+ from os .path import join
4
4
from multiprocessing import cpu_count
5
- from glob import glob
6
5
7
- from pythonforandroid .logger import warning
8
6
from pythonforandroid .recipe import Recipe
9
7
from pythonforandroid .util import BuildInterruptingException , build_platform
10
8
11
9
12
10
class Arch :
13
11
14
- toolchain_prefix = None
15
- '''The prefix for the toolchain dir in the NDK.'''
16
-
17
12
command_prefix = None
18
13
'''The prefix for NDK commands such as gcc.'''
19
14
@@ -30,8 +25,7 @@ class Arch:
30
25
31
26
common_cppflags = [
32
27
'-DANDROID' ,
33
- '-D__ANDROID_API__={ctx.ndk_api}' ,
34
- '-I{ctx.ndk_sysroot}/usr/include/{command_prefix}' ,
28
+ '-I{ctx.ndk_sysroot}/usr/include' ,
35
29
'-I{python_includes}' ,
36
30
]
37
31
@@ -62,20 +56,6 @@ def __str__(self):
62
56
def ndk_lib_dir (self ):
63
57
return join (self .ctx .ndk_sysroot , 'usr' , 'lib' , self .command_prefix , str (self .ctx .ndk_api ))
64
58
65
- @property
66
- def ndk_platform (self ):
67
- warning ("ndk_platform is deprecated and should be avoided in new recipes" )
68
- ndk_platform = join (
69
- self .ctx .ndk_dir ,
70
- 'platforms' ,
71
- 'android-{}' .format (self .ctx .ndk_api ),
72
- self .platform_dir )
73
- if not exists (ndk_platform ):
74
- BuildInterruptingException (
75
- "The requested platform folder doesn't exist. If you're building on ndk >= r22, and seeing this error, one of the required recipe is using a removed feature."
76
- )
77
- return ndk_platform
78
-
79
59
@property
80
60
def include_dirs (self ):
81
61
return [
@@ -97,13 +77,10 @@ def target(self):
97
77
@property
98
78
def clang_path (self ):
99
79
"""Full path of the clang compiler"""
100
- llvm_dirname = split (
101
- glob (join (self .ctx .ndk_dir , 'toolchains' , 'llvm*' ))[- 1 ]
102
- )[- 1 ]
103
80
return join (
104
81
self .ctx .ndk_dir ,
105
82
'toolchains' ,
106
- llvm_dirname ,
83
+ 'llvm' ,
107
84
'prebuilt' ,
108
85
build_platform ,
109
86
'bin' ,
@@ -190,12 +167,10 @@ def get_env(self, with_flags_in_cc=True):
190
167
)
191
168
192
169
# Compiler: `CC` and `CXX` (and make sure that the compiler exists)
193
- environ ['PATH' ] = '{clang_path}:{path}' .format (
194
- clang_path = self .clang_path , path = environ ['PATH' ]
195
- )
196
- cc = find_executable (self .clang_exe , path = environ ['PATH' ])
170
+ env ['PATH' ] = self .ctx .env ['PATH' ]
171
+ cc = find_executable (self .clang_exe , path = env ['PATH' ])
197
172
if cc is None :
198
- print ('Searching path are: {!r}' .format (environ ['PATH' ]))
173
+ print ('Searching path are: {!r}' .format (env ['PATH' ]))
199
174
raise BuildInterruptingException (
200
175
'Couldn\' t find executable for CC. This indicates a '
201
176
'problem locating the {} executable in the Android '
@@ -219,21 +194,18 @@ def get_env(self, with_flags_in_cc=True):
219
194
execxx = self .clang_exe_cxx ,
220
195
ccache = ccache )
221
196
222
- # Android's binaries
223
- command_prefix = self .command_prefix
224
- env ['AR' ] = '{}-ar' .format (command_prefix )
225
- env ['RANLIB' ] = '{}-ranlib' .format (command_prefix )
226
- env ['STRIP' ] = '{}-strip --strip-unneeded' .format (command_prefix )
197
+ # Android's LLVM binutils
198
+ env ['AR' ] = f'{ self .clang_path } /llvm-ar'
199
+ env ['RANLIB' ] = f'{ self .clang_path } /llvm-ranlib'
200
+ env ['STRIP' ] = f'{ self .clang_path } /llvm-strip --strip-unneeded'
201
+ env ['READELF' ] = f'{ self .clang_path } /llvm-readelf'
202
+ env ['OBJCOPY' ] = f'{ self .clang_path } /llvm-objcopy'
203
+
227
204
env ['MAKE' ] = 'make -j{}' .format (str (cpu_count ()))
228
- env ['READELF' ] = '{}-readelf' .format (command_prefix )
229
- env ['NM' ] = '{}-nm' .format (command_prefix )
230
- env ['LD' ] = '{}-ld' .format (command_prefix )
231
205
232
206
# Android's arch/toolchain
233
207
env ['ARCH' ] = self .arch
234
208
env ['NDK_API' ] = 'android-{}' .format (str (self .ctx .ndk_api ))
235
- env ['TOOLCHAIN_PREFIX' ] = self .toolchain_prefix
236
- env ['TOOLCHAIN_VERSION' ] = self .ctx .toolchain_version
237
209
238
210
# Custom linker options
239
211
env ['LDSHARED' ] = env ['CC' ] + ' ' + ' ' .join (self .common_ldshared )
@@ -251,8 +223,6 @@ def get_env(self, with_flags_in_cc=True):
251
223
),
252
224
)
253
225
254
- env ['PATH' ] = environ ['PATH' ]
255
-
256
226
# for reproducible builds
257
227
if 'SOURCE_DATE_EPOCH' in environ :
258
228
for k in 'LC_ALL TZ SOURCE_DATE_EPOCH PYTHONHASHSEED BUILD_DATE BUILD_TIME' .split ():
@@ -264,9 +234,7 @@ def get_env(self, with_flags_in_cc=True):
264
234
265
235
class ArchARM (Arch ):
266
236
arch = "armeabi"
267
- toolchain_prefix = 'arm-linux-androideabi'
268
237
command_prefix = 'arm-linux-androideabi'
269
- platform_dir = 'arch-arm'
270
238
271
239
@property
272
240
def target (self ):
@@ -290,12 +258,9 @@ class ArchARMv7_a(ArchARM):
290
258
291
259
class Archx86 (Arch ):
292
260
arch = 'x86'
293
- toolchain_prefix = 'x86'
294
261
command_prefix = 'i686-linux-android'
295
- platform_dir = 'arch-x86'
296
262
arch_cflags = [
297
263
'-march=i686' ,
298
- '-mtune=intel' ,
299
264
'-mssse3' ,
300
265
'-mfpmath=sse' ,
301
266
'-m32' ,
@@ -304,26 +269,22 @@ class Archx86(Arch):
304
269
305
270
class Archx86_64 (Arch ):
306
271
arch = 'x86_64'
307
- toolchain_prefix = 'x86_64'
308
272
command_prefix = 'x86_64-linux-android'
309
- platform_dir = 'arch-x86_64'
310
273
arch_cflags = [
311
274
'-march=x86-64' ,
312
275
'-msse4.2' ,
313
276
'-mpopcnt' ,
314
277
'-m64' ,
315
- '-mtune=intel' ,
316
278
'-fPIC' ,
317
279
]
318
280
319
281
320
282
class ArchAarch_64 (Arch ):
321
283
arch = 'arm64-v8a'
322
- toolchain_prefix = 'aarch64-linux-android'
323
284
command_prefix = 'aarch64-linux-android'
324
- platform_dir = 'arch-arm64'
325
285
arch_cflags = [
326
286
'-march=armv8-a' ,
287
+ '-fPIC'
327
288
# '-I' + join(dirname(__file__), 'includes', 'arm64-v8a'),
328
289
]
329
290
0 commit comments