Skip to content

Commit 60b9b07

Browse files
committed
Progressed the python3 recipe enough that python3 can be built
1 parent 21f44d8 commit 60b9b07

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

pythonforandroid/recipes/python3/__init__.py

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pythonforandroid.toolchain import shprint, current_directory, info
33
from pythonforandroid.patching import (is_darwin, is_api_gt,
44
check_all, is_api_lt, is_ndk)
5+
from pythonforandroid.logger import logger
56
from pythonforandroid.util import ensure_dir
67
from os.path import exists, join, realpath
78
from os import environ
@@ -33,11 +34,10 @@ def build_arch(self, arch):
3334
with current_directory(build_dir):
3435
env = environ.copy()
3536

36-
3737
# TODO: Get this information from p4a's arch system
3838
android_host = 'arm-linux-androideabi'
3939
android_build = sh.Command(join(recipe_build_dir, 'config.guess'))().stdout.strip().decode('utf-8')
40-
platform_dir = join(self.ctx.ndk_dir, 'platforms', 'android-19', 'arch-arm')
40+
platform_dir = join(self.ctx.ndk_dir, 'platforms', 'android-21', 'arch-arm')
4141
toolchain = '{android_host}-4.9'.format(android_host=android_host)
4242
toolchain = join(self.ctx.ndk_dir, 'toolchains', toolchain, 'prebuilt', 'linux-x86_64')
4343
CC = '{clang} -target {target} -gcc-toolchain {toolchain}'.format(
@@ -58,34 +58,57 @@ def build_arch(self, arch):
5858
env['READELF'] = READELF
5959
env['STRIP'] = STRIP
6060

61-
ndk_flags = '--sysroot={ndk_sysroot} -D__ANDROID_API__=19 -isystem {ndk_android_host}'.format(
61+
ndk_flags = '--sysroot={ndk_sysroot} -D__ANDROID_API__=21 -isystem {ndk_android_host}'.format(
6262
ndk_sysroot=join(self.ctx.ndk_dir, 'sysroot'),
6363
ndk_android_host=join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include', android_host))
64-
sysroot = join(self.ctx.ndk_dir, 'platforms', 'android-19', 'arch-arm')
64+
sysroot = join(self.ctx.ndk_dir, 'platforms', 'android-21', 'arch-arm')
6565
env['CFLAGS'] = env.get('CFLAGS', '') + ' ' + ndk_flags
6666
env['CPPFLAGS'] = env.get('CPPFLAGS', '') + ' ' + ndk_flags
67-
env['LDFLAGS'] = env.get('LDFLAGS', '') + ' --sysroot={} -march=armv7-a -Wl,--fix-cortex-a8'.format(sysroot)
67+
env['LDFLAGS'] = env.get('LDFLAGS', '') + ' --sysroot={} -L{}'.format(sysroot, join(sysroot, 'usr', 'lib'))
68+
69+
# Manually add the libs directory, and copy some object
70+
# files to the current directory otherwise they aren't
71+
# picked up. This seems necessary because the --sysroot
72+
# setting in LDFLAGS is overridden by the other flags.
73+
# TODO: Work out why this doesn't happen in the original
74+
# bpo-30386 Makefile system.
75+
logger.warning('Doing some hacky stuff to link properly')
76+
lib_dir = join(sysroot, 'usr', 'lib')
77+
env['LDFLAGS'] += ' -L{}'.format(lib_dir)
78+
shprint(sh.cp, join(lib_dir, 'crtbegin_so.o'), './')
79+
shprint(sh.cp, join(lib_dir, 'crtend_so.o'), './')
80+
81+
env['SYSROOT'] = sysroot
6882

6983
print('CPPflags', env['CPPFLAGS'])
7084
print('LDFLAGS', env['LDFLAGS'])
7185

7286
print('LD is', env['LD'])
7387

74-
shprint(sh.Command(join(recipe_build_dir, 'configure')),
75-
*(' '.join(('--host={android_host}',
76-
'--build={android_build}',
77-
'--enable-shared',
78-
'--disable-ipv6',
79-
'ac_cv_file__dev_ptmx=yes',
80-
'ac_cv_file__dev_ptc=no',
81-
'--without-ensurepip',
82-
'ac_cv_little_endian_double=yes',
83-
'--prefix={prefix}',
84-
'--exec-prefix={exec_prefix}')).format(
85-
android_host=android_host,
86-
android_build=android_build,
87-
prefix=sys_prefix,
88-
exec_prefix=sys_exec_prefix)).split(' '), _env=env)
88+
if not exists('config.status'):
89+
shprint(sh.Command(join(recipe_build_dir, 'configure')),
90+
*(' '.join(('--host={android_host}',
91+
'--build={android_build}',
92+
'--enable-shared',
93+
'--disable-ipv6',
94+
'ac_cv_file__dev_ptmx=yes',
95+
'ac_cv_file__dev_ptc=no',
96+
'--without-ensurepip',
97+
'ac_cv_little_endian_double=yes',
98+
'--prefix={prefix}',
99+
'--exec-prefix={exec_prefix}')).format(
100+
android_host=android_host,
101+
android_build=android_build,
102+
prefix=sys_prefix,
103+
exec_prefix=sys_exec_prefix)).split(' '), _env=env)
104+
105+
import ipdb
106+
ipdb.set_trace()
107+
108+
shprint(sh.make, 'all', _env=env)
109+
110+
exit(1)
111+
89112

90113
# if not exists('config.status'):
91114

0 commit comments

Comments
 (0)