Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 5d84ccb

Browse files
Merge pull request #2474 from livecodefraser/gyp-android_toolchain_tweaks
Gyp android toolchain tweaks
2 parents 40709f4 + a09f5e3 commit 5d84ccb

File tree

7 files changed

+145
-27
lines changed

7 files changed

+145
-27
lines changed

INSTALL-android.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,44 @@ mkdir -p ~/android/toolchain
2323
cd ~/android/toolchain
2424

2525
tar -xf ~/Downloads/android-sdk_r24.1.2-linux.tgz
26-
7z x ~/Downloads/android-ndk-r10d-linux-x86_64.bin
26+
7z x ~/Downloads/android-ndk-r10e-linux-x86_64.bin
2727
````
2828

2929
Update the SDK:
3030

31-
android-sdk-linuxl/tools/android update sdk --no-ui
31+
android-sdk-linux/tools/android update sdk --no-ui
3232

3333
### Setting up the ARM toolchain
3434

3535
Create a standalone toolchain (this simplifies setting up the build environment):
3636

3737
````bash
38-
android-ndk-r10d/build/tools/make-standalone-toolchain.sh \
39-
--toolchain=arm-linux-androideabi-clang3.4 \
38+
android-ndk-r10e/build/tools/make-standalone-toolchain.sh \
39+
--toolchain=arm-linux-androideabi-clang3.5 \
4040
--platform=android-8 \
41-
--install-dir=~/android/toolchain/standalone
41+
--install-dir=${HOME}/android/toolchain/standalone
4242
````
4343

4444
By default, the Android toolchain uses the `gold` linker. However, this doesn't work for compiling LiveCode, so it's necessary to change the default linker to `ld.bfd` by replacing the `ld` symlink:
4545

4646
````bash
4747
rm standalone/bin/arm-linux-androideabi-ld
48-
ln -s standalone/bin/arm-linux-androideabi-ld.bfd \
48+
ln -s arm-linux-androideabi-ld.bfd \
4949
standalone/bin/arm-linux-androideabi-ld
5050
````
5151

52+
Add a couple of symlinks to allow the engine configuration script to find the Android toolchain:
53+
54+
````bash
55+
ln -s android-ndk-r10e android-ndk
56+
ln -s android-sdk-linux android-sdk
57+
````
58+
5259
## Configuring LiveCode
5360

5461
### Build environment
5562

56-
The Android build expects a large number of environment variables to be set. If the environment variables aren't set, the build process will attempt to guess sensible defaults.
63+
The Android build expects a large number of environment variables to be set. If the environment variables aren't set, the build process will attempt to guess sensible defaults. If you've set up the directory structure as described above, the make command should detect everything automatically and these variables shouldn't be necessary.
5764

5865
The following script will set up the environment variables correctly. You may need to edit it depending on where your JDK and ARM toolchain are installed:
5966

config.sh

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ fi
204204
# If no output type specified, guess from platform:
205205
if test -z "$FORMATS"; then
206206
case ${OS} in
207-
linux|android) FORMATS="make" ;;
207+
# Always use Linux-style makefiles for Android as the Android toolchain
208+
# is more Linux-y than Darwin-y
209+
linux|android) FORMATS="make-linux" ;;
208210
mac|ios) FORMATS="xcode" ;;
209211
win) FORMATS="msvs" ;;
210212
esac
@@ -262,22 +264,87 @@ fi
262264
WIN_PERL=${WIN_PERL:-"C:/perl/bin/perl.exe"}
263265

264266
# Android default settings and tools
265-
ANDROID_BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-22.0.1}
266-
ANDROID_JAVA_SDK=${ANDROID_JAVA_SDK:-${JAVA_SDK:-/usr/lib/jvm/java-7-openjdk-amd64}}
267267
ANDROID_NDK_VERSION=${ANDROID_NDK_VERSION:-r10d}
268-
ANDROID_NDK=${ANDROID_NDK:-${HOME}/Workspace/android-ndk-${ANDROID_NDK_VERSION}}
269268
ANDROID_PLATFORM=${ANDROID_PLATFORM:-android-8}
270-
ANDROID_SDK=${ANDROID_SDK:-${HOME}/Workspace/android-sdk-linux}
271269

