Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feature/prefab #3262

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ codec/build/iOS/dec/welsdec/build/
# editor files
*~

#prefab
/openh264.aar
/aar/
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -291,28 +291,28 @@ $(PROJECT_NAME)-static.pc: $(PROJECT_NAME).pc.in
@sed -e 's;@prefix@;$(PREFIX);' -e 's;@libdir@;$(PREFIX)/lib;' -e 's;@VERSION@;$(FULL_VERSION);' -e 's;@LIBS@;$(STATIC_LDFLAGS);' -e 's;@LIBS_PRIVATE@;;' < $< > $@

install-headers:
mkdir -p $(DESTDIR)$(PREFIX)/include/wels
install -m 644 $(SRC_PATH)/codec/api/svc/codec*.h $(DESTDIR)$(PREFIX)/include/wels
$(QUIET)mkdir -p $(DESTDIR)$(PREFIX)/include/wels
$(QUIET)install -m 644 $(SRC_PATH)/codec/api/svc/codec*.h $(DESTDIR)$(PREFIX)/include/wels

install-static-lib: $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) install-headers
mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)
install -m 644 $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)
$(QUIET)mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)
$(QUIET)install -m 644 $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)

install-static: install-static-lib $(PROJECT_NAME)-static.pc
mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig
install -m 644 $(PROJECT_NAME)-static.pc $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig/$(PROJECT_NAME).pc
$(QUIET)mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig
$(QUIET)install -m 644 $(PROJECT_NAME)-static.pc $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig/$(PROJECT_NAME).pc

install-shared: $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) install-headers $(PROJECT_NAME).pc
mkdir -p $(DESTDIR)$(SHAREDLIB_DIR)
install -m 755 $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXFULLVER) $(DESTDIR)$(SHAREDLIB_DIR)
if [ "$(SHAREDLIBSUFFIXFULLVER)" != "$(SHAREDLIBSUFFIX)" ]; then \
cp -a $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXMAJORVER) $(DESTDIR)$(SHAREDLIB_DIR) ; \
cp -a $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) $(DESTDIR)$(SHAREDLIB_DIR) ; \
$(QUIET)mkdir -p $(DESTDIR)$(SHAREDLIB_DIR)
$(QUIET)install -m 755 $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXFULLVER) $(DESTDIR)$(SHAREDLIB_DIR)
$(QUIET)if [ "$(SHAREDLIBSUFFIXFULLVER)" != "$(SHAREDLIBSUFFIX)" ]; then \
$(QUIET)cp -a $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXMAJORVER) $(DESTDIR)$(SHAREDLIB_DIR) ; \
$(QUIET)cp -a $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) $(DESTDIR)$(SHAREDLIB_DIR) ; \
fi
mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig
install -m 644 $(PROJECT_NAME).pc $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig
$(QUIET)mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig
$(QUIET)install -m 644 $(PROJECT_NAME).pc $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig
ifneq ($(EXTRA_LIBRARY),)
install -m 644 $(EXTRA_LIBRARY) $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)
$(QUIET)install -m 644 $(EXTRA_LIBRARY) $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)
endif

install: install-static-lib install-shared
Expand Down
48 changes: 48 additions & 0 deletions build/platform-android-prefab.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# implementing the prefab packager (see https://google.github.io/prefab/ and https://developer.android.com/studio/preview/features#native-dependencies)

.PHONY: prefab prefab-clean $(PROJECT_NAME).aar # always rebuild
prefab: $(PROJECT_NAME).aar

prefab-clean:
-$(QUIET)rm -r aar

$(PROJECT_NAME).aar: aar/AndroidManifest.xml aar/META-INF/LICENSE aar/prefab
$(QUIET)rm $@ 2>/dev/null
$(QUIET)cd aar && zip -r ../$@ *

