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
17LOCAL_PATH := $(call my-dir)
18
19include art/build/Android.common_build.mk
20
21LIBART_COMMON_SRC_FILES := \
22  atomic.cc.arm \
23  barrier.cc \
24  base/allocator.cc \
25  base/bit_vector.cc \
26  base/hex_dump.cc \
27  base/logging.cc \
28  base/mutex.cc \
29  base/scoped_flock.cc \
30  base/stringpiece.cc \
31  base/stringprintf.cc \
32  base/timing_logger.cc \
33  base/unix_file/fd_file.cc \
34  base/unix_file/mapped_file.cc \
35  base/unix_file/null_file.cc \
36  base/unix_file/random_access_file_utils.cc \
37  base/unix_file/string_file.cc \
38  check_jni.cc \
39  class_linker.cc \
40  common_throws.cc \
41  debugger.cc \
42  dex_file.cc \
43  dex_file_verifier.cc \
44  dex_instruction.cc \
45  elf_file.cc \
46  field_helper.cc \
47  gc/allocator/dlmalloc.cc \
48  gc/allocator/rosalloc.cc \
49  gc/accounting/card_table.cc \
50  gc/accounting/heap_bitmap.cc \
51  gc/accounting/mod_union_table.cc \
52  gc/accounting/remembered_set.cc \
53  gc/accounting/space_bitmap.cc \
54  gc/collector/concurrent_copying.cc \
55  gc/collector/garbage_collector.cc \
56  gc/collector/immune_region.cc \
57  gc/collector/mark_compact.cc \
58  gc/collector/mark_sweep.cc \
59  gc/collector/partial_mark_sweep.cc \
60  gc/collector/semi_space.cc \
61  gc/collector/sticky_mark_sweep.cc \
62  gc/gc_cause.cc \
63  gc/heap.cc \
64  gc/reference_processor.cc \
65  gc/reference_queue.cc \
66  gc/space/bump_pointer_space.cc \
67  gc/space/dlmalloc_space.cc \
68  gc/space/image_space.cc \
69  gc/space/large_object_space.cc \
70  gc/space/malloc_space.cc \
71  gc/space/rosalloc_space.cc \
72  gc/space/space.cc \
73  gc/space/zygote_space.cc \
74  hprof/hprof.cc \
75  image.cc \
76  indirect_reference_table.cc \
77  instruction_set.cc \
78  instrumentation.cc \
79  intern_table.cc \
80  interpreter/interpreter.cc \
81  interpreter/interpreter_common.cc \
82  interpreter/interpreter_switch_impl.cc \
83  jdwp/jdwp_event.cc \
84  jdwp/jdwp_expand_buf.cc \
85  jdwp/jdwp_handler.cc \
86  jdwp/jdwp_main.cc \
87  jdwp/jdwp_request.cc \
88  jdwp/jdwp_socket.cc \
89  jdwp/object_registry.cc \
90  jni_internal.cc \
91  jobject_comparator.cc \
92  mem_map.cc \
93  memory_region.cc \
94  method_helper.cc \
95  mirror/art_field.cc \
96  mirror/art_method.cc \
97  mirror/array.cc \
98  mirror/class.cc \
99  mirror/dex_cache.cc \
100  mirror/object.cc \
101  mirror/reference.cc \
102  mirror/stack_trace_element.cc \
103  mirror/string.cc \
104  mirror/throwable.cc \
105  monitor.cc \
106  native_bridge_art_interface.cc \
107  native/dalvik_system_DexFile.cc \
108  native/dalvik_system_VMDebug.cc \
109  native/dalvik_system_VMRuntime.cc \
110  native/dalvik_system_VMStack.cc \
111  native/dalvik_system_ZygoteHooks.cc \
112  native/java_lang_Class.cc \
113  native/java_lang_DexCache.cc \
114  native/java_lang_Object.cc \
115  native/java_lang_Runtime.cc \
116  native/java_lang_String.cc \
117  native/java_lang_System.cc \
118  native/java_lang_Thread.cc \
119  native/java_lang_Throwable.cc \
120  native/java_lang_VMClassLoader.cc \
121  native/java_lang_ref_FinalizerReference.cc \
122  native/java_lang_ref_Reference.cc \
123  native/java_lang_reflect_Array.cc \
124  native/java_lang_reflect_Constructor.cc \
125  native/java_lang_reflect_Field.cc \
126  native/java_lang_reflect_Method.cc \
127  native/java_lang_reflect_Proxy.cc \
128  native/java_util_concurrent_atomic_AtomicLong.cc \
129  native/org_apache_harmony_dalvik_ddmc_DdmServer.cc \
130  native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc \
131  native/sun_misc_Unsafe.cc \
132  oat.cc \
133  oat_file.cc \
134  object_lock.cc \
135  offsets.cc \
136  os_linux.cc \
137  parsed_options.cc \
138  primitive.cc \
139  quick_exception_handler.cc \
140  quick/inline_method_analyser.cc \
141  reference_table.cc \
142  reflection.cc \
143  runtime.cc \
144  signal_catcher.cc \
145  stack.cc \
146  thread.cc \
147  thread_list.cc \
148  thread_pool.cc \
149  throw_location.cc \
150  trace.cc \
151  transaction.cc \
152  profiler.cc \
153  fault_handler.cc \
154  utf.cc \
155  utils.cc \
156  verifier/dex_gc_map.cc \
157  verifier/instruction_flags.cc \
158  verifier/method_verifier.cc \
159  verifier/reg_type.cc \
160  verifier/reg_type_cache.cc \
161  verifier/register_line.cc \
162  well_known_classes.cc \
163  zip_archive.cc
164
165LIBART_COMMON_SRC_FILES += \
166  arch/context.cc \
167  arch/memcmp16.cc \
168  arch/arm/registers_arm.cc \
169  arch/arm64/registers_arm64.cc \
170  arch/x86/registers_x86.cc \
171  arch/mips/registers_mips.cc \
172  entrypoints/entrypoint_utils.cc \
173  entrypoints/interpreter/interpreter_entrypoints.cc \
174  entrypoints/jni/jni_entrypoints.cc \
175  entrypoints/math_entrypoints.cc \
176  entrypoints/portable/portable_alloc_entrypoints.cc \
177  entrypoints/portable/portable_cast_entrypoints.cc \
178  entrypoints/portable/portable_dexcache_entrypoints.cc \
179  entrypoints/portable/portable_field_entrypoints.cc \
180  entrypoints/portable/portable_fillarray_entrypoints.cc \
181  entrypoints/portable/portable_invoke_entrypoints.cc \
182  entrypoints/portable/portable_jni_entrypoints.cc \
183  entrypoints/portable/portable_lock_entrypoints.cc \
184  entrypoints/portable/portable_thread_entrypoints.cc \
185  entrypoints/portable/portable_throw_entrypoints.cc \
186  entrypoints/portable/portable_trampoline_entrypoints.cc \
187  entrypoints/quick/quick_alloc_entrypoints.cc \
188  entrypoints/quick/quick_cast_entrypoints.cc \
189  entrypoints/quick/quick_deoptimization_entrypoints.cc \
190  entrypoints/quick/quick_dexcache_entrypoints.cc \
191  entrypoints/quick/quick_field_entrypoints.cc \
192  entrypoints/quick/quick_fillarray_entrypoints.cc \
193  entrypoints/quick/quick_instrumentation_entrypoints.cc \
194  entrypoints/quick/quick_jni_entrypoints.cc \
195  entrypoints/quick/quick_lock_entrypoints.cc \
196  entrypoints/quick/quick_math_entrypoints.cc \
197  entrypoints/quick/quick_thread_entrypoints.cc \
198  entrypoints/quick/quick_throw_entrypoints.cc \
199  entrypoints/quick/quick_trampoline_entrypoints.cc
200
201# Source files that only compile with GCC.
202LIBART_GCC_ONLY_SRC_FILES := \
203  interpreter/interpreter_goto_table_impl.cc
204
205LIBART_TARGET_LDFLAGS :=
206LIBART_HOST_LDFLAGS :=
207
208LIBART_TARGET_SRC_FILES := \
209  $(LIBART_COMMON_SRC_FILES) \
210  base/logging_android.cc \
211  jdwp/jdwp_adb.cc \
212  monitor_android.cc \
213  runtime_android.cc \
214  thread_android.cc
215
216LIBART_TARGET_SRC_FILES_arm := \
217  arch/arm/context_arm.cc.arm \
218  arch/arm/entrypoints_init_arm.cc \
219  arch/arm/jni_entrypoints_arm.S \
220  arch/arm/memcmp16_arm.S \
221  arch/arm/portable_entrypoints_arm.S \
222  arch/arm/quick_entrypoints_arm.S \
223  arch/arm/arm_sdiv.S \
224  arch/arm/thread_arm.cc \
225  arch/arm/fault_handler_arm.cc
226
227LIBART_TARGET_SRC_FILES_arm64 := \
228  arch/arm64/context_arm64.cc \
229  arch/arm64/entrypoints_init_arm64.cc \
230  arch/arm64/jni_entrypoints_arm64.S \
231  arch/arm64/memcmp16_arm64.S \
232  arch/arm64/portable_entrypoints_arm64.S \
233  arch/arm64/quick_entrypoints_arm64.S \
234  arch/arm64/thread_arm64.cc \
235  monitor_pool.cc \
236  arch/arm64/fault_handler_arm64.cc
237
238LIBART_SRC_FILES_x86 := \
239  arch/x86/context_x86.cc \
240  arch/x86/entrypoints_init_x86.cc \
241  arch/x86/jni_entrypoints_x86.S \
242  arch/x86/memcmp16_x86.S \
243  arch/x86/portable_entrypoints_x86.S \
244  arch/x86/quick_entrypoints_x86.S \
245  arch/x86/thread_x86.cc \
246  arch/x86/fault_handler_x86.cc
247
248LIBART_TARGET_SRC_FILES_x86 := \
249  $(LIBART_SRC_FILES_x86)
250
251# Note that the fault_handler_x86.cc is not a mistake.  This file is
252# shared between the x86 and x86_64 architectures.
253LIBART_SRC_FILES_x86_64 := \
254  arch/x86_64/context_x86_64.cc \
255  arch/x86_64/entrypoints_init_x86_64.cc \
256  arch/x86_64/jni_entrypoints_x86_64.S \
257  arch/x86_64/memcmp16_x86_64.S \
258  arch/x86_64/portable_entrypoints_x86_64.S \
259  arch/x86_64/quick_entrypoints_x86_64.S \
260  arch/x86_64/thread_x86_64.cc \
261  monitor_pool.cc \
262  arch/x86/fault_handler_x86.cc
263
264LIBART_TARGET_SRC_FILES_x86_64 := \
265  $(LIBART_SRC_FILES_x86_64) \
266
267LIBART_TARGET_SRC_FILES_mips := \
268  arch/mips/context_mips.cc \
269  arch/mips/entrypoints_init_mips.cc \
270  arch/mips/jni_entrypoints_mips.S \
271  arch/mips/memcmp16_mips.S \
272  arch/mips/portable_entrypoints_mips.S \
273  arch/mips/quick_entrypoints_mips.S \
274  arch/mips/thread_mips.cc \
275  arch/mips/fault_handler_mips.cc
276
277ifeq ($(TARGET_ARCH),mips64)
278$(info TODOMips64: $(LOCAL_PATH)/Android.mk Add mips64 specific runtime files)
279endif # TARGET_ARCH != mips64
280
281LIBART_HOST_SRC_FILES := \
282  $(LIBART_COMMON_SRC_FILES) \
283  base/logging_linux.cc \
284  monitor_linux.cc \
285  runtime_linux.cc \
286  thread_linux.cc
287
288LIBART_HOST_SRC_FILES_32 := \
289  $(LIBART_SRC_FILES_x86)
290
291LIBART_HOST_SRC_FILES_64 := \
292  $(LIBART_SRC_FILES_x86_64)
293
294LIBART_ENUM_OPERATOR_OUT_HEADER_FILES := \
295  arch/x86_64/registers_x86_64.h \
296  base/allocator.h \
297  base/mutex.h \
298  dex_file.h \
299  dex_instruction.h \
300  gc/collector/gc_type.h \
301  gc/collector_type.h \
302  gc/space/space.h \
303  gc/heap.h \
304  indirect_reference_table.h \
305  instruction_set.h \
306  invoke_type.h \
307  jdwp/jdwp.h \
308  jdwp/jdwp_constants.h \
309  lock_word.h \
310  mirror/class.h \
311  oat.h \
312  object_callbacks.h \
313  quick/inline_method_analyser.h \
314  thread.h \
315  thread_state.h \
316  verifier/method_verifier.h
317
318LIBART_CFLAGS :=
319ifeq ($(ART_USE_PORTABLE_COMPILER),true)
320  LIBART_CFLAGS += -DART_USE_PORTABLE_COMPILER=1
321endif
322
323ifeq ($(MALLOC_IMPL),dlmalloc)
324  LIBART_CFLAGS += -DUSE_DLMALLOC
325else
326  LIBART_CFLAGS += -DUSE_JEMALLOC
327endif
328
329ifeq ($(ART_USE_HSPACE_COMPACT),true)
330  LIBART_CFLAGS += -DART_USE_HSPACE_COMPACT
331endif
332
333# $(1): target or host
334# $(2): ndebug or debug
335define build-libart
336  ifneq ($(1),target)
337    ifneq ($(1),host)
338      $$(error expected target or host for argument 1, received $(1))
339    endif
340  endif
341  ifneq ($(2),ndebug)
342    ifneq ($(2),debug)
343      $$(error expected ndebug or debug for argument 2, received $(2))
344    endif
345  endif
346
347  art_target_or_host := $(1)
348  art_ndebug_or_debug := $(2)
349
350  include $$(CLEAR_VARS)
351  LOCAL_CPP_EXTENSION := $$(ART_CPP_EXTENSION)
352  ifeq ($$(art_ndebug_or_debug),ndebug)
353    LOCAL_MODULE := libart
354    LOCAL_FDO_SUPPORT := true
355  else # debug
356    LOCAL_MODULE := libartd
357  endif
358
359  LOCAL_MODULE_TAGS := optional
360  LOCAL_MODULE_CLASS := SHARED_LIBRARIES
361
362  ifeq ($$(art_target_or_host),target)
363    LOCAL_SRC_FILES := $$(LIBART_TARGET_SRC_FILES)
364    $$(foreach arch,$$(ART_TARGET_SUPPORTED_ARCH), \
365      $$(eval LOCAL_SRC_FILES_$$(arch) := $$$$(LIBART_TARGET_SRC_FILES_$$(arch))))
366  else # host
367    LOCAL_SRC_FILES := $$(LIBART_HOST_SRC_FILES)
368    LOCAL_SRC_FILES_32 := $$(LIBART_HOST_SRC_FILES_32)
369    LOCAL_SRC_FILES_64 := $$(LIBART_HOST_SRC_FILES_64)
370    LOCAL_IS_HOST_MODULE := true
371  endif
372
373  GENERATED_SRC_DIR := $$(call local-generated-sources-dir)
374  ENUM_OPERATOR_OUT_CC_FILES := $$(patsubst %.h,%_operator_out.cc,$$(LIBART_ENUM_OPERATOR_OUT_HEADER_FILES))
375  ENUM_OPERATOR_OUT_GEN := $$(addprefix $$(GENERATED_SRC_DIR)/,$$(ENUM_OPERATOR_OUT_CC_FILES))
376
377$$(ENUM_OPERATOR_OUT_GEN): art/tools/generate-operator-out.py
378$$(ENUM_OPERATOR_OUT_GEN): PRIVATE_CUSTOM_TOOL = art/tools/generate-operator-out.py $(LOCAL_PATH) $$< > $$@
379$$(ENUM_OPERATOR_OUT_GEN): $$(GENERATED_SRC_DIR)/%_operator_out.cc : $(LOCAL_PATH)/%.h
380	$$(transform-generated-source)
381
382  LOCAL_GENERATED_SOURCES += $$(ENUM_OPERATOR_OUT_GEN)
383
384  LOCAL_CFLAGS := $$(LIBART_CFLAGS)
385  LOCAL_LDFLAGS := $$(LIBART_LDFLAGS)
386  ifeq ($$(art_target_or_host),target)
387    LOCAL_LDFLAGS += $$(LIBART_TARGET_LDFLAGS)
388  else
389    LOCAL_LDFLAGS += $$(LIBART_HOST_LDFLAGS)
390  endif
391  $$(foreach arch,$$(ART_TARGET_SUPPORTED_ARCH), \
392    $$(eval LOCAL_LDFLAGS_$$(arch) := $$(LIBART_TARGET_LDFLAGS_$$(arch))))
393
394  # Clang usage
395  ifeq ($$(art_target_or_host),target)
396    $$(eval $$(call set-target-local-clang-vars))
397    $$(eval $$(call set-target-local-cflags-vars,$(2)))
398    # TODO: Loop with ifeq, ART_TARGET_CLANG
399    ifneq ($$(ART_TARGET_CLANG_$$(TARGET_ARCH)),true)
400      LOCAL_SRC_FILES_$$(TARGET_ARCH) += $$(LIBART_GCC_ONLY_SRC_FILES)
401    endif
402    ifneq ($$(ART_TARGET_CLANG_$$(TARGET_2ND_ARCH)),true)
403      LOCAL_SRC_FILES_$$(TARGET_2ND_ARCH) += $$(LIBART_GCC_ONLY_SRC_FILES)
404    endif
405  else # host
406    LOCAL_CLANG := $$(ART_HOST_CLANG)
407    ifeq ($$(ART_HOST_CLANG),false)
408      LOCAL_SRC_FILES += $$(LIBART_GCC_ONLY_SRC_FILES)
409    endif
410    LOCAL_CFLAGS += $$(ART_HOST_CFLAGS)
411    ifeq ($$(art_ndebug_or_debug),debug)
412      LOCAL_CFLAGS += $$(ART_HOST_DEBUG_CFLAGS)
413      LOCAL_LDLIBS += $$(ART_HOST_DEBUG_LDLIBS)
414      LOCAL_STATIC_LIBRARIES := libgtest_host
415    else
416      LOCAL_CFLAGS += $$(ART_HOST_NON_DEBUG_CFLAGS)
417    endif
418  endif
419
420  LOCAL_C_INCLUDES += $$(ART_C_INCLUDES)
421  LOCAL_C_INCLUDES += art/sigchainlib
422
423  LOCAL_SHARED_LIBRARIES += liblog libnativehelper libnativebridge
424  include external/libcxx/libcxx.mk
425  LOCAL_SHARED_LIBRARIES += libbacktrace_libc++
426  ifeq ($$(art_target_or_host),target)
427    LOCAL_SHARED_LIBRARIES += libcutils libdl libselinux libutils libsigchain
428    LOCAL_STATIC_LIBRARIES := libziparchive libz
429  else # host
430    LOCAL_STATIC_LIBRARIES += libcutils libziparchive-host libz libutils
431    LOCAL_SHARED_LIBRARIES += libsigchain
432    LOCAL_LDLIBS += -ldl -lpthread
433    ifeq ($$(HOST_OS),linux)
434      LOCAL_LDLIBS += -lrt
435    endif
436    LOCAL_MULTILIB := both
437  endif
438  ifeq ($$(ART_USE_PORTABLE_COMPILER),true)
439    include $$(LLVM_GEN_INTRINSICS_MK)
440    ifeq ($$(art_target_or_host),target)
441      include $$(LLVM_DEVICE_BUILD_MK)
442    else # host
443      include $$(LLVM_HOST_BUILD_MK)
444    endif
445  endif
446  LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_build.mk
447#  LOCAL_ADDITIONAL_DEPENDENCIES += $$(LOCAL_PATH)/Android.mk
448
449  ifeq ($$(art_target_or_host),target)
450    LOCAL_MODULE_TARGET_ARCH := $$(ART_TARGET_SUPPORTED_ARCH)
451  endif
452
453  ifeq ($$(art_target_or_host),target)
454    ifneq ($$(art_ndebug_or_debug),debug)
455      # Leave the symbols in the shared library so that stack unwinders can
456      # produce meaningful name resolution.
457      LOCAL_STRIP_MODULE := keep_symbols
458    endif
459    include $$(BUILD_SHARED_LIBRARY)
460  else # host
461    include $$(BUILD_HOST_SHARED_LIBRARY)
462  endif
463
464  # Clear locally defined variables.
465  GENERATED_SRC_DIR :=
466  ENUM_OPERATOR_OUT_CC_FILES :=
467  ENUM_OPERATOR_OUT_GEN :=
468  art_target_or_host :=
469  art_ndebug_or_debug :=
470endef
471
472# We always build dex2oat and dependencies, even if the host build is otherwise disabled, since
473# they are used to cross compile for the target.
474ifeq ($(ART_BUILD_NDEBUG),true)
475  $(eval $(call build-libart,host,ndebug))
476endif
477ifeq ($(ART_BUILD_DEBUG),true)
478  $(eval $(call build-libart,host,debug))
479endif
480
481ifeq ($(ART_BUILD_TARGET_NDEBUG),true)
482#  $(error $(call build-libart,target,ndebug))
483  $(eval $(call build-libart,target,ndebug))
484endif
485ifeq ($(ART_BUILD_TARGET_DEBUG),true)
486  $(eval $(call build-libart,target,debug))
487endif
488
489# Clear locally defined variables.
490LOCAL_PATH :=
491LIBART_COMMON_SRC_FILES :=
492LIBART_GCC_ONLY_SRC_FILES :=
493LIBART_TARGET_LDFLAGS :=
494LIBART_HOST_LDFLAGS :=
495LIBART_TARGET_SRC_FILES :=
496LIBART_TARGET_SRC_FILES_arm :=
497LIBART_TARGET_SRC_FILES_arm64 :=
498LIBART_TARGET_SRC_FILES_x86 :=
499LIBART_TARGET_SRC_FILES_x86_64 :=
500LIBART_TARGET_SRC_FILES_mips :=
501LIBART_HOST_SRC_FILES :=
502LIBART_HOST_SRC_FILES_32 :=
503LIBART_HOST_SRC_FILES_64 :=
504LIBART_ENUM_OPERATOR_OUT_HEADER_FILES :=
505LIBART_CFLAGS :=
506build-libart :=
507