1###########################################################
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
15ifdef target-executable-hook
16$(call target-executable-hook)
17endif
18
19skip_build_from_source :=
20ifdef LOCAL_PREBUILT_MODULE_FILE
21ifeq (,$(call if-build-from-source,$(LOCAL_MODULE),$(LOCAL_PATH)))
22include $(BUILD_SYSTEM)/prebuilt_internal.mk
23skip_build_from_source := true
24endif
25endif
26
27ifndef skip_build_from_source
28
29include $(BUILD_SYSTEM)/dynamic_binary.mk
30
31# Check for statically linked libc
32ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
33ifneq ($(filter $(my_static_libraries),libc),)
34$(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)
35endif
36endif
37
38# Define PRIVATE_ variables from global vars
39ifeq ($(LOCAL_NO_LIBCRT_BUILTINS),true)
40my_target_libcrt_builtins :=
41else
42my_target_libcrt_builtins := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)LIBCRT_BUILTINS)
43endif
44my_target_libatomic := $(call intermediates-dir-for,STATIC_LIBRARIES,libatomic,,,$(LOCAL_2ND_ARCH_VAR_PREFIX))/libatomic.a
45ifeq ($(LOCAL_NO_CRT),true)
46my_target_crtbegin_dynamic_o :=
47my_target_crtbegin_static_o :=
48my_target_crtend_o :=
49else ifdef LOCAL_USE_VNDK
50my_target_crtbegin_dynamic_o := $(SOONG_$(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJECT_crtbegin_dynamic.vendor)
51my_target_crtbegin_static_o := $(SOONG_$(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJECT_crtbegin_static.vendor)
52my_target_crtend_o := $(SOONG_$(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJECT_crtend_android.vendor)
53else
54my_target_crtbegin_dynamic_o := $(SOONG_$(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJECT_crtbegin_dynamic)
55my_target_crtbegin_static_o := $(SOONG_$(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJECT_crtbegin_static)
56my_target_crtend_o := $(SOONG_$(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJECT_crtend_android)
57endif
58ifneq ($(LOCAL_SDK_VERSION),)
59my_target_crtbegin_dynamic_o := $(wildcard $(my_ndk_sysroot_lib)/crtbegin_dynamic.o)
60my_target_crtbegin_static_o := $(wildcard $(my_ndk_sysroot_lib)/crtbegin_static.o)
61my_target_crtend_o := $(wildcard $(my_ndk_sysroot_lib)/crtend_android.o)
62endif
63$(linked_module): PRIVATE_TARGET_LIBCRT_BUILTINS := $(my_target_libcrt_builtins)
64$(linked_module): PRIVATE_TARGET_LIBATOMIC := $(my_target_libatomic)
65$(linked_module): PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O := $(my_target_crtbegin_dynamic_o)
66$(linked_module): PRIVATE_TARGET_CRTBEGIN_STATIC_O := $(my_target_crtbegin_static_o)
67$(linked_module): PRIVATE_TARGET_CRTEND_O := $(my_target_crtend_o)
68$(linked_module): PRIVATE_POST_LINK_CMD := $(LOCAL_POST_LINK_CMD)
69
70ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
71$(linked_module): $(my_target_crtbegin_static_o) $(all_objects) $(all_libraries) $(my_target_crtend_o) $(my_target_libcrt_builtins) $(my_target_libatomic) $(CLANG_CXX)
72	$(transform-o-to-static-executable)
73	$(PRIVATE_POST_LINK_CMD)
74else
75$(linked_module): $(my_target_crtbegin_dynamic_o) $(all_objects) $(all_libraries) $(my_target_crtend_o) $(my_target_libcrt_builtins) $(my_target_libatomic) $(CLANG_CXX)
76	$(transform-o-to-executable)
77	$(PRIVATE_POST_LINK_CMD)
78endif
79
80ifeq ($(my_native_coverage),true)
81gcno_suffix := .zip
82
83built_whole_gcno_libraries := \
84    $(foreach lib,$(my_whole_static_libraries), \
85      $(call intermediates-dir-for, \
86        STATIC_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX), \
87        $(my_host_cross))/$(lib)$(gcno_suffix))
88
89built_static_gcno_libraries := \
90    $(foreach lib,$(my_static_libraries), \
91      $(call intermediates-dir-for, \
92        STATIC_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX), \
93        $(my_host_cross))/$(lib)$(gcno_suffix))
94
95ifdef LOCAL_IS_HOST_MODULE
96my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path))
97else
98my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
99endif
100
101GCNO_ARCHIVE := $(my_installed_module_stem)$(gcno_suffix)
102
103$(intermediates)/$(GCNO_ARCHIVE) : $(SOONG_ZIP) $(MERGE_ZIPS)
104$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS := $(strip $(LOCAL_GCNO_FILES))
105$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(strip $(built_whole_gcno_libraries)) $(strip $(built_static_gcno_libraries))
106$(intermediates)/$(GCNO_ARCHIVE) : $(LOCAL_GCNO_FILES) $(built_whole_gcno_libraries) $(built_static_gcno_libraries)
107	$(package-coverage-files)
108
109$(my_coverage_path)/$(GCNO_ARCHIVE) : $(intermediates)/$(GCNO_ARCHIVE)
110	$(copy-file-to-target)
111
112$(LOCAL_BUILT_MODULE): $(my_coverage_path)/$(GCNO_ARCHIVE)
113endif
114
115endif  # skip_build_from_source
116