Skip to content

Commit

Permalink
Update build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed May 30, 2022
1 parent 2e51fe2 commit e4094c0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
21 changes: 7 additions & 14 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,6 @@ def build_binary(args):

dump_flag_header()

# Build shared executables

flag = ''

if 'magisk' in args.target:
Expand All @@ -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'

Expand All @@ -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')
Expand Down
5 changes: 1 addition & 4 deletions native/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ LOCAL_SRC_FILES := \
init/twostage.cpp \
init/selinux.cpp

LOCAL_LDFLAGS := -static
include $(BUILD_EXECUTABLE)

endif
Expand Down Expand Up @@ -109,7 +108,6 @@ LOCAL_SRC_FILES := \
boot/pattern.cpp \
boot/cpio.cpp

LOCAL_LDFLAGS := -static
include $(BUILD_EXECUTABLE)

endif
Expand Down Expand Up @@ -145,7 +143,6 @@ LOCAL_SRC_FILES := \
resetprop/resetprop.cpp \

LOCAL_CFLAGS := -DAPPLET_STUB_MAIN=resetprop_main
LOCAL_LDFLAGS := -static
include $(BUILD_EXECUTABLE)

endif
Expand All @@ -170,7 +167,7 @@ endif
########################

include $(CLEAR_VARS)
LOCAL_MODULE:= libpolicy
LOCAL_MODULE := libpolicy
LOCAL_STATIC_LIBRARIES := \
libbase \
libsepol
Expand Down
7 changes: 1 addition & 6 deletions native/jni/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions native/jni/base/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

0 comments on commit e4094c0

Please sign in to comment.