Skip to content

Commit 01a7042

Browse files
authored
Adding recipe for pygame-ce
Tested with buildozer and pygame-ce + pygame-community/pygame-ce#2249
1 parent da9a194 commit 01a7042

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from os.path import join
2+
3+
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
4+
from pythonforandroid.toolchain import current_directory
5+
6+
7+
class PygameCeRecipe(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.2.1'
17+
url = 'https://github.com/pygame-community/pygame-ce/archive/{version}.tar.gz'
18+
19+
site_packages_name = 'pygame-ce'
20+
name = 'pygame-ce'
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+
for i in range(100):
27+
print("HELLO FROM MY CUSTOM PYGAMECE RECIPE !!!!")
28+
29+
def prebuild_arch(self, arch):
30+
super().prebuild_arch(arch)
31+
with current_directory(self.get_build_dir(arch.arch)):
32+
setup_template = open(join("buildconfig", "Setup.Android.SDL2.in")).read()
33+
env = self.get_recipe_env(arch)
34+
env['ANDROID_ROOT'] = join(self.ctx.ndk.sysroot, 'usr')
35+
36+
png = self.get_recipe('png', self.ctx)
37+
png_lib_dir = join(png.get_build_dir(arch.arch), '.libs')
38+
png_inc_dir = png.get_build_dir(arch)
39+
40+
jpeg = self.get_recipe('jpeg', self.ctx)
41+
jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch)
42+
43+
sdl_mixer_includes = ""
44+
sdl2_mixer_recipe = self.get_recipe('sdl2_mixer', self.ctx)
45+
for include_dir in sdl2_mixer_recipe.get_include_dirs(arch):
46+
sdl_mixer_includes += f"-I{include_dir} "
47+
48+
setup_file = setup_template.format(
49+
sdl_includes=(
50+
" -I" + join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include') +
51+
" -L" + join(self.ctx.bootstrap.build_dir, "libs", str(arch)) +
52+
" -L" + png_lib_dir + " -L" + jpeg_lib_dir + " -L" + arch.ndk_lib_dir_versioned),
53+
sdl_ttf_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
54+
sdl_image_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'),
55+
sdl_mixer_includes=sdl_mixer_includes,
56+
jpeg_includes="-I"+jpeg_inc_dir,
57+
png_includes="-I"+png_inc_dir,
58+
freetype_includes=""
59+
)
60+
open("Setup", "w").write(setup_file)
61+
62+
def get_recipe_env(self, arch):
63+
env = super().get_recipe_env(arch)
64+
env['USE_SDL2'] = '1'
65+
env["PYGAME_CROSS_COMPILE"] = "TRUE"
66+
env["PYGAME_ANDROID"] = "TRUE"
67+
return env
68+
69+
70+
recipe = PygameCeRecipe()

0 commit comments

Comments
 (0)