blob: 0602a5bb518dab2b5862de53e87b98f93781a2b8 [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
Jesse Wilsond5d35262010-05-12 23:56:14 -070024# libcore is divided into modules.
25#
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
Jesse Wilson32cfe952010-05-04 16:36:03 -070040define all-main-java-files-under
41$(foreach dir,$(1),$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find $(dir)/src/main/java -name "*.java" 2> /dev/null)))
42endef
43
44define all-test-java-files-under
45$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find $(1)/src/test/java -name "*.java" 2> /dev/null))
Dan Bornstein6ac43c22009-10-24 15:33:49 -070046endef
47
Dan Bornstein6ac43c22009-10-24 15:33:49 -070048define all-core-resource-dirs
49$(shell cd $(LOCAL_PATH) && ls -d */src/$(1)/{java,resources} 2> /dev/null)
50endef
51
Jesse Wilsond5d35262010-05-12 23:56:14 -070052# 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)
Dan Bornstein6ac43c22009-10-24 15:33:49 -070055test_resource_dirs := $(call all-core-resource-dirs,test)
56
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 Wilson32cfe952010-05-04 16:36:03 -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
Jesse Wilson1708c112010-05-13 15:50:15 -070095# 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
Jesse Wilson32cfe952010-05-04 16:36:03 -0700115
Jesse Wilsond5d35262010-05-12 23:56:14 -0700116# 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)
Jesse Wilsond5d35262010-05-12 23:56:14 -0700125LOCAL_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
Jesse Wilsond5d35262010-05-12 23:56:14 -0700129LOCAL_DX_FLAGS := --core-library
130LOCAL_MODULE_TAGS := tests
131LOCAL_MODULE := core-tests-dom
Jesse Wilsond5d35262010-05-12 23:56:14 -0700132include $(BUILD_JAVA_LIBRARY)
133
134include $(CLEAR_VARS)
135LOCAL_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
Jesse Wilsond5d35262010-05-12 23:56:14 -0700139LOCAL_DX_FLAGS := --core-library
140LOCAL_MODULE_TAGS := tests
141LOCAL_MODULE := core-tests-json
Jesse Wilsond5d35262010-05-12 23:56:14 -0700142include $(BUILD_JAVA_LIBRARY)
143
144include $(CLEAR_VARS)
145LOCAL_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.
152LOCAL_JAVA_LIBRARIES := \
153 core \
154 core-junit \
Jesse Wilson1708c112010-05-13 15:50:15 -0700155 core-junitrunner \
Jesse Wilsond5d35262010-05-12 23:56:14 -0700156 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
Jesse Wilsond5d35262010-05-12 23:56:14 -0700161LOCAL_DX_FLAGS := --core-library
162LOCAL_MODULE_TAGS := tests
Brian Carlstromb094af32010-05-28 17:37:37 -0700163LOCAL_MODULE := core-tests
Jesse Wilsond5d35262010-05-12 23:56:14 -0700164include $(BUILD_JAVA_LIBRARY)
165
166include $(CLEAR_VARS)
Elliott Hughes7ee3a062010-02-18 17:20:15 -0800167LOCAL_SRC_FILES := $(call all-test-java-files-under,support)
Jesse Wilsond5d35262010-05-12 23:56:14 -0700168LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
169LOCAL_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
Jesse Wilsond5d35262010-05-12 23:56:14 -0700173LOCAL_MODULE := core-tests-support
Jesse Wilsond5d35262010-05-12 23:56:14 -0700174include $(BUILD_JAVA_LIBRARY)
175
176include $(CLEAR_VARS)
177LOCAL_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
Jesse Wilsond5d35262010-05-12 23:56:14 -0700181LOCAL_DX_FLAGS := --core-library
182LOCAL_MODULE_TAGS := tests
183LOCAL_MODULE := core-tests-xml
Jesse Wilsond5d35262010-05-12 23:56:14 -0700184include $(BUILD_JAVA_LIBRARY)
Dan Bornstein6ac43c22009-10-24 15:33:49 -0700185
186# This one's tricky. One of our tests needs to have a
187# resource with a "#" in its name, but Perforce doesn't
188# allow us to submit such a file. So we create it here
189# on-the-fly.
190TMP_RESOURCE_DIR := $(OUT_DIR)/tmp/
191TMP_RESOURCE_FILE := org/apache/harmony/luni/tests/java/lang/test\#.properties
192
193$(TMP_RESOURCE_DIR)$(TMP_RESOURCE_FILE):
194 @mkdir -p $(dir $@)
195 @echo "Hello, world!" > $@
196
197$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args) -C $(TMP_RESOURCE_DIR) $(TMP_RESOURCE_FILE)
198$(LOCAL_INTERMEDIATE_TARGETS): $(TMP_RESOURCE_DIR)$(TMP_RESOURCE_FILE)
199
200# Definitions for building a version of the core-tests.jar
201# that is suitable for execution on the RI. This JAR would
202# be better located in $HOST_OUT_JAVA_LIBRARIES, but it is
203# not possible to refer to that from a shell script (the
204# variable is not exported from envsetup.sh). There is also
205# some trickery involved: we need to include some classes
206# that reside in core.jar, but since we cannot incldue the
207# whole core.jar in the RI classpath, we copy those classses
208# over to our new file.
209HOST_CORE_JAR := $(HOST_COMMON_OUT_ROOT)/core-tests.jar
210
211$(HOST_CORE_JAR): PRIVATE_LOCAL_BUILT_MODULE := $(LOCAL_BUILT_MODULE)
212$(HOST_CORE_JAR): PRIVATE_CORE_INTERMEDIATES := $(core-intermediates)
213$(HOST_CORE_JAR): $(LOCAL_BUILT_MODULE)
214 @rm -rf $(dir $<)/hostctsclasses
215 $(call unzip-jar-files,$(dir $<)classes.jar,$(dir $<)hostctsclasses)
216 @unzip -qx -o $(PRIVATE_CORE_INTERMEDIATES)/classes.jar dalvik/annotation/* -d $(dir $<)hostctsclasses
217 @cp $< $@
218 @jar uf $@ -C $(dir $<)hostctsclasses .
219
220$(LOCAL_INSTALLED_MODULE): $(HOST_CORE_JAR)
221
222$(LOCAL_INSTALLED_MODULE): run-core-tests
223
224# Definitions to copy the core-tests runner script.
225
226include $(CLEAR_VARS)
227LOCAL_SRC_FILES := run-core-tests
228LOCAL_MODULE_CLASS := EXECUTABLES
229LOCAL_MODULE_TAGS := tests
230LOCAL_MODULE := run-core-tests
231include $(BUILD_PREBUILT)
232
233include $(CLEAR_VARS)
234LOCAL_SRC_FILES := run-core-tests-on-ri
235LOCAL_IS_HOST_MODULE := true
236LOCAL_MODULE_CLASS := EXECUTABLES
237LOCAL_MODULE_TAGS := tests
238LOCAL_MODULE := run-core-tests-on-ri
239include $(BUILD_PREBUILT)
240
241
242#
243# Build for the host.
244#
245
246ifeq ($(WITH_HOST_DALVIK),true)
247
248 # Definitions to make the core library.
249
250 include $(CLEAR_VARS)
251
252 LOCAL_SRC_FILES := $(core_src_files)
253 LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
254
255 LOCAL_NO_STANDARD_LIBRARIES := true
256 LOCAL_DX_FLAGS := --core-library
257
258 LOCAL_NO_EMMA_INSTRUMENT := true
259 LOCAL_NO_EMMA_COMPILE := true
260
261 LOCAL_MODULE := core
262
263 include $(BUILD_HOST_JAVA_LIBRARY)
264
Elliott Hughes67cc34b2010-02-19 22:14:19 -0800265endif