blob: 157500b4bb61c048003b6b695e3ade46d5f40134 [file] [log] [blame]
Brian Carlstrom69b15fb2011-09-03 12:25:21 -07001#
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
Ian Rogersafd9acc2014-06-17 08:21:54 -070017include art/build/Android.common_build.mk
Brian Carlstrom51c24672013-07-11 16:00:56 -070018
Brian Carlstromfa50baa2013-08-02 01:00:27 -070019ART_HOST_EXECUTABLES ?=
20ART_TARGET_EXECUTABLES ?=
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070021
Shih-wei Liaoc4c98812012-03-10 21:55:51 -080022ART_EXECUTABLES_CFLAGS :=
buzbee2cfc6392012-05-07 14:51:40 -070023
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070024# $(1): executable ("d" will be appended for debug version)
25# $(2): source
Brian Carlstrom7940e442013-07-12 13:46:57 -070026# $(3): extra shared libraries
27# $(4): extra include directories
28# $(5): target or host
29# $(6): ndebug or debug
Colin Crossd7475432014-03-20 12:55:13 -070030# $(7): value for LOCAL_MULTILIB (empty means default)
Calin Juravle65e069d2015-06-08 10:35:24 +010031# $(8): static or shared (empty means shared, applies only for host)
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070032define build-art-executable
Brian Carlstrom7940e442013-07-12 13:46:57 -070033 ifneq ($(5),target)
34 ifneq ($(5),host)
35 $$(error expected target or host for argument 5, received $(5))
Brian Carlstrom0796af02011-10-12 14:31:45 -070036 endif
37 endif
Brian Carlstrom7940e442013-07-12 13:46:57 -070038 ifneq ($(6),ndebug)
39 ifneq ($(6),debug)
40 $$(error expected ndebug or debug for argument 6, received $(6))
Brian Carlstrom0796af02011-10-12 14:31:45 -070041 endif
42 endif
43
44 art_executable := $(1)
45 art_source := $(2)
Calin Juravle65e069d2015-06-08 10:35:24 +010046 art_libraries := $(3)
Brian Carlstrom7940e442013-07-12 13:46:57 -070047 art_c_includes := $(4)
48 art_target_or_host := $(5)
49 art_ndebug_or_debug := $(6)
Colin Crossd7475432014-03-20 12:55:13 -070050 art_multilib := $(7)
Calin Juravle65e069d2015-06-08 10:35:24 +010051 art_static_or_shared := $(8)
Igor Murashkin37743352014-11-13 14:38:00 -080052 art_out_binary_name :=
Brian Carlstrom0796af02011-10-12 14:31:45 -070053
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070054 include $(CLEAR_VARS)
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070055 LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070056 LOCAL_MODULE_TAGS := optional
Dmitriy Ivanove49a4f62014-10-20 14:11:00 -070057 LOCAL_SRC_FILES := $$(art_source)
Igor Murashkin37743352014-11-13 14:38:00 -080058 LOCAL_C_INCLUDES += $(ART_C_INCLUDES) art/runtime art/cmdline $$(art_c_includes)
Calin Juravle65e069d2015-06-08 10:35:24 +010059
60 ifeq ($$(art_static_or_shared),static)
61 LOCAL_STATIC_LIBRARIES += $$(art_libraries)
62 else
63 LOCAL_SHARED_LIBRARIES += $$(art_libraries)
64 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -070065
66 ifeq ($$(art_ndebug_or_debug),ndebug)
67 LOCAL_MODULE := $$(art_executable)
68 else #debug
69 LOCAL_MODULE := $$(art_executable)d
Elliott Hughes1d3f1142011-09-13 12:00:00 -070070 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -070071
Calin Juravle65e069d2015-06-08 10:35:24 +010072 ifeq ($$(art_static_or_shared),static)
73 LOCAL_MODULE := $(LOCAL_MODULE)s
74 endif
75
Shih-wei Liaoc4c98812012-03-10 21:55:51 -080076 LOCAL_CFLAGS := $(ART_EXECUTABLES_CFLAGS)
Dan Albert7ccf48e2014-12-10 15:50:45 -080077 # Mac OS linker doesn't understand --export-dynamic.
Dmitriy Ivanov1d74e572014-10-14 12:18:10 -070078 ifneq ($$(HOST_OS)-$$(art_target_or_host),darwin-host)
Dan Albert7ccf48e2014-12-10 15:50:45 -080079 LOCAL_LDFLAGS := -Wl,--export-dynamic
Dmitriy Ivanov1d74e572014-10-14 12:18:10 -070080 endif
81
Brian Carlstrom89521892011-12-07 22:05:07 -080082 ifeq ($$(art_target_or_host),target)
Roland Levillain12bd7212015-06-04 17:50:27 +010083 $(call set-target-local-clang-vars)
84 $(call set-target-local-cflags-vars,$(6))
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -070085 LOCAL_SHARED_LIBRARIES += libdl
Brian Carlstrom0796af02011-10-12 14:31:45 -070086 else # host
Ian Rogerscd5d0422013-05-17 15:54:01 -070087 LOCAL_CLANG := $(ART_HOST_CLANG)
Ian Rogers6f3dbba2014-10-14 17:41:57 -070088 LOCAL_LDLIBS := $(ART_HOST_LDLIBS)
Shih-wei Liaoc4c98812012-03-10 21:55:51 -080089 LOCAL_CFLAGS += $(ART_HOST_CFLAGS)
Roland Levillain12bd7212015-06-04 17:50:27 +010090 LOCAL_ASFLAGS += $(ART_HOST_ASFLAGS)
Brian Carlstrom0796af02011-10-12 14:31:45 -070091 ifeq ($$(art_ndebug_or_debug),debug)
Brian Carlstrom86927212011-09-15 11:31:11 -070092 LOCAL_CFLAGS += $(ART_HOST_DEBUG_CFLAGS)
Roland Levillainb5390f72016-07-04 16:59:53 +010093 LOCAL_ASFLAGS += $(ART_HOST_DEBUG_ASFLAGS)
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070094 else
95 LOCAL_CFLAGS += $(ART_HOST_NON_DEBUG_CFLAGS)
Roland Levillainb5390f72016-07-04 16:59:53 +010096 LOCAL_ASFLAGS += $(ART_HOST_NON_DEBUG_ASFLAGS)
Brian Carlstrom86927212011-09-15 11:31:11 -070097 endif
Calin Juravle9b369142015-07-02 13:48:37 +010098 LOCAL_LDLIBS += -lpthread -ldl
Calin Juravle65e069d2015-06-08 10:35:24 +010099 ifeq ($$(art_static_or_shared),static)
100 LOCAL_LDFLAGS += -static
101 # We need this because GC stress mode makes use of _Unwind_GetIP and _Unwind_Backtrace and
102 # the symbols are also defined in libgcc_eh.a(unwind-dw2.o)
103 # TODO: Having this is not ideal as it might obscure errors. Try to get rid of it.
104 LOCAL_LDFLAGS += -z muldefs
Calin Juravle9b369142015-07-02 13:48:37 +0100105 ifeq ($$(HOST_OS),linux)
Yabin Cuif6010ec2015-09-21 20:28:36 -0700106 LOCAL_LDLIBS += -lrt -lncurses -ltinfo
107 endif
108 ifeq ($$(HOST_OS),darwin)
109 LOCAL_LDLIBS += -lncurses -ltinfo
Calin Juravle9b369142015-07-02 13:48:37 +0100110 endif
Calin Juravle65e069d2015-06-08 10:35:24 +0100111 endif
Calin Juravle9b369142015-07-02 13:48:37 +0100112
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700113 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -0700114
Calin Juravle65e069d2015-06-08 10:35:24 +0100115 # If dynamically linked add libart by default. Statically linked executables
116 # needs to specify it in art_libraries to ensure proper ordering.
Brian Carlstrom0796af02011-10-12 14:31:45 -0700117 ifeq ($$(art_ndebug_or_debug),ndebug)
Calin Juravle65e069d2015-06-08 10:35:24 +0100118 ifneq ($$(art_static_or_shared),static)
119 LOCAL_SHARED_LIBRARIES += libart
120 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -0700121 else # debug
Calin Juravle65e069d2015-06-08 10:35:24 +0100122 ifneq ($$(art_static_or_shared),static)
123 LOCAL_SHARED_LIBRARIES += libartd
124 endif
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700125 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -0700126
Ian Rogersafd9acc2014-06-17 08:21:54 -0700127 LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_build.mk
Igor Murashkin37743352014-11-13 14:38:00 -0800128 LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.common_utils.mk
Brian Carlstrom7940e442013-07-12 13:46:57 -0700129 LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.executable.mk
Brian Carlstromfa42b442013-06-17 12:53:45 -0700130
Brian Carlstrom0796af02011-10-12 14:31:45 -0700131 ifeq ($$(art_target_or_host),target)
Colin Crossdc781a12014-02-04 16:22:03 -0800132 LOCAL_MODULE_TARGET_ARCH := $(ART_SUPPORTED_ARCH)
133 endif
Andreas Gampe088b16e2014-12-03 21:59:27 -0800134
Ying Wang754a4452015-07-21 12:05:30 -0700135 ifdef ART_MULTILIB_OVERRIDE_$$(art_target_or_host)
136 art_multilib := $$(ART_MULTILIB_OVERRIDE_$$(art_target_or_host))
137 endif
138
Ian Rogersafd9acc2014-06-17 08:21:54 -0700139 LOCAL_MULTILIB := $$(art_multilib)
Igor Murashkin37743352014-11-13 14:38:00 -0800140 art_out_binary_name := $$(LOCAL_MODULE)
141
142 # If multilib=both (potentially building both 32-bit and 64-bit), need to provide stem.
Andreas Gampe088b16e2014-12-03 21:59:27 -0800143 ifeq ($$(art_multilib),both)
Igor Murashkin37743352014-11-13 14:38:00 -0800144 # Set up a 32-bit/64-bit stem if we are building both binaries.
145 # In this case, the 32-bit binary has an additional 32-bit suffix.
146 LOCAL_MODULE_STEM_32 := $$(LOCAL_MODULE)32
147 LOCAL_MODULE_STEM_64 := $$(LOCAL_MODULE)
148
149 # Remember the binary names so we can add them to the global art executables list later.
150 art_out_binary_name := $$(LOCAL_MODULE_STEM_32) $$(LOCAL_MODULE_STEM_64)
151
152 # For single-architecture targets, remove any binary name suffixes.
153 ifeq ($$(art_target_or_host),target)
154 ifeq (,$(TARGET_2ND_ARCH))
155 LOCAL_MODULE_STEM_32 := $$(LOCAL_MODULE)
156 art_out_binary_name := $$(LOCAL_MODULE)
157 endif
158 endif
159
160 # For single-architecture hosts, remove any binary name suffixes.
161 ifeq ($$(art_target_or_host),host)
162 ifeq (,$(HOST_2ND_ARCH))
163 LOCAL_MODULE_STEM_32 := $$(LOCAL_MODULE)
164 art_out_binary_name := $$(LOCAL_MODULE)
165 endif
Andreas Gampe088b16e2014-12-03 21:59:27 -0800166 endif
167 endif
Colin Crossdc781a12014-02-04 16:22:03 -0800168
Dan Albert31fb2602014-09-30 22:10:10 -0700169 LOCAL_NATIVE_COVERAGE := $(ART_COVERAGE)
170
Colin Crossdc781a12014-02-04 16:22:03 -0800171 ifeq ($$(art_target_or_host),target)
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700172 include $(BUILD_EXECUTABLE)
Igor Murashkin37743352014-11-13 14:38:00 -0800173 ART_TARGET_EXECUTABLES := $(ART_TARGET_EXECUTABLES) $$(foreach name,$$(art_out_binary_name),$(TARGET_OUT_EXECUTABLES)/$$(name))
Brian Carlstrom0796af02011-10-12 14:31:45 -0700174 else # host
Ian Rogersbd5ea6a2014-04-16 16:34:44 -0700175 LOCAL_IS_HOST_MODULE := true
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700176 include $(BUILD_HOST_EXECUTABLE)
Igor Murashkin37743352014-11-13 14:38:00 -0800177 ART_HOST_EXECUTABLES := $(ART_HOST_EXECUTABLES) $$(foreach name,$$(art_out_binary_name),$(HOST_OUT_EXECUTABLES)/$$(name))
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700178 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -0700179
Igor Murashkin37743352014-11-13 14:38:00 -0800180 # Clear out local variables now that we're done with them.
181 art_executable :=
182 art_source :=
Calin Juravle65e069d2015-06-08 10:35:24 +0100183 art_libraries :=
Igor Murashkin37743352014-11-13 14:38:00 -0800184 art_c_includes :=
185 art_target_or_host :=
186 art_ndebug_or_debug :=
187 art_multilib :=
Calin Juravle65e069d2015-06-08 10:35:24 +0100188 art_static_or_shared :=
Igor Murashkin37743352014-11-13 14:38:00 -0800189 art_out_binary_name :=
190
191endef
192
193#
194# Build many art executables from multiple variations (debug/ndebug, host/target, 32/64bit).
195# By default only either 32-bit or 64-bit is built (but not both -- see multilib arg).
196# All other variations are gated by ANDROID_BUILD_(TARGET|HOST)_[N]DEBUG.
197# The result must be eval-uated.
198#
199# $(1): executable name
200# $(2): source files
201# $(3): library dependencies (common); debug prefix is added on as necessary automatically.
202# $(4): library dependencies (target only)
203# $(5): library dependencies (host only)
204# $(6): extra include directories
205# $(7): multilib (default: empty), valid values: {,32,64,both})
Roland Levillain3045cfe2015-12-10 10:17:43 +0000206# $(8): host prefer 32-bit: {true, false} (default: false). If argument
207# `multilib` is explicitly set to 64, ignore the "host prefer 32-bit"
208# setting and only build a 64-bit executable on host.
Igor Murashkin37743352014-11-13 14:38:00 -0800209define build-art-multi-executable
210 $(foreach debug_flavor,ndebug debug,
211 $(foreach target_flavor,host target,
212 art-multi-binary-name := $(1)
213 art-multi-source-files := $(2)
214 art-multi-lib-dependencies := $(3)
215 art-multi-lib-dependencies-target := $(4)
216 art-multi-lib-dependencies-host := $(5)
217 art-multi-include-extra := $(6)
218 art-multi-multilib := $(7)
Roland Levillain3045cfe2015-12-10 10:17:43 +0000219 art-multi-host-prefer-32-bit := $(8)
Igor Murashkin37743352014-11-13 14:38:00 -0800220
221 # Add either -host or -target specific lib dependencies to the lib dependencies.
222 art-multi-lib-dependencies += $$(art-multi-lib-dependencies-$(target_flavor))
223
224 # Replace libart- prefix with libartd- for debug flavor.
225 ifeq ($(debug_flavor),debug)
226 art-multi-lib-dependencies := $$(subst libart-,libartd-,$$(art-multi-lib-dependencies))
227 endif
228
229 # Build the env guard var name, e.g. ART_BUILD_HOST_NDEBUG.
230 art-multi-env-guard := $$(call art-string-to-uppercase,ART_BUILD_$(target_flavor)_$(debug_flavor))
231
Roland Levillain3045cfe2015-12-10 10:17:43 +0000232 ifeq ($(target_flavor),host)
Roland Levillainea6f8d82015-12-10 11:04:25 +0000233 ifeq ($$(art-multi-host-prefer-32-bit),true)
234 ifneq ($$(art-multi-multilib),64)
Roland Levillain3045cfe2015-12-10 10:17:43 +0000235 art-multi-multilib := 32
236 endif
237 endif
238 endif
239
Igor Murashkin37743352014-11-13 14:38:00 -0800240 # Build the art executable only if the corresponding env guard was set.
241 ifeq ($$($$(art-multi-env-guard)),true)
242 $$(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)))
243 endif
244
245 # Clear locals now they've served their purpose.
246 art-multi-binary-name :=
247 art-multi-source-files :=
248 art-multi-lib-dependencies :=
249 art-multi-lib-dependencies-target :=
250 art-multi-lib-dependencies-host :=
251 art-multi-include-extra :=
252 art-multi-multilib :=
Roland Levillain3045cfe2015-12-10 10:17:43 +0000253 art-multi-host-prefer-32-bit :=
Igor Murashkin37743352014-11-13 14:38:00 -0800254 art-multi-env-guard :=
255 )
256 )
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700257endef