Skip to content

Commit c6ae76f

Browse files
author
Pol Canelles
committed
Sets the right include and link paths for all python versions (unified into PythonRecipe)
1 parent 23b98b6 commit c6ae76f

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

pythonforandroid/recipe.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,34 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
758758
env['PYTHONNOUSERSITE'] = '1'
759759

760760
if not self.call_hostpython_via_targetpython:
761+
# sets python headers/linkages...depending on python's recipe
762+
python_version = self.ctx.python_recipe.version
763+
python_short_version = '.'.join(python_version.split('.')[:2])
764+
if 'python2' in self.ctx.recipe_build_order:
765+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
766+
env['CFLAGS'] += ' -I' + env[
767+
'PYTHON_ROOT'] + '/include/python2.7'
768+
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
769+
' -lpython2.7'
770+
elif self.ctx.python_recipe.from_crystax:
771+
ndk_dir_python = join(self.ctx.ndk_dir, 'sources',
772+
'python', python_version)
773+
env['CFLAGS'] += '-I{} '.format(
774+
join(ndk_dir_python, 'include',
775+
'python'))
776+
env['LDFLAGS'] += ' -L{}'.format(
777+
join(ndk_dir_python, 'libs', arch.arch))
778+
env['LDFLAGS'] += ' -lpython{}m'.format(python_short_version)
779+
elif 'python3' in self.ctx.recipe_build_order:
780+
# This headers are unused cause python3 recipe was removed
781+
# TODO: should be reviewed when python3 recipe added
782+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
783+
env['CFLAGS'] += ' -I' + env[
784+
'PYTHON_ROOT'] + '/include/python{}m'.format(
785+
python_short_version)
786+
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
787+
' -lpython{}m'.format(
788+
python_short_version)
761789
hppath = []
762790
hppath.append(join(dirname(self.hostpython_location), 'Lib'))
763791
hppath.append(join(hppath[0], 'site-packages'))
@@ -844,17 +872,6 @@ class CompiledComponentsPythonRecipe(PythonRecipe):
844872

845873
build_cmd = 'build_ext'
846874

847-
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
848-
env = super(CompiledComponentsPythonRecipe,
849-
self).get_recipe_env(arch, with_flags_in_cc)
850-
if not self.call_hostpython_via_targetpython:
851-
if 'python2' in self.ctx.recipe_build_order:
852-
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
853-
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
854-
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
855-
' -lpython2.7'
856-
return env
857-
858875
def build_arch(self, arch):
859876
'''Build any cython components, then install the Python module by
860877
calling setup.py install with the target Python dir.
@@ -900,17 +917,14 @@ def get_recipe_env(self, arch):
900917
keys = dict(
901918
ctx=self.ctx,
902919
arch=arch,
903-
arch_noeabi=arch.arch.replace('eabi', ''),
904-
pyroot=self.ctx.get_python_install_dir()
920+
arch_noeabi=arch.arch.replace('eabi', '')
905921
)
906922
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
907-
env['CFLAGS'] += " -I{pyroot}/include/python2.7 " \
908-
" -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \
923+
env['CFLAGS'] += " -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \
909924
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/include" \
910925
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}/include".format(**keys)
911926
env['CXXFLAGS'] = env['CFLAGS'] + ' -frtti -fexceptions'
912927
env['LDFLAGS'] += " -L{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}" \
913-
" -lpython2.7" \
914928
" -lgnustl_shared".format(**keys)
915929

916930
return env
@@ -1053,21 +1067,6 @@ def get_recipe_env(self, arch, with_flags_in_cc=True):
10531067
env['LIBLINK_PATH'] = liblink_path
10541068
ensure_dir(liblink_path)
10551069

1056-
if self.ctx.python_recipe.from_crystax:
1057-
env['CFLAGS'] = '-I{} '.format(
1058-
join(self.ctx.ndk_dir, 'sources', 'python',
1059-
self.ctx.python_recipe.version, 'include',
1060-
'python')) + env['CFLAGS']
1061-
1062-
# Temporarily hardcode the -lpython3.x as this does not
1063-
# get applied automatically in some environments. This
1064-
# will need generalising, along with the other hardcoded
1065-
# py3.5 references, to support other python3 or crystax
1066-
# python versions.
1067-
python3_version = self.ctx.python_recipe.version
1068-
python3_version = '.'.join(python3_version.split('.')[:2])
1069-
env['LDFLAGS'] = env['LDFLAGS'] + ' -lpython{}m'.format(python3_version)
1070-
10711070
return env
10721071

10731072

0 commit comments

Comments
 (0)