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 |
| 37 | my_target_global_ld_dirs := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LD_DIRS) |
Dan Albert | 4bbc6c7 | 2014-09-19 14:25:57 -0700 | [diff] [blame] | 38 | my_target_libgcov := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBGCOV) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 39 | my_target_libgcc := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBGCC) |
Andrew Hsieh | 4c952d7 | 2014-05-29 02:47:27 -0700 | [diff] [blame] | 40 | my_target_libatomic := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBATOMIC) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 41 | my_target_crtbegin_dynamic_o := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTBEGIN_DYNAMIC_O) |
| 42 | my_target_crtbegin_static_o := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTBEGIN_STATIC_O) |
| 43 | my_target_crtend_o := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTEND_O) |
| 44 | ifdef LOCAL_SDK_VERSION |
| 45 | # Make sure the prebuilt NDK paths are put ahead of the TARGET_GLOBAL_LD_DIRS, |
| 46 | # so we don't have race condition when the system libraries (such as libc, libstdc++) are also built in the tree. |
| 47 | my_target_global_ld_dirs := \ |
| 48 | $(addprefix -L, $(patsubst %/,%,$(dir $(my_ndk_stl_shared_lib_fullpath))) \ |
Andrew Hsieh | 140761a | 2014-04-25 23:47:10 -0700 | [diff] [blame] | 49 | $(my_ndk_sysroot_lib)) \ |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 50 | $(my_target_global_ld_dirs) |
| 51 | my_target_global_ldflags := $(my_ndk_stl_shared_lib) $(my_target_global_ldflags) |
Andrew Hsieh | 140761a | 2014-04-25 23:47:10 -0700 | [diff] [blame] | 52 | my_target_crtbegin_dynamic_o := $(wildcard $(my_ndk_sysroot_lib)/crtbegin_dynamic.o) |
| 53 | my_target_crtbegin_static_o := $(wildcard $(my_ndk_sysroot_lib)/crtbegin_static.o) |
| 54 | my_target_crtend_o := $(wildcard $(my_ndk_sysroot_lib)/crtend_android.o) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 55 | endif |
| 56 | $(linked_module): PRIVATE_TARGET_GLOBAL_LD_DIRS := $(my_target_global_ld_dirs) |
| 57 | $(linked_module): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags) |
Dan Albert | 4bbc6c7 | 2014-09-19 14:25:57 -0700 | [diff] [blame] | 58 | $(linked_module): PRIVATE_TARGET_LIBGCOV := $(my_target_libgcov) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 59 | $(linked_module): PRIVATE_TARGET_LIBGCC := $(my_target_libgcc) |
Andrew Hsieh | 4c952d7 | 2014-05-29 02:47:27 -0700 | [diff] [blame] | 60 | $(linked_module): PRIVATE_TARGET_LIBATOMIC := $(my_target_libatomic) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 61 | $(linked_module): PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O := $(my_target_crtbegin_dynamic_o) |
| 62 | $(linked_module): PRIVATE_TARGET_CRTBEGIN_STATIC_O := $(my_target_crtbegin_static_o) |
| 63 | $(linked_module): PRIVATE_TARGET_CRTEND_O := $(my_target_crtend_o) |
Ying Wang | 9fb3526 | 2014-02-21 16:17:05 -0800 | [diff] [blame] | 64 | $(linked_module): PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 65 | |
| 66 | ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
Ying Wang | 8b34769 | 2014-09-05 15:46:43 -0700 | [diff] [blame] | 67 | $(linked_module): PRIVATE_POST_LINK_CMD := $(LOCAL_POST_LINK_CMD) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 68 | $(linked_module): $(my_target_crtbegin_static_o) $(all_objects) $(all_libraries) $(my_target_crtend_o) |
| 69 | $(transform-o-to-static-executable) |
Ying Wang | 8b34769 | 2014-09-05 15:46:43 -0700 | [diff] [blame] | 70 | $(PRIVATE_POST_LINK_CMD) |
Ying Wang | dd814bf | 2014-01-17 16:17:28 -0800 | [diff] [blame] | 71 | else |
| 72 | $(linked_module): $(my_target_crtbegin_dynamic_o) $(all_objects) $(all_libraries) $(my_target_crtend_o) |
| 73 | $(transform-o-to-executable) |
| 74 | endif |
| 75 | |
| 76 | endif # skip_build_from_source |