diff --git a/pythonforandroid/recipe.py b/pythonforandroid/recipe.py index f1708e02ba..20bab446e3 100644 --- a/pythonforandroid/recipe.py +++ b/pythonforandroid/recipe.py @@ -758,6 +758,34 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True): env['PYTHONNOUSERSITE'] = '1' if not self.call_hostpython_via_targetpython: + # sets python headers/linkages...depending on python's recipe + python_version = self.ctx.python_recipe.version + python_short_version = '.'.join(python_version.split('.')[:2]) + if 'python2' in self.ctx.recipe_build_order: + env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() + env['CFLAGS'] += ' -I' + env[ + 'PYTHON_ROOT'] + '/include/python2.7' + env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \ + ' -lpython2.7' + elif self.ctx.python_recipe.from_crystax: + ndk_dir_python = join(self.ctx.ndk_dir, 'sources', + 'python', python_version) + env['CFLAGS'] += ' -I{} '.format( + join(ndk_dir_python, 'include', + 'python')) + env['LDFLAGS'] += ' -L{}'.format( + join(ndk_dir_python, 'libs', arch.arch)) + env['LDFLAGS'] += ' -lpython{}m'.format(python_short_version) + elif 'python3' in self.ctx.recipe_build_order: + # This headers are unused cause python3 recipe was removed + # TODO: should be reviewed when python3 recipe added + env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() + env['CFLAGS'] += ' -I' + env[ + 'PYTHON_ROOT'] + '/include/python{}m'.format( + python_short_version) + env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \ + ' -lpython{}m'.format( + python_short_version) hppath = [] hppath.append(join(dirname(self.hostpython_location), 'Lib')) hppath.append(join(hppath[0], 'site-packages')) @@ -889,17 +917,14 @@ def get_recipe_env(self, arch): keys = dict( ctx=self.ctx, arch=arch, - arch_noeabi=arch.arch.replace('eabi', ''), - pyroot=self.ctx.get_python_install_dir() + arch_noeabi=arch.arch.replace('eabi', '') ) env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' - env['CFLAGS'] += " -I{pyroot}/include/python2.7 " \ - " -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \ + env['CFLAGS'] += " -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \ " -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/include" \ " -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}/include".format(**keys) env['CXXFLAGS'] = env['CFLAGS'] + ' -frtti -fexceptions' env['LDFLAGS'] += " -L{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}" \ - " -lpython2.7" \ " -lgnustl_shared".format(**keys) return env @@ -919,6 +944,7 @@ class CythonRecipe(PythonRecipe): pre_build_ext = False cythonize = True cython_args = [] + call_hostpython_via_targetpython = False def __init__(self, *args, **kwargs): super(CythonRecipe, self).__init__(*args, **kwargs) @@ -1042,21 +1068,6 @@ def get_recipe_env(self, arch, with_flags_in_cc=True): env['LIBLINK_PATH'] = liblink_path ensure_dir(liblink_path) - if self.ctx.python_recipe.from_crystax: - env['CFLAGS'] = '-I{} '.format( - join(self.ctx.ndk_dir, 'sources', 'python', - self.ctx.python_recipe.version, 'include', - 'python')) + env['CFLAGS'] - - # Temporarily hardcode the -lpython3.x as this does not - # get applied automatically in some environments. This - # will need generalising, along with the other hardcoded - # py3.5 references, to support other python3 or crystax - # python versions. - python3_version = self.ctx.python_recipe.version - python3_version = '.'.join(python3_version.split('.')[:2]) - env['LDFLAGS'] = env['LDFLAGS'] + ' -lpython{}m'.format(python3_version) - return env diff --git a/pythonforandroid/recipes/cryptography/__init__.py b/pythonforandroid/recipes/cryptography/__init__.py index 3c4deef401..b5de84f3a3 100644 --- a/pythonforandroid/recipes/cryptography/__init__.py +++ b/pythonforandroid/recipes/cryptography/__init__.py @@ -1,5 +1,4 @@ from pythonforandroid.recipe import CompiledComponentsPythonRecipe -from os.path import join class CryptographyRecipe(CompiledComponentsPythonRecipe): @@ -13,14 +12,9 @@ def get_recipe_env(self, arch): env = super(CryptographyRecipe, self).get_recipe_env(arch) r = self.get_recipe('openssl', self.ctx) openssl_dir = r.get_build_dir(arch.arch) - env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() - env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' + \ - ' -I' + join(openssl_dir, 'include') # Set linker to use the correct gcc env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' - env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \ - ' -L' + openssl_dir + \ - ' -lpython2.7' + \ + env['LDFLAGS'] += ' -L' + openssl_dir + \ ' -lssl' + r.version + \ ' -lcrypto' + r.version return env diff --git a/pythonforandroid/recipes/m2crypto/__init__.py b/pythonforandroid/recipes/m2crypto/__init__.py index 1532820ce8..399cdbeb48 100644 --- a/pythonforandroid/recipes/m2crypto/__init__.py +++ b/pythonforandroid/recipes/m2crypto/__init__.py @@ -1,47 +1,42 @@ -from pythonforandroid.recipe import PythonRecipe -from pythonforandroid.toolchain import current_directory, shprint -from os.path import join +from pythonforandroid.recipe import CompiledComponentsPythonRecipe +from pythonforandroid.toolchain import current_directory +from pythonforandroid.logger import shprint, info +import glob import sh -class M2CryptoRecipe(PythonRecipe): +class M2CryptoRecipe(CompiledComponentsPythonRecipe): version = '0.24.0' url = 'https://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-{version}.tar.gz' - #md5sum = '89557730e245294a6cab06de8ad4fb42' + # md5sum = '89557730e245294a6cab06de8ad4fb42' depends = ['openssl', 'hostpython2', 'python2', 'setuptools'] site_packages_name = 'M2Crypto' call_hostpython_via_targetpython = False - def build_arch(self, arch): + def build_compiled_components(self, arch): + info('Building compiled components in {}'.format(self.name)) + env = self.get_recipe_env(arch) with current_directory(self.get_build_dir(arch.arch)): # Build M2Crypto hostpython = sh.Command(self.hostpython_location) - r = self.get_recipe('openssl', self.ctx) - openssl_dir = r.get_build_dir(arch.arch) - shprint(hostpython, - 'setup.py', - 'build_ext', + if self.install_in_hostpython: + shprint(hostpython, 'setup.py', 'clean', '--all', _env=env) + shprint(hostpython, 'setup.py', self.build_cmd, '-p' + arch.arch, '-c' + 'unix', - '--openssl=' + openssl_dir, _env=env) - # Install M2Crypto - super(M2CryptoRecipe, self).build_arch(arch) + '-o' + env['OPENSSL_BUILD_PATH'], + '-L' + env['OPENSSL_BUILD_PATH'], + _env=env, *self.setup_extra_args) + build_dir = glob.glob('build/lib.*')[0] + shprint(sh.find, build_dir, '-name', '"*.o"', '-exec', + env['STRIP'], '{}', ';', _env=env) def get_recipe_env(self, arch): env = super(M2CryptoRecipe, self).get_recipe_env(arch) - r = self.get_recipe('openssl', self.ctx) - openssl_dir = r.get_build_dir(arch.arch) - env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() - env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' + \ - ' -I' + join(openssl_dir, 'include') + env['OPENSSL_BUILD_PATH'] = self.get_recipe('openssl', self.ctx).get_build_dir(arch.arch) # Set linker to use the correct gcc env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' - env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \ - ' -L' + openssl_dir + \ - ' -lpython2.7' + \ - ' -lssl' + r.version + \ - ' -lcrypto' + r.version return env diff --git a/pythonforandroid/recipes/pyleveldb/__init__.py b/pythonforandroid/recipes/pyleveldb/__init__.py index f249a91cfc..f0913b0662 100644 --- a/pythonforandroid/recipes/pyleveldb/__init__.py +++ b/pythonforandroid/recipes/pyleveldb/__init__.py @@ -25,12 +25,9 @@ def get_recipe_env(self, arch): env = super(PyLevelDBRecipe, self).get_recipe_env(arch) # Copy environment from leveldb recipe env.update(self.get_recipe('leveldb', self.ctx).get_recipe_env(arch)) - env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() - env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' # Set linker to use the correct gcc env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' - env['LDFLAGS'] += ' -lpython2.7' + \ - ' -lleveldb' + env['LDFLAGS'] += ' -lleveldb' return env