ifeq ($(NDK_TOOLCHAIN),)
$(error Must export standalone NDK_TOOLCHAIN location before building for Android - use NDK's build/tools/make-standalone-toolchain.sh to build)
endif
NDK_ROOT:=$(NDK_TOOLCHAIN)

CROSS_SYSROOT:=$(NDK_TOOLCHAIN)/sysroot
CROSS_PREFIX24:=$(NDK_TOOLCHAIN)/bin/armv7a-linux-androideabi24-
CROSS_PREFIX:=$(NDK_TOOLCHAIN)/bin/arm-linux-androideabi-

CXX:=$(CROSS_PREFIX24)clang++
CC:=$(CROSS_PREFIX24)clang
AR:=$(CROSS_PREFIX)ar
AS:=$(CROSS_PREFIX)as
LD:=$(CROSS_PREFIX)ld
NM:=$(CROSS_PREFIX)nm
OBJCOPY:=$(CROSS_PREFIX)objcopy
OBJDUMP:=$(CROSS_PREFIX)objdump
RANLIB:=$(CROSS_PREFIX)ranlib
STRIP:=$(CROSS_PREFIX)strip


COMMON_FLAGS=-ggdb -DFB_SEND_FLAGS=MSG_NOSIGNAL -DLINUX -DANDROID -DARM -pipe -MMD -fPIC -fmessage-length=0 \
			 -I$(ROOT)/extern/libtommath --sysroot=$(CROSS_SYSROOT) \
			 -I$(CROSS_SYSROOT)/usr/include -I$(ROOT)/gen/cross -fsigned-char \
			 -Wno-inline-new-delete

OPTIMIZE_FLAGS=-fno-omit-frame-pointer
WARN_FLAGS=-Wall -Wno-switch -Wno-parentheses -Wno-unknown-pragmas -Wno-unused-variable

PROD_FLAGS=$(COMMON_FLAGS) $(OPTIMIZE_FLAGS)
DEV_FLAGS=$(COMMON_FLAGS) $(WARN_FLAGS)

CXXFLAGS=-std=gnu++03

CROSS_CONFIG=android.arme

LDFLAGS += --sysroot=$(CROSS_PLATFORM) -static-libstdc++
DroidLibs := -lm -ldl

LINK_LIBS = $(DroidLibs)
STATICLINK_LIBS = $(DroidLibs)
SO_LINK_LIBS = $(DroidLibs)

EXE_LINK_OPTIONS= $(LDFLAGS) $(UNDEF_FLAGS) $(LIB_PATH_OPTS) $(LINK_EMPTY_SYMBOLS) -pie
LIB_LINK_OPTIONS= $(LDFLAGS) -shared

UNICODE_DIR := $(shell dirname `find /usr/include -name ucnv.h`)
UNICODE_DIR := $(filter %unicode, $(UNICODE_DIR))
UNICODE_DIR := $(firstword $(UNICODE_DIR))
ifndef UNICODE_DIR
	$(error ERROR while locating ICU include directory, probably missing ucnv.h)
endif

.PHONY:	prerequisites
prerequisites: $(ROOT)/gen/cross/unicode

$(ROOT)/gen/cross/unicode:
	echo $(UNICODE_DIR)
	rm -rf $(ROOT)/gen/cross
	mkdir $(ROOT)/gen/cross
	ln -s $(UNICODE_DIR) cross/unicode
