From 67b61145ac9e01d678d1df38d54b740f04245750 Mon Sep 17 00:00:00 2001 From: "Fraser J. Gordon" Date: Tue, 23 Jun 2015 18:02:10 +0100 Subject: [PATCH 1/9] Make the config.sh script much smarter at detecting Android settings --- config.sh | 78 +++++++++++++++++++++++++++++++++++++++++---- config/android.gypi | 2 +- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/config.sh b/config.sh index ecbc22b6144..a3bda914198 100755 --- a/config.sh +++ b/config.sh @@ -204,7 +204,9 @@ fi # If no output type specified, guess from platform: if test -z "$FORMATS"; then case ${OS} in - linux|android) FORMATS="make" ;; + # Always use Linux-style makefiles for Android as the Android toolchain + # is more Linux-y than Darwin-y + linux|android) FORMATS="make-linux" ;; mac|ios) FORMATS="xcode" ;; win) FORMATS="msvs" ;; esac @@ -259,14 +261,60 @@ if test -z "$TARGET_ARCH"; then fi # Android default settings and tools -ANDROID_BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-22.0.1} -ANDROID_JAVA_SDK=${ANDROID_JAVA_SDK:-${JAVA_SDK:-/usr/lib/jvm/java-7-openjdk-amd64}} ANDROID_NDK_VERSION=${ANDROID_NDK_VERSION:-r10d} -ANDROID_NDK=${ANDROID_NDK:-${HOME}/Workspace/android-ndk-${ANDROID_NDK_VERSION}} ANDROID_PLATFORM=${ANDROID_PLATFORM:-android-8} -ANDROID_SDK=${ANDROID_SDK:-${HOME}/Workspace/android-sdk-linux} -ANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN:-${HOME}/android-armv6-standalone/bin/arm-linux-androideabi-} +# Attempt to locate an Android NDK +if [ -z "${ANDROID_NDK}" ] ; then + # Try the symlink we suggest in INSTALL-android.md + if [ -d "${HOME}/android/toolchain/android-ndk" ] ; then + ANDROID_NDK="${HOME}/android/toolchain/android-ndk" + else + if [ "${OS}" = "android" ] ; then + echo >&2 "Error: Android NDK not found (set \$ANDROID_NDK)" + exit 1 + fi + fi +fi + +# Attempt to locate an Android SDK +if [ -z "${ANDROID_SDK}" ] ; then + # Try the symlink we suggest in INSTALL-android.md + if [ -d "${HOME}/android/toolchain/android-sdk" ] ; then + ANDROID_SDK="${HOME}/android/toolchain/android-sdk" + else + if [ "${OS}" = "android" ] ; then + echo >&2 "Error: Android SDK not found (set \$ANDROID_SDK)" + exit 1 + fi + fi +fi + +# Attempt to guess the Android build tools version +if [ -z "${ANDROID_BUILD_TOOLS}" ] ; then + # Check for a sub-folder in the appropriate place + # Possibly fragile - are there ever multiple sub-folders? + if [ ! "$(echo \"${ANDROID_SDK}/build-tools/\"*)" = "${ANDROID_SDK}/build-tools/*" ] ; then + ANDROID_BUILD_TOOLS=$(basename $(echo "${ANDROID_SDK}/build-tools/"*)) + else + if [ "${OS}" = "android" ] ; then + echo >&2 "Error: Android build tools not found (set \$ANDROID_BUILD_TOOLS)" + exit 1 + fi + fi +fi + +if [ -z "${ANDROID_TOOLCHAIN}" ] ; then + # Try the folder we suggest in INSTALL-android.md + if [ -d "${HOME}/android/toolchain/standalone" ] ; then + ANDROID_TOOLCHAIN="${HOME}/android/toolchain/standalone/bin/arm-linux-androideabi-" + else + if [ "${OS}" = "android" ] ; then + echo >&2 "Error: Android toolchain not found (set \$ANDROID_TOOLCHAIN)" + exit 1 + fi + fi +fi ANDROID_AR=${AR:-${ANDROID_TOOLCHAIN}ar} ANDROID_CC=${CC:-${ANDROID_TOOLCHAIN}clang -target arm-linux-androideabi -march=armv6 -integrated-as} @@ -275,6 +323,24 @@ ANDROID_LINK=${LINK:-${ANDROID_TOOLCHAIN}clang -target arm-linux-androideabi -ma ANDROID_OBJCOPY=${OBJCOPY:-${ANDROID_TOOLCHAIN}objcopy} ANDROID_STRIP=${STRIP:-${ANDROID_TOOLCHAIN}strip} +if [ -z "${JAVA_SDK}" ] ; then + # Utility used to locate Java on OSX systems + if [ -x /usr/libexec/java_home ] ; then + ANDROID_JAVA_SDK="$(/usr/libexec/java_home)" + elif [ -d /usr/lib/jvm/default ] ; then + ANDROID_JAVA_SDK=/usr/lib/jvm/default + elif [ -d /usr/lib/jvm/default-jvm ] ; then + ANDROID_JAVA_SDK=/usr/lib/jvm/default-jvm + else + if [ "${OS}" = "android" ] ; then + echo >&2 "Error: no Java SDK found - set \$JAVA_SDK" + exit 1 + fi + fi +else + ANDROID_JAVA_SDK="${JAVA_SDK}" +fi + ################################################################ # Invoke gyp diff --git a/config/android.gypi b/config/android.gypi index e3b08e5a1f8..ba12b9ee618 100644 --- a/config/android.gypi +++ b/config/android.gypi @@ -5,7 +5,7 @@ 'variables': { - 'java_sdk_path%': ' Date: Tue, 23 Jun 2015 18:03:51 +0100 Subject: [PATCH 2/9] [[ Gyp Patch ]] Make Gyp's make-linux flavour Makefiles work on OSX The Android toolchain is Linux-y so we need to use the make-linux flavour. However, we need to compile some host tools so do just enough to get that working on OSX hosts. --- gyp/pylib/gyp/generator/make.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gyp/pylib/gyp/generator/make.py b/gyp/pylib/gyp/generator/make.py index 05ca2eedf46..714a0e5fc24 100644 --- a/gyp/pylib/gyp/generator/make.py +++ b/gyp/pylib/gyp/generator/make.py @@ -138,11 +138,18 @@ def CalculateGeneratorInputInfo(params): quiet_cmd_alink_thin = AR($(TOOLSET)) $@ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^) +# Figure out the correct --start-group and --end-group commands (not needed for +# the MacOS linker) +ifeq ($(shell uname),Linux) + opt_start_group := -Wl,--start-group + opt_end_group := -Wl,--end-group +endif + # Due to circular dependencies between libraries :(, we wrap the # special "figure out circular dependencies" flags around the entire # input list during linking. quiet_cmd_link = LINK($(TOOLSET)) $@ -cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS) +cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(opt_start_group) $(LD_INPUTS) $(opt_end_group) $(LIBS) # We support two kinds of shared objects (.so): # 1) shared_library, which is just bundling together many dependent libraries @@ -164,7 +171,7 @@ def CalculateGeneratorInputInfo(params): cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS) quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@ -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) +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) """ LINK_COMMANDS_MAC = """\ From 8250ef667088bd6c6da158e22bdfa8020bb47b57 Mon Sep 17 00:00:00 2001 From: "Fraser J. Gordon" Date: Tue, 23 Jun 2015 18:07:22 +0100 Subject: [PATCH 3/9] Make the mac-bundle-ness of the engine conditional Gyp gets confused and tries to add resources to the mac bundle for the Android engine when building on OSX, which obviously doesn't work. --- engine/app-bundle-template.gypi | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/engine/app-bundle-template.gypi b/engine/app-bundle-template.gypi index 668ccab8472..dfc4c56e3a0 100644 --- a/engine/app-bundle-template.gypi +++ b/engine/app-bundle-template.gypi @@ -1,17 +1,26 @@ { 'type': 'executable', - 'mac_bundle': 1, - 'mac_bundle_resources': + 'conditions': [ - 'rsrc/LiveCode-Community.rsrc', - 'rsrc/English.lproj/Localisation.strings', - 'rsrc/LiveCodeDoc.icns', - 'rsrc/LiveCode.icns', - ], + [ + 'OS == "mac" or OS == "ios"', + { + 'mac_bundle': 1, + + 'mac_bundle_resources': + [ + 'rsrc/LiveCode-Community.rsrc', + 'rsrc/English.lproj/Localisation.strings', + 'rsrc/LiveCodeDoc.icns', + 'rsrc/LiveCode.icns', + ], - 'xcode_settings': - { - 'INFOPLIST_FILE': '<(app_plist)', - }, + 'xcode_settings': + { + 'INFOPLIST_FILE': '<(app_plist)', + }, + } + ], + ], } From b0aac6b7113200a58b917109ed42f025ea836e36 Mon Sep 17 00:00:00 2001 From: "Fraser J. Gordon" Date: Tue, 23 Jun 2015 18:10:24 +0100 Subject: [PATCH 4/9] Update the Android instructions to better match reality --- INSTALL-android.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/INSTALL-android.md b/INSTALL-android.md index 4447736e493..0bcb16e9196 100644 --- a/INSTALL-android.md +++ b/INSTALL-android.md @@ -23,37 +23,44 @@ mkdir -p ~/android/toolchain cd ~/android/toolchain tar -xf ~/Downloads/android-sdk_r24.1.2-linux.tgz -7z x ~/Downloads/android-ndk-r10d-linux-x86_64.bin +7z x ~/Downloads/android-ndk-r10e-linux-x86_64.bin ```` Update the SDK: - android-sdk-linuxl/tools/android update sdk --no-ui + android-sdk-linux/tools/android update sdk --no-ui ### Setting up the ARM toolchain Create a standalone toolchain (this simplifies setting up the build environment): ````bash -android-ndk-r10d/build/tools/make-standalone-toolchain.sh \ - --toolchain=arm-linux-androideabi-clang3.4 \ +android-ndk-r10e/build/tools/make-standalone-toolchain.sh \ + --toolchain=arm-linux-androideabi-clang3.5 \ --platform=android-8 \ - --install-dir=~/android/toolchain/standalone + --install-dir=${HOME}/android/toolchain/standalone ```` 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: ````bash rm standalone/bin/arm-linux-androideabi-ld -ln -s standalone/bin/arm-linux-androideabi-ld.bfd \ +ln -s arm-linux-androideabi-ld.bfd \ standalone/bin/arm-linux-androideabi-ld ```` +Add a couple of symlinks to allow the engine configuration script to find the Android toolchain: + +````bash +ln -s android-ndk-r10e android-ndk +ln -s android-sdk-linux android-sdk +```` + ## Configuring LiveCode ### Build environment -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. +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. 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: From 59d40ec05a774f96b639fd2ceb35b17f400c0fbb Mon Sep 17 00:00:00 2001 From: "Fraser J. Gordon" Date: Wed, 24 Jun 2015 09:10:06 +0100 Subject: [PATCH 5/9] Fix an iOS configure failure --- engine/app-bundle-template.gypi | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/engine/app-bundle-template.gypi b/engine/app-bundle-template.gypi index dfc4c56e3a0..d28c5fcd013 100644 --- a/engine/app-bundle-template.gypi +++ b/engine/app-bundle-template.gypi @@ -6,7 +6,15 @@ [ 'OS == "mac" or OS == "ios"', { - 'mac_bundle': 1, + 'target_conditions': + [ + [ + '_type != "none"', + { + 'mac_bundle': 1, + }, + ], + ], 'mac_bundle_resources': [ From d647ddc9da1872221dc84cf721da98f196831168 Mon Sep 17 00:00:00 2001 From: "Fraser J. Gordon" Date: Wed, 24 Jun 2015 11:00:10 +0100 Subject: [PATCH 6/9] Add objdump to the list of Android build tools we use --- config.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.sh b/config.sh index a3bda914198..5881c7e161b 100755 --- a/config.sh +++ b/config.sh @@ -321,6 +321,7 @@ ANDROID_CC=${CC:-${ANDROID_TOOLCHAIN}clang -target arm-linux-androideabi -march= ANDROID_CXX=${CXX:-${ANDROID_TOOLCHAIN}clang -target arm-linux-androideabi -march=armv6 -integrated-as} ANDROID_LINK=${LINK:-${ANDROID_TOOLCHAIN}clang -target arm-linux-androideabi -march=armv6 -integrated-as} ANDROID_OBJCOPY=${OBJCOPY:-${ANDROID_TOOLCHAIN}objcopy} +ANDROID_OBJDUMP=${OBJDUMP:-${ANDROID_TOOLCHAIN}objdump} ANDROID_STRIP=${STRIP:-${ANDROID_TOOLCHAIN}strip} if [ -z "${JAVA_SDK}" ] ; then @@ -370,6 +371,7 @@ case ${OS} in export CXX="${ANDROID_CXX}" export LINK="${ANDROID_LINK}" export OBJCOPY="${ANDROID_OBJCOPY}" + export OBJDUMP="${ANDROID_OBJDUMP}" export STRIP="${ANDROID_STRIP}" invoke_gyp $basic_args "-DOS=${OS}" "-Dtarget_arch=${TARGET_ARCH}" \ -Dcross_compile=1 \ From 601b301ecddd1befa67b0c862eeda88cd1052909 Mon Sep 17 00:00:00 2001 From: "Fraser J. Gordon" Date: Wed, 24 Jun 2015 11:00:31 +0100 Subject: [PATCH 7/9] Capture the values of $OBJCOPY,$OBJDUMP,$STRIP at configure time --- config/android.gypi | 5 +++++ config/debug_syms.gypi | 9 +++++++++ config/linux.gypi | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/config/android.gypi b/config/android.gypi index ba12b9ee618..ba644ab8278 100644 --- a/config/android.gypi +++ b/config/android.gypi @@ -22,6 +22,11 @@ 'java_classpath': '<(android_sdk_path)/platforms/<(android_platform)/android.jar', 'output_dir': '../android-<(target_arch)-bin', + + # Capture the values of some build tool environment vars + 'objcopy': '(debug_info_suffix)', diff --git a/config/linux.gypi b/config/linux.gypi index e14fa9acd6b..d63e7918f34 100644 --- a/config/linux.gypi +++ b/config/linux.gypi @@ -2,6 +2,11 @@ 'variables': { 'output_dir': '../linux-<(target_arch)-bin', + + # Capture the values of some build tool environment vars + 'objcopy': ' Date: Thu, 25 Jun 2015 08:10:22 +0100 Subject: [PATCH 8/9] Fix a silly typo --- config/linux.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/linux.gypi b/config/linux.gypi index d63e7918f34..01df2c565ad 100644 --- a/config/linux.gypi +++ b/config/linux.gypi @@ -6,7 +6,7 @@ # Capture the values of some build tool environment vars 'objcopy': ' Date: Thu, 25 Jun 2015 08:10:55 +0100 Subject: [PATCH 9/9] Fix a copy-and-pasted instance of the same silly typo --- config/android.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/android.gypi b/config/android.gypi index ba644ab8278..5ee8768dc5f 100644 --- a/config/android.gypi +++ b/config/android.gypi @@ -26,7 +26,7 @@ # Capture the values of some build tool environment vars 'objcopy': '