blob: 593f9f445f6872aaabd1065f43dc14dcf3036b01 [file] [log] [blame]
Ying Wangdd814bf2014-01-17 16:17:28 -08001###########################################################
2## Standard rules for building an executable file.
3##
4## Additional inputs from base_rules.make:
5## None.
6###########################################################
7
8ifeq ($(strip $(LOCAL_MODULE_CLASS)),)
9LOCAL_MODULE_CLASS := EXECUTABLES
10endif
11ifeq ($(strip $(LOCAL_MODULE_SUFFIX)),)
12LOCAL_MODULE_SUFFIX := $(TARGET_EXECUTABLE_SUFFIX)
13endif
14
15$(call target-executable-hook)
16
17skip_build_from_source :=
18ifdef LOCAL_PREBUILT_MODULE_FILE
19ifeq (,$(call if-build-from-source,$(LOCAL_MODULE),$(LOCAL_PATH)))
Ying Wang58f462f2014-02-25 18:26:29 -080020include $(BUILD_SYSTEM)/prebuilt_internal.mk
Ying Wangdd814bf2014-01-17 16:17:28 -080021skip_build_from_source := true
22endif
23endif
24
25ifndef skip_build_from_source
26
27include $(BUILD_SYSTEM)/dynamic_binary.mk
28
Dmitriy Ivanov655d6852014-08-15 11:30:23 -070029# Check for statically linked libc
30ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
31ifneq ($(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)
33endif
34endif
35
Ying Wangdd814bf2014-01-17 16:17:28 -080036# Define PRIVATE_ variables from global vars
Colin Cross067d7812016-09-09 10:09:47 -070037my_target_global_ld_dirs :=
Ying Wang75011b22015-07-02 11:05:27 -070038ifeq ($(LOCAL_NO_LIBGCC),true)
39my_target_libgcc :=
40else
Dan Willemsendb16dd22016-05-16 14:41:49 -070041my_target_libgcc := $(call intermediates-dir-for,STATIC_LIBRARIES,libgcc,,,$(LOCAL_2ND_ARCH_VAR_PREFIX))/libgcc.a
Ying Wang75011b22015-07-02 11:05:27 -070042endif
Dan Willemsendb16dd22016-05-16 14:41:49 -070043my_target_libatomic := $(call intermediates-dir-for,STATIC_LIBRARIES,libatomic,,,$(LOCAL_2ND_ARCH_VAR_PREFIX))/libatomic.a
Ying Wang491fca92015-07-02 15:57:45 -070044ifeq ($(LOCAL_NO_CRT),true)
45my_target_crtbegin_dynamic_o :=
46my_target_crtbegin_static_o :=
47my_target_crtend_o :=
48else
Dan Willemsen056609c2016-05-16 22:07:31 -070049my_target_crtbegin_dynamic_o := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
50my_target_crtbegin_static_o := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
51my_target_crtend_o := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
Ying Wang491fca92015-07-02 15:57:45 -070052endif
Ying Wangdd814bf2014-01-17 16:17:28 -080053ifdef 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.
56my_target_global_ld_dirs := \
57 $(addprefix -L, $(patsubst %/,%,$(dir $(my_ndk_stl_shared_lib_fullpath))) \
Andrew Hsieh140761af02014-04-25 23:47:10 -070058 $(my_ndk_sysroot_lib)) \
Ying Wangdd814bf2014-01-17 16:17:28 -080059 $(my_target_global_ld_dirs)
60my_target_global_ldflags := $(my_ndk_stl_shared_lib) $(my_target_global_ldflags)
Andrew Hsieh140761af02014-04-25 23:47:10 -070061my_target_crtbegin_dynamic_o := $(wildcard $(my_ndk_sysroot_lib)/crtbegin_dynamic.o)
62my_target_crtbegin_static_o := $(wildcard $(my_ndk_sysroot_lib)/crtbegin_static.o)
63my_target_crtend_o := $(wildcard $(my_ndk_sysroot_lib)/crtend_android.o)
Ying Wangdd814bf2014-01-17 16:17:28 -080064endif
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 Wangdd814bf2014-01-17 16:17:28 -080067$(linked_module): PRIVATE_TARGET_LIBGCC := $(my_target_libgcc)
Andrew Hsieh4c952d72014-05-29 02:47:27 -070068$(linked_module): PRIVATE_TARGET_LIBATOMIC := $(my_target_libatomic)
Ying Wangdd814bf2014-01-17 16:17:28 -080069$(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 Wang9fb35262014-02-21 16:17:05 -080072$(linked_module): PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)
Yabin Cui273e9102016-03-02 14:03:41 -080073$(linked_module): PRIVATE_POST_LINK_CMD := $(LOCAL_POST_LINK_CMD)
Ying Wangdd814bf2014-01-17 16:17:28 -080074
75ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
Dan Willemsendb16dd22016-05-16 14:41:49 -070076$(linked_module): $(my_target_crtbegin_static_o) $(all_objects) $(all_libraries) $(my_target_crtend_o) $(my_target_libgcc) $(my_target_libatomic)
Ying Wangdd814bf2014-01-17 16:17:28 -080077 $(transform-o-to-static-executable)
Ying Wang8b347692014-09-05 15:46:43 -070078 $(PRIVATE_POST_LINK_CMD)
Ying Wangdd814bf2014-01-17 16:17:28 -080079else
Dan Willemsendb16dd22016-05-16 14:41:49 -070080$(linked_module): $(my_target_crtbegin_dynamic_o) $(all_objects) $(all_libraries) $(my_target_crtend_o) $(my_target_libgcc) $(my_target_libatomic)
Ying Wangdd814bf2014-01-17 16:17:28 -080081 $(transform-o-to-executable)
Yabin Cui273e9102016-03-02 14:03:41 -080082 $(PRIVATE_POST_LINK_CMD)
Ying Wangdd814bf2014-01-17 16:17:28 -080083endif
84
85endif # skip_build_from_source