am 91fd1231
: Support to build executables against the NDK
* commit '91fd1231c3254bc9d0642e5a646b5657bdaedffa': Support to build executables against the NDK
This commit is contained in:
commit
15f116b2bb
6 changed files with 67 additions and 45 deletions
|
@ -13,10 +13,6 @@ ifdef LOCAL_SDK_VERSION
|
|||
ifdef LOCAL_IS_HOST_MODULE
|
||||
$(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
|
||||
endif
|
||||
ifneq ($(filter-out SHARED_LIBRARIES STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
|
||||
$(error $(LOCAL_PATH): NDK can only be used to build target shared/static libraries, \
|
||||
while your module is of class $(LOCAL_MODULE_CLASS))
|
||||
endif
|
||||
my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources
|
||||
my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_ARCH)
|
||||
|
||||
|
|
|
@ -276,10 +276,10 @@ $(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic -fPIE -pie \
|
|||
-Wl,--gc-sections \
|
||||
-Wl,-z,nocopyreloc \
|
||||
-o $@ \
|
||||
$(TARGET_GLOBAL_LD_DIRS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
|
||||
-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
|
||||
$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
|
||||
$(PRIVATE_ALL_OBJECTS) \
|
||||
-Wl,--whole-archive \
|
||||
$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
|
||||
|
@ -287,20 +287,20 @@ $(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic -fPIE -pie \
|
|||
$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
|
||||
$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
|
||||
$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
|
||||
$(TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_LDFLAGS) \
|
||||
$(TARGET_FDO_LIB) \
|
||||
$(TARGET_LIBGCC) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
|
||||
$(PRIVATE_TARGET_FDO_LIB) \
|
||||
$(PRIVATE_TARGET_LIBGCC) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
|
||||
endef
|
||||
|
||||
define transform-o-to-static-executable-inner
|
||||
$(hide) $(PRIVATE_CXX) -nostdlib -Bstatic \
|
||||
-Wl,--gc-sections \
|
||||
-o $@ \
|
||||
$(TARGET_GLOBAL_LD_DIRS) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_STATIC_O)) \
|
||||
$(TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_LDFLAGS) \
|
||||
$(PRIVATE_ALL_OBJECTS) \
|
||||
-Wl,--whole-archive \
|
||||
|
@ -310,8 +310,8 @@ $(hide) $(PRIVATE_CXX) -nostdlib -Bstatic \
|
|||
-Wl,--start-group \
|
||||
$(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
|
||||
$(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
|
||||
$(TARGET_FDO_LIB) \
|
||||
$(TARGET_LIBGCC) \
|
||||
$(PRIVATE_TARGET_FDO_LIB) \
|
||||
$(PRIVATE_TARGET_LIBGCC) \
|
||||
-Wl,--end-group \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
|
||||
endef
|
||||
|
|
|
@ -248,36 +248,36 @@ $(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic -fPIE -pie \
|
|||
-Wl,--gc-sections \
|
||||
-Wl,-z,nocopyreloc \
|
||||
-o $@ \
|
||||
$(TARGET_GLOBAL_LD_DIRS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
|
||||
-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
|
||||
$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
|
||||
$(PRIVATE_ALL_OBJECTS) \
|
||||
$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
|
||||
$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
|
||||
$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
|
||||
$(TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_LDFLAGS) \
|
||||
$(TARGET_FDO_LIB) \
|
||||
$(TARGET_LIBGCC) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
|
||||
$(PRIVATE_TARGET_FDO_LIB) \
|
||||
$(PRIVATE_TARGET_LIBGCC) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
|
||||
endef
|
||||
|
||||
define transform-o-to-static-executable-inner
|
||||
$(hide) $(PRIVATE_CXX) -nostdlib -Bstatic \
|
||||
-Wl,--gc-sections \
|
||||
-o $@ \
|
||||
$(TARGET_GLOBAL_LD_DIRS) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_STATIC_O)) \
|
||||
$(TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_LDFLAGS) \
|
||||
$(PRIVATE_ALL_OBJECTS) \
|
||||
$(call normalize-target-libraries,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES)))) \
|
||||
-Wl,--start-group \
|
||||
$(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
|
||||
$(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
|
||||
$(TARGET_FDO_LIB) \
|
||||
$(TARGET_LIBGCC) \
|
||||
$(PRIVATE_TARGET_FDO_LIB) \
|
||||
$(PRIVATE_TARGET_LIBGCC) \
|
||||
-Wl,--end-group \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
|
||||
endef
|
||||
|
|
|
@ -191,16 +191,16 @@ endef
|
|||
|
||||
define transform-o-to-executable-inner
|
||||
$(hide) $(PRIVATE_CXX) \
|
||||
$(TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
|
||||
-nostdlib -Bdynamic \
|
||||
-Wl,-dynamic-linker,/system/bin/linker \
|
||||
-Wl,-z,nocopyreloc \
|
||||
-fPIE -pie \
|
||||
-o $@ \
|
||||
$(TARGET_GLOBAL_LD_DIRS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
|
||||
-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
|
||||
$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
|
||||
$(PRIVATE_ALL_OBJECTS) \
|
||||
-Wl,--whole-archive \
|
||||
$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
|
||||
|
@ -209,17 +209,17 @@ $(hide) $(PRIVATE_CXX) \
|
|||
$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
|
||||
$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
|
||||
$(PRIVATE_LDFLAGS) \
|
||||
$(TARGET_LIBGCC) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
|
||||
$(PRIVATE_TARGET_LIBGCC) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
|
||||
endef
|
||||
|
||||
define transform-o-to-static-executable-inner
|
||||
$(hide) $(PRIVATE_CXX) \
|
||||
$(TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
|
||||
-nostdlib -Bstatic \
|
||||
-o $@ \
|
||||
$(TARGET_GLOBAL_LD_DIRS) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_STATIC_O)) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
|
||||
$(PRIVATE_LDFLAGS) \
|
||||
$(PRIVATE_ALL_OBJECTS) \
|
||||
-Wl,--whole-archive \
|
||||
|
@ -227,9 +227,9 @@ $(hide) $(PRIVATE_CXX) \
|
|||
-Wl,--no-whole-archive \
|
||||
-Wl,--start-group \
|
||||
$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
|
||||
$(TARGET_LIBGCC) \
|
||||
$(PRIVATE_TARGET_LIBGCC) \
|
||||
-Wl,--end-group \
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
|
||||
$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
|
||||
endef
|
||||
|
||||
# Special check for x86 NDK ABI compatibility.
|
||||
|
|
|
@ -1259,13 +1259,11 @@ endef
|
|||
ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
|
||||
define transform-o-to-executable-inner
|
||||
$(hide) $(PRIVATE_CXX) \
|
||||
$(TARGET_GLOBAL_LDFLAGS) \
|
||||
-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
|
||||
$(TARGET_GLOBAL_LD_DIRS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
|
||||
$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
|
||||
-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
|
||||
-Wl,-rpath,\$$ORIGIN/../lib \
|
||||
$(PRIVATE_LDFLAGS) \
|
||||
$(TARGET_GLOBAL_LD_DIRS) \
|
||||
$(PRIVATE_ALL_OBJECTS) \
|
||||
-Wl,--whole-archive \
|
||||
$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
|
||||
|
|
|
@ -26,10 +26,38 @@ endif
|
|||
|
||||
include $(BUILD_SYSTEM)/dynamic_binary.mk
|
||||
|
||||
# Define PRIVATE_ variables from global vars
|
||||
my_target_global_ld_dirs := $(TARGET_GLOBAL_LD_DIRS)
|
||||
my_target_global_ldflags := $(TARGET_GLOBAL_LDFLAGS)
|
||||
my_target_fdo_lib := $(TARGET_FDO_LIB)
|
||||
my_target_libgcc := $(TARGET_LIBGCC)
|
||||
my_target_crtbegin_dynamic_o := $(TARGET_CRTBEGIN_DYNAMIC_O)
|
||||
my_target_crtbegin_static_o := $(TARGET_CRTBEGIN_STATIC_O)
|
||||
my_target_crtend_o := $(TARGET_CRTEND_O)
|
||||
ifdef LOCAL_SDK_VERSION
|
||||
# Make sure the prebuilt NDK paths are put ahead of the TARGET_GLOBAL_LD_DIRS,
|
||||
# so we don't have race condition when the system libraries (such as libc, libstdc++) are also built in the tree.
|
||||
my_target_global_ld_dirs := \
|
||||
$(addprefix -L, $(patsubst %/,%,$(dir $(my_ndk_stl_shared_lib_fullpath))) \
|
||||
$(my_ndk_version_root)/usr/lib) \
|
||||
$(my_target_global_ld_dirs)
|
||||
my_target_global_ldflags := $(my_ndk_stl_shared_lib) $(my_target_global_ldflags)
|
||||
my_target_crtbegin_dynamic_o := $(wildcard $(my_ndk_version_root)/usr/lib/crtbegin_dynamic.o)
|
||||
my_target_crtbegin_static_o := $(wildcard $(my_ndk_version_root)/usr/lib/crtbegin_static.o)
|
||||
my_target_crtend_o := $(wildcard $(my_ndk_version_root)/usr/lib/crtend_android.o)
|
||||
endif
|
||||
$(linked_module): PRIVATE_TARGET_GLOBAL_LD_DIRS := $(my_target_global_ld_dirs)
|
||||
$(linked_module): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
|
||||
$(linked_module): PRIVATE_TARGET_FDO_LIB := $(my_target_fdo_lib)
|
||||
$(linked_module): PRIVATE_TARGET_LIBGCC := $(my_target_libgcc)
|
||||
$(linked_module): PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O := $(my_target_crtbegin_dynamic_o)
|
||||
$(linked_module): PRIVATE_TARGET_CRTBEGIN_STATIC_O := $(my_target_crtbegin_static_o)
|
||||
$(linked_module): PRIVATE_TARGET_CRTEND_O := $(my_target_crtend_o)
|
||||
|
||||
ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
|
||||
$(linked_module): $(TARGET_CRTBEGIN_STATIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
|
||||
$(linked_module): $(my_target_crtbegin_static_o) $(all_objects) $(all_libraries) $(my_target_crtend_o)
|
||||
$(transform-o-to-static-executable)
|
||||
else
|
||||
$(linked_module): $(TARGET_CRTBEGIN_DYNAMIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
|
||||
else
|
||||
$(linked_module): $(my_target_crtbegin_dynamic_o) $(all_objects) $(all_libraries) $(my_target_crtend_o)
|
||||
$(transform-o-to-executable)
|
||||
endif
|
||||
|
|
Loading…
Reference in a new issue