diff --git a/master/platforms.py b/master/platforms.py index 00ee8bef..8ed5e8e8 100644 --- a/master/platforms.py +++ b/master/platforms.py @@ -112,6 +112,95 @@ def _3ds(): platforms.append(platform) _3ds() +def android(suffix, scummvm_target, ndk_target, cxx_target, abi_version, + android_master_root = "/opt/android/master", + android_stable_root = "/opt/android/stable"): + android_master_toolchain = "{0}/ndk/toolchains/llvm/prebuilt/linux-x86_64".format( + android_master_root) + android_stable_toolchain = "{0}/toolchain".format(android_stable_root) + platform = Platform("android_{0}".format(suffix)) + platform.workerimage = "android" + platform.compatibleBuilds = (builds.ScummVMBuild, ) + platform.buildenv = { + builds.ScummVMBuild: { + "ANDROID_NDK_ROOT": "{0}/ndk".format(android_master_root), + # configure script will find everything from this + "ANDROID_TOOLCHAIN": "{0}".format(android_master_toolchain), + # We keep SDK and gradle dynamic and outside the container + # Their versions can change without the need to regenerate the image + # Android build system can be shared across all versions so we don't specialize + # the directory in /data/bshomes + "ANDROID_SDK_ROOT": "/data/bshomes/android/sdk", + "ANDROID_SDK_HOME": "/data/bshomes/android/sdk-home", + "GRADLE_USER_HOME": "/data/bshomes/android/gradle", + "CXX": "ccache {0}/bin/{1}{2}-clang++".format( + android_master_toolchain, cxx_target, abi_version), + # Worker has all libraries installed in the NDK sysroot + "PKG_CONFIG_LIBDIR": "{0}/sysroot/usr/lib/{1}/{2}/pkgconfig".format( + android_master_toolchain, ndk_target, abi_version), + }, + builds.ScummVMStableBuild: { + "ANDROID_NDK": "{0}/ndk".format(android_stable_root), + "ANDROID_SDK": "{0}/sdk".format(android_stable_root), + "ANDROID_SDK_HOME": "/data/bshomes/android/sdk-home", + "AR": "{0}/bin/{1}-ar".format( + android_stable_toolchain, ndk_target), + "AS": "{0}/bin/{1}-as".format( + android_stable_toolchain, ndk_target), + "RANLIB": "{0}/bin/{1}-ranlib".format( + android_stable_toolchain, ndk_target), + "STRIP": "{0}/bin/{1}-strip".format( + android_stable_toolchain, ndk_target), + "STRINGS": "{0}/bin/{1}-strings".format( + android_stable_toolchain, ndk_target), + "CXX": "ccache {0}/bin/{1}-clang++".format( + android_stable_toolchain, ndk_target), + "CC": "ccache {0}/bin/{1}-clang".format( + android_stable_toolchain, ndk_target), + # Worker has all libraries installed in the toolchain + "PKG_CONFIG_LIBDIR": "{0}/sysroot/usr/lib/{1}/pkgconfig".format( + android_stable_toolchain, ndk_target), + } + } + platform.configureargs.append("--host=android-{0}".format(scummvm_target)) + platform.buildconfigureargs = { + builds.ScummVMBuild: [ "--enable-debug", + # libcurl is detected using curl-config. Instead of modifying PATH just provide path to it to configure. + "--with-libcurl-prefix={0}/sysroot/usr/bin/{1}/{2}".format(android_master_toolchain, ndk_target, abi_version)], + builds.ScummVMStableBuild: [ "--enable-debug", + # libcurl is detected using curl-config. Instead of modifying PATH just provide path to it to configure. + "--with-libcurl-prefix={0}/sysroot/usr/bin/{1}".format(android_stable_toolchain, ndk_target)], + } + platform.packaging_cmd = "androiddistdebug" + platform.built_files = { + builds.ScummVMBuild: [ "debug" ], + } + platform.archiveext = "zip" + platform.testable = False + platform.run_tests = False + platforms.append(platform) + +android(suffix="arm", + scummvm_target="arm-v7a", + ndk_target="arm-linux-androideabi", + cxx_target="armv7a-linux-androideabi", + abi_version=16) +android(suffix="arm64", + scummvm_target="arm64-v8a", + ndk_target="aarch64-linux-android", + cxx_target="aarch64-linux-android", + abi_version=21) +android(suffix="x86", + scummvm_target="x86", + ndk_target="i686-linux-android", + cxx_target="i686-linux-android", + abi_version=16) +android(suffix="x86_64", + scummvm_target="x86_64", + ndk_target="x86_64-linux-android", + cxx_target="x86_64-linux-android", + abi_version=21) + def debian_x86_64(): platform = Platform("debian-x86_64") platform.env["CXX"] = "ccache g++" diff --git a/toolchains/android/Dockerfile.m4 b/toolchains/android/Dockerfile.m4 new file mode 100644 index 00000000..82954ad5 --- /dev/null +++ b/toolchains/android/Dockerfile.m4 @@ -0,0 +1,175 @@ +# This toolchain is made of two sub-toolchains one for stable ScummVM and one for master one +# Two sub-toolchains are used to avoid invalidating one when updating the other +# The merging process, being only copies, is faster + +FROM toolchains/common AS helpers + +m4_include(`paths.m4')m4_dnl + +# Don't import packages.m4 as it clashes with functions defined here + +m4_define(`local_sdk_package', COPY packages/$1 lib-helpers/packages/$1/ +RUN $3 lib-helpers/packages/$1/build.sh $2) +m4_define(`local_package', COPY packages/$1 lib-helpers/packages/$1/ +RUN $3 lib-helpers/multi-build.sh lib-helpers/packages/$1/build.sh $2) +m4_define(`helpers_package', COPY --from=helpers /lib-helpers/packages/$1 lib-helpers/packages/$1/ +RUN $3 lib-helpers/multi-build.sh lib-helpers/packages/$1/build.sh $2) + +##### master toolchain : NDK 21.0.6113669 + SDK licenses only / SDK and tools are download by Gradle ##### +FROM debian:stable-slim AS toolchain-master +USER root + +WORKDIR /usr/src + +# Copy and execute each step separately to avoid invalidating cache +COPY --from=helpers /lib-helpers/prepare.sh lib-helpers/ +RUN lib-helpers/prepare.sh + +COPY --from=helpers /lib-helpers/functions.sh lib-helpers/ + +COPY functions-platform.sh lib-helpers/ +COPY functions-sdk.sh lib-helpers/ +COPY multi-build.sh lib-helpers/ + +# nasm is used for x86 ScummVM +# Create man directories to please openjdk which expects them +# cf. https://github.com/debuerreotype/debuerreotype/issues/10 +RUN for i in $(seq 1 8); do mkdir -p "/usr/share/man/man${i}"; done && \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + default-jre-headless \ + golang-go \ + nasm && \ + rm -rf /var/lib/apt/lists/* + +# API is the API versions for which we will compile packages +# This variable can also be : +# - all which means all API versions of all possible targets +# - lowest the lowest API version for each target +# - version[:version...] which will search for the specified versions (or most approaching) in all targets +# +# API and ANDROID_NDK_VERSION must be kept in sync with ScummVM source tree +# If multiple NDKs must be installed (for stable and master), +# we should duplicate all instructions from this point +# +# API is synchronized with ScummVM minSdkVersion +# As we follow same rules as Android, we should +# always get the same API versions as expected by Android + +ENV ANDROID_ROOT=/opt/android/master + +ENV ANDROID_NDK_ROOT=${ANDROID_ROOT}/ndk \ + ANDROID_NDK_VERSION=21.0.6113669 \ + API=16 \ + HOST_TAG=linux-x86_64 + +# Install NDK using settings above +local_sdk_package(ndk) + +# Include the packaging instructions +m4_include(`packages_list.m4') + +# Only install licenses on this version as everything will be installed by gradle +# It's installed last to avoid rebuilding everything if we just want to update licenses + +ENV ANDROID_SDK_ROOT=${ANDROID_ROOT}/sdk +# Install SDK using settings above +local_sdk_package(sdk) + +##### stable toolchain : NDK r14b and SDK 25 ##### +FROM debian:stable-slim AS toolchain-stable +USER root + +WORKDIR /usr/src + +# Copy and execute each step separately to avoid invalidating cache +COPY --from=helpers /lib-helpers/prepare.sh lib-helpers/ +RUN lib-helpers/prepare.sh + +COPY --from=helpers /lib-helpers/functions.sh lib-helpers/ + +COPY functions-platform.sh lib-helpers/ +# We don't need these functions for older SDK but that let's image reuse possible +COPY functions-sdk.sh lib-helpers/ +COPY multi-build.sh lib-helpers/ + +# nasm is used for x86 ScummVM +# JDK is needed instead of JRE to patch Android SDK for OpenJDK 11 +# Create man directories to please openjdk which expects them +# cf. https://github.com/debuerreotype/debuerreotype/issues/10 +RUN for i in $(seq 1 8); do mkdir -p "/usr/share/man/man${i}"; done && \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + default-jdk-headless \ + golang-go \ + nasm && \ + rm -rf /var/lib/apt/lists/* + +# Unlike the newer toolchain, this one is quite static because it shouldn't evolve in time +# and many tricks may depend on the NDK version + +ENV ANDROID_ROOT=/opt/android/stable + +# Old toolchains need python to create toolchains and old ncurses +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libncurses5 \ + python && \ + rm -rf /var/lib/apt/lists/* + +# ABIS is for ndk-old package and determine how the unified toolchain will be composed +# API is none because we don't have new style folder hierarchy +ENV ANDROID_NDK_ROOT=${ANDROID_ROOT}/ndk \ + TOOLCHAIN=${ANDROID_ROOT}/toolchain \ + ABIS="arm/9 arm64/21 x86/9 x86_64/21" \ + API="none" \ + HOST_TAG=linux-x86_64 + +# Install NDK using settings above +local_sdk_package(ndk-old) + +# Include the packaging instructions +m4_include(`packages_list.m4') + +# Install an old (unsupported) SDK because build process depends on android project command + +ENV ANDROID_SDK_ROOT=${ANDROID_ROOT}/sdk +local_sdk_package(sdk-old) + +##### Resulting toolchain ##### +FROM debian:stable-slim +USER root + +WORKDIR /usr/src + +# Copy and execute each step separately to avoid invalidating cache +COPY --from=helpers /lib-helpers/prepare.sh lib-helpers/ +RUN lib-helpers/prepare.sh + +COPY --from=helpers /lib-helpers/functions.sh lib-helpers/ + +COPY functions-platform.sh lib-helpers/ +COPY functions-sdk.sh lib-helpers/ +COPY multi-build.sh lib-helpers/ + +# Create man directories to please openjdk which expects them +# cf. https://github.com/debuerreotype/debuerreotype/issues/10 +# ant is used by ScummVM build system +# file is used ndk-build in NDK 14 +# libncurses5 is used by binaries in NDK 14 +# nasm is used for x86 ScummVM +RUN for i in $(seq 1 8); do mkdir -p "/usr/share/man/man${i}"; done && \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ant \ + default-jre-headless \ + file \ + libncurses5 \ + nasm && \ + rm -rf /var/lib/apt/lists/* + +ENV ANDROID_ROOT=/opt/android + +# Toolchains are not (yet?) relocatable, so we must not change their path once they are compiled +COPY --from=toolchain-master ${ANDROID_ROOT}/master/ ${ANDROID_ROOT}/master/ +COPY --from=toolchain-stable ${ANDROID_ROOT}/stable/ ${ANDROID_ROOT}/stable/ diff --git a/toolchains/android/functions-platform.sh b/toolchains/android/functions-platform.sh new file mode 100644 index 00000000..d8ccb010 --- /dev/null +++ b/toolchains/android/functions-platform.sh @@ -0,0 +1,37 @@ +# Paths are not standard in Android toolchain, adapt them +__do_configure_android () { + if [ "${API}" = "." ]; then + __do_configure --libdir=${PREFIX}/lib/${TARGET} --bindir=${PREFIX}/bin/${TARGET} "$@" + else + __do_configure --libdir=${PREFIX}/lib/${TARGET}/${API} \ + --bindir=${PREFIX}/bin/${TARGET}/${API} "$@" + fi +} + +__do_cmake_android () { + local cmake_target cmake_args orig_api + orig_api=${API} + if [ "${API}" = "." ]; then + API=$(sed -ne 's/^.*-D__ANDROID_API__=\([0-9]\+\) .*$/\1/p' "$CC") + cmake_args="-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang" + fi + case $TARGET in + arm-linux-androideabi) cmake_target=armeabi-v7a ;; + aarch64-linux-android) cmake_target=arm64-v8a ;; + i686-linux-android) cmake_target=x86 ;; + x86_64-linux-android) cmake_target=x86_64 ;; + *) error "Unknown target ${TARGET}" ;; + esac + __do_cmake -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \ + -DANDROID_ABI=${cmake_target} \ + -DANDROID_NATIVE_API_LEVEL=${API} \ + -DCMAKE_INSTALL_LIBDIR=${PREFIX}/lib/${TARGET}/${orig_api} \ + -DCMAKE_INSTALL_BINDIR=${PREFIX}/bin/${TARGET}/${orig_api} \ + $cmake_args \ + "$@" +} + +for f in do_configure do_cmake; do + unset -f $f + eval "$f () { __${f}_android \"\$@\"; }" +done diff --git a/toolchains/android/functions-sdk.sh b/toolchains/android/functions-sdk.sh new file mode 100644 index 00000000..76b5cf3d --- /dev/null +++ b/toolchains/android/functions-sdk.sh @@ -0,0 +1,37 @@ +CMDLINE_TOOLS_VERSION=6200805 +CMDLINE_TOOLS_CHECKSUM="sha256:f10f9d5bca53cc27e2d210be2cbc7c0f1ee906ad9b868748d74d62e10f2c8275" + +# Disable HTTPS to allow caching in optional proxy + +do_install_sdk_tools () { + do_http_fetch tools "https://dl.google.com/android/repository/commandlinetools-${HOST_TAG%%-*}-${CMDLINE_TOOLS_VERSION}_latest.zip" 'unzip' \ + "${CMDLINE_TOOLS_CHECKSUM}" + + # Don't stay in tools subdirectory + cd .. + + ANDROID_TEMP_SDK_DIR="$(pwd)" + export ANDROID_SDK_HOME="$(pwd)" + + # Make sure we have the last version + yes | "${ANDROID_TEMP_SDK_DIR}/tools/bin/sdkmanager" --sdk_root="${ANDROID_TEMP_SDK_DIR}" --no_https --install "cmdline-tools;latest" +} + +do_sdk_accept_licenses () { + local dst=$1 + if [ -z "$dst" ]; then + dst=${ANDROID_TEMP_SDK_DIR} + fi + + yes | "${ANDROID_TEMP_SDK_DIR}/tools/bin/sdkmanager" --sdk_root="$dst" --no_https --licenses >/dev/null +} + +do_sdk_install () { + local pkg=$1 dst=$2 + if [ -z "$dst" ]; then + dst=${ANDROID_TEMP_SDK_DIR} + fi + + # Install requested NDK + yes | "${ANDROID_TEMP_SDK_DIR}/tools/bin/sdkmanager" --sdk_root="$dst" --no_https --install "$pkg" +} diff --git a/toolchains/android/multi-build.sh b/toolchains/android/multi-build.sh new file mode 100755 index 00000000..14898e09 --- /dev/null +++ b/toolchains/android/multi-build.sh @@ -0,0 +1,87 @@ +#! /bin/sh + +#set -x +set -e + +build_script=$1 +shift 1 + +original_path=$PATH + +if [ -z "$API" ]; then + API=all +fi + +# Old toolchains don't have this architecure so let it be configurable +if [ -z "$TOOLCHAIN" ]; then + TOOLCHAIN="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${HOST_TAG}" +fi + +targets=$(cd "$TOOLCHAIN/sysroot/usr/lib" && ls -d */) + +for t in "$TOOLCHAIN/sysroot/usr/lib/"*/; do + t=$(basename $t) + if [ "$API" = "none" ]; then + refined_apis='.' + else + lowest=$(basename "$(cd "$TOOLCHAIN/sysroot/usr/lib/$t" && ls -1d */ | head -n1)") + if [ "$API" = "all" ]; then + apis=$(cd "$TOOLCHAIN/sysroot/usr/lib/$t" && ls -1d */ | while read v; do echo -n "$(basename "$v") "; done) + elif [ "$API" = "lowest" ]; then + apis=$lowest + else + apis=$API + fi + + refined_apis= + for a in $apis; do + # Try to find the best API version available like specified in Android docs + while [ ! -d "$TOOLCHAIN/sysroot/usr/lib/$t/$a" ]; do + # First, decrement + if [ $a -le 0 ]; then + break + fi + a=$(($a - 1)) + done + if [ ! -d "$TOOLCHAIN/sysroot/usr/lib/$t/$a" ]; then + # Still not found, lowest supported version by NDK + a=$lowest + fi + refined_apis="$refined_apis\n$a" + done + refined_apis=$(echo $refined_apis | sort -u | tr '\n' ' ') + fi + + for a in $refined_apis; do + # Define all environment variables now that we have the target platform and API + export HOST=$t TARGET=$t + + # Don't know why but tools and compiler don't have the same target prefix for ARM + comp_target=$TARGET + if [ $comp_target = "arm-linux-androideabi" ]; then + comp_target=armv7a-linux-androideabi + fi + for c in ar as c++filt ld nm objcopy objdump ranlib readelf strings strip; do + v=$(echo $c | tr 'a-z+-' 'A-ZX_') + export $v="$TOOLCHAIN/bin/$TARGET-$c" + done + # Frankenstein unified toolchains don't have the API version and use same name as TARGET + if [ -f "$TOOLCHAIN/bin/$comp_target$a-clang" ]; then + export CC=$TOOLCHAIN/bin/$comp_target$a-clang + export CXX=$TOOLCHAIN/bin/$comp_target$a-clang++ + else + export CC=$TOOLCHAIN/bin/$TARGET-clang + export CXX=$TOOLCHAIN/bin/$TARGET-clang + fi + + export PREFIX=$TOOLCHAIN/sysroot/usr + export PATH=$original_path:$TOOLCHAIN/bin:$PREFIX/bin/$TARGET/$a + export ACLOCAL_PATH=$PREFIX/share/aclocal + export PKG_CONFIG_LIBDIR=$PREFIX/lib/$TARGET/$a + export PKG_CONFIG_PATH=$PREFIX/lib/$TARGET/$a/pkgconfig + + echo "Building for $TARGET-$a" + + API=$a $build_script "$@" + done +done diff --git a/toolchains/android/packages/fluidsynth-lite/patches/fix-install-dirs.patch b/toolchains/android/packages/fluidsynth-lite/patches/fix-install-dirs.patch new file mode 100644 index 00000000..8f7d88a1 --- /dev/null +++ b/toolchains/android/packages/fluidsynth-lite/patches/fix-install-dirs.patch @@ -0,0 +1,47 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9dca996..6cc709e 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -72,6 +72,7 @@ mark_as_advanced ( LIB_SUFFIX ) + + # Default install directory names + include ( DefaultDirs ) ++include ( GNUInstallDirs ) + + # Basic C library checks + include ( CheckSTDC ) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index 76a8f87..7973219 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -22,5 +22,5 @@ + add_subdirectory ( fluidsynth ) + + IF (NOT MACOSX_FRAMEWORK ) +- install ( FILES fluidsynth.h DESTINATION ${INCLUDE_INSTALL_DIR} ) ++ install ( FILES fluidsynth.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) + ENDIF (NOT MACOSX_FRAMEWORK ) +diff --git a/include/fluidsynth/CMakeLists.txt b/include/fluidsynth/CMakeLists.txt +index b146d13..d4c00b4 100644 +--- a/include/fluidsynth/CMakeLists.txt ++++ b/include/fluidsynth/CMakeLists.txt +@@ -46,6 +46,6 @@ if ( NOT MACOSX_FRAMEWORK ) + ${include_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/version.h + DESTINATION +- ${INCLUDE_INSTALL_DIR}/fluidsynth ++ ${CMAKE_INSTALL_INCLUDEDIR}/fluidsynth + ) + endif ( NOT MACOSX_FRAMEWORK ) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index c14622d..4e99dab 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -152,5 +152,5 @@ target_link_libraries ( libfluidsynth + ) + + install(TARGETS libfluidsynth +- LIBRARY DESTINATION lib +- ARCHIVE DESTINATION lib) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/toolchains/android/packages/libsdl2-net/patches/no-sdl.patch b/toolchains/android/packages/libsdl2-net/patches/no-sdl.patch new file mode 100644 index 00000000..69e4cdd3 --- /dev/null +++ b/toolchains/android/packages/libsdl2-net/patches/no-sdl.patch @@ -0,0 +1,262 @@ +diff --git a/SDL2_net.pc.in b/SDL2_net.pc.in +index e3ad892..e7731be 100644 +--- a/SDL2_net.pc.in ++++ b/SDL2_net.pc.in +@@ -6,6 +6,6 @@ includedir=@includedir@ + Name: SDL2_net + Description: net library for Simple DirectMedia Layer + Version: @VERSION@ +-Requires: sdl2 >= @SDL_VERSION@ ++Requires: + Libs: -L${libdir} -lSDL2_net + Cflags: -I${includedir}/SDL2 +diff --git a/SDL_net.h b/SDL_net.h +index bd5ec7f..c7293e9 100644 +--- a/SDL_net.h ++++ b/SDL_net.h +@@ -25,7 +25,10 @@ + #ifndef _SDL_NET_H + #define _SDL_NET_H + ++#define WITHOUT_SDL ++ + #ifdef WITHOUT_SDL ++#include + #include + typedef uint8_t Uint8; + typedef uint16_t Uint16; +@@ -37,6 +40,11 @@ typedef struct SDLNet_version { + Uint8 patch; + } SDLNet_version; + ++#define SDL_memcpy memcpy ++#define SDL_memset memset ++#define SDL_malloc malloc ++#define SDL_free free ++ + #else /* WITHOUT_SDL */ + + #include "SDL.h" +@@ -47,7 +55,156 @@ typedef SDL_version SDLNet_version; + + #endif /* WITHOUT_SDL */ + +-#include "begin_code.h" ++//#include "begin_code.h" ++/** ++ * \file begin_code.h ++ * ++ * This file sets things up for C dynamic library function definitions, ++ * static inlined functions, and structures aligned at 4-byte alignment. ++ * If you don't like ugly C preprocessor code, don't look at this file. :) ++ */ ++ ++/* This shouldn't be nested -- included it around code only. */ ++#ifdef _begin_code_h ++#error Nested inclusion of begin_code.h ++#endif ++#define _begin_code_h ++ ++#ifndef SDL_DEPRECATED ++# if (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */ ++# define SDL_DEPRECATED __attribute__((deprecated)) ++# else ++# define SDL_DEPRECATED ++# endif ++#endif ++ ++#ifndef SDL_UNUSED ++# ifdef __GNUC__ ++# define SDL_UNUSED __attribute__((unused)) ++# else ++# define SDL_UNUSED ++# endif ++#endif ++ ++/* Some compilers use a special export keyword */ ++#ifndef DECLSPEC ++# if defined(__WIN32__) || defined(__WINRT__) ++# ifdef __BORLANDC__ ++# ifdef BUILD_SDL ++# define DECLSPEC ++# else ++# define DECLSPEC __declspec(dllimport) ++# endif ++# else ++# define DECLSPEC __declspec(dllexport) ++# endif ++# elif defined(__OS2__) ++# ifdef BUILD_SDL ++# define DECLSPEC __declspec(dllexport) ++# else ++# define DECLSPEC ++# endif ++# else ++# if defined(__GNUC__) && __GNUC__ >= 4 ++# define DECLSPEC __attribute__ ((visibility("default"))) ++# else ++# define DECLSPEC ++# endif ++# endif ++#endif ++ ++/* By default SDL uses the C calling convention */ ++#ifndef SDLCALL ++#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__) ++#define SDLCALL __cdecl ++#elif defined(__OS2__) || defined(__EMX__) ++#define SDLCALL _System ++# if defined (__GNUC__) && !defined(_System) ++# define _System /* for old EMX/GCC compat. */ ++# endif ++#else ++#define SDLCALL ++#endif ++#endif /* SDLCALL */ ++ ++/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */ ++#ifdef __SYMBIAN32__ ++#undef DECLSPEC ++#define DECLSPEC ++#endif /* __SYMBIAN32__ */ ++ ++/* Force structure packing at 4 byte alignment. ++ This is necessary if the header is included in code which has structure ++ packing set to an alternate value, say for loading structures from disk. ++ The packing is reset to the previous value in close_code.h ++ */ ++#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) ++#ifdef _MSC_VER ++#pragma warning(disable: 4103) ++#endif ++#ifdef __clang__ ++#pragma clang diagnostic ignored "-Wpragma-pack" ++#endif ++#ifdef __BORLANDC__ ++#pragma nopackwarning ++#endif ++#ifdef _M_X64 ++/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */ ++#pragma pack(push,8) ++#else ++#pragma pack(push,4) ++#endif ++#endif /* Compiler needs structure packing set */ ++ ++#ifndef SDL_INLINE ++#if defined(__GNUC__) ++#define SDL_INLINE __inline__ ++#elif defined(_MSC_VER) || defined(__BORLANDC__) || \ ++ defined(__DMC__) || defined(__SC__) || \ ++ defined(__WATCOMC__) || defined(__LCC__) || \ ++ defined(__DECC) || defined(__CC_ARM) ++#define SDL_INLINE __inline ++#ifndef __inline__ ++#define __inline__ __inline ++#endif ++#else ++#define SDL_INLINE inline ++#ifndef __inline__ ++#define __inline__ inline ++#endif ++#endif ++#endif /* SDL_INLINE not defined */ ++ ++#ifndef SDL_FORCE_INLINE ++#if defined(_MSC_VER) ++#define SDL_FORCE_INLINE __forceinline ++#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) ) ++#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__ ++#else ++#define SDL_FORCE_INLINE static SDL_INLINE ++#endif ++#endif /* SDL_FORCE_INLINE not defined */ ++ ++#ifndef SDL_NORETURN ++#if defined(__GNUC__) ++#define SDL_NORETURN __attribute__((noreturn)) ++#elif defined(_MSC_VER) ++#define SDL_NORETURN __declspec(noreturn) ++#else ++#define SDL_NORETURN ++#endif ++#endif /* SDL_NORETURN not defined */ ++ ++/* Apparently this is needed by several Windows compilers */ ++#if !defined(__MACH__) ++#ifndef NULL ++#ifdef __cplusplus ++#define NULL 0 ++#else ++#define NULL ((void *)0) ++#endif ++#endif /* NULL */ ++#endif /* ! Mac OS X - breaks precompiled headers */ + + /* Set up for C function definitions, even when using C++ */ + #ifdef __cplusplus +@@ -438,6 +595,25 @@ SDL_FORCE_INLINE Uint32 _SDLNet_Read32(const void *areap) + #ifdef __cplusplus + } + #endif +-#include "close_code.h" ++//#include "close_code.h" ++/** ++ * \file close_code.h ++ * ++ * This file reverses the effects of begin_code.h and should be included ++ * after you finish any function and structure declarations in your headers ++ */ ++ ++#ifndef _begin_code_h ++#error close_code.h included without matching begin_code.h ++#endif ++#undef _begin_code_h ++ ++/* Reset structure packing at previous byte alignment */ ++#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) ++#ifdef __BORLANDC__ ++#pragma nopackwarning ++#endif ++#pragma pack(pop) ++#endif /* Compiler needs structure packing set */ + + #endif /* _SDL_NET_H */ +diff --git a/SDLnet.c b/SDLnet.c +index 53d125a..7e54e63 100644 +--- a/SDLnet.c ++++ b/SDLnet.c +@@ -66,7 +66,12 @@ void SDLCALL SDLNet_SetError(const char *fmt, ...) + { + va_list argp; + va_start(argp, fmt); ++#ifdef WITHOUT_SDL ++ memset(errorbuf, 0, sizeof(errorbuf)); ++#else + SDL_vsnprintf(errorbuf, sizeof(errorbuf), fmt, argp); ++#endif ++ vsnprintf(errorbuf, sizeof(errorbuf), fmt, argp); + va_end(argp); + #ifndef WITHOUT_SDL + SDL_SetError("%s", errorbuf); +diff --git a/configure.in b/configure.in +index 4228c6f..dca90a6 100644 +--- a/configure.in ++++ b/configure.in +@@ -107,16 +107,6 @@ case "$host" in + esac + AC_SUBST(INETLIB) + +-dnl Check for SDL +-SDL_VERSION=2.0.0 +-AC_SUBST(SDL_VERSION) +-AM_PATH_SDL2($SDL_VERSION, +- :, +- AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!]) +-) +-CFLAGS="$CFLAGS $SDL_CFLAGS" +-LIBS="$LIBS $SDL_LIBS" +- + dnl Check for GUI library for the chat client + have_GUI=no + AC_ARG_ENABLE(gui, diff --git a/toolchains/android/packages/libsdl2/build.sh b/toolchains/android/packages/libsdl2/build.sh new file mode 100755 index 00000000..5d8d3863 --- /dev/null +++ b/toolchains/android/packages/libsdl2/build.sh @@ -0,0 +1,38 @@ +#! /bin/sh + +PACKAGE_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +HELPERS_DIR=$PACKAGE_DIR/../.. +. $HELPERS_DIR/functions.sh + +do_make_bdir + +do_pkg_fetch libsdl2 +do_configure + +do_make +do_make install + +# SDL uses SDL_config.h to enable features but they depend on architecture being cross-compiled. +# As we use a unified include directory we must trick, so we move SDL_config.h to an arch +# dependent name andwe create a toplevel file which selects the good file to include +mv $PREFIX/include/SDL2/SDL_config.h $PREFIX/include/SDL2/SDL_config_$TARGET.h + +cat > $PREFIX/include/SDL2/SDL_config.h <$/i #include ' '{}' + + +# What we do now is like Frankenstein, we make a unified toolchain from parts of toolchains not inteded to be unified. +# It's not perfect (GCC don't work) but it works when compiling ScummVM, so who cares? + +mkdir -p "${ANDROID_NDK_ROOT}/" +# mv is faster than cp +mv ./* "${ANDROID_NDK_ROOT}/" + +mkdir -p "${TOOLCHAIN}/" + +for t in ${ABIS}; do + arch=${t%/*} + api=${t##*/} + echo "Installing ${arch} with API ${api}" + + "${ANDROID_NDK_ROOT}/build/tools/make_standalone_toolchain.py" --arch "${arch}" --api "${api}" --install-dir toolchain-temp --unified-headers + + triple=$(ls toolchain-temp/bin/*-clang| sed -n -e 's#^.*/\([^/]\+\)-clang$#\1#p') + echo "Using triple ${triple}" + + libdir=toolchain-temp/sysroot/usr/lib64 + if [ ! -d "${libdir}" ]; then + libdir=toolchain-temp/sysroot/usr/lib + fi + + # Copy the whole toolchain + cp -Rf toolchain-temp/. "${TOOLCHAIN}/" + + # Remove parts which are arch specific + rm -Rf "${TOOLCHAIN}"/sysroot/usr/lib64 "${TOOLCHAIN}"/sysroot/usr/lib + rm -Rf "${TOOLCHAIN}"/sysroot/usr/include/asm + rm -Rf "${TOOLCHAIN}"/sysroot/usr/include/machine + rm -Rf "${TOOLCHAIN}"/bin/clang "${TOOLCHAIN}"/bin/clang++ + # Remove GCC as it's unsupported + rm -Rf "${TOOLCHAIN}"/bin/${triple}-gcc "${TOOLCHAIN}"/bin/${triple}-g++ + + # Copy back arch specific missing parts to their right place + # We use a temporary directory to not be picky when erasing above + mkdir -p "${TOOLCHAIN}/sysroot/usr/.lib/${triple}" + cp -Rf "${libdir}"/. "${TOOLCHAIN}/sysroot/usr/.lib/${triple}" + + # Don't repeat over and over this, needs to be escaped, part + sysroot_path='`dirname $0`/../sysroot' + # Patch include search path to add arch specific directory + for f in "${TOOLCHAIN}"/bin/${triple}-clang "${TOOLCHAIN}"/bin/${triple}-clang++; do + sed -i -e "2 r /dev/stdin" \ + -e "s#--sysroot#-B=/usr/lib/${triple} \"\$linker\" -idirafter ${sysroot_path}/usr/include/${triple} &#" \ + "$f" <##' ./ant/build.xml + +# OpenJDK 11 doesn't have sun.misc.Base64Encoder anymore, provide it and patch sdklibs.jar +cp $PACKAGE_DIR/sun_misc_base64.jar ./lib/ +# Spawn a subshell to not alter working directory +(DIR=$(pwd) && \ + cd .. && \ + jar xf "$DIR/lib/sdklib.jar" META-INF/MANIFEST.MF && \ + sed -i -e 's/^Class-Path: /Class-Path: sun_misc_base64.jar /' -e '/^Manifest-Version:/d' META-INF/MANIFEST.MF && \ + jar ufm "$DIR/lib/sdklib.jar" META-INF/MANIFEST.MF && \ + rm -rf META-INF) + +mkdir -p "${ANDROID_SDK_ROOT}" + +# Download needed parts +yes | ./bin/sdkmanager --sdk_root="${ANDROID_SDK_ROOT}" "build-tools;25.0.3" platform-tools "platforms;android-28" + +# Cleanup what we don't need in tools +rm -rf apps lib/monitor-x86 lib/monitor-x86_64 qemu emulator* bin64 lib64 emulator64-crash-service + +# Move +mkdir "${ANDROID_SDK_ROOT}/tools/" +mv ./* "${ANDROID_SDK_ROOT}/tools/" + +do_clean_bdir diff --git a/toolchains/android/packages/sdk-old/sun_misc_base64.jar b/toolchains/android/packages/sdk-old/sun_misc_base64.jar new file mode 100644 index 00000000..a6271fc5 Binary files /dev/null and b/toolchains/android/packages/sdk-old/sun_misc_base64.jar differ diff --git a/toolchains/android/packages/sdk/build.sh b/toolchains/android/packages/sdk/build.sh new file mode 100755 index 00000000..fedb5d5e --- /dev/null +++ b/toolchains/android/packages/sdk/build.sh @@ -0,0 +1,29 @@ +#! /bin/sh + +PACKAGE_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +HELPERS_DIR=$PACKAGE_DIR/../.. + +# Don't load functions-platform.sh as it's not needed +NO_FUNCTIONS_PLATFORM=yes + +. $HELPERS_DIR/functions-sdk.sh +. $HELPERS_DIR/functions.sh + +do_make_bdir + +do_install_sdk_tools + +mkdir -p "${ANDROID_SDK_ROOT}" + +# Install licences outside the build tree +do_sdk_accept_licenses "${ANDROID_SDK_ROOT}" + +if [ -n "${ANDROID_SDK_VERSION}" ]; then + do_sdk_install "platforms;android-${SDK_VERSION}" + do_sdk_install "platform-tools" +fi +if [ -n "${ANDROID_BUILD_TOOLS_VERSION}" ]; then + do_sdk_install "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" +fi + +do_clean_bdir diff --git a/toolchains/android/packages/zlib/build.sh b/toolchains/android/packages/zlib/build.sh new file mode 100755 index 00000000..a7cde71f --- /dev/null +++ b/toolchains/android/packages/zlib/build.sh @@ -0,0 +1,35 @@ +#! /bin/sh + +PACKAGE_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +HELPERS_DIR=$PACKAGE_DIR/../.. +. $HELPERS_DIR/functions.sh + +do_make_bdir + +# Android already comes with zlib but it doesn't advertise it with pkg-config +# As other libraries (libpng) requires it, just create a dummy .pc file + +# Determine zlib version (the same way original zlib configure does) +ZLIB_VERSION=$(sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${PREFIX}/include/zlib.h) +if [ -z "${ZLIB_VERSION}" ]; then + error "Can't find Android zlib version" +fi + +cat > zlib.pc < "${GRADLE_USER_HOME}"/gradle.properties + +# Don't do anything after so replace our process +exec "$@"