2019-03-30 21:58:45 +01:00
|
|
|
from os.path import join
|
2017-08-13 03:24:00 +02:00
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
|
|
|
|
from pythonforandroid.toolchain import current_directory
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
class Pygame2Recipe(CompiledComponentsPythonRecipe):
|
|
|
|
"""
|
|
|
|
Recipe to build apps based on SDL2-based pygame.
|
2017-08-13 03:24:00 +02:00
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
.. warning:: 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.
|
|
|
|
"""
|
2019-03-30 21:58:45 +01:00
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
version = '2.1.0'
|
|
|
|
url = 'https://github.com/pygame/pygame/archive/{version}.tar.gz'
|
2019-03-30 21:58:45 +01:00
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
site_packages_name = 'pygame'
|
|
|
|
name = 'pygame'
|
2017-08-13 03:24:00 +02:00
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools', 'jpeg', 'png']
|
|
|
|
call_hostpython_via_targetpython = False # Due to setuptools
|
|
|
|
install_in_hostpython = False
|
2017-08-13 03:24:00 +02:00
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
def prebuild_arch(self, arch):
|
|
|
|
super().prebuild_arch(arch)
|
2017-08-13 03:24:00 +02:00
|
|
|
with current_directory(self.get_build_dir(arch.arch)):
|
2022-12-02 21:15:34 +01:00
|
|
|
setup_template = open(join("buildconfig", "Setup.Android.SDL2.in")).read()
|
|
|
|
env = self.get_recipe_env(arch)
|
|
|
|
env['ANDROID_ROOT'] = join(self.ctx.ndk.sysroot, 'usr')
|
|
|
|
|
|
|
|
png = self.get_recipe('png', self.ctx)
|
|
|
|
png_lib_dir = join(png.get_build_dir(arch.arch), '.libs')
|
|
|
|
png_inc_dir = png.get_build_dir(arch)
|
|
|
|
|
|
|
|
jpeg = self.get_recipe('jpeg', self.ctx)
|
|
|
|
jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch)
|
|
|
|
|
|
|
|
sdl_mixer_includes = ""
|
|
|
|
sdl2_mixer_recipe = self.get_recipe('sdl2_mixer', self.ctx)
|
|
|
|
for include_dir in sdl2_mixer_recipe.get_include_dirs(arch):
|
|
|
|
sdl_mixer_includes += f"-I{include_dir} "
|
|
|
|
|
|
|
|
setup_file = setup_template.format(
|
|
|
|
sdl_includes=(
|
|
|
|
" -I" + join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include') +
|
|
|
|
" -L" + join(self.ctx.bootstrap.build_dir, "libs", str(arch)) +
|
|
|
|
" -L" + png_lib_dir + " -L" + jpeg_lib_dir + " -L" + arch.ndk_lib_dir_versioned),
|
|
|
|
sdl_ttf_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
|
|
|
|
sdl_image_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'),
|
|
|
|
sdl_mixer_includes=sdl_mixer_includes,
|
|
|
|
jpeg_includes="-I"+jpeg_inc_dir,
|
|
|
|
png_includes="-I"+png_inc_dir,
|
|
|
|
freetype_includes=""
|
|
|
|
)
|
|
|
|
open("Setup", "w").write(setup_file)
|
|
|
|
|
|
|
|
def get_recipe_env(self, arch):
|
|
|
|
env = super().get_recipe_env(arch)
|
|
|
|
env['USE_SDL2'] = '1'
|
|
|
|
env["PYGAME_CROSS_COMPILE"] = "TRUE"
|
|
|
|
env["PYGAME_ANDROID"] = "TRUE"
|
|
|
|
return env
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
recipe = Pygame2Recipe()
|