Ticket #10303: 0003-update-native-build-to-include-Android-NDK-build-fla.patch

File 0003-update-native-build-to-include-Android-NDK-build-fla.patch, 6.1 KB (added by hans, 7 years ago)

apply patches with 'git am /path/to/000*.patch'

  • external/Makefile

    From ca8197fa5b2dc22f538943482849b9ee90a1b808 Mon Sep 17 00:00:00 2001
    From: Hans-Christoph Steiner <hans@eds.org>
    Date: Thu, 5 Dec 2013 19:28:54 -0500
    Subject: [PATCH 3/3] update native build to include Android NDK build flags
    
    This updates external/Makefile to be more integrated into the Android NDK,
    by using the same variable names and including build flags from the NDK.
    ---
     external/Makefile |  122 +++++++++++++++++++++++++++++++++--------------------
     1 file changed, 77 insertions(+), 45 deletions(-)
    
    diff --git a/external/Makefile b/external/Makefile
    index 6ecc3f6..b6771a4 100644
    a b  
    55# on Debian or Ubuntu
    66
    77### these modify the calling shell
    8 # point pkg-config to the .pc files generated from these builds
    9 export PKG_CONFIG_PATH=$(LOCAL)/lib/pkgconfig
    108# workaround for cross-compiling bug in autoconf
    119export ac_cv_func_malloc_0_nonnull=yes
    1210export ac_cv_func_setpgrp_void=yes
    1311
    14 CWD = $(shell pwd)
    15 PROJECT_ROOT = $(CWD)/..
    16 EXTERNAL_ROOT = $(CWD)
    17 
    18 # Android NDK setup:
    19 NDK_BASE ?= /usr/local/android-ndk
    20 NDK_PLATFORM_LEVEL ?= 8
    21 NDK_TOOLCHAIN_VERSION=4.6
    22 NDK_SYSROOT=$(NDK_BASE)/platforms/android-$(NDK_PLATFORM_LEVEL)/arch-arm
    23 NDK_UNAME:=`uname -s | tr '[A-Z]' '[a-z]'`
    24 NDK_PROCESSOR:=`uname -m`
    25 
    26 #NDK_TOOLCHAIN=$(NDK_BASE)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$(NDK_UNAME)-$(NDK_PROCESSOR)
    27 NDK_TOOLCHAIN=$(NDK_BASE)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(NDK_UNAME)-$(NDK_PROCESSOR)
    28 
    29 # to use the real HOST tag, you need the latest libtool files:
    30 # http://stackoverflow.com/questions/4594736/configure-does-not-recognize-androideabi
    31 #HOST := arm-none-linux-gnueabi
    32 HOST := arm-linux-androideabi
    33 
    34 # install root for built files
    35 DESTDIR = $(EXTERNAL_ROOT)
    36 # TODO try adding the Android-style /data/app.name here
    37 prefix =
    38 LOCAL := $(DESTDIR)$(prefix)
    39 
    40 export PATH := ${PATH}:$(NDK_TOOLCHAIN)/bin:$(LOCAL)/bin
    41 
    42 CC := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-gcc --sysroot=$(NDK_SYSROOT)
    43 CXX := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-g++
    44 CPP := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-cpp
    45 LD := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-ld
    46 AR := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-ar
    47 RANLIB := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-ranlib
    48 STRIP := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-strip \
     12EXTERNAL_ROOT := $(shell pwd)
     13
     14# Android now has 64-bit and 32-bit versions of the NDK for GNU/Linux.  We
     15# assume that the build platform uses the appropriate version, otherwise the
     16# user building this will have to manually set NDK_PROCESSOR or NDK_TOOLCHAIN.
     17CPU := $(shell uname -m)
     18ifeq ($(CPU),x86_64)
     19 NDK_PROCESSOR=x86_64
     20else
     21 NDK_PROCESSOR=x86
     22endif
     23
     24# Android NDK setup
     25NDK_BASE ?= /opt/android-ndk
     26NDK_ABI=arm
     27APP_ABI=armeabi
     28# NDK platform level, aka APP_PLATFORM, is equivalent to minSdkVersion
     29APP_PLATFORM := android-$(shell sed -n 's,.*android:minSdkVersion="\([0-9][0-9]*\)".*,\1,p' \
     30        $(EXTERNAL_ROOT)/../AndroidManifest.xml)
     31NDK_SYSROOT=$(NDK_BASE)/platforms/$(APP_PLATFORM)/arch-$(NDK_ABI)
     32NDK_TOOLCHAIN_VERSION=4.7
     33NDK_UNAME := $(shell uname -s | tr '[A-Z]' '[a-z]')
     34ifeq ($(NDK_ABI),x86)
     35 HOST = i686-linux-android
     36 NDK_TOOLCHAIN = $(NDK_ABI)-$(NDK_TOOLCHAIN_VERSION)
     37else
     38 HOST = $(NDK_ABI)-linux-androideabi
     39 NDK_TOOLCHAIN = $(HOST)-$(NDK_TOOLCHAIN_VERSION)
     40endif
     41NDK_TOOLCHAIN_BASE=$(NDK_BASE)/toolchains/$(NDK_TOOLCHAIN)/prebuilt/$(NDK_UNAME)-$(NDK_PROCESSOR)
     42
     43# include Android's build flags
     44TARGET_ARCH_ABI = $(APP_ABI)
     45include $(NDK_BASE)/toolchains/$(NDK_TOOLCHAIN)/setup.mk
     46
     47CC := $(NDK_TOOLCHAIN_BASE)/bin/$(HOST)-gcc --sysroot=$(NDK_SYSROOT)
     48CXX := $(NDK_TOOLCHAIN_BASE)/bin/$(HOST)-g++
     49CPP := $(NDK_TOOLCHAIN_BASE)/bin/$(HOST)-cpp
     50LD := $(NDK_TOOLCHAIN_BASE)/bin/$(HOST)-ld
     51AR := $(NDK_TOOLCHAIN_BASE)/bin/$(HOST)-ar
     52RANLIB := $(NDK_TOOLCHAIN_BASE)/bin/$(HOST)-ranlib
     53STRIP := $(NDK_TOOLCHAIN_BASE)/bin/$(HOST)-strip \
    4954        --strip-unneeded -R .note -R .comment
    5055
    51 CFLAGS = -DANDROID -I$(LOCAL) -I$(LOCAL)/include -I$(NDK_SYSROOT)/usr/include
    52 LDFLAGS = -L$(LOCAL) -L$(LOCAL)/lib -L$(NDK_SYSROOT)/usr/lib
    53 
    54 # build as small as possible, mostly useful for static binaries
    55 CFLAGS += -fdata-sections -ffunction-sections -Os
    56 LDFLAGS += -Wl,--gc-sections
     56CFLAGS = -DANDROID $(TARGET_CFLAGS)
     57LDFLAGS = -llog $(TARGET_LDFLAGS)
     58
     59# change 'release' to 'debug' for unoptimized debug builds
     60ifeq ($(APP_ABI),armeabi-v7a)
     61        CFLAGS += $(TARGET_arm_release_CFLAGS)
     62endif
     63ifeq ($(APP_ABI),armeabi)
     64        CFLAGS += $(TARGET_thumb_release_CFLAGS)
     65endif
     66
     67.PHONY = clean showsetup \
     68        assets assets-clean \
     69        openssl-static openssl-static-clean \
     70        libevent libevent-clean \
     71        iptables iptables-clean \
     72        tor tor-clean \
     73        obfsproxy obfsproxy-clean \
     74        privoxy privoxy-clean
    5775
    5876all: assets
    5977
    tor/Makefile: tor/configure 
    158176                        LIBS="-L$(EXTERNAL_ROOT)/lib" CFLAGS="-I$(EXTERNAL_ROOT)/include -I$(EXTERNAL_ROOT)/include/event2" \
    159177                        ./configure \
    160178                                --host=$(HOST) \
    161                                 --prefix=$(NDK_TOOLCHAIN) \
    162179                                --disable-asciidoc \
    163180                                --enable-static-libevent --with-libevent-dir=$(EXTERNAL_ROOT) \
    164181                                --enable-static-openssl --with-openssl-dir=$(EXTERNAL_ROOT) \
    obfsproxy/Makefile: 
    197214                        libcrypto_LIBS="-L$(EXTERNAL_ROOT)/lib -lcrypto" libcrypto_CFLAGS="-I$(EXTERNAL_ROOT)/include" \
    198215                        ./configure \
    199216                                --host=$(HOST) \
    200                                 --prefix=$(NDK_TOOLCHAIN) \
    201217
    202218obfsproxy-build-stamp: obfsproxy/Makefile
    203219        $(MAKE) -C obfsproxy
    assets-clean: 
    319335# cleanup, cleanup, put the toys away
    320336
    321337clean: openssl-static-clean libevent-clean tor-clean privoxy-clean jtorctl-clean assets-clean
     338
     339
     340#------------------------------------------------------------------------------#
     341# debugging stuff
     342
     343showsetup:
     344        @echo "NDK_TOOLCHAIN_VERSION: $(NDK_TOOLCHAIN_VERSION)"
     345        @echo "NDK_TOOLCHAIN: $(NDK_TOOLCHAIN)"
     346        @echo "NDK_SYSROOT: $(NDK_SYSROOT)"
     347        @echo "APP_PLATFORM: $(APP_PLATFORM)"
     348        @echo "APP_ABI: $(APP_ABI)"
     349        @echo "HOST: $(HOST)"
     350        @echo "CC: $(CC)"
     351        @echo "LD: $(LD)"
     352        @echo "CFLAGS: $(CFLAGS)"
     353        @echo "LDFLAGS: $(LDFLAGS)"