|
| 1 | +from pythonforandroid.recipe import CompiledComponentsPythonRecipe |
| 2 | +from os.path import join |
| 3 | +from shutil import copyfile |
| 4 | +from pythonforandroid.toolchain import current_directory |
| 5 | +import glob |
| 6 | + |
| 7 | +class Pygame2Recipe(CompiledComponentsPythonRecipe): |
| 8 | + |
| 9 | + version = '2.0.0-dev5' |
| 10 | + url = 'https://github.com/pygame/pygame/archive/android.zip' |
| 11 | + |
| 12 | + site_packages_name = 'pygame' |
| 13 | + name = 'pygame2' |
| 14 | + |
| 15 | + depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools'] |
| 16 | + call_hostpython_via_targetpython = False # Due to setuptools |
| 17 | + install_in_hostpython = False |
| 18 | + |
| 19 | + def cythonize_file(self, env, build_dir, filename): |
| 20 | + # We can ignore a few files that aren't important to the |
| 21 | + # android build, and may not work on Android anyway |
| 22 | + do_not_cythonize = [] |
| 23 | + if basename(filename) in do_not_cythonize: |
| 24 | + return |
| 25 | + super(Pygame2Recipe, self).cythonize_file(env, build_dir, filename) |
| 26 | + |
| 27 | + def prebuild_arch(self, arch): |
| 28 | + super(Pygame2Recipe, self).prebuild_arch(arch) |
| 29 | + with current_directory(self.get_build_dir(arch.arch)): |
| 30 | + setup_template=open(join("buildconfig", "Setup.Android.SDL2.in")).read() |
| 31 | + env=self.get_recipe_env(arch) |
| 32 | + setup_file=setup_template.format( |
| 33 | + sdl_includes=( |
| 34 | + " -I" + join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include') + |
| 35 | + " -L" + join(self.ctx.bootstrap.build_dir, "libs", str(arch))), |
| 36 | + sdl_ttf_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'), |
| 37 | + sdl_image_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'), |
| 38 | + sdl_mixer_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer')) |
| 39 | + open("Setup", "w").write(setup_file) |
| 40 | + |
| 41 | + def get_recipe_env(self, arch): |
| 42 | + env = super(Pygame2Recipe, self).get_recipe_env(arch) |
| 43 | + if 'sdl2' in self.ctx.recipe_build_order: |
| 44 | + env['USE_SDL2'] = '1' |
| 45 | + |
| 46 | + env["PYGAME_CROSS_COMPILE"]="TRUE" |
| 47 | + env["PYGAME_ANDROID"]="TRUE" |
| 48 | + return env |
| 49 | + |
| 50 | +recipe = Pygame2Recipe() |
0 commit comments