Skip to content

Commit

Permalink
pick up PR#3261 (#3599)
Browse files Browse the repository at this point in the history
1. switch from ant to gradle
2. use clang as the default toolchain
Co-authored-by: alexcohn <[email protected]>
  • Loading branch information
GuangweiWang authored Dec 27, 2022
1 parent c4156d5 commit b16f0c2
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ codec/build/iOS/dec/welsdec/build/
# editor files
*~

# android gradle integration – regenerated when the project is opened in Android Studio
/.idea/
/.gradle/
/gradle/
/gradlew.bat
/local.properties
30 changes: 30 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}

allprojects {
repositories {
google()
jcenter()
}
}

apply plugin: 'idea'

idea.module {
excludeDirs -= file("build")
excludeDirs += file(".idea")
excludeDirs += file("gradle")
sourceDirs += file("build")
sourceDirs += file("codec")
testSourceDirs += file("test")
testSourceDirs += file("autotest")
resourceDirs += file("res")
resourceDirs += file("docs")
}
82 changes: 40 additions & 42 deletions build/platform-android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ SHAREDLIBSUFFIX = so
SHAREDLIBSUFFIXFULLVER=$(SHAREDLIBSUFFIX)
SHAREDLIBSUFFIXMAJORVER=$(SHAREDLIBSUFFIX)
SHLDFLAGS =
NDKLEVEL = 12

NDK_TOOLCHAIN_VERSION = clang

ifeq ($(ARCH), arm)
ifneq ($(APP_ABI), armeabi)
CFLAGS += -march=armv7-a -mfloat-abi=softfp
Expand All @@ -32,48 +34,49 @@ endif
ifndef NDKROOT
$(error NDKROOT is not set)
endif

ifndef TARGET
$(error TARGET is not set)
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++
CC = $(TOOLCHAINPREFIX)gcc
AR = $(TOOLCHAINPREFIX)ar
CFLAGS += -DANDROID_NDK -fpic --sysroot=$(SYSROOT) -MMD -MP
ifeq ($(USE_STACK_PROTECTOR), Yes)
CFLAGS += -fstack-protector-all
ifeq ($(NDKLEVEL),)
NDKLEVEL = $(TARGET:android-%=%)
endif
CFLAGS += -isystem $(NDKROOT)/sysroot/usr/include -isystem $(NDKROOT)/sysroot/usr/include/$(TOOLCHAIN_NAME) -D__ANDROID_API__=$(NDKLEVEL)