272-
ANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN:-${HOME}/android-armv6-standalone/bin/arm-linux-androideabi-}
270+
# Attempt to locate an Android NDK
271+
if [ -z "${ANDROID_NDK}" ] ; then
272+
# Try the symlink we suggest in INSTALL-android.md
273+
if [ -d "${HOME}/android/toolchain/android-ndk" ] ; then
274+
ANDROID_NDK="${HOME}/android/toolchain/android-ndk"
275+
else
276+
if [ "${OS}" = "android" ] ; then
277+
echo >&2 "Error: Android NDK not found (set \$ANDROID_NDK)"
278+
exit 1
279+
fi
280+
fi
281+
fi
282+
283+
# Attempt to locate an Android SDK
284+
if [ -z "${ANDROID_SDK}" ] ; then
285+
# Try the symlink we suggest in INSTALL-android.md
286+
if [ -d "${HOME}/android/toolchain/android-sdk" ] ; then
287+
ANDROID_SDK="${HOME}/android/toolchain/android-sdk"
288+
else
289+
if [ "${OS}" = "android" ] ; then
290+
echo >&2 "Error: Android SDK not found (set \$ANDROID_SDK)"
291+
exit 1
292+
fi
293+
fi
294+
fi
295+
296+
# Attempt to guess the Android build tools version
297+
if [ -z "${ANDROID_BUILD_TOOLS}" ] ; then
298+
# Check for a sub-folder in the appropriate place
299+
# Possibly fragile - are there ever multiple sub-folders?
300+
if [ ! "$(echo \"${ANDROID_SDK}/build-tools/\"*)" = "${ANDROID_SDK}/build-tools/*" ] ; then
301+
ANDROID_BUILD_TOOLS=$(basename $(echo "${ANDROID_SDK}/build-tools/"*))
302+
else
303+
if [ "${OS}" = "android" ] ; then
304+
echo >&2 "Error: Android build tools not found (set \$ANDROID_BUILD_TOOLS)"
305+
exit 1
306+
fi
307+
fi
308+
fi
309+
310+
if [ -z "${ANDROID_TOOLCHAIN}" ] ; then
311+
# Try the folder we suggest in INSTALL-android.md
312+
if [ -d "${HOME}/android/toolchain/standalone" ] ; then
313+
ANDROID_TOOLCHAIN="${HOME}/android/toolchain/standalone/bin/arm-linux-androideabi-"
314+
else
315+
if [ "${OS}" = "android" ] ; then
316+
echo >&2 "Error: Android toolchain not found (set \$ANDROID_TOOLCHAIN)"
317+
exit 1
318+
fi
319+
fi
320+
fi
273321

274322
ANDROID_AR=${AR:-${ANDROID_TOOLCHAIN}ar}
275323
ANDROID_CC=${CC:-${ANDROID_TOOLCHAIN}clang -target arm-linux-androideabi -march=armv6 -integrated-as}
276324
ANDROID_CXX=${CXX:-${ANDROID_TOOLCHAIN}clang -target arm-linux-androideabi -march=armv6 -integrated-as}
277325
ANDROID_LINK=${LINK:-${ANDROID_TOOLCHAIN}clang -target arm-linux-androideabi -march=armv6 -integrated-as}
278326
ANDROID_OBJCOPY=${OBJCOPY:-${ANDROID_TOOLCHAIN}objcopy}
327+
ANDROID_OBJDUMP=${OBJDUMP:-${ANDROID_TOOLCHAIN}objdump}
279328
ANDROID_STRIP=${STRIP:-${ANDROID_TOOLCHAIN}strip}
280329

330+
if [ -z "${JAVA_SDK}" ] ; then
331+
# Utility used to locate Java on OSX systems
332+
if [ -x /usr/libexec/java_home ] ; then
333+
ANDROID_JAVA_SDK="$(/usr/libexec/java_home)"
334+
elif [ -d /usr/lib/jvm/default ] ; then
335+
ANDROID_JAVA_SDK=/usr/lib/jvm/default
336+
elif [ -d /usr/lib/jvm/default-jvm ] ; then
337+
ANDROID_JAVA_SDK=/usr/lib/jvm/default-jvm
338+
else
339+
if [ "${OS}" = "android" ] ; then
340+
echo >&2 "Error: no Java SDK found - set \$JAVA_SDK"
341+
exit 1
342+
fi
343+
fi
344+
else
345+
ANDROID_JAVA_SDK="${JAVA_SDK}"
346+
fi
347+
281348

282349
################################################################
283350
# Invoke gyp
@@ -307,6 +374,7 @@ case ${OS} in
307374
export CXX="${ANDROID_CXX}"
308375
export LINK="${ANDROID_LINK}"
309376
export OBJCOPY="${ANDROID_OBJCOPY}"
377+
export OBJDUMP="${ANDROID_OBJDUMP}"
310378
export STRIP="${ANDROID_STRIP}"
311379
invoke_gyp $basic_args "-DOS=${OS}" "-Dtarget_arch=${TARGET_ARCH}" \
312380
-Dcross_compile=1 \

