Skip to content

Commit 039d50a

Browse files
committed
various changes
1 parent d57d10a commit 039d50a

13 files changed

Lines changed: 108 additions & 62 deletions

File tree

pythonforandroid/archs.py

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,25 @@ def include_dirs(self):
3030
d.format(arch=self))
3131
for d in self.ctx.include_dirs]
3232

33-
def get_env(self, with_flags_in_cc=True):
33+
def get_env(self, with_flags_in_cc=True, clang=False):
3434
env = {}
3535

36-
env['CFLAGS'] = ' '.join([
37-
'-DANDROID', '-mandroid', '-fomit-frame-pointer'
38-
' -D__ANDROID_API__={}'.format(self.ctx.ndk_api),
39-
])
36+
cflags = [
37+
'-DANDROID',
38+
'-fomit-frame-pointer',
39+
'-D__ANDROID_API__={}'.format(self.ctx.ndk_api)]
40+
# '-D__ANDROID_API__={}'.format(self.ctx._android_api)]
41+
if not clang:
42+
cflags += ['-mandroid']
43+
else:
44+
cflags += ['-target armv7-none-linux-androideabi']
45+
android_host = 'arm-linux-androideabi'
46+
platform_dir = join(self.ctx.ndk_dir, 'platforms', 'android-{}'.format(self.ctx.ndk_api), 'arch-arm')
47+
toolchain = '{android_host}-4.9'.format(android_host=android_host)
48+
toolchain = join(self.ctx.ndk_dir, 'toolchains', toolchain, 'prebuilt', 'linux-x86_64')
49+
cflags += ['-gcc-toolchain {}'.format(toolchain)]
50+
51+
env['CFLAGS'] = ' '.join(cflags)
4052
env['LDFLAGS'] = ' '
4153

4254
sysroot = join(self.ctx._ndk_dir, 'sysroot')
@@ -82,9 +94,21 @@ def get_env(self, with_flags_in_cc=True):
8294
env['NDK_CCACHE'] = self.ctx.ccache
8395
env.update({k: v for k, v in environ.items() if k.startswith('CCACHE_')})
8496

85-
cc = find_executable('{command_prefix}-gcc'.format(
86-
command_prefix=command_prefix), path=environ['PATH'])
97+
if clang:
98+
clang_path = join(
99+
self.ctx.ndk_dir, 'toolchains', 'llvm', 'prebuilt',
100+
'linux-x86_64', 'bin')
101+
environ['PATH'] = '{clang_path}:{path}'.format(
102+
clang_path=clang_path, path=environ['PATH'])
103+
exe = join(clang_path, 'clang')
104+
execxx = join(clang_path, 'clang++')
105+
else:
106+
exe = '{command_prefix}-gcc'.format(command_prefix=command_prefix)
107+
execxx = '{command_prefix}-g++'.format(command_prefix=command_prefix)
108+
109+
cc = find_executable(exe, path=environ['PATH'])
87110
if cc is None:
111+
print(environ['PATH'])
88112
print('Searching path are: {!r}'.format(environ['PATH']))
89113
warning('Couldn\'t find executable for CC. This indicates a '
90114
'problem locating the {} executable in the Android '
@@ -93,20 +117,20 @@ def get_env(self, with_flags_in_cc=True):
93117
exit(1)
94118

95119
if with_flags_in_cc:
96-
env['CC'] = '{ccache}{command_prefix}-gcc {cflags}'.format(
97-
command_prefix=command_prefix,
120+
env['CC'] = '{ccache}{exe} {cflags}'.format(
121+
exe=exe,
98122
ccache=ccache,
99123
cflags=env['CFLAGS'])
100-
env['CXX'] = '{ccache}{command_prefix}-g++ {cxxflags}'.format(
101-
command_prefix=command_prefix,
124+
env['CXX'] = '{ccache}{execxx} {cxxflags}'.format(
125+
execxx=execxx,
102126
ccache=ccache,
103127
cxxflags=env['CXXFLAGS'])
104128
else:
105-
env['CC'] = '{ccache}{command_prefix}-gcc'.format(
106-
command_prefix=command_prefix,
129+
env['CC'] = '{ccache}{exe}'.format(
130+
exe=exe,
107131
ccache=ccache)
108-
env['CXX'] = '{ccache}{command_prefix}-g++'.format(
109-
command_prefix=command_prefix,
132+
env['CXX'] = '{ccache}{execxx}'.format(
133+
execxx=execxx,
110134
ccache=ccache)
111135

112136
env['AR'] = '{}-ar'.format(command_prefix)
@@ -151,8 +175,8 @@ class ArchARM(Arch):
151175
class ArchARMv7_a(ArchARM):
152176
arch = 'armeabi-v7a'
153177

154-
def get_env(self, with_flags_in_cc=True):
155-
env = super(ArchARMv7_a, self).get_env(with_flags_in_cc)
178+
def get_env(self, with_flags_in_cc=True, clang=False):
179+
env = super(ArchARMv7_a, self).get_env(with_flags_in_cc, clang=clang)
156180
env['CFLAGS'] = (env['CFLAGS'] +
157181
(' -march=armv7-a -mfloat-abi=softfp '
158182
'-mfpu=vfp -mthumb'))
@@ -166,8 +190,8 @@ class Archx86(Arch):
166190
command_prefix = 'i686-linux-android'
167191
platform_dir = 'arch-x86'
168192

169-
def get_env(self, with_flags_in_cc=True):
170-
env = super(Archx86, self).get_env(with_flags_in_cc)
193+
def get_env(self, with_flags_in_cc=True, clang=False):
194+
env = super(Archx86, self).get_env(with_flags_in_cc, clang=clang)
171195
env['CFLAGS'] = (env['CFLAGS'] +
172196
' -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32')
173197
env['CXXFLAGS'] = env['CFLAGS']
@@ -180,8 +204,8 @@ class Archx86_64(Arch):
180204
command_prefix = 'x86_64-linux-android'
181205
platform_dir = 'arch-x86'
182206

183-
def get_env(self, with_flags_in_cc=True):
184-
env = super(Archx86_64, self).get_env(with_flags_in_cc)
207+
def get_env(self, with_flags_in_cc=True, clang=False):
208+
env = super(Archx86_64, self).get_env(with_flags_in_cc, clang=clang)
185209
env['CFLAGS'] = (env['CFLAGS'] +
186210
' -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel')
187211
env['CXXFLAGS'] = env['CFLAGS']
@@ -194,8 +218,8 @@ class ArchAarch_64(Arch):
194218
command_prefix = 'aarch64-linux-android'
195219
platform_dir = 'arch-arm64'
196220

197-
def get_env(self, with_flags_in_cc=True):
198-
env = super(ArchAarch_64, self).get_env(with_flags_in_cc)
221+
def get_env(self, with_flags_in_cc=True, clang=False):
222+
env = super(ArchAarch_64, self).get_env(with_flags_in_cc, clang=clang)
199223
incpath = ' -I' + join(dirname(__file__), 'includes', 'arm64-v8a')
200224
env['EXTRA_CFLAGS'] = incpath
201225
env['CFLAGS'] += incpath

pythonforandroid/recipe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,12 @@ def unpack(self, arch):
406406
else:
407407
info('{} is already unpacked, skipping'.format(self.name))
408408

409-
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
409+
def get_recipe_env(self, arch=None, with_flags_in_cc=True, clang=False):
410410
"""Return the env specialized for the recipe
411411
"""
412412
if arch is None:
413413
arch = self.filtered_archs[0]
414-
return arch.get_env(with_flags_in_cc=with_flags_in_cc)
414+
return arch.get_env(with_flags_in_cc=with_flags_in_cc, clang=clang)
415415

416416
def prebuild_arch(self, arch):
417417
'''Run any pre-build tasks for the Recipe. By default, this checks if

pythonforandroid/recipes/android/src/android/_android.pyx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ IF BOOTSTRAP == 'pygame':
99

1010
def check_pause():
1111
return SDL_ANDROID_CheckPause()
12-
12+
1313
def wait_for_resume():
1414
android_accelerometer_enable(False)
1515
SDL_ANDROID_WaitForResume()
1616
android_accelerometer_enable(accelerometer_enabled)
17-
17+
1818
def map_key(scancode, keysym):
1919
SDL_ANDROID_MapKey(scancode, keysym)
2020

@@ -300,16 +300,16 @@ IF IS_PYGAME:
300300
j_chooser_title = <bytes>chooser_title
301301
android_action_send(j_mimetype, j_filename, j_subject, j_text,
302302
j_chooser_title)
303-
303+
304304
cdef extern int android_checkstop()
305305
cdef extern void android_ackstop()
306-
306+
307307
def check_stop():
308308
return android_checkstop()
309-
309+
310310
def ack_stop():
311311
android_ackstop()
312-
312+
313313
# -------------------------------------------------------------------
314314
# URL Opening.
315315
def open_url(url):
@@ -330,7 +330,7 @@ class AndroidBrowser(object):
330330
return open_url(url)
331331
def open_new_tab(self, url):
332332
return open_url(url)
333-
333+
334334
import webbrowser
335335
webbrowser.register('android', AndroidBrowser)
336336

@@ -381,5 +381,3 @@ class AndroidService(object):
381381
'''Stop the service.
382382
'''
383383
stop_service()
384-
385-

pythonforandroid/recipes/cryptography/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def get_recipe_env(self, arch):
1717
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
1818
env['CFLAGS'] += ' -I' + join(openssl_dir, 'include')
1919
env['LDFLAGS'] += ' -L' + openssl_dir + \
20-
' -lssl' + r.version + \
21-
' -lcrypto' + r.version
20+
' -lssl' + r.lib_version + \
21+
' -lcrypto' + r.lib_version
2222

2323
return env
2424

pythonforandroid/recipes/dateutil/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class DateutilRecipe(PythonRecipe):
66
version = '2.6.0'
77
url = 'https://pypi.python.org/packages/51/fc/39a3fbde6864942e8bb24c93663734b74e281b984d1b8c4f95d64b0c21f6/python-dateutil-2.6.0.tar.gz'
88

9-
depends = ['python2', "setuptools"]
9+
depends = [('python2', 'python3'), "setuptools"]
1010
call_hostpython_via_targetpython = False
1111
install_in_hostpython = True
1212

pythonforandroid/recipes/libcurl/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class LibcurlRecipe(Recipe):
1010
depends = ['openssl']
1111

1212
def should_build(self, arch):
13+
return True
1314
super(LibcurlRecipe, self).should_build(arch)
1415
return not exists(join(self.ctx.get_libs_dir(arch.arch), 'libcurl.so'))
1516

@@ -20,6 +21,10 @@ def build_arch(self, arch):
2021
r = self.get_recipe('openssl', self.ctx)
2122
openssl_dir = r.get_build_dir(arch.arch)
2223

24+
# with-ssl assume the libcrypto is in lib/ subdirectory
25+
# but it will be within the openssl_dir directory directly.
26+
env["LDFLAGS"] += " -L{}".format(openssl_dir)
27+
2328
with current_directory(self.get_build_dir(arch.arch)):
2429
dst_dir = join(self.get_build_dir(arch.arch), 'dist')
2530
shprint(

pythonforandroid/recipes/libtorrent/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_recipe_env(self, arch):
7272
if 'openssl' in recipe.ctx.recipe_build_order:
7373
r = self.get_recipe('openssl', self.ctx)
7474
env['OPENSSL_BUILD_PATH'] = r.get_build_dir(arch.arch)
75-
env['OPENSSL_VERSION'] = r.version
75+
env['OPENSSL_VERSION'] = r.lib_version
7676
return env
7777

7878

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
--- openssl/Makefile 2016-01-28 17:26:49.159522273 +0100
2-
+++ b/Makefile 2016-01-28 17:26:54.358438402 +0100
3-
@@ -342,7 +342,7 @@
4-
link-shared:
5-
@ set -e; for i in $(SHLIBDIRS); do \
6-
$(MAKE) -f $(HERE)/Makefile.shared -e $(BUILDENV) \
7-
- LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \
8-
+ LIBNAME=$$i LIBVERSION= \
9-
LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \
10-
symlink.$(SHLIB_TARGET); \
11-
libs="$$libs -l$$i"; \
12-
@@ -356,7 +356,7 @@
13-
libs="$(LIBKRB5) $$libs"; \
14-
fi; \
15-
$(CLEARENV) && $(MAKE) -f Makefile.shared -e $(BUILDENV) \
16-
- LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \
17-
+ LIBNAME=$$i LIBVERSION= \
18-
LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \
19-
LIBDEPS="$$libs $(EX_LIBS)" \
20-
link_a.$(SHLIB_TARGET); \
1+
--- openssl/Makefile.orig 2018-10-20 22:49:40.418310423 +0200
2+
+++ openssl/Makefile 2018-10-20 22:50:23.347322403 +0200
3+
@@ -19,7 +19,7 @@
4+
SHLIB_MAJOR=1
5+
SHLIB_MINOR=1
6+
SHLIB_TARGET=linux-shared
7+
-SHLIB_EXT=.so.$(SHLIB_VERSION_NUMBER)
8+
+SHLIB_EXT=$(SHLIB_VERSION_NUMBER).so
9+
SHLIB_EXT_SIMPLE=.so
10+
SHLIB_EXT_IMPORT=
11+

pythonforandroid/recipes/python2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def do_python_build(self, arch):
9696
setuplocal = join('Modules', 'Setup.local')
9797
shprint(sh.cp, join(self.get_recipe_dir(), 'Setup.local-ssl'), setuplocal)
9898
shprint(sh.sed, '-i.backup', 's#^SSL=.*#SSL={}#'.format(openssl_build_dir), setuplocal)
99-
env['OPENSSL_VERSION'] = recipe.version
99+
env['OPENSSL_VERSION'] = recipe.lib_version
100100

101101
if 'sqlite3' in self.ctx.recipe_build_order:
102102
# Include sqlite3 in python2 build
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SSL=
2+
_ssl _ssl.c \
3+
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
4+
-L$(SSL) -lssl$(OPENSSL_VERSION) -lcrypto$(OPENSSL_VERSION)

0 commit comments

Comments
 (0)