include ../common.mk DBG ?= 0 SRCDIR = src OBJDIR = obj BORINGSSL_DIR = ../bssl/src MBEDTLS_DIR = ../mbedtls/src ## Debug/Release configuration ifeq ($(DBG),1) DEBUG = -DDEBUG -g -O0 RELEASE = STRIP = true else DEBUG = RELEASE = -Os -fdata-sections -ffunction-sections STRIP = $(NDK)/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip endif ## NDK configuration. NDK = $(ANDROID_NDK) NDK_TARGETARCH = aarch64-linux-android NDK_TARGETSHORTARCH = arm64 NDK_TOOLVER = 4.9 NDK_HOSTARCH = linux-x86_64 NDK_TOOLS = $(NDK)/toolchains/llvm/prebuilt/$(NDK_HOSTARCH)/bin NDK_SYSROOT = $(NDK)/sysroot NDK_TOOL = $(NDK_TOOLS)/clang NDK_LIBS = $(NDK)/toolchains/$(NDK_TARGETARCH)-$(NDK_TOOLVER)/prebuilt/linux-x86_64/lib/gcc/$(NDK_TARGETARCH)/4.9.x NDK_INCLUDES = -I$(NDK)/sysroot/usr/include \ -I$(NDK)/sysroot/usr/include/$(NDK_TARGETARCH) NDK_SYSROOT = $(NDK)/platforms/android-$(NDK_TARGETVER)/arch-$(NDK_TARGETSHORTARCH) OPT = $(DEBUG) \ $(RELEASE) \ -std=c99 \ -fPIE \ -Wall \ -target $(NDK_TARGETARCH) CFLAGS = $(OPT) \ $(NDK_INCLUDES) CFLAGS_BORINGSSL = $(CFLAGS) \ -I$(BORINGSSL_DIR) -I$(BORINGSSL_DIR)/include CFLAGS_MBEDTLS = $(CFLAGS) \ -I$(MBEDTLS_DIR)/include LDFLAGS = $(OPT) \ $(DEBUG) $(RELEASE) \ -pie \ --sysroot=$(NDK_SYSROOT) \ -B $(ANDROID_NDK)/toolchains/$(NDK_TARGETARCH)-$(NDK_TOOLVER)/prebuilt/linux-x86_64/$(NDK_TARGETARCH)/bin \ -L$(NDK_LIBS) \ -Wl,--gc-sections LDFLAGS_BORINGSSL = $(LDFLAGS) \ -L$(BORINGSSL_DIR)/build/crypto -L$(BORINGSSL_DIR)/build/ssl \ -lssl -lcrypto LDFLAGS_MBEDTLS = $(LDFLAGS) \ -L$(MBEDTLS_DIR)/library -lmbedx509 -lmbedtls -lmbedcrypto .PHONY: print_boring_ld print_mbed_ld all: init b_client m_client server init: mkdir -p $(OBJDIR) # Create 1MB file with random data dd if=/dev/urandom of=etc/random_data bs=1024 count=1024 clean: rm -rf $(OBJDIR) rm -rf b_client rm -rf m_client rm -rf server b_client: common $(NDK_TOOL) -c $(SRCDIR)/b_client.c -o $(OBJDIR)/b_client.o $(CFLAGS_BORINGSSL) $(NDK_TOOL) -o b_client $(OBJDIR)/b_client.o $(OBJDIR)/common.o $(OBJDIR)/common_boring.o $(LDFLAGS_BORINGSSL) $(STRIP) -s b_client m_client: common $(NDK_TOOL) -c $(SRCDIR)/m_client.c -o $(OBJDIR)/m_client.o $(CFLAGS_MBEDTLS) $(NDK_TOOL) -o m_client $(OBJDIR)/m_client.o $(OBJDIR)/common.o $(LDFLAGS_MBEDTLS) $(STRIP) -s m_client server: common $(NDK_TOOL) -c $(SRCDIR)/server.c -o $(OBJDIR)/server.o $(CFLAGS_BORINGSSL) $(NDK_TOOL) -o server $(OBJDIR)/server.o $(OBJDIR)/common.o $(OBJDIR)/common_boring.o $(LDFLAGS_BORINGSSL) $(STRIP) -s server common: $(NDK_TOOL) -c $(SRCDIR)/common.c -o $(OBJDIR)/common.o $(CFLAGS) $(NDK_TOOL) -c $(SRCDIR)/common_boring.c -o $(OBJDIR)/common_boring.o $(CFLAGS_BORINGSSL) adb-prepare: adb root adb remount adb shell rm -rf /data/app/test_space/* adb shell mkdir -p /data/app/test_space/etc # Need to reset date to 10th of April this year, otherwise, cert verification fails adb shell "toybox date 041910002018" push: adb-prepare adb push b_client /data/app/test_space/ adb push m_client /data/app/test_space/ adb push server /data/app/test_space/ adb push etc/* /data/app/test_space/etc/