Skip to content

Commit 9dded87

Browse files
Robert PfeifferAndreMiras
Robert Pfeiffer
authored andcommitted
Adds pygame recipe
As discussed on the Discord, this is a recipe to build apps based on SDL2-based pygame. It currently references a RC until we have an official stable release of pygame based on SDL2 with android support. Simple examples have been tested by other pygame users (it doesn't just build on my own machine) but some pygame functionality is still untested, and some dependencies like freetype, postmidi and libjpeg are currently not part of the build. It's usable, but not complete.
1 parent 3bdeaca commit 9dded87

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from os.path import join
2+
3+
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
4+
from pythonforandroid.toolchain import current_directory
5+
6+
7+
class Pygame2Recipe(CompiledComponentsPythonRecipe):
8+
"""
9+
Recipe to build apps based on SDL2-based pygame.
10+
11+
.. warning:: Some pygame functionality is still untested, and some
12+
dependencies like freetype, postmidi and libjpeg are currently
13+
not part of the build. It's usable, but not complete.
14+
"""
15+
16+
version = '2.0.0-dev7'
17+
url = 'https://github.com/pygame/pygame/archive/android-{version}.tar.gz'
18+
19+
site_packages_name = 'pygame'
20+
name = 'pygame'
21+
22+
depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools', 'jpeg', 'png']
23+
call_hostpython_via_targetpython = False # Due to setuptools
24+
install_in_hostpython = False
25+
26+
def prebuild_arch(self, arch):
27+
super().prebuild_arch(arch)
28+
with current_directory(self.get_build_dir(arch.arch)):
29+
setup_template = open(join("buildconfig", "Setup.Android.SDL2.in")).read()
30+
env = self.get_recipe_env(arch)
31+
env['ANDROID_ROOT'] = join(self.ctx.ndk_platform, 'usr')
32+
33+
ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib')
34+
35+
png = self.get_recipe('png', self.ctx)
36+
png_lib_dir = join(png.get_build_dir(arch.arch), '.libs')
37+
png_inc_dir = png.get_build_dir(arch)
38+
39+
jpeg = self.get_recipe('jpeg', self.ctx)
40+
jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch)
41+
42+
setup_file = setup_template.format(
43+
sdl_includes=(
44+
" -I" + join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include') +
45+
" -L" + join(self.ctx.bootstrap.build_dir, "libs", str(arch)) +
46+
" -L" + png_lib_dir + " -L" + jpeg_lib_dir + " -L" + ndk_lib_dir),
47+
sdl_ttf_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
48+
sdl_image_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'),
49+
sdl_mixer_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer'),
50+
jpeg_includes="-I"+jpeg_inc_dir,
51+
png_includes="-I"+png_inc_dir,
52+
freetype_includes=""
53+
)
54+
open("Setup", "w").write(setup_file)
55+
56+
def get_recipe_env(self, arch):
57+
env = super().get_recipe_env(arch)
58+
env['USE_SDL2'] = '1'
59+
env["PYGAME_CROSS_COMPILE"] = "TRUE"
60+
env["PYGAME_ANDROID"] = "TRUE"
61+
return env
62+
63+
64+
recipe = Pygame2Recipe()

0 commit comments

Comments
 (0)