1#
2# Copyright (C) 2011 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17include art/build/Android.common_build.mk
18
19ART_HOST_EXECUTABLES ?=
20ART_TARGET_EXECUTABLES ?=
21
22ART_EXECUTABLES_CFLAGS :=
23
24# $(1): executable ("d" will be appended for debug version)
25# $(2): source
26# $(3): extra shared libraries
27# $(4): extra include directories
28# $(5): target or host
29# $(6): ndebug or debug
30# $(7): value for LOCAL_MULTILIB (empty means default)
31define build-art-executable
32  ifneq ($(5),target)
33    ifneq ($(5),host)
34      $$(error expected target or host for argument 5, received $(5))
35    endif
36  endif
37  ifneq ($(6),ndebug)
38    ifneq ($(6),debug)
39      $$(error expected ndebug or debug for argument 6, received $(6))
40    endif
41  endif
42
43  art_executable := $(1)
44  art_source := $(2)
45  art_shared_libraries := $(3)
46  art_c_includes := $(4)
47  art_target_or_host := $(5)
48  art_ndebug_or_debug := $(6)
49  art_multilib := $(7)
50  art_out_binary_name :=
51
52  include $(CLEAR_VARS)
53  LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
54  LOCAL_MODULE_TAGS := optional
55  LOCAL_SRC_FILES := $$(art_source)
56  LOCAL_C_INCLUDES += $(ART_C_INCLUDES) art/runtime art/cmdline $$(art_c_includes)
57  LOCAL_SHARED_LIBRARIES += $$(art_shared_libraries)
58  LOCAL_WHOLE_STATIC_LIBRARIES += libsigchain
59
60  ifeq ($$(art_ndebug_or_debug),ndebug)
61    LOCAL_MODULE := $$(art_executable)
62  else #debug
63    LOCAL_MODULE := $$(art_executable)d
64  endif
65
66  LOCAL_CFLAGS := $(ART_EXECUTABLES_CFLAGS)
67  # Mac OS linker doesn't understand --export-dynamic.
68  ifneq ($$(HOST_OS)-$$(art_target_or_host),darwin-host)
69    LOCAL_LDFLAGS := -Wl,--export-dynamic
70  endif
71
72  ifeq ($$(art_target_or_host),target)
73  	$(call set-target-local-clang-vars)
74  	$(call set-target-local-cflags-vars,$(6))
75    LOCAL_SHARED_LIBRARIES += libdl
76  else # host
77    LOCAL_CLANG := $(ART_HOST_CLANG)
78    LOCAL_LDLIBS := $(ART_HOST_LDLIBS)
79    LOCAL_CFLAGS += $(ART_HOST_CFLAGS)
80    ifeq ($$(art_ndebug_or_debug),debug)
81      LOCAL_CFLAGS += $(ART_HOST_DEBUG_CFLAGS)
82    else
83      LOCAL_CFLAGS += $(ART_HOST_NON_DEBUG_CFLAGS)
84    endif
85    LOCAL_LDLIBS += -lpthread -ldl
86  endif
87
88  ifeq ($$(art_ndebug_or_debug),ndebug)
89    LOCAL_SHARED_LIBRARIES += libart
90  else # debug
91    LOCAL_SHARED_LIBRARIES += libartd
92  endif
93
94  LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_build.mk
95  LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.common_utils.mk
96  LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.executable.mk
97
98  ifeq ($$(art_target_or_host),target)
99    LOCAL_MODULE_TARGET_ARCH := $(ART_SUPPORTED_ARCH)
100  endif
101
102  LOCAL_MULTILIB := $$(art_multilib)
103  art_out_binary_name := $$(LOCAL_MODULE)
104
105  # If multilib=both (potentially building both 32-bit and 64-bit), need to provide stem.
106  ifeq ($$(art_multilib),both)
107    # Set up a 32-bit/64-bit stem if we are building both binaries.
108    # In this case, the 32-bit binary has an additional 32-bit suffix.
109    LOCAL_MODULE_STEM_32 := $$(LOCAL_MODULE)32
110    LOCAL_MODULE_STEM_64 := $$(LOCAL_MODULE)
111
112    # Remember the binary names so we can add them to the global art executables list later.
113    art_out_binary_name := $$(LOCAL_MODULE_STEM_32) $$(LOCAL_MODULE_STEM_64)
114
115    # For single-architecture targets, remove any binary name suffixes.
116    ifeq ($$(art_target_or_host),target)
117      ifeq (,$(TARGET_2ND_ARCH))
118        LOCAL_MODULE_STEM_32 := $$(LOCAL_MODULE)
119        art_out_binary_name := $$(LOCAL_MODULE)
120      endif
121    endif
122
123    # For single-architecture hosts, remove any binary name suffixes.
124    ifeq ($$(art_target_or_host),host)
125      ifeq (,$(HOST_2ND_ARCH))
126        LOCAL_MODULE_STEM_32 := $$(LOCAL_MODULE)
127        art_out_binary_name := $$(LOCAL_MODULE)
128      endif
129    endif
130  endif
131
132  LOCAL_NATIVE_COVERAGE := $(ART_COVERAGE)
133
134  ifeq ($$(art_target_or_host),target)
135    include $(BUILD_EXECUTABLE)
136    ART_TARGET_EXECUTABLES := $(ART_TARGET_EXECUTABLES) $$(foreach name,$$(art_out_binary_name),$(TARGET_OUT_EXECUTABLES)/$$(name))
137  else # host
138    LOCAL_IS_HOST_MODULE := true
139    include $(BUILD_HOST_EXECUTABLE)
140    ART_HOST_EXECUTABLES := $(ART_HOST_EXECUTABLES) $$(foreach name,$$(art_out_binary_name),$(HOST_OUT_EXECUTABLES)/$$(name))
141  endif
142
143  # Clear out local variables now that we're done with them.
144  art_executable :=
145  art_source :=
146  art_shared_libraries :=
147  art_c_includes :=
148  art_target_or_host :=
149  art_ndebug_or_debug :=
150  art_multilib :=
151  art_out_binary_name :=
152
153endef
154
155#
156# Build many art executables from multiple variations (debug/ndebug, host/target, 32/64bit).
157# By default only either 32-bit or 64-bit is built (but not both -- see multilib arg).
158# All other variations are gated by ANDROID_BUILD_(TARGET|HOST)_[N]DEBUG.
159# The result must be eval-uated.
160#
161# $(1): executable name
162# $(2): source files
163# $(3): library dependencies (common); debug prefix is added on as necessary automatically.
164# $(4): library dependencies (target only)
165# $(5): library dependencies (host only)
166# $(6): extra include directories
167# $(7): multilib (default: empty), valid values: {,32,64,both})
168define build-art-multi-executable
169  $(foreach debug_flavor,ndebug debug,
170    $(foreach target_flavor,host target,
171      art-multi-binary-name := $(1)
172      art-multi-source-files := $(2)
173      art-multi-lib-dependencies := $(3)
174      art-multi-lib-dependencies-target := $(4)
175      art-multi-lib-dependencies-host := $(5)
176      art-multi-include-extra := $(6)
177      art-multi-multilib := $(7)
178
179      # Add either -host or -target specific lib dependencies to the lib dependencies.
180      art-multi-lib-dependencies += $$(art-multi-lib-dependencies-$(target_flavor))
181
182      # Replace libart- prefix with libartd- for debug flavor.
183      ifeq ($(debug_flavor),debug)
184        art-multi-lib-dependencies := $$(subst libart-,libartd-,$$(art-multi-lib-dependencies))
185      endif
186
187      # Build the env guard var name, e.g. ART_BUILD_HOST_NDEBUG.
188      art-multi-env-guard := $$(call art-string-to-uppercase,ART_BUILD_$(target_flavor)_$(debug_flavor))
189
190      # Build the art executable only if the corresponding env guard was set.
191      ifeq ($$($$(art-multi-env-guard)),true)
192        $$(eval $$(call build-art-executable,$$(art-multi-binary-name),$$(art-multi-source-files),$$(art-multi-lib-dependencies),$$(art-multi-include-extra),$(target_flavor),$(debug_flavor),$$(art-multi-multilib)))
193      endif
194
195      # Clear locals now they've served their purpose.
196      art-multi-binary-name :=
197      art-multi-source-files :=
198      art-multi-lib-dependencies :=
199      art-multi-lib-dependencies-target :=
200      art-multi-lib-dependencies-host :=
201      art-multi-include-extra :=
202      art-multi-multilib :=
203      art-multi-env-guard :=
204    )
205  )
206endef
207