1# Copyright (C) 2008 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15#
16# Common definitions for host or target builds of libdvm.
17#
18# If you enable or disable optional features here, make sure you do
19# a "clean" build -- not everything depends on Dalvik.h.  (See Android.mk
20# for the exact command.)
21#
22
23
24#
25# Compiler defines.
26#
27
28LOCAL_CFLAGS += -fstrict-aliasing -Wstrict-aliasing=2
29LOCAL_CFLAGS += -Wall -Wextra -Wno-unused-parameter
30LOCAL_CFLAGS += -DARCH_VARIANT=\"$(dvm_arch_variant)\"
31
32ifneq ($(strip $(LOCAL_CLANG)),true)
33LOCAL_CFLAGS += -fno-align-jumps
34endif
35
36#
37# Optional features.  These may impact the size or performance of the VM.
38#
39
40# Make a debugging version when building the simulator (if not told
41# otherwise) and when explicitly asked.
42dvm_make_debug_vm := false
43ifneq ($(strip $(DEBUG_DALVIK_VM)),)
44  dvm_make_debug_vm := $(DEBUG_DALVIK_VM)
45endif
46
47ifeq ($(dvm_make_debug_vm),true)
48  #
49  # "Debug" profile:
50  # - debugger enabled
51  # - profiling enabled
52  # - tracked-reference verification enabled
53  # - allocation limits enabled
54  # - GDB helpers enabled
55  # - LOGV
56  # - assert()
57  #
58  LOCAL_CFLAGS += -DWITH_INSTR_CHECKS
59  LOCAL_CFLAGS += -DWITH_EXTRA_OBJECT_VALIDATION
60  LOCAL_CFLAGS += -DWITH_TRACKREF_CHECKS
61  LOCAL_CFLAGS += -DWITH_EXTRA_GC_CHECKS=1
62  #LOCAL_CFLAGS += -DCHECK_MUTEX
63  LOCAL_CFLAGS += -DDVM_SHOW_EXCEPTION=3
64  # add some extra stuff to make it easier to examine with GDB
65  LOCAL_CFLAGS += -DEASY_GDB
66  # overall config may be for a "release" build, so reconfigure these
67  LOCAL_CFLAGS += -UNDEBUG -DDEBUG=1 -DLOG_NDEBUG=1 -DWITH_DALVIK_ASSERT
68else  # !dvm_make_debug_vm
69  #
70  # "Performance" profile:
71  # - all development features disabled
72  # - compiler optimizations enabled (redundant for "release" builds)
73  # - (debugging and profiling still enabled)
74  #
75  #LOCAL_CFLAGS += -DNDEBUG -DLOG_NDEBUG=1
76  # "-O2" is redundant for device (release) but useful for sim (debug)
77  #LOCAL_CFLAGS += -O2 -Winline
78  #LOCAL_CFLAGS += -DWITH_EXTRA_OBJECT_VALIDATION
79  LOCAL_CFLAGS += -DDVM_SHOW_EXCEPTION=1
80  # if you want to try with assertions on the device, add:
81  #LOCAL_CFLAGS += -UNDEBUG -DDEBUG=1 -DLOG_NDEBUG=1 -DWITH_DALVIK_ASSERT
82endif  # !dvm_make_debug_vm
83
84# bug hunting: checksum and verify interpreted stack when making JNI calls
85#LOCAL_CFLAGS += -DWITH_JNI_STACK_CHECK
86
87LOCAL_SRC_FILES := \
88	AllocTracker.cpp \
89	Atomic.cpp.arm \
90	AtomicCache.cpp \
91	BitVector.cpp.arm \
92	CheckJni.cpp \
93	Ddm.cpp \
94	Debugger.cpp \
95	DvmDex.cpp \
96	Exception.cpp \
97	Hash.cpp \
98	IndirectRefTable.cpp.arm \
99	Init.cpp \
100	InitRefs.cpp \
101	InlineNative.cpp.arm \
102	Inlines.cpp \
103	Intern.cpp \
104	Jni.cpp \
105	JarFile.cpp \
106	LinearAlloc.cpp \
107	Misc.cpp \
108	Native.cpp \
109	PointerSet.cpp \
110	Profile.cpp \
111	RawDexFile.cpp \
112	ReferenceTable.cpp \
113	SignalCatcher.cpp \
114	StdioConverter.cpp \
115	Sync.cpp \
116	Thread.cpp \
117	UtfString.cpp \
118	alloc/Alloc.cpp \
119	alloc/CardTable.cpp \
120	alloc/HeapBitmap.cpp.arm \
121	alloc/HeapDebug.cpp \
122	alloc/Heap.cpp.arm \
123	alloc/DdmHeap.cpp \
124	alloc/Verify.cpp \
125	alloc/Visit.cpp \
126	analysis/CodeVerify.cpp \
127	analysis/DexPrepare.cpp \
128	analysis/DexVerify.cpp \
129	analysis/Liveness.cpp \
130	analysis/Optimize.cpp \
131	analysis/RegisterMap.cpp \
132	analysis/VerifySubs.cpp \
133	analysis/VfyBasicBlock.cpp \
134	hprof/Hprof.cpp \
135	hprof/HprofClass.cpp \
136	hprof/HprofHeap.cpp \
137	hprof/HprofOutput.cpp \
138	hprof/HprofString.cpp \
139	interp/Interp.cpp.arm \
140	interp/Stack.cpp \
141	jdwp/ExpandBuf.cpp \
142	jdwp/JdwpAdb.cpp \
143	jdwp/JdwpConstants.cpp \
144	jdwp/JdwpEvent.cpp \
145	jdwp/JdwpHandler.cpp \
146	jdwp/JdwpMain.cpp \
147	jdwp/JdwpSocket.cpp \
148	mterp/Mterp.cpp.arm \
149	mterp/out/InterpC-portable.cpp.arm \
150	native/InternalNative.cpp \
151	native/dalvik_bytecode_OpcodeInfo.cpp \
152	native/dalvik_system_DexFile.cpp \
153	native/dalvik_system_VMDebug.cpp \
154	native/dalvik_system_VMRuntime.cpp \
155	native/dalvik_system_VMStack.cpp \
156	native/dalvik_system_Zygote.cpp \
157	native/java_lang_Class.cpp \
158	native/java_lang_Double.cpp \
159	native/java_lang_Float.cpp \
160	native/java_lang_Math.cpp \
161	native/java_lang_Object.cpp \
162	native/java_lang_Runtime.cpp \
163	native/java_lang_String.cpp \
164	native/java_lang_System.cpp \
165	native/java_lang_Throwable.cpp \
166	native/java_lang_VMClassLoader.cpp \
167	native/java_lang_VMThread.cpp \
168	native/java_lang_reflect_AccessibleObject.cpp \
169	native/java_lang_reflect_Array.cpp \
170	native/java_lang_reflect_Constructor.cpp \
171	native/java_lang_reflect_Field.cpp \
172	native/java_lang_reflect_Method.cpp \
173	native/java_lang_reflect_Proxy.cpp \
174	native/java_util_concurrent_atomic_AtomicLong.cpp \
175	native/org_apache_harmony_dalvik_NativeTestTarget.cpp \
176	native/org_apache_harmony_dalvik_ddmc_DdmServer.cpp \
177	native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cpp \
178	native/sun_misc_Unsafe.cpp \
179	oo/AccessCheck.cpp \
180	oo/Array.cpp \
181	oo/Class.cpp \
182	oo/Object.cpp \
183	oo/Resolve.cpp \
184	oo/TypeCheck.cpp \
185	reflect/Annotation.cpp \
186	reflect/Proxy.cpp \
187	reflect/Reflect.cpp \
188	test/AtomicTest.cpp.arm \
189	test/TestHash.cpp \
190	test/TestIndirectRefTable.cpp
191
192# TODO: this is the wrong test, but what's the right one?
193ifneq ($(filter arm mips,$(dvm_arch)),)
194  LOCAL_SRC_FILES += os/android.cpp
195else
196  LOCAL_SRC_FILES += os/linux.cpp
197endif
198
199WITH_COPYING_GC := $(strip $(WITH_COPYING_GC))
200
201ifeq ($(WITH_COPYING_GC),true)
202  LOCAL_CFLAGS += -DWITH_COPYING_GC
203  LOCAL_SRC_FILES += \
204	alloc/Copying.cpp.arm
205else
206  LOCAL_SRC_FILES += \
207	alloc/DlMalloc.cpp \
208	alloc/HeapSource.cpp \
209	alloc/MarkSweep.cpp.arm
210endif
211
212WITH_JIT := $(strip $(WITH_JIT))
213
214ifeq ($(WITH_JIT),true)
215  LOCAL_CFLAGS += -DWITH_JIT
216  LOCAL_SRC_FILES += \
217	compiler/Compiler.cpp \
218	compiler/Frontend.cpp \
219	compiler/Utility.cpp \
220	compiler/InlineTransformation.cpp \
221	compiler/IntermediateRep.cpp \
222	compiler/Dataflow.cpp \
223	compiler/SSATransformation.cpp \
224	compiler/Loop.cpp \
225	compiler/Ralloc.cpp \
226	interp/Jit.cpp
227endif
228
229LOCAL_C_INCLUDES += \
230	dalvik \
231	dalvik/vm \
232	external/zlib \
233	libcore/include \
234
235MTERP_ARCH_KNOWN := false
236
237ifeq ($(dvm_arch),arm)
238  #dvm_arch_variant := armv7-a
239  #LOCAL_CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfp
240  LOCAL_CFLAGS += -Werror
241  MTERP_ARCH_KNOWN := true
242  # Select architecture-specific sources (armv5te, armv7-a, etc.)
243  LOCAL_SRC_FILES += \
244		arch/arm/CallOldABI.S \
245		arch/arm/CallEABI.S \
246		arch/arm/HintsEABI.cpp \
247		mterp/out/InterpC-$(dvm_arch_variant).cpp.arm \
248		mterp/out/InterpAsm-$(dvm_arch_variant).S
249
250  ifeq ($(WITH_JIT),true)
251    LOCAL_SRC_FILES += \
252		compiler/codegen/RallocUtil.cpp \
253		compiler/codegen/arm/$(dvm_arch_variant)/Codegen.cpp \
254		compiler/codegen/arm/$(dvm_arch_variant)/CallingConvention.S \
255		compiler/codegen/arm/Assemble.cpp \
256		compiler/codegen/arm/ArchUtility.cpp \
257		compiler/codegen/arm/LocalOptimizations.cpp \
258		compiler/codegen/arm/GlobalOptimizations.cpp \
259		compiler/codegen/arm/ArmRallocUtil.cpp \
260		compiler/template/out/CompilerTemplateAsm-$(dvm_arch_variant).S
261  endif
262endif
263
264ifeq ($(dvm_arch),mips)
265  MTERP_ARCH_KNOWN := true
266  LOCAL_C_INCLUDES += external/libffi/$(TARGET_OS)-$(TARGET_ARCH)
267  LOCAL_SHARED_LIBRARIES += libffi
268  LOCAL_SRC_FILES += \
269		arch/mips/CallO32.S \
270		arch/mips/HintsO32.cpp \
271		arch/generic/Call.cpp \
272		mterp/out/InterpC-mips.cpp \
273		mterp/out/InterpAsm-mips.S
274
275  ifeq ($(WITH_JIT),true)
276    dvm_arch_variant := mips
277    LOCAL_SRC_FILES += \
278		compiler/codegen/mips/RallocUtil.cpp \
279		compiler/codegen/mips/$(dvm_arch_variant)/Codegen.cpp \
280		compiler/codegen/mips/$(dvm_arch_variant)/CallingConvention.S \
281		compiler/codegen/mips/Assemble.cpp \
282		compiler/codegen/mips/ArchUtility.cpp \
283		compiler/codegen/mips/LocalOptimizations.cpp \
284		compiler/codegen/mips/GlobalOptimizations.cpp \
285		compiler/template/out/CompilerTemplateAsm-$(dvm_arch_variant).S
286  endif
287endif
288
289ifeq ($(dvm_arch),x86)
290  ifeq ($(dvm_os),linux)
291    MTERP_ARCH_KNOWN := true
292    LOCAL_CFLAGS += -DDVM_JMP_TABLE_MTERP=1 \
293                    -DMTERP_STUB
294    LOCAL_SRC_FILES += \
295		arch/$(dvm_arch_variant)/Call386ABI.S \
296		arch/$(dvm_arch_variant)/Hints386ABI.cpp \
297		mterp/out/InterpC-$(dvm_arch_variant).cpp \
298		mterp/out/InterpAsm-$(dvm_arch_variant).S
299    ifeq ($(WITH_JIT),true)
300      LOCAL_CFLAGS += -DARCH_IA32
301      LOCAL_SRC_FILES += \
302                compiler/codegen/x86/LowerAlu.cpp \
303                compiler/codegen/x86/LowerConst.cpp \
304                compiler/codegen/x86/LowerMove.cpp \
305                compiler/codegen/x86/Lower.cpp \
306                compiler/codegen/x86/LowerHelper.cpp \
307                compiler/codegen/x86/LowerJump.cpp \
308                compiler/codegen/x86/LowerObject.cpp \
309                compiler/codegen/x86/AnalysisO1.cpp \
310                compiler/codegen/x86/BytecodeVisitor.cpp \
311                compiler/codegen/x86/NcgAot.cpp \
312                compiler/codegen/x86/CodegenInterface.cpp \
313                compiler/codegen/x86/LowerInvoke.cpp \
314                compiler/codegen/x86/LowerReturn.cpp \
315                compiler/codegen/x86/NcgHelper.cpp \
316                compiler/codegen/x86/LowerGetPut.cpp
317
318      # need apache harmony x86 encoder/decoder
319      LOCAL_C_INCLUDES += \
320                dalvik/vm/compiler/codegen/x86/libenc
321      LOCAL_SRC_FILES += \
322                compiler/codegen/x86/libenc/enc_base.cpp \
323                compiler/codegen/x86/libenc/dec_base.cpp \
324                compiler/codegen/x86/libenc/enc_wrapper.cpp \
325                compiler/codegen/x86/libenc/enc_tabl.cpp
326
327    endif
328  endif
329endif
330
331ifeq ($(MTERP_ARCH_KNOWN),false)
332  # unknown architecture, try to use FFI
333  LOCAL_C_INCLUDES += external/libffi/$(dvm_os)-$(dvm_arch)
334
335  ifeq ($(dvm_os)-$(dvm_arch),darwin-x86)
336      # OSX includes libffi, so just make the linker aware of it directly.
337      LOCAL_LDLIBS += -lffi
338  else
339      LOCAL_SHARED_LIBRARIES += libffi
340  endif
341
342  LOCAL_SRC_FILES += \
343		arch/generic/Call.cpp \
344		arch/generic/Hints.cpp \
345		mterp/out/InterpC-allstubs.cpp
346
347  # The following symbols are usually defined in the asm file, but
348  # since we don't have an asm file in this case, we instead just
349  # peg them at 0 here, and we add an #ifdef'able define for good
350  # measure, too.
351  LOCAL_CFLAGS += -DdvmAsmInstructionStart=0 -DdvmAsmInstructionEnd=0 \
352	-DdvmAsmSisterStart=0 -DdvmAsmSisterEnd=0 -DDVM_NO_ASM_INTERP=1
353endif
354