Last active
October 26, 2018 13:21
-
-
Save molind/6d0505040890fc2964d7f525147180e9 to your computer and use it in GitHub Desktop.
Android / iOS cross compile example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NICE_PRINT = "\033[1;32m Building $(1)\033[0m\n" | |
export PREFIX = ${CURDIR}/build/Android/${ARCH} | |
TOOLCHAIN = toolchain/${ARCH} | |
LIBDIR = ${PREFIX}/lib | |
INCLUDEDIR = ${PREFIX}/include | |
export PATH := $(CURDIR)/${TOOLCHAIN}/bin:${PATH} | |
export AR=${HOST}-ar | |
export AS=${HOST}-clang | |
export CC=${HOST}-clang | |
export CXX=${HOST}-clang++ | |
export LD=${HOST}-ld | |
export STRIP=${HOST}-strip | |
export CFLAGS = -fPIC -O3 -I${INCLUDEDIR} | |
export CXXFLAGS = -fPIC -O3 -std=c++17 -I${INCLUDEDIR} | |
export LDFLAGS = -L${LIBDIR} | |
ifeq ($(ARCH),armeabi-v7a) | |
export CFLAGS = -fPIC -O3 -march=armv7-a -mfloat-abi=softfp -I${INCLUDEDIR} | |
export CXXFLAGS = -fPIC -O3 -std=c++17 -march=armv7-a -mfloat-abi=softfp -I${INCLUDEDIR} | |
export LDFLAGS = -march=armv7-a -Wl,--fix-cortex-a8 -L${LIBDIR} | |
endif | |
LDFLAGS_PROTOBUF = -llog | |
CXXFLAGS_VALHALLA = -DHAS_REMOTE_API=0 -DUSE_OS_TZDB=0 -DINSTALL=. -DMISSING_LEAP_SECONDS=0 | |
# Build separate architectures | |
all: | |
mkdir -p download | |
@${MAKE} -f Android.mk arch ARCH=armeabi-v7a HOST=arm-linux-androideabi | |
@${MAKE} -f Android.mk arch ARCH=arm64-v8a HOST=aarch64-linux-android >/dev/null | |
@${MAKE} -f Android.mk arch ARCH=x86 HOST=i686-linux-android >/dev/null | |
@${MAKE} -f Android.mk arch ARCH=x86_64 HOST=x86_64-linux-android >/dev/null | |
arch: status | ${LIBDIR}/libcurl.a ${LIBDIR}/libsqlite3.a | |
status: | |
@printf $(call NICE_PRINT,$(ARCH)) 1>&2; | |
include download.mk | |
${LIBDIR}/libssl.a: download/libressl | |
@printf $(call NICE_PRINT,$@) 1>&2; | |
cd ${LIBRESSL_DIR} && \ | |
./configure --host=${HOST} --prefix=${PREFIX} --disable-shared --disable-asm && \ | |
${MAKE} clean && \ | |
${MAKE} -j8 install | |
${LIBDIR}/libcurl.a: download/curl ${LIBDIR}/libssl.a | |
@printf $(call NICE_PRINT,$@) 1>&2; | |
cd ${CURL_DIR} && \ | |
./configure --host=${HOST} --prefix=${PREFIX} --disable-shared --with-ssl --disable-verbose --enable-ipv6 --enable-hidden-symbols --enable-threaded-resolver &&\ | |
${MAKE} clean && \ | |
${MAKE} -j8 install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NICE_PRINT = "\033[1;32m Building $(1)\033[0m\n" | |
API=16 | |
API64=21 | |
STL=libc++ | |
all: \ | |
toolchain/armeabi-v7a \ | |
toolchain/arm64-v8a \ | |
toolchain/x86 \ | |
toolchain/x86_64 | |
toolchain/armeabi-v7a: | |
@printf $(call NICE_PRINT,$@) 1>&2; | |
@${NDK_PATH}/build/tools/make_standalone_toolchain.py --stl ${STL} --arch arm --api ${API} --install-dir "toolchain/armeabi-v7a" | |
toolchain/arm64-v8a: | |
@printf $(call NICE_PRINT,$@) 1>&2; | |
@${NDK_PATH}/build/tools/make_standalone_toolchain.py --stl ${STL} --arch arm64 --api ${API64} --install-dir "toolchain/arm64-v8a" | |
toolchain/x86: | |
@printf $(call NICE_PRINT,$@) 1>&2; | |
@${NDK_PATH}/build/tools/make_standalone_toolchain.py --stl ${STL} --arch x86 --api ${API} --install-dir "toolchain/x86" | |
toolchain/x86_64: | |
@printf $(call NICE_PRINT,$@) 1>&2; | |
@${NDK_PATH}/build/tools/make_standalone_toolchain.py --stl ${STL} --arch x86_64 --api ${API64} --install-dir "toolchain/x86_64" | |
clean: | |
rm -rf toolchain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CURL_VER = 7.61.1 | |
SQLITE3_VER = 3250000 | |
LIBRESSL_VER = 2.8.0 | |
CURL_DIR = download/curl-${CURL_VER} | |
SQLITE3_DIR = download/sqlite3-${SQLITE3_VER} | |
LIBRESSL_DIR = download/libressl-${LIBRESSL_VER} | |
LIB_DIRS = \ | |
${CURL_DIR} \ | |
${SQLITE3_DIR} \ | |
${LIBRESSL_DIR} | |
# Downloading libs | |
${SQLITE3_DIR}: | |
rm -f download/sqlite3 | |
wget https://www.sqlite.org/2018/sqlite-autoconf-${SQLITE3_VER}.tar.gz | |
tar xzvf sqlite-autoconf-${SQLITE3_VER}.tar.gz | |
rm sqlite-autoconf-${SQLITE3_VER}.tar.gz | |
mv sqlite-autoconf-${SQLITE3_VER} ${SQLITE3_DIR} | |
download/sqlite3: | ${SQLITE3_DIR} | |
echo ${SQLITE3_VER} > download/sqlite3 | |
${LIBRESSL_DIR}: | |
rm -f download/libressl | |
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${LIBRESSL_VER}.tar.gz | |
tar xzvf libressl-${LIBRESSL_VER}.tar.gz | |
rm libressl-${LIBRESSL_VER}.tar.gz | |
mv libressl-${LIBRESSL_VER} ${LIBRESSL_DIR} | |
cd ${LIBRESSL_DIR} && patch -p0 < ../../patch/libressl.patch && aclocal && automake && autoconf | |
download/libressl: | ${LIBRESSL_DIR} | |
echo ${LIBRESSL_VER} > download/libressl | |
${CURL_DIR}: | |
rm -f download/curl | |
wget http://curl.haxx.se/download/curl-${CURL_VER}.tar.gz | |
tar xzvf curl-${CURL_VER}.tar.gz | |
rm curl-${CURL_VER}.tar.gz | |
mv curl-${CURL_VER} ${CURL_DIR} | |
download/curl: | ${CURL_DIR} | |
echo ${CURL_VER} > download/curl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NICE_PRINT = "\033[1;32m Building $(1)\033[0m\n" | |
XCODE_TOOLCHAIN = $(shell xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain | |
IOS_PLATFORM ?= iphoneos | |
IOS_SDK = $(shell xcrun -sdk ${IOS_PLATFORM} -show-sdk-path) | |
export PREFIX = ${CURDIR}/build/iOS/${ARCH} | |
LIBDIR = ${PREFIX}/lib | |
export CXX = ${XCODE_TOOLCHAIN}/usr/bin/clang++ | |
export CC = ${XCODE_TOOLCHAIN}/usr/bin/clang | |
export CFLAGS = -O3 -isysroot ${IOS_SDK} -I${IOS_SDK}/usr/include -arch ${ARCH} -miphoneos-version-min=8.0 -fembed-bitcode -fvisibility=hidden | |
export CXXFLAGS = ${CFLAGS} -std=c++14 -fno-aligned-allocation -stdlib=libc++ -I${PREFIX}/include | |
export LDFLAGS = -e _main -stdlib=libc++ -isysroot ${IOS_SDK} -L${LIBDIR} -L${IOS_SDK}/usr/lib -arch ${ARCH} -miphoneos-version-min=8.0 | |
HOST = arm-apple-darwin | |
LIBTOOLFLAGS = -arch_only ${ARCH} | |
ifeq ($(ARCH),$(filter $(ARCH),armv7 arm64)) | |
CXXFLAGS += -D__ARM_EABI__=1 | |
CFLAGS += -D__ARM_EABI__=1 | |
endif | |
# Build separate architectures | |
all: | |
mkdir -p download | |
@${MAKE} -f iOS.mk ios_arch ARCH=x86_64 IOS_PLATFORM=iphonesimulator | |
@${MAKE} -f iOS.mk ios_arch ARCH=armv7 IOS_PLATFORM=iphoneos >/dev/null | |
@${MAKE} -f iOS.mk ios_arch ARCH=arm64 IOS_PLATFORM=iphoneos >/dev/null | |
@${MAKE} -f iOS.mk ios_arch ARCH=i386 IOS_PLATFORM=iphonesimulator >/dev/null | |
ios_arch: status | ${LIBDIR}/libsqlite3.a ${LIBDIR}/libcurl.a | |
status: | |
@printf $(call NICE_PRINT,$(ARCH)) 1>&2; | |
include download.mk | |
## Only libs with different settings below | |
${LIBDIR}/libcurl.a: download/curl | |
@printf $(call NICE_PRINT,$@) 1>&2; | |
cd ${CURL_DIR} && \ | |
./configure --host=${HOST} --prefix=${PREFIX} --disable-shared --enable-ipv6 --with-darwinssl --enable-threaded-resolver && \ | |
${MAKE} clean && \ | |
${MAKE} -j8 install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -rupN ../libressl-orig/m4/check-os-options.m4 ./m4/check-os-options.m4 | |
--- ../libressl-orig/m4/check-os-options.m4 2018-03-24 17:29:25.000000000 +0300 | |
+++ ./m4/check-os-options.m4 2018-05-23 10:48:09.000000000 +0300 | |
@@ -76,6 +76,12 @@ char buf[1]; getentropy(buf, 1); | |
CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=600 -D__STRICT_ALIGNMENT" | |
AC_SUBST([PLATFORM_LDADD], ['-lpthread']) | |
;; | |
+ *android*) | |
+ HOST_OS=linux | |
+ HOST_ABI=elf | |
+ CPPFLAGS="$CPPFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE" | |
+ AC_SUBST([PLATFORM_LDADD], []) | |
+ ;; | |
*linux*) | |
HOST_OS=linux | |
HOST_ABI=elf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: ios android cleanup | |
include download.mk | |
ios: | |
@${MAKE} -f iOS.mk | |
android: android_toolchain | |
@${MAKE} -f Android.mk | |
android_toolchain: | |
@${MAKE} -f AndroidToolchain.mk | |
clean: | |
rm -rf build | |
clean_all: clean | |
rm -rf ${LIB_DIRS} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment