Skip to content

Commit 82b2f97

Browse files
committed
Added matplotlib recipe (and unnecessary png changes)
1 parent b8cd0e2 commit 82b2f97

File tree

5 files changed

+197
-1
lines changed

5 files changed

+197
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
from pythonforandroid.recipe import CppCompiledComponentsPythonRecipe, warning, Recipe
3+
4+
from os.path import join
5+
import shutil
6+
7+
class MatplotlibRecipe(CppCompiledComponentsPythonRecipe):
8+
9+
version = '3.0.3'
10+
url = 'https://github.com/matplotlib/matplotlib/archive/v{version}.zip'
11+
12+
depends = ['numpy', 'setuptools', 'freetype', 'kiwisolver']
13+
14+
python_depends = ['pyparsing', 'cycler', 'python-dateutil']
15+
16+
# We need to patch to:
17+
# - make mpl build against the same numpy version as the numpy recipe
18+
# (this could be done better by setting the target version dynamically)
19+
# - prevent mpl trying to build TkAgg, which wouldn't work on Android anyway but has build issues
20+
patches = ['mpl_android_fixes.patch']
21+
22+
call_hostpython_via_targetpython = False
23+
24+
def get_recipe_env(self, arch):
25+
env = super(MatplotlibRecipe, self).get_recipe_env(arch)
26+
27+
numpy_recipe = Recipe.get_recipe('numpy', self.ctx)
28+
29+
env['NUMPY_INCLUDE_DIR'] = join(
30+
numpy_recipe.get_build_container_dir(arch.arch),
31+
'numpy', 'core', 'include')
32+
33+
env['CFLAGS'] = env['CFLAGS'] + ' -I{jni_path}/png -I{jni_path}/freetype/include'.format(
34+
jni_path=join(self.ctx.bootstrap.build_dir, 'jni'))
35+
36+
freetype_so_dir = join(
37+
Recipe.get_recipe('freetype', self.ctx).get_build_dir(arch),
38+
'objs', '.libs'
39+
)
40+
env['CFLAGS'] += ' -L{}'.format(freetype_so_dir)
41+
env['LDFLAGS'] += ' -L{}'.format(freetype_so_dir)
42+
43+
env['CFLAGS'] += ' -L/home/sandy/kivytest'
44+
env['LDFLAGS'] += ' -L/home/sandy/kivytest'
45+
46+
return env
47+
48+
def prebuild_arch(self, arch):
49+
with open(join(self.get_recipe_dir(), 'setup.cfg.template')) as fileh:
50+
setup_cfg = fileh.read()
51+
52+
with open(join(self.get_build_dir(arch), 'setup.cfg'), 'w') as fileh:
53+
fileh.write(setup_cfg.format(
54+
ndk_sysroot_usr=join(self.ctx.ndk_dir, 'sysroot', 'usr')))
55+
56+
57+
recipe = MatplotlibRecipe()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
diff --git a/setupext.py b/setupext.py
2+
index fc82d5d..2067db0 100644
3+
--- a/setupext.py
4+
+++ b/setupext.py
5+
@@ -1004,10 +1004,10 @@ class Numpy(SetupPackage):
6+
ext.define_macros.append(('__STDC_FORMAT_MACROS', 1))
7+
8+
def get_setup_requires(self):
9+
- return ['numpy>=1.10.0']
10+
+ return ['numpy==1.15.1'] # to match p4a's target version
11+
12+
def get_install_requires(self):
13+
- return ['numpy>=1.10.0']
14+
+ return ['numpy==1.15.1'] # to match p4a's target version
15+
16+
17+
class LibAgg(SetupPackage):
18+
@@ -1443,9 +1443,10 @@ class BackendAgg(OptionalBackendPackage):
19+
20+
class BackendTkAgg(OptionalBackendPackage):
21+
name = "tkagg"
22+
- force = True
23+
+ force = False
24+
25+
def check(self):
26+
+ raise CheckFailed("Disabled by patching during Android build") # tk doesn't work on Android but causes build problems
27+
return "installing; run-time loading from Python Tcl / Tk"
28+
29+
def get_extension(self):
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Rename this file to setup.cfg to modify Matplotlib's
2+
# build options.
3+
4+
[egg_info]
5+
6+
[directories]
7+
# Uncomment to override the default basedir in setupext.py.
8+
# This can be a single directory or a comma-delimited list of directories.
9+
basedirlist = {ndk_sysroot_usr}
10+
11+
[test]
12+
# If you plan to develop Matplotlib and run or add to the test suite,
13+
# set this to True. It will download and build a specific version of
14+
# FreeType, and then use that to build the ft2font extension. This
15+
# ensures that test images are exactly reproducible.
16+
# local_freetype = True
17+
18+
[status]
19+
# To suppress display of the dependencies and their versions
20+
# at the top of the build log, uncomment the following line:
21+
#suppress = True
22+
23+
[packages]
24+
# There are a number of subpackages of Matplotlib that are considered
25+
# optional. All except tests are installed by default, but that can
26+
# be changed here.
27+
#
28+
tests = False
29+
sample_data = False
30+
#toolkits = True
31+
# Tests for the toolkits are only automatically installed
32+
# if the tests and toolkits packages are also getting installed.
33+
toolkits_tests = False
34+
35+
[gui_support]
36+
# Matplotlib supports multiple GUI toolkits, including
37+
# GTK3, MacOSX, Qt4, Qt5, Tk, and WX. Support for many of
38+
# these toolkits requires AGG, the Anti-Grain Geometry library,
39+
# which is provided by Matplotlib and built by default.
40+
#
41+
# Some backends are written in pure Python, and others require
42+
# extension code to be compiled. By default, Matplotlib checks for
43+
# these GUI toolkits during installation and, if present, compiles the
44+
# required extensions to support the toolkit.
45+
#
46+
# - Tk support requires Tk development headers and Tkinter.
47+
# - Mac OSX backend requires the Cocoa headers included with XCode.
48+
# - Windowing is MS-Windows specific, and requires the "windows.h"
49+
# header.
50+
#
51+
# The other GUI toolkits do not require any extension code, and can be
52+
# used as long as the libraries are installed on your system --
53+
# therefore they are installed unconditionally.
54+
#
55+
# You can uncomment any the following lines to change this
56+
# behavior. Acceptable values are:
57+
#
58+
# True: build the extension. Exits with a warning if the
59+
# required dependencies are not available
60+
# False: do not build the extension
61+
# auto: build if the required dependencies are available,
62+
# otherwise skip silently. This is the default
63+
# behavior
64+
#
65+
agg = True
66+
cairo = False
67+
gtk3agg = False
68+
gtk3cairo = False
69+
macosx = False
70+
pyside = False
71+
qt4agg = False
72+
tkagg = False
73+
windowing = False
74+
wxagg = False
75+
76+
[rc_options]
77+
# User-configurable options
78+
#
79+
# Default backend, one of: Agg, Cairo, GTK3Agg, GTK3Cairo, MacOSX, Pdf, Ps,
80+
# Qt4Agg, Qt5Agg, SVG, TkAgg, WX, WXAgg.
81+
#
82+
# The Agg, Ps, Pdf and SVG backends do not require external dependencies. Do
83+
# not choose MacOSX, or TkAgg if you have disabled the relevant extension
84+
# modules. Agg will be used by default.
85+
#
86+
backend = Agg
87+
#
88+
89+
[package_data]
90+
# Package additional files found in the lib/matplotlib directories.
91+
#
92+
# On Windows, package DLL files.
93+
#dlls = True

