1#
2## Cross-compile env for Android
3# Requires Android NDK >= r8
4# Requires the following env variables:
5#
6#    NDK_BASE         -  path to your NDK's root directory
7#                        e.g., /home/user/android-ndk
8#    OPENSSL_ANDROID  -  path to NDK built openssl
9#                        e.g., /home/user/src/openssl-android
10#
11
12# Android NDK setup
13NDK_COMPILER_VERSION=4.6
14NDK_ABI=arm
15NDK_BASE ?=  /usr/local/android-ndk
16#platform level >= 8 required for dladdr()
17NDK_PLATFORM_LEVEL ?= 8
18NDK_SYSROOT=$(NDK_BASE)/platforms/android-$(NDK_PLATFORM_LEVEL)/arch-arm
19NDK_UNAME=`uname -s | tr '[A-Z]' '[a-z]'`
20NDK_TOOLCHAIN=$(NDK_BASE)/toolchains/$(NDK_ABI)-linux-androideabi-$(NDK_COMPILER_VERSION)/prebuilt/$(NDK_UNAME)-x86
21
22# to use the real HOST tag, you need the latest libtool files:
23# http://stackoverflow.com/questions/4594736/configure-does-not-recognize-androideabi
24NDK_UNAME := `uname -s | tr '[A-Z]' '[a-z]'`
25HOST := arm-linux-androideabi
26
27LOCAL_LDFLAGS   = -L$(OPENSSL_ANDROID)/obj/local/armeabi/ -ldl -lcrypto -lssl -lz
28LOCAL_LDFLAGS += -L$(NDK_TOOLCHAIN)/lib/gcc/arm-linux-androideabi/$($NDK_COMPILER_VERSION) -lgcc
29CFLAGS = -I$(OPENSSL_ANDROID)/include
30CC := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-gcc --sysroot=$(NDK_SYSROOT)
31CXX := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-g++
32CPP := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-cpp
33LD := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-ld
34AR := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-ar
35RANLIB := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-ranlib
36STRIP := $(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-strip \
37
38all: $(OPENSSL_ANDROID)/libs/armeabi/libcrypto.so tlsdate-build
39
40$(OPENSSL_ANDROID)/libs/armeabi/libcrypto.so:
41	cd $(OPENSSL_ANDROID) && ndk-build -j4
42
43openssl-clean:
44	-cd $(OPENSSL_ANDROID) && ndk-build clean
45
46openssl-distclean:
47	-cd $(OPENSSL_ANDROID) && ndk-build distclean
48
49configure: configure.ac
50	./autogen.sh && \
51	CFLAGS="$(CFLAGS)" ./configure \
52			CC="$(CC)" \
53			AR=$(AR) \
54			RANLIB=$(RANLIB) \
55			CFLAGS="$(CFLAGS)" \
56			--disable-static \
57			--disable-languages \
58			--disable-dbus \
59			--host=$(HOST)
60			#--prefix=$(prefix) \
61			#--exec-prefix=$(prefix)
62
63tlsdate-build: configure
64	make -f Makefile CFLAGS="$(CFLAGS)" LDFLAGS="$(LOCAL_LDFLAGS)"
65
66tlsdate-clean:
67	-make -f Makefile clean
68
69tlsdate-distclean:
70	-make -f Makefile distclean && rm configure
71
72
73clean: openssl-clean tlsdate-clean
74distclean: openssl-distclean tlsdate-distclean
75
76.PHONY: clean openssl-clean tlsdate-clean
77