CFLAGS += -DANDROID_NDK -fpic -MMD -MP -fstack-protector-all
CXXFLAGS += -fno-rtti -fno-exceptions
LDFLAGS += --sysroot=$(SYSROOT)
SHLDFLAGS = -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -Wl,-soname,lib$(PROJECT_NAME).so
UTSHLDFLAGS = -Wl,-soname,libut.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++
LLVM_INSTALL_DIR = $(wildcard $(NDKROOT)/toolchains/llvm/prebuilt/*/bin)

ifeq ($(ARCH), arm)
TARGET_NAME = armv7-none-linux-androideabi
TARGET_NAME = armv7a-linux-androideabi
else ifeq ($(ARCH), arm64)
TARGET_NAME = aarch64-none-linux-android
TARGET_NAME = aarch64-linux-android
else ifeq ($(ARCH), x86)
TARGET_NAME = i686-none-linux-android
TARGET_NAME = i686-linux-android
else ifeq ($(ARCH), x86_64)
TARGET_NAME = x86_64-none-linux-android
TARGET_NAME = x86_64-linux-android
else
$(error "does not support this arch now!")
endif

CFLAGS += -target $(TARGET_NAME)
LDFLAGS += -target $(TARGET_NAME) -gcc-toolchain $(GCC_TOOLCHAIN_PATH)
CC = $(LLVM_INSTALL_DIR)/$(TARGET_NAME)$(NDKLEVEL)-clang
CXX = $(LLVM_INSTALL_DIR)/$(TARGET_NAME)$(NDKLEVEL)-clang++
AR = $(LLVM_INSTALL_DIR)/llvm-ar
SYSROOT = $(LLVM_INSTALL_DIR)/../sysroot
else
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++
CC = $(TOOLCHAINPREFIX)gcc
AR = $(TOOLCHAINPREFIX)ar
CFLAGS += -isystem $(NDKROOT)/sysroot/usr/include -isystem $(NDKROOT)/sysroot/usr/include/$(TOOLCHAIN_NAME) -D__ANDROID_API__=$(NDKLEVEL) --sysroot=$(SYSROOT)
endif

# background reading: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#unwinding
Expand All @@ -82,22 +85,9 @@ LDFLAGS += -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libunwind.a
ifneq ($(findstring /,$(CXX)),$(findstring \,$(CXX)))
ifneq ($(CXX),$(wildcard $(CXX)))
ifneq ($(CXX).exe,$(wildcard $(CXX).exe))
$(error Compiler not found, bad NDKROOT or ARCH?)
endif
$(error Compiler not found, bad NDKROOT or ARCH? $(CXX))
endif
endif

ifeq ($(NDK_TOOLCHAIN_VERSION), clang)
STL_INCLUDES = \
-I$(NDKROOT)/sources/cxx-stl/llvm-libc++/include \
-I$(NDKROOT)/sources/cxx-stl/llvm-libc++abi/include
STL_LIB = \
$(NDKROOT)/sources/cxx-stl/llvm-libc++/libs/$(APP_ABI)/libc++_static.a
else
STL_INCLUDES = \
-I$(NDKROOT)/sources/cxx-stl/stlport/stlport
STL_LIB = \
$(NDKROOT)/sources/cxx-stl/stlport/libs/$(APP_ABI)/libstlport_static.a
endif

GTEST_INCLUDES = $(STL_INCLUDES)
Expand All @@ -109,18 +99,26 @@ MODULE_LDFLAGS = $(STL_LIB)
ifeq (./,$(SRC_PATH))
binaries: decdemo encdemo

NDK_BUILD = $(NDKROOT)/ndk-build APP_ABI=$(APP_ABI) APP_PLATFORM=$(TARGET) NDK_TOOLCHAIN_VERSION=$(NDK_TOOLCHAIN_VERSION) V=$(V:Yes=1)

decdemo: libraries
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
$(NDK_BUILD) -C codec/build/android/dec -B
./gradlew test-dec:assembleDebug

encdemo: libraries
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
$(NDK_BUILD) -C codec/build/android/enc -B
./gradlew test-enc:assembleDebug

clean_Android: clean_Android_dec clean_Android_enc

clean_Android_dec:
-cd ./codec/build/android/dec && $(NDKROOT)/ndk-build APP_ABI=$(APP_ABI) clean && ant clean
-$(NDK_BUILD) -C codec/build/android/dec clean
-./gradlew test-dec:clean

clean_Android_enc:
-cd ./codec/build/android/enc && $(NDKROOT)/ndk-build APP_ABI=$(APP_ABI) clean && ant clean
-$(NDK_BUILD) -C codec/build/android/enc clean
-./gradlew test-enc:clean

else
clean_Android:
@:
Expand Down
1 change: 1 addition & 0 deletions codec/build/android/dec/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
12 changes: 12 additions & 0 deletions codec/build/android/dec/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29

sourceSets.main {
manifest.srcFile "AndroidManifest.xml"
res.srcDir "res"
java.srcDir "src"
jniLibs.srcDir "libs"
}
}
2 changes: 1 addition & 1 deletion codec/build/android/dec/src/com/wels/dec/WelsDecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public boolean onKeyDown (int keyCode, KeyEvent event) {
static {
try {
System.loadLibrary ("openh264");
System.loadLibrary ("stlport_shared");
System.loadLibrary ("c++_shared");
System.loadLibrary ("welsdecdemo");
Log.v (TAG, "Load libwelsdec successful");
} catch (Exception e) {
Expand Down
1 change: 1 addition & 0 deletions codec/build/android/enc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
12 changes: 12 additions & 0 deletions codec/build/android/enc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29

sourceSets.main {
manifest.srcFile "AndroidManifest.xml"
res.srcDir "res"
java.srcDir "src"
jniLibs.srcDir "libs"
}
}
2 changes: 1 addition & 1 deletion codec/build/android/enc/src/com/wels/enc/WelsEncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public native void DoEncoderAutoTest (String cfgFileName, String layerFileName,
static {
try {
System.loadLibrary ("openh264");
System.loadLibrary ("stlport_shared");
System.loadLibrary ("c++_shared");
System.loadLibrary ("welsencdemo");
Log.v (TAG, "Load libwelsencdemo.so successful");
} catch (Exception e) {
Expand Down
Loading

0 comments on commit b16f0c2

Please sign in to comment.