aar/AndroidManifest.xml:
@mkdir -p $(@D)
$(QUIET)echo '<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wels.openh264" android:versionCode="1" android:versionName="1.0">' >$@
$(QUIET)echo ' <uses-sdk android:minSdkVersion="$(NDKLEVEL)" android:targetSdkVersion="$(NDKLEVEL)"/>' >>$@
$(QUIET)echo '</manifest>' >>$@

aar/META-INF/LICENSE: ./LICENSE
@mkdir -p $(@D)
$(QUIET)cp $< $@

.PHONY: prefab.%
prefab.%: ARCH=$(@:prefab.%=%)
prefab.%:
$(QUIET)$(MAKE) --no-print-directory prefab-abi ARCH=$(ARCH)

prefab-abi: DESTDIR=aar/prefab/modules/$(PROJECT_NAME)/libs/$(OS).$(ARCH)
prefab-abi:
$(QUIET)$(MAKE) --no-print-directory clean install-shared $(DESTDIR)/abi.json \
SHAREDLIB_DIR=/. PREFIX=/. DESTDIR=$(DESTDIR) SRC_PATH=aar/../ # tune the destination for install, and trick clean to skip Android_clean the apps that are not there
-$(QUIET)rm -r $(DESTDIR)/lib # we don't need the pc file

%/abi.json:
$(QUIET)echo '{"abi":"$(APP_ABI)","api":$(NDKLEVEL),"ndk":20,"stl":"none"}' >$@

aar/prefab: prefab.arm prefab.arm64 prefab.x86 prefab.x86_64
@:

aar/prefab: aar/prefab/prefab.json
aar/prefab/prefab.json:
@mkdir -p $(@D)
$(QUIET)echo '{"name":"$(PROJECT_NAME)","schema_version":1,"dependencies":[],"version":"'$(FULL_VERSION)'"}' >$@

aar/prefab: aar/prefab/modules/$(PROJECT_NAME)/module.json
aar/prefab/modules/$(PROJECT_NAME)/module.json:
@mkdir -p $(@D)
$(QUIET)echo '{"export_libraries":[],"library_name":"lib$(PROJECT_NAME)"}' > $@
55 changes: 22 additions & 33 deletions build/platform-android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ SHAREDLIBSUFFIX = so
SHAREDLIBSUFFIXFULLVER=$(SHAREDLIBSUFFIX)
SHAREDLIBSUFFIXMAJORVER=$(SHAREDLIBSUFFIX)
SHLDFLAGS =
NDKLEVEL = 12
ifdef ANDROID_NDK_ROOT
NDKROOT = $(ANDROID_NDK_ROOT)
endif
NDK_TOOLCHAIN_VERSION = clang
NDKLEVEL = $(TARGET:android-%=%)
SUPPORTED_NDK_RELEASES = 20 21
ifeq ($(ARCH), arm)
ifneq ($(APP_ABI), armeabi)
CFLAGS += -march=armv7-a -mfloat-abi=softfp
Expand All @@ -32,45 +37,40 @@ endif
ifndef NDKROOT
$(error NDKROOT is not set)
endif
include $(NDKROOT)/source.properties
NDK_RELEASE = $(basename $(basename $(Pkg.Revision)))
ifeq (, $(filter $(NDK_RELEASE), $(SUPPORTED_NDK_RELEASES)))
$(error unsupported NDK release $(Pkg.Revision))
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 -fstack-protector-all
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
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
endif

# background reading: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#unwinding
Expand All @@ -84,19 +84,6 @@ endif
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)
CODEC_UNITTEST_INCLUDES = $(STL_INCLUDES)
CODEC_UNITTEST_LDFLAGS_SUFFIX = $(STL_LIB)
Expand Down Expand Up @@ -133,3 +120,5 @@ COMMON_CFLAGS += \

codec/common/src/cpu-features.$(OBJ): $(NDKROOT)/sources/android/cpufeatures/cpu-features.c
$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) $(COMMON_CFLAGS) $(COMMON_INCLUDES) -c $(CXX_O) $<

include build/platform-android-prefab.mk