Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 1 | ########################################################### |
| 2 | ## Standard rules for building an executable file. |
| 3 | ## |
| 4 | ## Additional inputs from base_rules.make: |
| 5 | ## None. |
| 6 | ########################################################### |
| 7 | |
| 8 | ifeq ($(strip $(LOCAL_MODULE_CLASS)),) |
| 9 | LOCAL_MODULE_CLASS := EXECUTABLES |
| 10 | endif |
| 11 | ifeq ($(strip $(LOCAL_MODULE_SUFFIX)),) |
| 12 | LOCAL_MODULE_SUFFIX := $(TARGET_EXECUTABLE_SUFFIX) |
| 13 | endif |
| 14 | |
| 15 | $(call target-executable-hook) |
| 16 | |
| 17 | skip_build_from_source := |
| 18 | ifdef LOCAL_PREBUILT_MODULE_FILE |
| 19 | ifeq (,$(call if-build-from-source,$(LOCAL_MODULE),$(LOCAL_PATH))) |
Ying Wang | 58f462f | 2014-02-25 18:26:29 -0800 | [diff] [blame] | 20 | include $(BUILD_SYSTEM)/prebuilt_internal.mk |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 21 | skip_build_from_source := true |
| 22 | endif |
| 23 | endif |
| 24 | |
| 25 | ifndef skip_build_from_source |
| 26 | |
| 27 | include $(BUILD_SYSTEM)/dynamic_binary.mk |
| 28 | |
Dmitriy Ivanov | 655d685 | 2014-08-15 11:30:23 -0700 | [diff] [blame] | 29 | # Check for statically linked libc |
| 30 | ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
| 31 | ifneq ($(filter $(my_static_libraries),libc),) |
| 32 | $(error $(LOCAL_PATH): $(LOCAL_MODULE) is statically linking libc to dynamic executable, please remove libc from static libs or set LOCAL_FORCE_STATIC_EXECUTABLE := true) |
| 33 | endif |
| 34 | endif |
| 35 | |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 36 | # Define PRIVATE_ variables from global vars |
Colin Cross | 067d781 | 2016-09-09 10:09:47 -0700 | [diff] [blame] | 37 | my_target_global_ld_dirs := |
Ying Wang | 75011b2 | 2015-07-02 11:05:27 -0700 | [diff] [blame] | 38 | ifeq ($(LOCAL_NO_LIBGCC),true) |
| 39 | my_target_libgcc := |
| 40 | else |
Dan Willemsen | db16dd2 | 2016-05-16 14:41:49 -0700 | [diff] [blame] | 41 | my_target_libgcc := $(call intermediates-dir-for,STATIC_LIBRARIES,libgcc,,,$(LOCAL_2ND_ARCH_VAR_PREFIX))/libgcc.a |
Ying Wang | 75011b2 | 2015-07-02 11:05:27 -0700 | [diff] [blame] | 42 | endif |
Dan Willemsen | db16dd2 | 2016-05-16 14:41:49 -0700 | [diff] [blame] | 43 | my_target_libatomic := $(call intermediates-dir-for,STATIC_LIBRARIES,libatomic,,,$(LOCAL_2ND_ARCH_VAR_PREFIX))/libatomic.a |
Ying Wang | 491fca9 | 2015-07-02 15:57:45 -0700 | [diff] [blame] | 44 | ifeq ($(LOCAL_NO_CRT),true) |
| 45 | my_target_crtbegin_dynamic_o := |
| 46 | my_target_crtbegin_static_o := |
| 47 | my_target_crtend_o := |
| 48 | else |
Dan Willemsen | 056609c | 2016-05-16 22:07:31 -0700 | [diff] [blame] | 49 | my_target_crtbegin_dynamic_o := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o |
| 50 | my_target_crtbegin_static_o := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o |
| 51 | my_target_crtend_o := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o |
Ying Wang | 491fca9 | 2015-07-02 15:57:45 -0700 | [diff] [blame] | 52 | endif |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 53 | ifdef LOCAL_SDK_VERSION |
| 54 | # Make sure the prebuilt NDK paths are put ahead of the TARGET_GLOBAL_LD_DIRS, |
| 55 | # so we don't have race condition when the system libraries (such as libc, libstdc++) are also built in the tree. |
| 56 | my_target_global_ld_dirs := \ |
| 57 | $(addprefix -L, $(patsubst %/,%,$(dir $(my_ndk_stl_shared_lib_fullpath))) \ |
Andrew Hsieh | 140761af0 | 2014-04-25 23:47:10 -0700 | [diff] [blame] | 58 | $(my_ndk_sysroot_lib)) \ |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 59 | $(my_target_global_ld_dirs) |
| 60 | my_target_global_ldflags := $(my_ndk_stl_shared_lib) $(my_target_global_ldflags) |
Andrew Hsieh | 140761af0 | 2014-04-25 23:47:10 -0700 | [diff] [blame] | 61 | my_target_crtbegin_dynamic_o := $(wildcard $(my_ndk_sysroot_lib)/crtbegin_dynamic.o) |
| 62 | my_target_crtbegin_static_o := $(wildcard $(my_ndk_sysroot_lib)/crtbegin_static.o) |
| 63 | my_target_crtend_o := $(wildcard $(my_ndk_sysroot_lib)/crtend_android.o) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 64 | endif |
| 65 | $(linked_module): PRIVATE_TARGET_GLOBAL_LD_DIRS := $(my_target_global_ld_dirs) |
| 66 | $(linked_module): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 67 | $(linked_module): PRIVATE_TARGET_LIBGCC := $(my_target_libgcc) |
Andrew Hsieh | 4c952d7 | 2014-05-29 02:47:27 -0700 | [diff] [blame] | 68 | $(linked_module): PRIVATE_TARGET_LIBATOMIC := $(my_target_libatomic) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 69 | $(linked_module): PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O := $(my_target_crtbegin_dynamic_o) |
| 70 | $(linked_module): PRIVATE_TARGET_CRTBEGIN_STATIC_O := $(my_target_crtbegin_static_o) |
| 71 | $(linked_module): PRIVATE_TARGET_CRTEND_O := $(my_target_crtend_o) |
Ying Wang | 9fb3526 | 2014-02-21 16:17:05 -0800 | [diff] [blame] | 72 | $(linked_module): PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES) |
Yabin Cui | 273e910 | 2016-03-02 14:03:41 -0800 | [diff] [blame] | 73 | $(linked_module): PRIVATE_POST_LINK_CMD := $(LOCAL_POST_LINK_CMD) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 74 | |
| 75 | ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
Dan Willemsen | db16dd2 | 2016-05-16 14:41:49 -0700 | [diff] [blame] | 76 | $(linked_module): $(my_target_crtbegin_static_o) $(all_objects) $(all_libraries) $(my_target_crtend_o) $(my_target_libgcc) $(my_target_libatomic) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 77 | $(transform-o-to-static-executable) |
Ying Wang | 8b34769 | 2014-09-05 15:46:43 -0700 | [diff] [blame] | 78 | $(PRIVATE_POST_LINK_CMD) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 79 | else |
Dan Willemsen | db16dd2 | 2016-05-16 14:41:49 -0700 | [diff] [blame] | 80 | $(linked_module): $(my_target_crtbegin_dynamic_o) $(all_objects) $(all_libraries) $(my_target_crtend_o) $(my_target_libgcc) $(my_target_libatomic) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 81 | $(transform-o-to-executable) |
Yabin Cui | 273e910 | 2016-03-02 14:03:41 -0800 | [diff] [blame] | 82 | $(PRIVATE_POST_LINK_CMD) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 83 | endif |
| 84 | |
| 85 | endif # skip_build_from_source |