blob: f0dcd02847d1a7bcff8ca7825bb7e8b13635a6a9 [file] [log] [blame]
Elliott Hughes7ee3a062010-02-18 17:20:15 -08001# -*- mode: makefile -*-
Dan Bornstein6ac43c22009-10-24 15:33:49 -07002# Copyright (C) 2007 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#
17# Definitions for building the Java library and associated tests.
18#
19
20#
21# Common definitions for host and target.
22#
23
Jean-Baptiste Queru6e1c2a92010-04-30 10:13:35 -070024# libcore is divided into modules.
Elliott Hughesb9cf9cb2010-02-26 14:46:53 -080025#
26# The structure of each module is:
27#
28# src/
29# main/ # To be shipped on every device.
30# java/ # Java source for library code.
31# native/ # C++ source for library code.
32# resources/ # Support files.
33# test/ # Built only on demand, for testing.
34# java/ # Java source for tests.
35# native/ # C++ source for tests (rare).
36# resources/ # Support files.
37#
38# All subdirectories are optional (hence the "2> /dev/null"s below).
Dan Bornstein6ac43c22009-10-24 15:33:49 -070039
Elliott Hughesb9cf9cb2010-02-26 14:46:53 -080040define all-main-java-files-under
41$(foreach dir,$(1),$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find $(dir)/src/main/java -name "*.java" 2> /dev/null)))
Dan Bornstein6ac43c22009-10-24 15:33:49 -070042endef
43
Elliott Hughes7ee3a062010-02-18 17:20:15 -080044define all-test-java-files-under
Elliott Hughesb9cf9cb2010-02-26 14:46:53 -080045$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find $(1)/src/test/java -name "*.java" 2> /dev/null))
Elliott Hughes7ee3a062010-02-18 17:20:15 -080046endef
47
Dan Bornstein6ac43c22009-10-24 15:33:49 -070048define all-core-resource-dirs
Elliott Hughes3e951a52010-02-22 15:01:55 -080049$(shell cd $(LOCAL_PATH) && ls -d */src/$(1)/{java,resources} 2> /dev/null)
Dan Bornstein6ac43c22009-10-24 15:33:49 -070050endef
51
Elliott Hughes3e951a52010-02-22 15:01:55 -080052# The Java files and their associated resources.
Jesse Wilson1708c112010-05-13 15:50:15 -070053core_src_files := $(call all-main-java-files-under,dalvik dom json luni openssl support xml)
Dan Bornstein6ac43c22009-10-24 15:33:49 -070054core_resource_dirs := $(call all-core-resource-dirs,main)
Elliott Hughes3e951a52010-02-22 15:01:55 -080055test_resource_dirs := $(call all-core-resource-dirs,test)
Dan Bornstein6ac43c22009-10-24 15:33:49 -070056
57
58#
59# Build for the target (device).
60#
61
62# Definitions to make the core library.
63
64include $(CLEAR_VARS)
65
66LOCAL_SRC_FILES := $(core_src_files)
67LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
68
Guang Zhu709c24d2010-03-10 15:51:58 -080069ifeq ($(EMMA_INSTRUMENT),true)
70LOCAL_SRC_FILES += $(call all-java-files-under, ../../external/emma/core ../../external/emma/pregenerated)
71LOCAL_JAVA_RESOURCE_DIRS += ../../external/emma/core/res ../../external/emma/pregenerated/res
72endif
73
Dan Bornstein6ac43c22009-10-24 15:33:49 -070074LOCAL_NO_STANDARD_LIBRARIES := true
75LOCAL_DX_FLAGS := --core-library
76
77LOCAL_NO_EMMA_INSTRUMENT := true
78LOCAL_NO_EMMA_COMPILE := true
79
80LOCAL_MODULE := core
81
82include $(BUILD_JAVA_LIBRARY)
83
84core-intermediates := ${intermediates}
85
86
Jesse Wilson1708c112010-05-13 15:50:15 -070087# Make core-junit
88include $(CLEAR_VARS)
89LOCAL_SRC_FILES := $(call all-main-java-files-under,junit)
90LOCAL_NO_STANDARD_LIBRARIES := true
91LOCAL_JAVA_LIBRARIES := core
92LOCAL_MODULE := core-junit
93include $(BUILD_JAVA_LIBRARY)
94
95# Make core-junitrunner
96include $(CLEAR_VARS)
97LOCAL_SRC_FILES := $(call all-test-java-files-under,junit)
98LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
99LOCAL_NO_STANDARD_LIBRARIES := true
100LOCAL_JAVA_LIBRARIES := core core-junit
101LOCAL_DX_FLAGS := --core-library
102LOCAL_MODULE_TAGS := tests
103LOCAL_MODULE := core-junitrunner
104include $(BUILD_JAVA_LIBRARY)
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800105
Elliott Hughesb9cf9cb2010-02-26 14:46:53 -0800106# Definitions to make the sqlite JDBC driver.
107
108include $(CLEAR_VARS)
109LOCAL_SRC_FILES := $(call all-main-java-files-under,sqlite-jdbc)
110LOCAL_NO_STANDARD_LIBRARIES := true
111LOCAL_JAVA_LIBRARIES := core
112LOCAL_MODULE := sqlite-jdbc
113include $(BUILD_JAVA_LIBRARY)
114
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800115
116# Definitions to make the core-tests libraries.
117#
118# We make a library per module, because otherwise the .jar files get too
119# large, to the point that dx(1) can't cope (and the build is
120# ridiculously slow).
121#
122# TODO: DalvikRunner will make this nonsense obsolete.
Dan Bornstein6ac43c22009-10-24 15:33:49 -0700123
124include $(CLEAR_VARS)
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800125LOCAL_SRC_FILES := $(call all-test-java-files-under,dom)
126LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
127LOCAL_NO_STANDARD_LIBRARIES := true
Jesse Wilson1708c112010-05-13 15:50:15 -0700128LOCAL_JAVA_LIBRARIES := core core-junit core-junitrunner core-tests-support
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800129LOCAL_DX_FLAGS := --core-library
130LOCAL_MODULE_TAGS := tests
131LOCAL_MODULE := core-tests-dom
132include $(BUILD_JAVA_LIBRARY)
133
134include $(CLEAR_VARS)
Elliott Hughesbf1ecf22010-02-22 12:45:26 -0800135LOCAL_SRC_FILES := $(call all-test-java-files-under,json)
136LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
137LOCAL_NO_STANDARD_LIBRARIES := true
Jesse Wilson1708c112010-05-13 15:50:15 -0700138LOCAL_JAVA_LIBRARIES := core core-junit core-junitrunner core-tests-support
Elliott Hughesbf1ecf22010-02-22 12:45:26 -0800139LOCAL_DX_FLAGS := --core-library
140LOCAL_MODULE_TAGS := tests
141LOCAL_MODULE := core-tests-json
142include $(BUILD_JAVA_LIBRARY)
143
144include $(CLEAR_VARS)
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800145LOCAL_SRC_FILES := $(call all-test-java-files-under,luni)
146LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
147LOCAL_NO_STANDARD_LIBRARIES := true
148# This module contains the top-level "tests.AllTests" that ties everything
149# together, so it has compile-time dependencies on all the other test
150# libraries.
151# TODO: we should have a bogus module that just contains tests.AllTests for speed.
Elliott Hughesbf1ecf22010-02-22 12:45:26 -0800152LOCAL_JAVA_LIBRARIES := \
153 core \
Jesse Wilson1708c112010-05-13 15:50:15 -0700154 core-junit \
155 core-junitrunner \
Elliott Hughesbf1ecf22010-02-22 12:45:26 -0800156 core-tests-support \
Elliott Hughesbf1ecf22010-02-22 12:45:26 -0800157 core-tests-dom \
Elliott Hughesbf1ecf22010-02-22 12:45:26 -0800158 core-tests-json \
Peter Hallamcec4dd42010-04-26 12:53:37 -0700159 core-tests-xml \
160 sqlite-jdbc
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800161LOCAL_DX_FLAGS := --core-library
162LOCAL_MODULE_TAGS := tests
163LOCAL_MODULE := core-tests-luni
164include $(BUILD_JAVA_LIBRARY)
165
166include $(CLEAR_VARS)
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800167LOCAL_SRC_FILES := $(call all-test-java-files-under,support)
168LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
Dan Bornstein6ac43c22009-10-24 15:33:49 -0700169LOCAL_NO_STANDARD_LIBRARIES := true
Jesse Wilson1708c112010-05-13 15:50:15 -0700170LOCAL_JAVA_LIBRARIES := core core-junit core-junitrunner
Dan Bornstein6ac43c22009-10-24 15:33:49 -0700171LOCAL_DX_FLAGS := --core-library
Dan Bornstein6ac43c22009-10-24 15:33:49 -0700172LOCAL_MODULE_TAGS := tests
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800173LOCAL_MODULE := core-tests-support
Dan Bornstein6ac43c22009-10-24 15:33:49 -0700174include $(BUILD_JAVA_LIBRARY)
175
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800176include $(CLEAR_VARS)
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800177LOCAL_SRC_FILES := $(call all-test-java-files-under,xml)
178LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
179LOCAL_NO_STANDARD_LIBRARIES := true
Jesse Wilson1708c112010-05-13 15:50:15 -0700180LOCAL_JAVA_LIBRARIES := core core-junit core-junitrunner core-tests-support
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800181LOCAL_DX_FLAGS := --core-library
182LOCAL_MODULE_TAGS := tests
183LOCAL_MODULE := core-tests-xml
184include $(BUILD_JAVA_LIBRARY)
185
186
Dan Bornstein6ac43c22009-10-24 15:33:49 -0700187
188
189# This one's tricky. One of our tests needs to have a
190# resource with a "#" in its name, but Perforce doesn't
191# allow us to submit such a file. So we create it here
192# on-the-fly.
193TMP_RESOURCE_DIR := $(OUT_DIR)/tmp/
194TMP_RESOURCE_FILE := org/apache/harmony/luni/tests/java/lang/test\#.properties
195
196$(TMP_RESOURCE_DIR)$(TMP_RESOURCE_FILE):
197 @mkdir -p $(dir $@)
198 @echo "Hello, world!" > $@
199
200$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args) -C $(TMP_RESOURCE_DIR) $(TMP_RESOURCE_FILE)
201$(LOCAL_INTERMEDIATE_TARGETS): $(TMP_RESOURCE_DIR)$(TMP_RESOURCE_FILE)
202
203# Definitions for building a version of the core-tests.jar
204# that is suitable for execution on the RI. This JAR would
205# be better located in $HOST_OUT_JAVA_LIBRARIES, but it is
206# not possible to refer to that from a shell script (the
207# variable is not exported from envsetup.sh). There is also
208# some trickery involved: we need to include some classes
209# that reside in core.jar, but since we cannot incldue the
210# whole core.jar in the RI classpath, we copy those classses
211# over to our new file.
212HOST_CORE_JAR := $(HOST_COMMON_OUT_ROOT)/core-tests.jar
213
214$(HOST_CORE_JAR): PRIVATE_LOCAL_BUILT_MODULE := $(LOCAL_BUILT_MODULE)
215$(HOST_CORE_JAR): PRIVATE_CORE_INTERMEDIATES := $(core-intermediates)
216$(HOST_CORE_JAR): $(LOCAL_BUILT_MODULE)
217 @rm -rf $(dir $<)/hostctsclasses
218 $(call unzip-jar-files,$(dir $<)classes.jar,$(dir $<)hostctsclasses)
219 @unzip -qx -o $(PRIVATE_CORE_INTERMEDIATES)/classes.jar dalvik/annotation/* -d $(dir $<)hostctsclasses
220 @cp $< $@
221 @jar uf $@ -C $(dir $<)hostctsclasses .
222
223$(LOCAL_INSTALLED_MODULE): $(HOST_CORE_JAR)
224
225$(LOCAL_INSTALLED_MODULE): run-core-tests
226
227# Definitions to copy the core-tests runner script.
228
229include $(CLEAR_VARS)
230LOCAL_SRC_FILES := run-core-tests
231LOCAL_MODULE_CLASS := EXECUTABLES
232LOCAL_MODULE_TAGS := tests
233LOCAL_MODULE := run-core-tests
234include $(BUILD_PREBUILT)
235
236include $(CLEAR_VARS)
237LOCAL_SRC_FILES := run-core-tests-on-ri
238LOCAL_IS_HOST_MODULE := true
239LOCAL_MODULE_CLASS := EXECUTABLES
240LOCAL_MODULE_TAGS := tests
241LOCAL_MODULE := run-core-tests-on-ri
242include $(BUILD_PREBUILT)
243
244
245#
246# Build for the host.
247#
248
249ifeq ($(WITH_HOST_DALVIK),true)
250
251 # Definitions to make the core library.
252
253 include $(CLEAR_VARS)
254
255 LOCAL_SRC_FILES := $(core_src_files)
256 LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
257
258 LOCAL_NO_STANDARD_LIBRARIES := true
259 LOCAL_DX_FLAGS := --core-library
260
261 LOCAL_NO_EMMA_INSTRUMENT := true
262 LOCAL_NO_EMMA_COMPILE := true
263
264 LOCAL_MODULE := core
265
266 include $(BUILD_HOST_JAVA_LIBRARY)
267
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800268endif