from os import environ from os.path import join from multiprocessing import cpu_count import shutil from pythonforandroid.recipe import Recipe from pythonforandroid.util import BuildInterruptingException, build_platform class Arch: command_prefix = None '''The prefix for NDK commands such as gcc.''' arch = "" '''Name of the arch such as: `armeabi-v7a`, `arm64-v8a`, `x86`...''' arch_cflags = [] '''Specific arch `cflags`, expect to be overwrote in subclass if needed.''' common_cflags = [ '-target {target}', '-fomit-frame-pointer' ] common_cppflags = [ '-DANDROID', '-I{ctx.ndk.sysroot_include_dir}', '-I{python_includes}', ] common_ldflags = ['-L{ctx_libs_dir}'] common_ldlibs = ['-lm'] common_ldshared = [ '-pthread', '-shared', '-Wl,-O1', '-Wl,-Bsymbolic-functions', ] def __init__(self, ctx): self.ctx = ctx # Allows injecting additional linker paths used by any recipe. # This can also be modified by recipes (like the librt recipe) # to make sure that some sort of global resource is available & # linked for all others. self.extra_global_link_paths = [] def __str__(self): return self.arch @property def ndk_lib_dir(self): return join(self.ctx.ndk.sysroot_lib_dir, self.command_prefix) @property def ndk_lib_dir_versioned(self): return join(self.ndk_lib_dir, str(self.ctx.ndk_api)) @property def include_dirs(self): return [ "{}/{}".format( self.ctx.include_dir, d.format(arch=self)) for d in self.ctx.include_dirs] @property def target(self): # As of NDK r19, the toolchains installed by default with the # NDK may be used in-place. The make_standalone_toolchain.py script # is no longer needed for interfacing with arbitrary build systems. # See: https://developer.android.com/ndk/guides/other_build_systems return '{triplet}{ndk_api}'.format( triplet=self.command_prefix, ndk_api=self.ctx.ndk_api ) @property def clang_exe(self): """Full path of the clang compiler depending on the android's ndk version used.""" return self.get_clang_exe() @property def clang_exe_cxx(self): """Full path of the clang++ compiler depending on the android's ndk version used.""" return self.get_clang_exe(plus_plus=True) def get_clang_exe(self, with_target=False, plus_plus=False): """Returns the full path of the clang/clang++ compiler, supports two kwargs: - `with_target`: prepend `target` to clang - `plus_plus`: will return the clang++ compiler (defaults to `False`) """ compiler = 'clang' if with_target: compiler = '{target}-{compiler}'.format( target=self.target, compiler=compiler ) if plus_plus: compiler += '++' return join(self.ctx.ndk.llvm_bin_dir, compiler) def get_env(self, with_flags_in_cc=True): env = {} # HOME: User's home directory # # Many tools