You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

108 line
3.5 KiB

  1. include ../common.mk
  2. DBG ?= 0
  3. SRCDIR = src
  4. OBJDIR = obj
  5. BORINGSSL_DIR = ../bssl/src
  6. MBEDTLS_DIR = ../mbedtls/src
  7. ## Debug/Release configuration
  8. ifeq ($(DBG),1)
  9. DEBUG = -DDEBUG -g -O0
  10. RELEASE =
  11. STRIP = true
  12. else
  13. DEBUG =
  14. RELEASE = -Os -fdata-sections -ffunction-sections
  15. STRIP = $(NDK)/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip
  16. endif
  17. ## NDK configuration.
  18. NDK = $(ANDROID_NDK)
  19. NDK_TARGETARCH = aarch64-linux-android
  20. NDK_TARGETSHORTARCH = arm64
  21. NDK_TOOLVER = 4.9
  22. NDK_HOSTARCH = linux-x86_64
  23. NDK_TOOLS = $(NDK)/toolchains/llvm/prebuilt/$(NDK_HOSTARCH)/bin
  24. NDK_SYSROOT = $(NDK)/sysroot
  25. NDK_TOOL = $(NDK_TOOLS)/clang
  26. NDK_LIBS = $(NDK)/toolchains/$(NDK_TARGETARCH)-$(NDK_TOOLVER)/prebuilt/linux-x86_64/lib/gcc/$(NDK_TARGETARCH)/4.9.x
  27. NDK_INCLUDES = -I$(NDK)/sysroot/usr/include \
  28. -I$(NDK)/sysroot/usr/include/$(NDK_TARGETARCH)
  29. NDK_SYSROOT = $(NDK)/platforms/android-$(NDK_TARGETVER)/arch-$(NDK_TARGETSHORTARCH)
  30. OPT = $(DEBUG) \
  31. $(RELEASE) \
  32. -std=c99 \
  33. -fPIE \
  34. -Wall \
  35. -target $(NDK_TARGETARCH)
  36. CFLAGS = $(OPT) \
  37. $(NDK_INCLUDES)
  38. CFLAGS_BORINGSSL = $(CFLAGS) \
  39. -I$(BORINGSSL_DIR) -I$(BORINGSSL_DIR)/include
  40. CFLAGS_MBEDTLS = $(CFLAGS) \
  41. -I$(MBEDTLS_DIR)/include
  42. LDFLAGS = $(OPT) \
  43. $(DEBUG) $(RELEASE) \
  44. -pie \
  45. --sysroot=$(NDK_SYSROOT) \
  46. -B $(ANDROID_NDK)/toolchains/$(NDK_TARGETARCH)-$(NDK_TOOLVER)/prebuilt/linux-x86_64/$(NDK_TARGETARCH)/bin \
  47. -L$(NDK_LIBS) \
  48. -Wl,--gc-sections
  49. LDFLAGS_BORINGSSL = $(LDFLAGS) \
  50. -L$(BORINGSSL_DIR)/build/crypto -L$(BORINGSSL_DIR)/build/ssl \
  51. -lssl -lcrypto
  52. LDFLAGS_MBEDTLS = $(LDFLAGS) \
  53. -L$(MBEDTLS_DIR)/library -lmbedx509 -lmbedtls -lmbedcrypto
  54. .PHONY: print_boring_ld print_mbed_ld
  55. all: init b_client m_client server
  56. init:
  57. mkdir -p $(OBJDIR)
  58. # Create 1MB file with random data
  59. dd if=/dev/urandom of=etc/random_data bs=1024 count=1024
  60. clean:
  61. rm -rf $(OBJDIR)
  62. rm -rf b_client
  63. rm -rf m_client
  64. rm -rf server
  65. b_client: common
  66. $(NDK_TOOL) -c $(SRCDIR)/b_client.c -o $(OBJDIR)/b_client.o $(CFLAGS_BORINGSSL)
  67. $(NDK_TOOL) -o b_client $(OBJDIR)/b_client.o $(OBJDIR)/common.o $(OBJDIR)/common_boring.o $(LDFLAGS_BORINGSSL)
  68. $(STRIP) -s b_client
  69. m_client: common
  70. $(NDK_TOOL) -c $(SRCDIR)/m_client.c -o $(OBJDIR)/m_client.o $(CFLAGS_MBEDTLS)
  71. $(NDK_TOOL) -o m_client $(OBJDIR)/m_client.o $(OBJDIR)/common.o $(LDFLAGS_MBEDTLS)
  72. $(STRIP) -s m_client
  73. server: common
  74. $(NDK_TOOL) -c $(SRCDIR)/server.c -o $(OBJDIR)/server.o $(CFLAGS_BORINGSSL)
  75. $(NDK_TOOL) -o server $(OBJDIR)/server.o $(OBJDIR)/common.o $(OBJDIR)/common_boring.o $(LDFLAGS_BORINGSSL)
  76. $(STRIP) -s server
  77. common:
  78. $(NDK_TOOL) -c $(SRCDIR)/common.c -o $(OBJDIR)/common.o $(CFLAGS)
  79. $(NDK_TOOL) -c $(SRCDIR)/common_boring.c -o $(OBJDIR)/common_boring.o $(CFLAGS_BORINGSSL)
  80. adb-prepare:
  81. adb root
  82. adb remount
  83. adb shell rm -rf /data/app/test_space/*
  84. adb shell mkdir -p /data/app/test_space/etc
  85. # Need to reset date to 10th of April this year, otherwise, cert verification fails
  86. adb shell "toybox date 041910002018"
  87. push: adb-prepare
  88. adb push b_client /data/app/test_space/
  89. adb push m_client /data/app/test_space/
  90. adb push server /data/app/test_space/
  91. adb push etc/* /data/app/test_space/etc/