Home | History | Annotate | Download | only in libcore
      1 # -*- mode: makefile -*-
      2 # 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 
     24 # 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).
     39 
     40 define all-main-java-files-under
     41 $(foreach dir,$(1),$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find $(dir)/src/main/java -name "*.java" 2> /dev/null)))
     42 endef
     43 
     44 define all-test-java-files-under
     45 $(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find $(1)/src/test/java -name "*.java" 2> /dev/null))
     46 endef
     47 
     48 define all-core-resource-dirs
     49 $(shell cd $(LOCAL_PATH) && ls -d */src/$(1)/{java,resources} 2> /dev/null)
     50 endef
     51 
     52 # The Java files and their associated resources.
     53 core_src_files := $(call all-main-java-files-under,dalvik dom json luni support xml)
     54 core_resource_dirs := $(call all-core-resource-dirs,main)
     55 test_resource_dirs := $(call all-core-resource-dirs,test)
     56 
     57 ifeq ($(EMMA_INSTRUMENT),true)
     58     core_src_files += $(call all-java-files-under, ../external/emma/core ../external/emma/pregenerated)
     59     core_resource_dirs += ../external/emma/core/res ../external/emma/pregenerated/res
     60 endif
     61 
     62 
     63 #
     64 # Build for the target (device).
     65 #
     66 
     67 # Definitions to make the core library.
     68 
     69 include $(CLEAR_VARS)
     70 
     71 LOCAL_SRC_FILES := $(core_src_files)
     72 LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
     73 
     74 LOCAL_NO_STANDARD_LIBRARIES := true
     75 LOCAL_JAVACFLAGS := -encoding UTF-8
     76 LOCAL_DX_FLAGS := --core-library
     77 
     78 LOCAL_NO_EMMA_INSTRUMENT := true
     79 LOCAL_NO_EMMA_COMPILE := true
     80 LOCAL_MODULE_TAGS := optional
     81 LOCAL_MODULE := core
     82 
     83 include $(BUILD_JAVA_LIBRARY)
     84 
     85 core-intermediates := ${intermediates}
     86 
     87 
     88 # Make core-junit
     89 include $(CLEAR_VARS)
     90 LOCAL_SRC_FILES := $(call all-main-java-files-under,junit)
     91 LOCAL_NO_STANDARD_LIBRARIES := true
     92 LOCAL_JAVA_LIBRARIES := core
     93 LOCAL_MODULE_TAGS := optional
     94 LOCAL_MODULE := core-junit
     95 include $(BUILD_JAVA_LIBRARY)
     96 
     97 # Make core-junitrunner
     98 include $(CLEAR_VARS)
     99 LOCAL_SRC_FILES := $(call all-test-java-files-under,junit)
    100 LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
    101 LOCAL_NO_STANDARD_LIBRARIES := true
    102 LOCAL_JAVA_LIBRARIES := core core-junit
    103 LOCAL_DX_FLAGS := --core-library
    104 LOCAL_MODULE_TAGS := tests
    105 LOCAL_MODULE := core-junitrunner
    106 include $(BUILD_JAVA_LIBRARY)
    107 
    108 # Definitions to make the sqlite JDBC driver.
    109 
    110 include $(CLEAR_VARS)
    111 LOCAL_SRC_FILES := $(call all-main-java-files-under,sqlite-jdbc)
    112 LOCAL_NO_STANDARD_LIBRARIES := true
    113 LOCAL_JAVA_LIBRARIES := core
    114 LOCAL_MODULE_TAGS := optional
    115 LOCAL_MODULE := sqlite-jdbc
    116 include $(BUILD_JAVA_LIBRARY)
    117 
    118 
    119 # Definitions to make the core-tests libraries.
    120 #
    121 # We make a library per module, because otherwise the .jar files get too
    122 # large, to the point that dx(1) can't cope (and the build is
    123 # ridiculously slow).
    124 #
    125 # TODO: vogar will make this nonsense obsolete.
    126 
    127 include $(CLEAR_VARS)
    128 LOCAL_SRC_FILES := $(call all-test-java-files-under,dalvik)
    129 LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
    130 LOCAL_NO_STANDARD_LIBRARIES := true
    131 LOCAL_JAVA_LIBRARIES := core core-junit core-junitrunner core-tests-support
    132 LOCAL_DX_FLAGS := --core-library
    133 LOCAL_MODULE_TAGS := tests
    134 LOCAL_MODULE := core-tests-dalvik
    135 include $(BUILD_JAVA_LIBRARY)
    136 
    137 include $(CLEAR_VARS)
    138 LOCAL_SRC_FILES := $(call all-test-java-files-under,dom)
    139 LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
    140 LOCAL_NO_STANDARD_LIBRARIES := true
    141 LOCAL_JAVA_LIBRARIES := core core-junit core-junitrunner core-tests-support
    142 LOCAL_DX_FLAGS := --core-library
    143 LOCAL_MODULE_TAGS := tests
    144 LOCAL_MODULE := core-tests-dom
    145 include $(BUILD_JAVA_LIBRARY)
    146 
    147 include $(CLEAR_VARS)
    148 LOCAL_SRC_FILES := $(call all-test-java-files-under,json)
    149 LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
    150 LOCAL_NO_STANDARD_LIBRARIES := true
    151 LOCAL_JAVA_LIBRARIES := core core-junit core-junitrunner core-tests-support
    152 LOCAL_DX_FLAGS := --core-library
    153 LOCAL_MODULE_TAGS := tests
    154 LOCAL_MODULE := core-tests-json
    155 include $(BUILD_JAVA_LIBRARY)
    156 
    157 include $(CLEAR_VARS)
    158 LOCAL_SRC_FILES := $(call all-test-java-files-under,luni)
    159 LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
    160 LOCAL_NO_STANDARD_LIBRARIES := true
    161 # This module contains the top-level "tests.AllTests" that ties everything
    162 # together, so it has compile-time dependencies on all the other test
    163 # libraries.
    164 # TODO: we should have a bogus module that just contains tests.AllTests for speed.
    165 LOCAL_JAVA_LIBRARIES := \
    166         bouncycastle \
    167         core \
    168         core-junit \
    169         core-junitrunner \
    170         core-tests-support \
    171         core-tests-dalvik \
    172         core-tests-dom \
    173         core-tests-json \
    174         core-tests-xml \
    175         sqlite-jdbc
    176 LOCAL_DX_FLAGS := --core-library
    177 LOCAL_MODULE_TAGS := tests
    178 LOCAL_MODULE := core-tests
    179 
    180 LOCAL_NO_EMMA_INSTRUMENT := true
    181 LOCAL_NO_EMMA_COMPILE := true
    182 
    183 include $(BUILD_JAVA_LIBRARY)
    184 
    185 include $(CLEAR_VARS)
    186 LOCAL_SRC_FILES := $(call all-test-java-files-under,support)
    187 LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
    188 LOCAL_NO_STANDARD_LIBRARIES := true
    189 LOCAL_JAVA_LIBRARIES := bouncycastle core core-junit core-junitrunner
    190 LOCAL_DX_FLAGS := --core-library
    191 LOCAL_MODULE_TAGS := tests
    192 LOCAL_MODULE := core-tests-support
    193 include $(BUILD_JAVA_LIBRARY)
    194 
    195 include $(CLEAR_VARS)
    196 LOCAL_SRC_FILES := $(call all-test-java-files-under,xml)
    197 LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
    198 LOCAL_NO_STANDARD_LIBRARIES := true
    199 LOCAL_JAVA_LIBRARIES := core core-junit core-junitrunner core-tests-support
    200 LOCAL_DX_FLAGS := --core-library
    201 LOCAL_MODULE_TAGS := tests
    202 LOCAL_MODULE := core-tests-xml
    203 include $(BUILD_JAVA_LIBRARY)
    204 
    205 # also build support as a static library for use by frameworks/base HTTPS tests
    206 include $(CLEAR_VARS)
    207 LOCAL_SRC_FILES := $(call all-test-java-files-under,support)
    208 LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
    209 LOCAL_NO_STANDARD_LIBRARIES := true
    210 LOCAL_JAVA_LIBRARIES := bouncycastle core core-junit core-junitrunner
    211 LOCAL_DX_FLAGS := --core-library
    212 LOCAL_MODULE_TAGS := tests
    213 LOCAL_MODULE := core-tests-supportlib
    214 include $(BUILD_STATIC_JAVA_LIBRARY)
    215 
    216 # This one's tricky. One of our tests needs to have a
    217 # resource with a "#" in its name, but Perforce doesn't
    218 # allow us to submit such a file. So we create it here
    219 # on-the-fly.
    220 TMP_RESOURCE_DIR := $(OUT_DIR)/tmp/
    221 TMP_RESOURCE_FILE := org/apache/harmony/luni/tests/java/lang/test\#.properties
    222 
    223 $(TMP_RESOURCE_DIR)$(TMP_RESOURCE_FILE):
    224 	@mkdir -p $(dir $@)
    225 	@echo "Hello, world!" > $@
    226 
    227 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args) -C $(TMP_RESOURCE_DIR) $(TMP_RESOURCE_FILE)
    228 $(LOCAL_INTERMEDIATE_TARGETS): $(TMP_RESOURCE_DIR)$(TMP_RESOURCE_FILE)
    229 
    230 # Definitions for building a version of the core-tests.jar
    231 # that is suitable for execution on the RI. This JAR would
    232 # be better located in $HOST_OUT_JAVA_LIBRARIES, but it is
    233 # not possible to refer to that from a shell script (the
    234 # variable is not exported from envsetup.sh). There is also
    235 # some trickery involved: we need to include some classes
    236 # that reside in core.jar, but since we cannot incldue the
    237 # whole core.jar in the RI classpath, we copy those classses
    238 # over to our new file.
    239 HOST_CORE_JAR := $(HOST_COMMON_OUT_ROOT)/core-tests.jar
    240 
    241 $(HOST_CORE_JAR): PRIVATE_LOCAL_BUILT_MODULE := $(LOCAL_BUILT_MODULE)
    242 $(HOST_CORE_JAR): PRIVATE_CORE_INTERMEDIATES := $(core-intermediates)
    243 $(HOST_CORE_JAR): $(LOCAL_BUILT_MODULE)
    244 	@rm -rf $(dir $<)/hostctsclasses
    245 	$(call unzip-jar-files,$(dir $<)classes.jar,$(dir $<)hostctsclasses)
    246 	@unzip -qx -o $(PRIVATE_CORE_INTERMEDIATES)/classes.jar dalvik/annotation/* -d $(dir $<)hostctsclasses
    247 	@cp $< $@
    248 	@jar uf $@ -C $(dir $<)hostctsclasses .
    249 
    250 $(LOCAL_INSTALLED_MODULE): $(HOST_CORE_JAR)
    251 
    252 $(LOCAL_INSTALLED_MODULE): run-core-tests
    253 
    254 # Definitions to copy the core-tests runner script.
    255 
    256 include $(CLEAR_VARS)
    257 LOCAL_SRC_FILES := run-core-tests
    258 LOCAL_MODULE_CLASS := EXECUTABLES
    259 LOCAL_MODULE_TAGS := tests
    260 LOCAL_MODULE := run-core-tests
    261 include $(BUILD_PREBUILT)
    262 
    263 include $(CLEAR_VARS)
    264 LOCAL_SRC_FILES := run-core-tests-on-ri
    265 LOCAL_IS_HOST_MODULE := true
    266 LOCAL_MODULE_CLASS := EXECUTABLES
    267 LOCAL_MODULE_TAGS := tests
    268 LOCAL_MODULE := run-core-tests-on-ri
    269 include $(BUILD_PREBUILT)
    270 
    271 
    272 #
    273 # Build for the host.
    274 #
    275 
    276 ifeq ($(WITH_HOST_DALVIK),true)
    277 
    278     # Definitions to make the core library.
    279 
    280     include $(CLEAR_VARS)
    281 
    282     LOCAL_SRC_FILES := $(core_src_files)
    283     LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
    284 
    285     LOCAL_NO_STANDARD_LIBRARIES := true
    286     LOCAL_JAVACFLAGS := -encoding UTF-8
    287     LOCAL_DX_FLAGS := --core-library
    288 
    289     LOCAL_NO_EMMA_INSTRUMENT := true
    290     LOCAL_NO_EMMA_COMPILE := true
    291     LOCAL_BUILD_HOST_DEX := true
    292 
    293     LOCAL_MODULE_TAGS := optional
    294     LOCAL_MODULE := core-hostdex
    295 
    296     include $(BUILD_HOST_JAVA_LIBRARY)
    297 
    298 endif
    299