• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1ARCH = arm
2include $(SRC_PATH)build/arch.mk
3SHAREDLIBSUFFIX = so
4# Android APK/JARs expect libraries to be unversioned
5SHAREDLIBSUFFIXFULLVER=$(SHAREDLIBSUFFIX)
6SHAREDLIBSUFFIXMAJORVER=$(SHAREDLIBSUFFIX)
7SHLDFLAGS =
8NDKLEVEL = 12
9ifeq ($(ARCH), arm)
10  ifneq ($(APP_ABI), armeabi)
11    CFLAGS += -march=armv7-a -mfloat-abi=softfp
12    CFLAGS += -mfpu=vfpv3-d16
13    LDFLAGS += -march=armv7-a -Wl,--fix-cortex-a8
14    APP_ABI = armeabi-v7a
15  endif
16else ifeq ($(ARCH), arm64)
17  APP_ABI = arm64-v8a
18else ifeq ($(ARCH), x86)
19  APP_ABI = x86
20  ifeq (Yes, $(USE_ASM))
21    ASMFLAGS += -f elf
22  endif
23else ifeq ($(ARCH), x86_64)
24  APP_ABI = x86_64
25  ifeq (Yes, $(USE_ASM))
26    ASMFLAGS += -f elf64
27  endif
28else
29  APP_ABI = $(ARCH)
30endif
31
32ifndef NDKROOT
33$(error NDKROOT is not set)
34endif
35ifndef TARGET
36$(error TARGET is not set)
37endif
38
39TOOLCHAINPREFIX = $(shell NDK_PROJECT_PATH=$(SRC_PATH)/codec/build/android/dec make --no-print-dir -f $(NDKROOT)/build/core/build-local.mk DUMP_TOOLCHAIN_PREFIX APP_ABI=$(APP_ABI))
40TOOLCHAIN_NAME = $(shell NDK_TOOLCHAIN_VERSION= NDK_PROJECT_PATH=$(SRC_PATH)/codec/build/android/dec make --no-print-dir -f $(NDKROOT)/build/core/build-local.mk DUMP_TOOLCHAIN_NAME APP_ABI=$(APP_ABI))
41GCC_TOOLCHAIN_PATH = $(shell dirname $(TOOLCHAINPREFIX) | xargs dirname )
42
43SYSROOT = $(NDKROOT)/platforms/android-$(NDKLEVEL)/arch-$(ARCH)
44CXX = $(TOOLCHAINPREFIX)g++
45CC = $(TOOLCHAINPREFIX)gcc
46AR = $(TOOLCHAINPREFIX)ar
47CFLAGS += -DANDROID_NDK -fpic --sysroot=$(SYSROOT) -MMD -MP
48ifeq ($(USE_STACK_PROTECTOR), Yes)
49CFLAGS += -fstack-protector-all
50endif
51CFLAGS += -isystem $(NDKROOT)/sysroot/usr/include -isystem $(NDKROOT)/sysroot/usr/include/$(TOOLCHAIN_NAME) -D__ANDROID_API__=$(NDKLEVEL)
52CXXFLAGS += -fno-rtti -fno-exceptions
53LDFLAGS += --sysroot=$(SYSROOT)
54SHLDFLAGS = -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -Wl,-soname,lib$(PROJECT_NAME).so
55UTSHLDFLAGS = -Wl,-soname,libut.so
56
57ifeq ($(NDK_TOOLCHAIN_VERSION), clang)
58  HOST_OS = $(shell uname -s | tr [A-Z] [a-z])
59  LLVM_INSTALL_DIR = $(NDKROOT)/toolchains/llvm/prebuilt/$(HOST_OS)-x86_64/bin
60  CC = $(LLVM_INSTALL_DIR)/clang
61  CXX = $(LLVM_INSTALL_DIR)/clang++
62
63  ifeq ($(ARCH), arm)
64    TARGET_NAME = armv7-none-linux-androideabi
65  else ifeq ($(ARCH), arm64)
66    TARGET_NAME = aarch64-none-linux-android
67  else ifeq ($(ARCH), x86)
68    TARGET_NAME = i686-none-linux-android
69  else ifeq ($(ARCH), x86_64)
70    TARGET_NAME = x86_64-none-linux-android
71  else
72    $(error "does not support this arch now!")
73  endif
74
75  CFLAGS += -target $(TARGET_NAME)
76  LDFLAGS += -target $(TARGET_NAME) -gcc-toolchain $(GCC_TOOLCHAIN_PATH)
77endif
78
79# background reading: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#unwinding
80LDFLAGS += -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libunwind.a
81
82ifneq ($(findstring /,$(CXX)),$(findstring \,$(CXX)))
83ifneq ($(CXX),$(wildcard $(CXX)))
84ifneq ($(CXX).exe,$(wildcard $(CXX).exe))
85$(error Compiler not found, bad NDKROOT or ARCH?)
86endif
87endif
88endif
89
90ifeq ($(NDK_TOOLCHAIN_VERSION), clang)
91STL_INCLUDES = \
92    -I$(NDKROOT)/sources/cxx-stl/llvm-libc++/include \
93    -I$(NDKROOT)/sources/cxx-stl/llvm-libc++abi/include
94STL_LIB = \
95    $(NDKROOT)/sources/cxx-stl/llvm-libc++/libs/$(APP_ABI)/libc++_static.a
96else
97STL_INCLUDES = \
98    -I$(NDKROOT)/sources/cxx-stl/stlport/stlport
99STL_LIB = \
100    $(NDKROOT)/sources/cxx-stl/stlport/libs/$(APP_ABI)/libstlport_static.a
101endif
102
103GTEST_INCLUDES = $(STL_INCLUDES)
104CODEC_UNITTEST_INCLUDES = $(STL_INCLUDES)
105CODEC_UNITTEST_LDFLAGS_SUFFIX = $(STL_LIB)
106MODULE_INCLUDES = $(STL_INCLUDES)
107MODULE_LDFLAGS = $(STL_LIB)
108
109ifeq (./,$(SRC_PATH))
110binaries: decdemo encdemo
111
112decdemo: libraries
113	cd ./codec/build/android/dec && $(NDKROOT)/ndk-build -B NDK_TOOLCHAIN_VERSION=$(NDK_TOOLCHAIN_VERSION) APP_ABI=$(APP_ABI) APP_PLATFORM=$(TARGET) && android update project -t $(TARGET) -p . && ant debug
114
115encdemo: libraries
116	cd ./codec/build/android/enc && $(NDKROOT)/ndk-build -B NDK_TOOLCHAIN_VERSION=$(NDK_TOOLCHAIN_VERSION) APP_ABI=$(APP_ABI) APP_PLATFORM=$(TARGET) && android update project -t $(TARGET) -p . && ant debug
117
118clean_Android: clean_Android_dec clean_Android_enc
119
120clean_Android_dec:
121	-cd ./codec/build/android/dec && $(NDKROOT)/ndk-build APP_ABI=$(APP_ABI) clean && ant clean
122clean_Android_enc:
123	-cd ./codec/build/android/enc && $(NDKROOT)/ndk-build APP_ABI=$(APP_ABI) clean && ant clean
124else
125clean_Android:
126	@:
127endif
128
129COMMON_INCLUDES += -I$(NDKROOT)/sources/android/cpufeatures
130COMMON_OBJS += $(COMMON_SRCDIR)/src/cpu-features.$(OBJ)
131
132COMMON_CFLAGS += \
133	-Dandroid_getCpuIdArm=wels_getCpuIdArm -Dandroid_setCpuArm=wels_setCpuArm \
134	-Dandroid_getCpuCount=wels_getCpuCount -Dandroid_getCpuFamily=wels_getCpuFamily \
135	-Dandroid_getCpuFeatures=wels_getCpuFeatures -Dandroid_setCpu=wels_setCpu \
136
137codec/common/src/cpu-features.$(OBJ): $(NDKROOT)/sources/android/cpufeatures/cpu-features.c
138	$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) $(COMMON_CFLAGS) $(COMMON_INCLUDES) -c $(CXX_O) $<
139