From e4094c0caafd6ac4b58eb3e2ab8f070ec666a6a3 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 30 May 2022 03:47:31 -0700 Subject: [PATCH] Update build scripts --- build.py | 21 +++++++-------------- native/jni/Android.mk | 5 +---- native/jni/Application.mk | 7 +------ native/jni/base/Android.mk | 12 ++++++++---- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/build.py b/build.py index 98ef2376c..0fcdafb36 100755 --- a/build.py +++ b/build.py @@ -328,8 +328,6 @@ def build_binary(args): dump_flag_header() - # Build shared executables - flag = '' if 'magisk' in args.target: @@ -344,18 +342,6 @@ def build_binary(args): if 'magiskinit' in args.target: flag += ' B_PRELOAD=1' - if flag: - run_ndk_build(flag + ' B_SHARED=1') - clean_elf() - - # Then build static executables - - flag = '' - - if 'magiskinit' in args.target: - dump_bin_header(args) - flag += ' B_INIT=1' - if 'resetprop' in args.target: flag += ' B_PROP=1' @@ -364,6 +350,13 @@ def build_binary(args): if flag: run_ndk_build(flag) + clean_elf() + + # magiskinit and busybox has to be built separately + + if 'magiskinit' in args.target: + dump_bin_header(args) + run_ndk_build('B_INIT=1') if 'busybox' in args.target: run_ndk_build('B_BB=1') diff --git a/native/jni/Android.mk b/native/jni/Android.mk index 1cdf8ad6b..eb9b54589 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -78,7 +78,6 @@ LOCAL_SRC_FILES := \ init/twostage.cpp \ init/selinux.cpp -LOCAL_LDFLAGS := -static include $(BUILD_EXECUTABLE) endif @@ -109,7 +108,6 @@ LOCAL_SRC_FILES := \ boot/pattern.cpp \ boot/cpio.cpp -LOCAL_LDFLAGS := -static include $(BUILD_EXECUTABLE) endif @@ -145,7 +143,6 @@ LOCAL_SRC_FILES := \ resetprop/resetprop.cpp \ LOCAL_CFLAGS := -DAPPLET_STUB_MAIN=resetprop_main -LOCAL_LDFLAGS := -static include $(BUILD_EXECUTABLE) endif @@ -170,7 +167,7 @@ endif ######################## include $(CLEAR_VARS) -LOCAL_MODULE:= libpolicy +LOCAL_MODULE := libpolicy LOCAL_STATIC_LIBRARIES := \ libbase \ libsepol diff --git a/native/jni/Application.mk b/native/jni/Application.mk index 8698f1f9a..be5423325 100644 --- a/native/jni/Application.mk +++ b/native/jni/Application.mk @@ -7,15 +7,10 @@ APP_PLATFORM := android-21 APP_THIN_ARCHIVE := true APP_STRIP_MODE := --strip-all -ifndef B_SHARED -# Fix static variables' ctor/dtor when using LTO -# See: https://github.com/android/ndk/issues/1461 -APP_LDFLAGS += -T jni/lto_fix.lds -endif - # Busybox should use stock libc.a ifdef B_BB APP_PLATFORM := android-24 +APP_LDFLAGS += -T jni/lto_fix.lds ifeq ($(OS),Windows_NT) APP_SHORT_COMMANDS := true endif diff --git a/native/jni/base/Android.mk b/native/jni/base/Android.mk index 4221d2e35..e5dcce192 100644 --- a/native/jni/base/Android.mk +++ b/native/jni/base/Android.mk @@ -3,7 +3,7 @@ LOCAL_PATH := $(call my-dir) # Magisk project-wide common code include $(CLEAR_VARS) -LOCAL_MODULE:= libbase +LOCAL_MODULE := libbase LOCAL_C_INCLUDES := jni/include $(LOCAL_PATH)/include out/generated LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) LOCAL_EXPORT_STATIC_LIBRARIES := libcxx @@ -18,10 +18,14 @@ LOCAL_SRC_FILES := \ stream.cpp include $(BUILD_STATIC_LIBRARY) -# Workaround "hacky" libc.a missing symbols -# To build Magisk with vanilla NDK, remove all usage of libcompat +# All static executables should link with libcompat include $(CLEAR_VARS) -LOCAL_MODULE:= libcompat +LOCAL_MODULE := libcompat +# Workaround "hacky" libc.a missing symbols +# To build Magisk with vanilla NDK, comment out the next line LOCAL_SRC_FILES := compat/compat.cpp +# Fix static variables' ctor/dtor when using LTO +# See: https://github.com/android/ndk/issues/1461 +LOCAL_EXPORT_LDLIBS := -static -T jni/lto_fix.lds include $(BUILD_STATIC_LIBRARY)