Skip to content

Commit b20fbaf

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 https://github.com/pygame/pygame/tree/android, a branch that will continue to live 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 b20fbaf

File tree

1 file changed

+56
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)