config/android.gypi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'variables':
77
{
8-
'java_sdk_path%': '<!(echo ${JAVA_SDK:-/usr/lib/jvm/java-6-openjdk-amd64})',
8+
'java_sdk_path%': '<!(echo ${JAVA_SDK})',
99
'android_sdk_path%': '<!(echo ${ANDROID_SDK})',
1010
'android_ndk_path%': '<!(echo ${ANDROID_NDK})',
1111
'android_platform%': '<!(echo ${ANDROID_PLATFORM})',
@@ -22,6 +22,11 @@
2222
'java_classpath': '<(android_sdk_path)/platforms/<(android_platform)/android.jar',
2323

2424
'output_dir': '../android-<(target_arch)-bin',
25+
26+
# Capture the values of some build tool environment vars
27+
'objcopy': '<!(echo ${OBJCOPY:-objcopy})',
28+
'objdump': '<!(echo ${OBJDUMP:-objdump})',
29+
'strip': '<!(echo ${STRIP:-strip})',
2530
},
2631

2732
'target_defaults':

config/debug_syms.gypi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
],
1313

1414
'extract-debug-symbols_path': '../tools/extract-debug-symbols.sh',
15+
16+
# These tools are only used for Linux and Android targets
17+
'objcopy%': '',
18+
'objdump%': '',
19+
'strip%': '',
1520
},
1621

1722
'actions':
@@ -33,6 +38,10 @@
3338

3439
'action':
3540
[
41+
'env',
42+
'OBJCOPY=<(objcopy)',
43+
'OBJDUMP=<(objdump)',
44+
'STRIP=<(strip)',
3645
'<(extract-debug-symbols_path)',
3746
'<(OS)',
3847
'>(debug_info_suffix)',

config/linux.gypi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
'variables':
33
{
44
'output_dir': '../linux-<(target_arch)-bin',
5+
6+
# Capture the values of some build tool environment vars
7+
'objcopy': '<!(echo ${OBJCOPY:-objcopy})',
8+
'objdump': '<!(echo ${OBJDUMP:-objdump})',
9+
'strip': '<!(echo ${STRIP:-strip})',
510
},
611

712
'target_defaults':

engine/app-bundle-template.gypi

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
{
22
'type': 'executable',
3-
'mac_bundle': 1,
43

5-
'mac_bundle_resources':
4+
'conditions':
65
[
7-
'rsrc/LiveCode-Community.rsrc',
8-
'rsrc/English.lproj/Localisation.strings',
9-
'rsrc/LiveCodeDoc.icns',
10-
'rsrc/LiveCode.icns',
11-
],
6+
[
7+
'OS == "mac" or OS == "ios"',
8+
{
9+
'target_conditions':
10+
[
11+
[
12+
'_type != "none"',
13+
{
14+
'mac_bundle': 1,
15+
},
16+
],
17+
],
18+
19+
'mac_bundle_resources':
20+
[
21+
'rsrc/LiveCode-Community.rsrc',
22+
'rsrc/English.lproj/Localisation.strings',
23+
'rsrc/LiveCodeDoc.icns',
24+
'rsrc/LiveCode.icns',
25+
],
1226

13-
'xcode_settings':
14-
{
15-
'INFOPLIST_FILE': '<(app_plist)',
16-
},
27+
'xcode_settings':
28+
{
29+
'INFOPLIST_FILE': '<(app_plist)',
30+
},
31+
}
32+
],
33+
],
1734
}

gyp/pylib/gyp/generator/make.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,18 @@ def CalculateGeneratorInputInfo(params):
138138
quiet_cmd_alink_thin = AR($(TOOLSET)) $@
139139
cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
140140
141+
# Figure out the correct --start-group and --end-group commands (not needed for
142+
# the MacOS linker)
143+
ifeq ($(shell uname),Linux)
144+
opt_start_group := -Wl,--start-group
145+
opt_end_group := -Wl,--end-group
146+
endif
147+
141148
# Due to circular dependencies between libraries :(, we wrap the
142149
# special "figure out circular dependencies" flags around the entire
143150
# input list during linking.
144151
quiet_cmd_link = LINK($(TOOLSET)) $@
145-
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
152+
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(opt_start_group) $(LD_INPUTS) $(opt_end_group) $(LIBS)
146153
147154
# We support two kinds of shared objects (.so):
148155
# 1) shared_library, which is just bundling together many dependent libraries
@@ -164,7 +171,7 @@ def CalculateGeneratorInputInfo(params):
164171
cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
165172
166173
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
167-
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
174+
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ $(opt_start_group) $(filter-out FORCE_DO_CMD, $^) $(opt_end_group) $(LIBS)
168175
"""
169176

170177
LINK_COMMANDS_MAC = """\

0 commit comments

Comments
 (0)