pythonforandroid/recipes/png/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PngRecipe(NDKRecipe):
1313
# TODO: Try to move the repo to mainline
1414
url = 'https://github.com/julienr/libpng-android/archive/{version}.zip'
1515

16-
generated_libraries = ['libpng.a']
16+
patches = ['build_shared_library.patch']
1717

1818

1919
recipe = PngRecipe()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
diff --git a/jni/Android.mk b/jni/Android.mk
2+
index df2ff1a..2f70985 100644
3+
--- a/jni/Android.mk
4+
+++ b/jni/Android.mk
5+
@@ -26,8 +26,9 @@ LOCAL_SRC_FILES :=\
6+
arm/filter_neon_intrinsics.c
7+
8+
#LOCAL_SHARED_LIBRARIES := -lz
9+
-LOCAL_EXPORT_LDLIBS := -lz
10+
+# LOCAL_EXPORT_LDLIBS := -lz
11+
+LOCAL_LDLIBS := -lz
12+
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.
13+
14+
-#include $(BUILD_SHARED_LIBRARY)
15+
-include $(BUILD_STATIC_LIBRARY)
16+
+include $(BUILD_SHARED_LIBRARY)
17+
+# include $(BUILD_STATIC_LIBRARY)

0 commit comments

Comments
 (0)