From adb9a193672fa7970969a5fae44ca40cd78bf3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=A3=D8=AD=D9=85=D8=AF=20=D8=A7=D9=84=D9=85=D8=AD=D9=85?= =?UTF-8?q?=D9=88=D8=AF=D9=8A=20=28Ahmed=20El-Mahmoudy=29?= Date: Mon, 27 Apr 2015 17:58:57 +0200 Subject: [PATCH 1/5] Add support for variable arch builds to support mips & 64-bit archs --- external/Makefile | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/external/Makefile b/external/Makefile index b9cd7352..9a31f4fe 100644 --- a/external/Makefile +++ b/external/Makefile @@ -24,17 +24,37 @@ endif # Android NDK setup NDK_BASE ?= /opt/android-ndk NDK_PLATFORM_LEVEL ?= 16 -NDK_ABI ?= arm NDK_TOOLCHAIN_VERSION=4.8 APP_ABI ?= armeabi + +NDK_ABI := $(APP_ABI) +ifneq ($(filter arm%, $(APP_ABI)),) + NDK_ABI := arm +endif +ifneq ($(filter arm64%, $(APP_ABI)),) + NDK_ABI := arm64 +endif NDK_SYSROOT=$(NDK_BASE)/platforms/android-$(NDK_PLATFORM_LEVEL)/arch-$(NDK_ABI) NDK_UNAME := $(shell uname -s | tr '[A-Z]' '[a-z]') -ifeq ($(NDK_ABI),x86) - HOST = i686-linux-android - NDK_TOOLCHAIN = $(NDK_ABI)-$(NDK_TOOLCHAIN_VERSION) -else - HOST = $(NDK_ABI)-linux-androideabi - NDK_TOOLCHAIN = $(HOST)-$(NDK_TOOLCHAIN_VERSION) +ifneq ($(filter mips%, $(NDK_ABI)),) + HOST := $(NDK_ABI)el-linux-android +endif +ifneq ($(filter arm64, $(NDK_ABI)),) + HOST := aarch64-linux-android +endif +ifneq ($(filter arm, $(NDK_ABI)),) + HOST := arm-linux-androideabi +endif +ifneq ($(filter x86, $(NDK_ABI)),) + HOST := i686-linux-android +endif +ifneq ($(filter x86_64, $(NDK_ABI)),) + HOST := x86_64-linux-android +endif + +NDK_TOOLCHAIN := $(HOST)-$(NDK_TOOLCHAIN_VERSION) +ifneq ($(filter x86%, $(NDK_ABI)),) + NDK_TOOLCHAIN := $(NDK_ABI)-$(NDK_TOOLCHAIN_VERSION) endif NDK_TOOLCHAIN_BASE=$(NDK_BASE)/toolchains/$(NDK_TOOLCHAIN)/prebuilt/$(NDK_UNAME)-$(NDK_PROCESSOR) From ebe85e55bced81db0ce6f27d2f2f6c952a74b60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=A3=D8=AD=D9=85=D8=AF=20=D8=A7=D9=84=D9=85=D8=AD=D9=85?= =?UTF-8?q?=D9=88=D8=AF=D9=8A=20=28Ahmed=20El-Mahmoudy=29?= Date: Tue, 28 Apr 2015 17:13:06 +0200 Subject: [PATCH 2/5] Add iptables-clean prerequisite to clean target --- external/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Makefile b/external/Makefile index 9a31f4fe..90e80e22 100644 --- a/external/Makefile +++ b/external/Makefile @@ -298,7 +298,7 @@ assets-clean: # cleanup, cleanup, put the toys away ##clean: openssl-clean libevent-clean tor-clean polipo-clean jtorctl-clean assets-clean -clean: openssl-clean libevent-clean tor-clean polipo-clean jtorctl-clean assets-clean +clean: openssl-clean libevent-clean tor-clean polipo-clean iptables-clean jtorctl-clean assets-clean #------------------------------------------------------------------------------# # debugging stuff From 81a945e6326f32b47895cf71db595736ce934f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=A3=D8=AD=D9=85=D8=AF=20=D8=A7=D9=84=D9=85=D8=AD=D9=85?= =?UTF-8?q?=D9=88=D8=AF=D9=8A=20=28Ahmed=20El-Mahmoudy=29?= Date: Wed, 29 Apr 2015 15:29:28 +0200 Subject: [PATCH 3/5] Patch libevent to compile for 64-bit archs. --- external/Makefile | 3 +++ external/libevent-patch-1 | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 external/libevent-patch-1 diff --git a/external/Makefile b/external/Makefile index 90e80e22..d9a34431 100644 --- a/external/Makefile +++ b/external/Makefile @@ -132,6 +132,9 @@ openssl-clean: libevent/Makefile: sed -i 's@\(SUBDIRS = . include\) sample test@\1@' libevent/Makefile.am + cp libevent-patch-1 libevent + -cd libevent && \ + patch -N -p1 --reject-file=- < libevent-patch-1 ##sed -i 's@\(AC_OUTPUT(Makefile include/Makefile\) test/Makefile sample/Makefile)@\1)@' libevent/configure.in cd libevent && ./autogen.sh cp config.sub libevent diff --git a/external/libevent-patch-1 b/external/libevent-patch-1 new file mode 100644 index 00000000..babcf9e5 --- /dev/null +++ b/external/libevent-patch-1 @@ -0,0 +1,29 @@ +For some reason arc4random_addrandom isn't present in 64-bit android archs. ! + +diff --git a/configure.ac b/configure.ac +index d42edd8..c511be7 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -290,7 +290,7 @@ AC_HEADER_TIME + + dnl Checks for library functions. + AC_CHECK_FUNCS([gettimeofday vasprintf fcntl clock_gettime strtok_r strsep]) +-AC_CHECK_FUNCS([getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random arc4random_buf issetugid geteuid getegid getprotobynumber setenv unsetenv putenv sysctl]) ++AC_CHECK_FUNCS([getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random arc4random_buf arc4random_addrandom issetugid geteuid getegid getprotobynumber setenv unsetenv putenv sysctl]) + AC_CHECK_FUNCS([umask]) + + AC_CACHE_CHECK( +diff --git a/evutil_rand.c b/evutil_rand.c +index 284341c..97161e4 100644 +--- a/evutil_rand.c ++++ b/evutil_rand.c +@@ -174,7 +174,9 @@ evutil_secure_rng_get_bytes(void *buf, size_t n) + void + evutil_secure_rng_add_bytes(const char *buf, size_t n) + { ++#ifdef _EVENT_HAVE_ARC4RANDOM_ADDRANDOM + arc4random_addrandom((unsigned char*)buf, + n>(size_t)INT_MAX ? INT_MAX : (int)n); ++#endif + } + From 8d7c32c84b94d242f86ed09d60a5064d4b868c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=A3=D8=AD=D9=85=D8=AF=20=D8=A7=D9=84=D9=85=D8=AD=D9=85?= =?UTF-8?q?=D9=88=D8=AF=D9=8A=20=28Ahmed=20El-Mahmoudy=29?= Date: Wed, 29 Apr 2015 16:08:02 +0200 Subject: [PATCH 4/5] Update OpenSSL to 1.0.2a Also, disable rc4 cipher for 64-bit archs, to avoid this link error for tor: external/lib/libcrypto.a(e_rc4_hmac_md5.o):e_rc4_hmac_md5.c:function rc4_hmac_md5_cipher: error: undefined reference to 'rc4_md5_enc' --- external/Makefile | 13 +++++++++++-- external/openssl | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/external/Makefile b/external/Makefile index d9a34431..f499ff50 100644 --- a/external/Makefile +++ b/external/Makefile @@ -97,16 +97,25 @@ all: assets #------------------------------------------------------------------------------# # openssl +# Disable rc4 cipher for 64-bit archs, to avoid this link error for tor: +# external/lib/libcrypto.a(e_rc4_hmac_md5.o):e_rc4_hmac_md5.c:function rc4_hmac_md5_cipher: error: undefined reference to 'rc4_md5_enc' +OPENSSL_CONF_FLAG= +ifneq ($(findstring 64, $(NDK_ABI)),) + OPENSSL_CONF_FLAG=no-rc4 +endif + lib/libcrypto.a: cd openssl && \ - ./Configure android -DL_ENDIAN && \ + ./Configure android -DL_ENDIAN $(OPENSSL_CONF_FLAG) && \ + make CC="$(CC)" ANDROID_DEV=$(NDK_SYSROOT)/usr depend && \ make CC="$(CC)" ANDROID_DEV=$(NDK_SYSROOT)/usr build_libs lib/libssl.a: cp config.sub openssl cp config.guess openssl cd openssl && \ - ./Configure android -DL_ENDIAN && \ + ./Configure android -DL_ENDIAN $(OPENSSL_CONF_FLAG) && \ + make CC="$(CC)" ANDROID_DEV=$(NDK_SYSROOT)/usr depend && \ make CC="$(CC)" ANDROID_DEV=$(NDK_SYSROOT)/usr build_libs openssl-build-stamp: lib/libcrypto.a lib/libssl.a diff --git a/external/openssl b/external/openssl index 2b456034..3df69d3a 160000 --- a/external/openssl +++ b/external/openssl @@ -1 +1 @@ -Subproject commit 2b456034457b58454aae3998a2765b6a5b9bc837 +Subproject commit 3df69d3aefde7671053d4e3c242b228e5d79c83f From d5e937d2a0d1ab07cdff1f10ee375181d7d9478a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=A3=D8=AD=D9=85=D8=AF=20=D8=A7=D9=84=D9=85=D8=AD=D9=85?= =?UTF-8?q?=D9=88=D8=AF=D9=8A=20=28Ahmed=20El-Mahmoudy=29?= Date: Wed, 29 Apr 2015 22:57:13 +0200 Subject: [PATCH 5/5] Fix build for mips* archs. OpenSSL's 'make depend' fails if _MIPS_SZLONG is not set --- external/Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/external/Makefile b/external/Makefile index f499ff50..22af090c 100644 --- a/external/Makefile +++ b/external/Makefile @@ -101,7 +101,16 @@ all: assets # external/lib/libcrypto.a(e_rc4_hmac_md5.o):e_rc4_hmac_md5.c:function rc4_hmac_md5_cipher: error: undefined reference to 'rc4_md5_enc' OPENSSL_CONF_FLAG= ifneq ($(findstring 64, $(NDK_ABI)),) - OPENSSL_CONF_FLAG=no-rc4 + OPENSSL_CONF_FLAG+=no-rc4 +endif + +# OpenSSL's 'make depend' fails if _MIPS_SZLONG is not set: +ifneq ($(filter mips%, $(NDK_ABI)),) + ifneq ($(findstring 64, $(NDK_ABI)),) + OPENSSL_CONF_FLAG+=-D_MIPS_SZLONG=64 + else + OPENSSL_CONF_FLAG+=-D_MIPS_SZLONG=32 + endif endif lib/libcrypto.a: