Skip to content

Commit a6d0fc1

Browse files
committed
Got ndk builds working
1 parent c6cc367 commit a6d0fc1

File tree

6 files changed

+61
-23
lines changed

6 files changed

+61
-23
lines changed

bootstrap_templates/pygame/jni/Application.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ APP_PROJECT_PATH := $(call my-dir)/..
88
APP_MODULES := application sdl sdl_main tremor png jpeg freetype sdl_ttf sdl_image sqlite3
99

1010
APP_ABI := $(ARCH)
11+
# AND: I have no idea why I have to specify app_platform when distribute.sh seems to just set the sysroot cflag
12+
# AND: Either way, this has to *at least* be configurable
13+
APP_PLATFORM := android-14
1114
APP_STL := gnustl_static
1215
APP_CFLAGS += $(OFLAG)

bootstrap_templates/pygame/jni/application/Android.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ LOCAL_CFLAGS := $(foreach D, $(APP_SUBDIRS), -I$(LOCAL_PATH)/$(D)) \
1818
-I$(LOCAL_PATH)/../jpeg \
1919
-I$(LOCAL_PATH)/../intl \
2020
-I$(LOCAL_PATH)/.. \
21-
-I$(LOCAL_PATH)/../../../build/python-install/include/python2.7
21+
-I$(LOCAL_PATH)/../../../../python-install/include/python2.7
22+
# -I$(LOCAL_PATH)/../../../build/python-install/include/python2.7
2223

2324

2425
LOCAL_CFLAGS += $(APPLICATION_ADDITIONAL_CFLAGS)
@@ -36,7 +37,8 @@ LOCAL_STATIC_LIBRARIES := jpeg png
3637

3738
LOCAL_LDLIBS := -lpython2.7 -lGLESv1_CM -ldl -llog -lz
3839

39-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../build/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
40+
# AND: Another hardcoded path that should be templated
41+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
4042

4143
LIBS_WITH_LONG_SYMBOLS := $(strip $(shell \
4244
for f in $(LOCAL_PATH)/../../libs/$ARCH/*.so ; do \

recipes/kivy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
from toolchain import PythonRecipe, shprint
2+
from toolchain import CythonRecipe, shprint
33

44

5-
class KivyRecipe(PythonRecipe):
5+
class KivyRecipe(CythonRecipe):
66
version = 'stable'
77
url = 'https://github.com/kivy/kivy/archive/{version}.zip'
88
name = 'kivy'

recipes/pyjnius/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
from toolchain import PythonRecipe, shprint
2+
from toolchain import CythonRecipe, shprint
33

44

5-
class PyjniusRecipe(PythonRecipe):
5+
class PyjniusRecipe(CythonRecipe):
66
version = 'master'
77
url = 'https://github.com/kivy/pyjnius/archive/{version}.zip'
88
name = 'pyjnius'

recipes/sdl/__init__.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from toolchain import NDKRecipe, shprint
1+
from toolchain import NDKRecipe, shprint, ArchAndroid, current_directory
2+
from os.path import exists, join
23
import sh
34

4-
5-
65
class LibSDLRecipe(NDKRecipe):
76
version = "1.2.14"
87
url = None
@@ -12,18 +11,27 @@ class LibSDLRecipe(NDKRecipe):
1211
def prebuild_armeabi(self):
1312
print('Debug: sdl recipe dir is ' + self.get_build_dir())
1413

15-
def build_arch(self, arch):
16-
# shprint(sh.xcodebuild,
17-
# "ONLY_ACTIVE_ARCH=NO",
18-
# "ARCHS={}".format(arch.arch),
19-
# "-sdk", arch.sdk,
20-
# "-project", "Xcode-iOS/SDL/SDL.xcodeproj",
21-
# "-tarelf.et", "libSDL",
22-
# "-configuration", "Release")
23-
env = self.get_recipe_env(arch)
24-
shprint(sh.ndk_build,
25-
"V=1", "sdl2",
26-
_env=env)
14+
def build_armeabi(self):
15+
16+
if exists(join(self.ctx.libs_dir, 'libsdl.so')):
17+
print('libsdl.so already exists, skipping sdl build.')
18+
return
19+
20+
env = ArchAndroid(self.ctx).get_env()
21+
22+
print('env is', env)
23+
24+
with current_directory(self.get_jni_dir()):
25+
shprint(sh.ndk_build, 'V=1', _env=env)
26+
27+
libs_dir = join(self.ctx.bootstrap.build_dir, 'libs', 'armeabi')
28+
import os
29+
print('libs dir is', libs_dir)
30+
contents = list(os.walk(libs_dir))[0][-1]
31+
print('contents are', contents)
32+
for content in contents:
33+
shprint(sh.cp, '-a', join(self.ctx.bootstrap.build_dir, 'libs', 'armeabi', content),
34+
self.ctx.libs_dir)
2735

2836

2937
recipe = LibSDLRecipe()

toolchain.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
from sys import stdout
1313
from os.path import join, dirname, realpath, exists, isdir, basename
14-
from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk
14+
from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk, uname
1515
import zipfile
1616
import tarfile
1717
import importlib
@@ -251,6 +251,15 @@ def get_env(self):
251251
env['MAKE'] = 'make -j5'
252252
env['READELF'] = '{}-readelf'.format(toolchain_prefix)
253253

254+
hostpython_recipe = Recipe.get_recipe('hostpython2', self.ctx)
255+
256+
# AND: This hardcodes python version 2.7, needs fixing
257+
# AND: This also hardcodes armeabi, which isn't even correct, don't forget to fix!
258+
env['BUILDLIB_PATH'] = join(hostpython_recipe.get_actual_build_dir('armeabi'),
259+
'build', 'lib.linux-{}-2.7'.format(uname()[-1]))
260+
261+
env['ARCH'] = self.arch
262+
254263
return env
255264

256265

@@ -459,9 +468,9 @@ def __init__(self):
459468
ensure_dir(join(self.build_dir, 'other_builds')) # where everything else is built
460469

461470
# # remove the most obvious flags that can break the compilation
471+
self.env.pop("LDFLAGS", None)
462472
self.env.pop("ARCHFLAGS", None)
463473
self.env.pop("CFLAGS", None)
464-
self.env.pop("LDFLAGS", None)
465474

466475
# set the state
467476
self.state = JsonStore(join(self.dist_dir, "state.db"))
@@ -502,6 +511,7 @@ class Bootstrap(object):
502511
# blacklist.txt
503512
#
504513

514+
505515
@property
506516
def jni_dir(self):
507517
return self.bootstrap_template_dir + self.jni_subdir
@@ -984,6 +994,9 @@ def prebuild(self):
984994
def build(self):
985995
self.build_arch(self.ctx.archs[0]) # Same here!
986996

997+
def postbuild(self):
998+
self.postbuild_arch(self.ctx.archs[0])
999+
9871000
def prebuild_arch(self, arch):
9881001
prebuild = "prebuild_{}".format(arch.arch)
9891002
if hasattr(self, prebuild):
@@ -1121,6 +1134,9 @@ class NDKRecipe(Recipe):
11211134
def get_build_dir(self):
11221135
return join(self.ctx.bootstrap.build_dir, 'jni', self.name)
11231136

1137+
def get_jni_dir(self):
1138+
return join(self.ctx.bootstrap.build_dir, 'jni')
1139+
11241140
def prepare_build_dir(self, ctx):
11251141
self.ctx = ctx
11261142
print('{} is an NDK recipe, it is alread included in the '
@@ -1276,13 +1292,22 @@ def build_recipes(names, ctx):
12761292
for recipe in recipes:
12771293
recipe.build()
12781294

1295+
# 4) biglink everything
1296+
biglink(ctx)
1297+
1298+
# 5) postbuild packages
1299+
for recipe in recipes:
1300+
recipe.postbuild()
12791301

12801302
return
12811303
for recipe in recipes:
12821304
recipe.init_with_ctx(ctx)
12831305
for recipe in recipes:
12841306
recipe.execute()
12851307

1308+
def biglink(ctx):
1309+
print('skipping biglink...there is no libpymodules.so?')
1310+
12861311

12871312
def ensure_dir(filename):
12881313
if not exists(filename):

0 commit comments

Comments
 (0)