From 306b753b387d232c56ad8ab71f1c2222326b6f4e Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 4 Apr 2021 09:21:25 +0800 Subject: [PATCH 1/4] add support pygame_sdl2 module --- .../recipes/pygame_sdl2/__init__.py | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 pythonforandroid/recipes/pygame_sdl2/__init__.py diff --git a/pythonforandroid/recipes/pygame_sdl2/__init__.py b/pythonforandroid/recipes/pygame_sdl2/__init__.py new file mode 100644 index 0000000000..9ca9a15826 --- /dev/null +++ b/pythonforandroid/recipes/pygame_sdl2/__init__.py @@ -0,0 +1,117 @@ +from os.path import join + +from pythonforandroid.recipe import PythonRecipe, warning + +from pythonforandroid.recipe import CompiledComponentsPythonRecipe +from pythonforandroid.toolchain import current_directory + + + +class Pygame_sdl2Recipe(CompiledComponentsPythonRecipe): + + version = 'renpy-7.3.5.606' + url = 'https://github.com/renpy/pygame_sdl2/archive/{version}.tar.gz' + + name = 'pygame_sdl2' + version = '2.1.0' + #url = 'https://nightly.renpy.org/current/pygame_sdl2-2.1.0-for-renpy-nightly-2021-03-19-50aedffdd.tar.gz' + + site_packages_name= 'pygame_sdl2' + + #depends = [] + + depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools', 'jpeg', 'png'] + call_hostpython_via_targetpython = False # Due to setuptools + install_in_hostpython = False + + def prebuild_arch(self, arch): + super().prebuild_arch(arch) + + def include_flags(self, arch): + '''Returns a string with the include folders''' + + 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_ttf_includes= join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf') + sdl_image_includes= join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image') + sdl_mixer_includes= join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer') + + sdl2_includes = join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include') + + return (' -I' + sdl2_includes + + ' -I' + sdl_ttf_includes + + ' -I' + sdl_image_includes + + ' -I' + sdl_mixer_includes + + ' -I' + jpeg_inc_dir + + ' -I' + png_inc_dir) + + def link_dirs_flags(self, arch): + + png = self.get_recipe('png', self.ctx) + png_lib_dir = join(png.get_build_dir(arch.arch), '.libs') + + jpeg = self.get_recipe('jpeg', self.ctx) + jpeg_lib_dir = jpeg.get_build_dir(arch.arch) + + ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib') + + return ( + ' -L' + join(self.ctx.bootstrap.build_dir, "libs", str(arch)) + + ' -L' + png_lib_dir + + ' -L' + jpeg_lib_dir + + ' -L' + ndk_lib_dir) + + # def prebuild_arch(self, arch): + # super(Pygame_sdl2Recipe, self).prebuild_arch(arch) + # # AND: Fix this warning! + # warning('Pygame_sdl2 is built assuming the archiver name is ' + # 'arm-linux-androideabi-ar, which may not always be true!') + + # def prebuild_arch(self, arch): + # super().prebuild_arch(arch) + # with current_directory(self.get_build_dir(arch.arch)): + # setup_template = open(join("buildconfig", "Setup.Android.SDL2.in")).read() + # env = self.get_recipe_env(arch) + # env['ANDROID_ROOT'] = join(self.ctx.ndk_platform, 'usr') + + # ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib') + + # 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) + + # 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" + ndk_lib_dir), + # 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="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer'), + # 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["PYGAME_SDL2_ANDROID"] = "TRUE" + env['CFLAGS'] += self.include_flags(arch) + env['LDFLAGS'] += self.link_dirs_flags(arch) + + env['USE_SDL2'] = '1' + env["PYGAME_CROSS_COMPILE"] = "TRUE" + env["PYGAME_ANDROID"] = "TRUE" + return env + +recipe = Pygame_sdl2Recipe() From 539bfed950d361ff2c7fbe03f78f3be7e1cf1cb7 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 4 Apr 2021 09:26:03 +0800 Subject: [PATCH 2/4] add sample use pygame_sdl2 --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index e5eadf4a05..902c4256a1 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,16 @@ If you did this, to build an APK with SDL2 you can try e.g.: For full instructions and parameter options, see [the documentation](https://python-for-android.readthedocs.io/en/latest/quickstart/#usage). +add support pygame_sdl2 sample: + + import pygame_sdl2 + pygame_sdl2.import_as_pygame() + + import pygame + from pygame.locals import * + from pygame.render import * + + ## Support If you need assistance, you can ask for help on our mailing list: From 7db6dabb7ed6507c40ab165eb5d112fbf7b70f4c Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 10 Apr 2021 22:54:13 +0800 Subject: [PATCH 3/4] update for pygame_sdl2 --- pythonforandroid/recipes/pygame_sdl2/__init__.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pythonforandroid/recipes/pygame_sdl2/__init__.py b/pythonforandroid/recipes/pygame_sdl2/__init__.py index 9ca9a15826..6e96efe60f 100644 --- a/pythonforandroid/recipes/pygame_sdl2/__init__.py +++ b/pythonforandroid/recipes/pygame_sdl2/__init__.py @@ -13,13 +13,8 @@ class Pygame_sdl2Recipe(CompiledComponentsPythonRecipe): url = 'https://github.com/renpy/pygame_sdl2/archive/{version}.tar.gz' name = 'pygame_sdl2' - version = '2.1.0' - #url = 'https://nightly.renpy.org/current/pygame_sdl2-2.1.0-for-renpy-nightly-2021-03-19-50aedffdd.tar.gz' - site_packages_name= 'pygame_sdl2' - #depends = [] - depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools', 'jpeg', 'png'] call_hostpython_via_targetpython = False # Due to setuptools install_in_hostpython = False From 8a6187cba953423233b4772eaefd7de70cb8f525 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 12 Apr 2021 23:47:15 +0800 Subject: [PATCH 4/4] update pygame_sdl2 --- pythonforandroid/recipes/pygame_sdl2/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pythonforandroid/recipes/pygame_sdl2/__init__.py b/pythonforandroid/recipes/pygame_sdl2/__init__.py index 6e96efe60f..af5a860b59 100644 --- a/pythonforandroid/recipes/pygame_sdl2/__init__.py +++ b/pythonforandroid/recipes/pygame_sdl2/__init__.py @@ -9,8 +9,9 @@ class Pygame_sdl2Recipe(CompiledComponentsPythonRecipe): - version = 'renpy-7.3.5.606' - url = 'https://github.com/renpy/pygame_sdl2/archive/{version}.tar.gz' + #version = 'renpy-7.3.5.606' + #url = 'https://github.com/renpy/pygame_sdl2/archive/{version}.tar.gz' + url = 'https://nightly.renpy.org/current/pygame_sdl2-2.1.0-for-renpy-nightly-2021-04-12-df85cb574.tar.gz' name = 'pygame_sdl2' site_packages_name= 'pygame_sdl2'