shithub: openh264

Download patch

ref: d88e0899cedc9f06e71ea32d58f53421bcf069ae
parent: 241e9b775777a8dba2fa370f7fb73afd88aa6859
author: Guangwei <[email protected]>
date: Tue Oct 16 08:11:05 EDT 2018

add clang support for arm/arm64/x86/x86_64 when NDK version is greater then 17

--- a/build/platform-android.mk
+++ b/build/platform-android.mk
@@ -37,6 +37,8 @@
 endif
 
 TOOLCHAINPREFIX = $(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))
+TOOLCHAIN_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))
+GCC_TOOLCHAIN_PATH = $(shell dirname $(TOOLCHAINPREFIX) | xargs dirname )
 
 SYSROOT = $(NDKROOT)/platforms/android-$(NDKLEVEL)/arch-$(ARCH)
 CXX = $(TOOLCHAINPREFIX)g++
@@ -43,10 +45,34 @@
 CC = $(TOOLCHAINPREFIX)gcc
 AR = $(TOOLCHAINPREFIX)ar
 CFLAGS += -DANDROID_NDK -fpic --sysroot=$(SYSROOT) -MMD -MP
+CFLAGS += -isystem $(NDKROOT)/sysroot/usr/include -isystem $(NDKROOT)/sysroot/usr/include/$(TOOLCHAIN_NAME) -D__ANDROID_API__=$(NDKLEVEL)
 CXXFLAGS += -fno-rtti -fno-exceptions
 LDFLAGS += --sysroot=$(SYSROOT)
 SHLDFLAGS = -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -Wl,-soname,lib$(PROJECT_NAME).so
 
+ifeq ($(NDK_TOOLCHAIN_VERSION), clang)
+  HOST_OS = $(shell uname -s | tr [A-Z] [a-z])
+  LLVM_INSTALL_DIR = $(NDKROOT)/toolchains/llvm/prebuilt/$(HOST_OS)-x86_64/bin
+  CC = $(LLVM_INSTALL_DIR)/clang
+  CXX = $(LLVM_INSTALL_DIR)/clang++
+
+  ifeq ($(ARCH), arm)
+    TARGET_NAME = armv7-none-linux-androideabi
+  else ifeq ($(ARCH), arm64)
+    TARGET_NAME = aarch64-none-linux-android
+  else ifeq ($(ARCH), x86)
+    TARGET_NAME = i686-none-linux-android
+  else ifeq ($(ARCH), x86_64)
+    TARGET_NAME = x86_64-none-linux-android
+  else
+    $(error "does not support this arch now!")
+  endif
+
+  CFLAGS += -target $(TARGET_NAME)
+  LDFLAGS += -target $(TARGET_NAME) -gcc-toolchain $(GCC_TOOLCHAIN_PATH)
+  LDFLAGS += -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libunwind.a
+endif
+
 ifneq ($(CXX),$(wildcard $(CXX)))
 ifneq ($(CXX).exe,$(wildcard $(CXX).exe))
 $(error Compiler not found, bad NDKROOT or ARCH?)
@@ -68,10 +94,10 @@
 binaries: decdemo encdemo
 
 decdemo: libraries
-	cd ./codec/build/android/dec && $(NDKROOT)/ndk-build -B APP_ABI=$(APP_ABI) && android update project -t $(TARGET) -p . && ant debug
+	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
 
 encdemo: libraries
-	cd ./codec/build/android/enc && $(NDKROOT)/ndk-build -B APP_ABI=$(APP_ABI) && android update project -t $(TARGET) -p . && ant debug
+	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
 
 clean_Android: clean_Android_dec clean_Android_enc
 
--- a/codec/build/android/dec/jni/Application.mk
+++ b/codec/build/android/dec/jni/Application.mk
@@ -1,2 +1,6 @@
+ifeq ($(NDK_TOOLCHAIN_VERSION), clang)
+APP_STL := c++_shared
+else
 APP_STL := stlport_shared
+endif
 APP_PLATFORM := android-12
--- a/codec/build/android/enc/jni/Application.mk
+++ b/codec/build/android/enc/jni/Application.mk
@@ -1,2 +1,6 @@
+ifeq ($(NDK_TOOLCHAIN_VERSION), clang)
+APP_STL := c++_shared
+else
 APP_STL := stlport_shared
+endif
 APP_PLATFORM := android-12
--- a/codec/common/arm64/arm_arch64_common_macro.S
+++ b/codec/common/arm64/arm_arch64_common_macro.S
@@ -52,13 +52,17 @@
 .align 2
 .global \funcName
 .type \funcName, %function
+#ifndef __clang__
 .func \funcName
+#endif
 \funcName:
 .endm
 
 .macro WELS_ASM_AARCH64_FUNC_END
 ret
+#ifndef __clang__
 .endfunc
+#endif
 .endm
 
 #endif