blob: c35833de0a33dd8029ceda7a8b241069fcc05803 [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
Shih-wei Liaoc4c98812012-03-10 21:55:51 -080019ART_EXECUTABLES_CFLAGS :=
buzbee2cfc6392012-05-07 14:51:40 -070020
Roland Levillainaf547852016-09-05 16:27:20 +010021# $(1): executable ("d" will be appended for debug version, "s" will be appended for static version)
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070022# $(2): source
Brian Carlstrom7940e442013-07-12 13:46:57 -070023# $(3): extra shared libraries
24# $(4): extra include directories
25# $(5): target or host
26# $(6): ndebug or debug
Colin Crossd7475432014-03-20 12:55:13 -070027# $(7): value for LOCAL_MULTILIB (empty means default)
Calin Juravle65e069d2015-06-08 10:35:24 +010028# $(8): static or shared (empty means shared, applies only for host)
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070029define build-art-executable
Brian Carlstrom7940e442013-07-12 13:46:57 -070030 ifneq ($(5),target)
31 ifneq ($(5),host)
32 $$(error expected target or host for argument 5, received $(5))
Brian Carlstrom0796af02011-10-12 14:31:45 -070033 endif
34 endif
Brian Carlstrom7940e442013-07-12 13:46:57 -070035 ifneq ($(6),ndebug)
36 ifneq ($(6),debug)
37 $$(error expected ndebug or debug for argument 6, received $(6))
Brian Carlstrom0796af02011-10-12 14:31:45 -070038 endif
39 endif
40
41 art_executable := $(1)
42 art_source := $(2)
Calin Juravle65e069d2015-06-08 10:35:24 +010043 art_libraries := $(3)
Brian Carlstrom7940e442013-07-12 13:46:57 -070044 art_c_includes := $(4)
45 art_target_or_host := $(5)
46 art_ndebug_or_debug := $(6)
Colin Crossd7475432014-03-20 12:55:13 -070047 art_multilib := $(7)
Calin Juravle65e069d2015-06-08 10:35:24 +010048 art_static_or_shared := $(8)
Igor Murashkin37743352014-11-13 14:38:00 -080049 art_out_binary_name :=
Brian Carlstrom0796af02011-10-12 14:31:45 -070050
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070051 include $(CLEAR_VARS)
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070052 LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070053 LOCAL_MODULE_TAGS := optional
Dmitriy Ivanove49a4f62014-10-20 14:11:00 -070054 LOCAL_SRC_FILES := $$(art_source)
Igor Murashkin37743352014-11-13 14:38:00 -080055 LOCAL_C_INCLUDES += $(ART_C_INCLUDES) art/runtime art/cmdline $$(art_c_includes)
Calin Juravle65e069d2015-06-08 10:35:24 +010056
57 ifeq ($$(art_static_or_shared),static)
58 LOCAL_STATIC_LIBRARIES += $$(art_libraries)
59 else
60 LOCAL_SHARED_LIBRARIES += $$(art_libraries)
61 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -070062
63 ifeq ($$(art_ndebug_or_debug),ndebug)
64 LOCAL_MODULE := $$(art_executable)
65 else #debug
66 LOCAL_MODULE := $$(art_executable)d
Elliott Hughes1d3f1142011-09-13 12:00:00 -070067 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -070068
Calin Juravle65e069d2015-06-08 10:35:24 +010069 ifeq ($$(art_static_or_shared),static)
Roland Levillainaf547852016-09-05 16:27:20 +010070 LOCAL_MODULE := $$(LOCAL_MODULE)s
Calin Juravle65e069d2015-06-08 10:35:24 +010071 endif
72
Shih-wei Liaoc4c98812012-03-10 21:55:51 -080073 LOCAL_CFLAGS := $(ART_EXECUTABLES_CFLAGS)
Dan Albert7ccf48e2014-12-10 15:50:45 -080074 # Mac OS linker doesn't understand --export-dynamic.
Dmitriy Ivanov1d74e572014-10-14 12:18:10 -070075 ifneq ($$(HOST_OS)-$$(art_target_or_host),darwin-host)
Dan Albert7ccf48e2014-12-10 15:50:45 -080076 LOCAL_LDFLAGS := -Wl,--export-dynamic
Dmitriy Ivanov1d74e572014-10-14 12:18:10 -070077 endif
78
Brian Carlstrom89521892011-12-07 22:05:07 -080079 ifeq ($$(art_target_or_host),target)
Colin Crossecf75a62016-07-28 16:01:42 -070080 LOCAL_CLANG := $(ART_TARGET_CLANG)
Roland Levillain12bd7212015-06-04 17:50:27 +010081 $(call set-target-local-cflags-vars,$(6))
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -070082 LOCAL_SHARED_LIBRARIES += libdl
Brian Carlstrom0796af02011-10-12 14:31:45 -070083 else # host
Ian Rogerscd5d0422013-05-17 15:54:01 -070084 LOCAL_CLANG := $(ART_HOST_CLANG)
Shih-wei Liaoc4c98812012-03-10 21:55:51 -080085 LOCAL_CFLAGS += $(ART_HOST_CFLAGS)
Roland Levillain12bd7212015-06-04 17:50:27 +010086 LOCAL_ASFLAGS += $(ART_HOST_ASFLAGS)
Brian Carlstrom0796af02011-10-12 14:31:45 -070087 ifeq ($$(art_ndebug_or_debug),debug)
Brian Carlstrom86927212011-09-15 11:31:11 -070088 LOCAL_CFLAGS += $(ART_HOST_DEBUG_CFLAGS)
Roland Levillainb5390f72016-07-04 16:59:53 +010089 LOCAL_ASFLAGS += $(ART_HOST_DEBUG_ASFLAGS)
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070090 else
91 LOCAL_CFLAGS += $(ART_HOST_NON_DEBUG_CFLAGS)
Roland Levillainb5390f72016-07-04 16:59:53 +010092 LOCAL_ASFLAGS += $(ART_HOST_NON_DEBUG_ASFLAGS)
Brian Carlstrom86927212011-09-15 11:31:11 -070093 endif
Calin Juravle9b369142015-07-02 13:48:37 +010094 LOCAL_LDLIBS += -lpthread -ldl
Calin Juravle65e069d2015-06-08 10:35:24 +010095 ifeq ($$(art_static_or_shared),static)
96 LOCAL_LDFLAGS += -static
97 # We need this because GC stress mode makes use of _Unwind_GetIP and _Unwind_Backtrace and
98 # the symbols are also defined in libgcc_eh.a(unwind-dw2.o)
99 # TODO: Having this is not ideal as it might obscure errors. Try to get rid of it.
100 LOCAL_LDFLAGS += -z muldefs
Calin Juravle9b369142015-07-02 13:48:37 +0100101 ifeq ($$(HOST_OS),linux)
Yabin Cuif6010ec2015-09-21 20:28:36 -0700102 LOCAL_LDLIBS += -lrt -lncurses -ltinfo
103 endif
104 ifeq ($$(HOST_OS),darwin)
105 LOCAL_LDLIBS += -lncurses -ltinfo
Calin Juravle9b369142015-07-02 13:48:37 +0100106 endif
Calin Juravle65e069d2015-06-08 10:35:24 +0100107 endif
Calin Juravle9b369142015-07-02 13:48:37 +0100108
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700109 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -0700110
Calin Juravle65e069d2015-06-08 10:35:24 +0100111 # If dynamically linked add libart by default. Statically linked executables
112 # needs to specify it in art_libraries to ensure proper ordering.
Brian Carlstrom0796af02011-10-12 14:31:45 -0700113 ifeq ($$(art_ndebug_or_debug),ndebug)
Calin Juravle65e069d2015-06-08 10:35:24 +0100114 ifneq ($$(art_static_or_shared),static)
115 LOCAL_SHARED_LIBRARIES += libart
116 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -0700117 else # debug
Calin Juravle65e069d2015-06-08 10:35:24 +0100118 ifneq ($$(art_static_or_shared),static)
119 LOCAL_SHARED_LIBRARIES += libartd
120 endif
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700121 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -0700122
Ian Rogersafd9acc2014-06-17 08:21:54 -0700123 LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_build.mk
Igor Murashkin37743352014-11-13 14:38:00 -0800124 LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.common_utils.mk
Brian Carlstrom7940e442013-07-12 13:46:57 -0700125 LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.executable.mk
Brian Carlstromfa42b442013-06-17 12:53:45 -0700126
Brian Carlstrom0796af02011-10-12 14:31:45 -0700127 ifeq ($$(art_target_or_host),target)
Colin Crossdc781a12014-02-04 16:22:03 -0800128 LOCAL_MODULE_TARGET_ARCH := $(ART_SUPPORTED_ARCH)
129 endif
Andreas Gampe088b16e2014-12-03 21:59:27 -0800130
Ying Wang754a4452015-07-21 12:05:30 -0700131 ifdef ART_MULTILIB_OVERRIDE_$$(art_target_or_host)
132 art_multilib := $$(ART_MULTILIB_OVERRIDE_$$(art_target_or_host))
133 endif
134
Ian Rogersafd9acc2014-06-17 08:21:54 -0700135 LOCAL_MULTILIB := $$(art_multilib)
Igor Murashkin37743352014-11-13 14:38:00 -0800136 art_out_binary_name := $$(LOCAL_MODULE)
137
138 # If multilib=both (potentially building both 32-bit and 64-bit), need to provide stem.
Andreas Gampe088b16e2014-12-03 21:59:27 -0800139 ifeq ($$(art_multilib),both)
Igor Murashkin37743352014-11-13 14:38:00 -0800140 # Set up a 32-bit/64-bit stem if we are building both binaries.
141 # In this case, the 32-bit binary has an additional 32-bit suffix.
142 LOCAL_MODULE_STEM_32 := $$(LOCAL_MODULE)32
143 LOCAL_MODULE_STEM_64 := $$(LOCAL_MODULE)
144
145 # Remember the binary names so we can add them to the global art executables list later.
146 art_out_binary_name := $$(LOCAL_MODULE_STEM_32) $$(LOCAL_MODULE_STEM_64)
147
148 # For single-architecture targets, remove any binary name suffixes.
149 ifeq ($$(art_target_or_host),target)
150 ifeq (,$(TARGET_2ND_ARCH))
151 LOCAL_MODULE_STEM_32 := $$(LOCAL_MODULE)
152 art_out_binary_name := $$(LOCAL_MODULE)
153 endif
154 endif
155
156 # For single-architecture hosts, remove any binary name suffixes.
157 ifeq ($$(art_target_or_host),host)
158 ifeq (,$(HOST_2ND_ARCH))
159 LOCAL_MODULE_STEM_32 := $$(LOCAL_MODULE)
160 art_out_binary_name := $$(LOCAL_MODULE)
161 endif
Andreas Gampe088b16e2014-12-03 21:59:27 -0800162 endif
163 endif
Colin Crossdc781a12014-02-04 16:22:03 -0800164
Dan Albert31fb2602014-09-30 22:10:10 -0700165 LOCAL_NATIVE_COVERAGE := $(ART_COVERAGE)
166
Colin Crossdc781a12014-02-04 16:22:03 -0800167 ifeq ($$(art_target_or_host),target)
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700168 include $(BUILD_EXECUTABLE)
Brian Carlstrom0796af02011-10-12 14:31:45 -0700169 else # host
Ian Rogersbd5ea6a2014-04-16 16:34:44 -0700170 LOCAL_IS_HOST_MODULE := true
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700171 include $(BUILD_HOST_EXECUTABLE)
172 endif
Brian Carlstrom0796af02011-10-12 14:31:45 -0700173
Igor Murashkin37743352014-11-13 14:38:00 -0800174 # Clear out local variables now that we're done with them.
175 art_executable :=
176 art_source :=
Calin Juravle65e069d2015-06-08 10:35:24 +0100177 art_libraries :=
Igor Murashkin37743352014-11-13 14:38:00 -0800178 art_c_includes :=
179 art_target_or_host :=
180 art_ndebug_or_debug :=
181 art_multilib :=
Calin Juravle65e069d2015-06-08 10:35:24 +0100182 art_static_or_shared :=
Igor Murashkin37743352014-11-13 14:38:00 -0800183 art_out_binary_name :=
184
185endef
186
187#
188# Build many art executables from multiple variations (debug/ndebug, host/target, 32/64bit).
189# By default only either 32-bit or 64-bit is built (but not both -- see multilib arg).
190# All other variations are gated by ANDROID_BUILD_(TARGET|HOST)_[N]DEBUG.
191# The result must be eval-uated.
192#
193# $(1): executable name
194# $(2): source files
195# $(3): library dependencies (common); debug prefix is added on as necessary automatically.
196# $(4): library dependencies (target only)
197# $(5): library dependencies (host only)
198# $(6): extra include directories
199# $(7): multilib (default: empty), valid values: {,32,64,both})
Roland Levillain3045cfe2015-12-10 10:17:43 +0000200# $(8): host prefer 32-bit: {true, false} (default: false). If argument
201# `multilib` is explicitly set to 64, ignore the "host prefer 32-bit"
202# setting and only build a 64-bit executable on host.
Igor Murashkin37743352014-11-13 14:38:00 -0800203define build-art-multi-executable
204 $(foreach debug_flavor,ndebug debug,
205 $(foreach target_flavor,host target,
206 art-multi-binary-name := $(1)
207 art-multi-source-files := $(2)
208 art-multi-lib-dependencies := $(3)
209 art-multi-lib-dependencies-target := $(4)
210 art-multi-lib-dependencies-host := $(5)
211 art-multi-include-extra := $(6)
212 art-multi-multilib := $(7)
Roland Levillain3045cfe2015-12-10 10:17:43 +0000213 art-multi-host-prefer-32-bit := $(8)
Igor Murashkin37743352014-11-13 14:38:00 -0800214
215 # Add either -host or -target specific lib dependencies to the lib dependencies.
216 art-multi-lib-dependencies += $$(art-multi-lib-dependencies-$(target_flavor))
217
218 # Replace libart- prefix with libartd- for debug flavor.
219 ifeq ($(debug_flavor),debug)
220 art-multi-lib-dependencies := $$(subst libart-,libartd-,$$(art-multi-lib-dependencies))
221 endif
222
223 # Build the env guard var name, e.g. ART_BUILD_HOST_NDEBUG.
224 art-multi-env-guard := $$(call art-string-to-uppercase,ART_BUILD_$(target_flavor)_$(debug_flavor))
225
Roland Levillain3045cfe2015-12-10 10:17:43 +0000226 ifeq ($(target_flavor),host)
Roland Levillainea6f8d82015-12-10 11:04:25 +0000227 ifeq ($$(art-multi-host-prefer-32-bit),true)
228 ifneq ($$(art-multi-multilib),64)
Roland Levillain3045cfe2015-12-10 10:17:43 +0000229 art-multi-multilib := 32
230 endif
231 endif
232 endif
233
Igor Murashkin37743352014-11-13 14:38:00 -0800234 # Build the art executable only if the corresponding env guard was set.
235 ifeq ($$($$(art-multi-env-guard)),true)
236 $$(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)))
237 endif
238
239 # Clear locals now they've served their purpose.
240 art-multi-binary-name :=
241 art-multi-source-files :=
242 art-multi-lib-dependencies :=
243 art-multi-lib-dependencies-target :=
244 art-multi-lib-dependencies-host :=
245 art-multi-include-extra :=
246 art-multi-multilib :=
Roland Levillain3045cfe2015-12-10 10:17:43 +0000247 art-multi-host-prefer-32-bit :=
Igor Murashkin37743352014-11-13 14:38:00 -0800248 art-multi-env-guard :=
249 )
250 )
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700251endef
Roland Levillain04147ef2016-09-06 11:09:41 +0100252
253# Note: the order is important because of static linking resolution.
254ART_STATIC_DEPENDENCIES := \
255 libziparchive \
256 libnativehelper \
257 libnativebridge \
258 libnativeloader \
259 libsigchain_dummy \
260 liblog \
261 libz \
262 libbacktrace \
263 libcutils \
264 libunwindbacktrace \
265 libutils \
266 libbase \
267 liblz4 \
268 liblzma