NativeCode.mk revision 64f2ba48fb9306ab1d97f5f83053ee7f48223de8
1# Copyright (C) 2007 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# Definitions for building the native code needed for the core library.
17#
18
19#
20# Common definitions for host and target.
21#
22
23# Get the list of all native directories that contain sub.mk files.
24# We're using "sub.mk" to make it clear that these are not typical
25# android makefiles.
26define all-core-native-dirs
27$(patsubst %/sub.mk,%,$(shell cd $(LOCAL_PATH) && ls -d */src/$(1)/native/sub.mk 2> /dev/null))
28endef
29
30# These two definitions are used to help sanity check what's put in
31# sub.mk. See, the "error" directives immediately below.
32core_magic_local_target := ...//::default:://...
33core_local_path := $(LOCAL_PATH)
34
35# Include a submakefile, resolve its source file locations,
36# and stick them on core_src_files.  The submakefiles are
37# free to append to LOCAL_SRC_FILES, LOCAL_C_INCLUDES,
38# LOCAL_SHARED_LIBRARIES, or LOCAL_STATIC_LIBRARIES, but nothing
39# else. All other LOCAL_* variables will be ignored.
40#
41# $(1): directory containing the makefile to include
42define include-core-native-dir
43    LOCAL_SRC_FILES :=
44    include $(LOCAL_PATH)/$(1)/sub.mk
45    ifneq ($$(LOCAL_MODULE),$(core_magic_local_target))
46        $$(error $(LOCAL_PATH)/$(1)/sub.mk should not include CLEAR_VARS \
47            or define LOCAL_MODULE)
48    endif
49    ifneq ($$(LOCAL_PATH),$(core_local_path))
50        $$(error $(LOCAL_PATH)/$(1)/sub.mk should not define LOCAL_PATH)
51    endif
52    core_src_files += $$(addprefix $(1)/,$$(LOCAL_SRC_FILES))
53    LOCAL_SRC_FILES :=
54endef
55
56# Find any native directories containing sub.mk files.
57core_native_dirs := $(strip $(call all-core-native-dirs,main))
58ifeq ($(core_native_dirs),)
59    $(error No native code defined for libcore)
60endif
61
62# Set up the default state. Note: We use CLEAR_VARS here, even though
63# we aren't quite defining a new rule yet, to make sure that the
64# sub.mk files don't see anything stray from the last rule that was
65# set up.
66include $(CLEAR_VARS)
67LOCAL_MODULE := $(core_magic_local_target)
68core_src_files :=
69
70# Include the sub.mk files.
71$(foreach dir, \
72    $(core_native_dirs), \
73    $(eval $(call include-core-native-dir,$(dir))))
74
75# Extract out the allowed LOCAL_* variables. Note: $(sort) also
76# removes duplicates.
77core_c_includes := $(sort dalvik/libcore/include $(LOCAL_C_INCLUDES) $(JNI_H_INCLUDE))
78core_shared_libraries := $(sort $(LOCAL_SHARED_LIBRARIES))
79core_static_libraries := $(sort $(LOCAL_STATIC_LIBRARIES))
80
81
82#
83# Build for the target (device).
84#
85
86include $(CLEAR_VARS)
87
88ifeq ($(TARGET_ARCH),arm)
89# Ignore "note: the mangling of 'va_list' has changed in GCC 4.4"
90LOCAL_CFLAGS += -Wno-psabi
91endif
92
93# Define the rules.
94LOCAL_SRC_FILES := $(core_src_files)
95LOCAL_C_INCLUDES := $(core_c_includes)
96LOCAL_SHARED_LIBRARIES := $(core_shared_libraries)
97LOCAL_STATIC_LIBRARIES := $(core_static_libraries)
98LOCAL_MODULE := libjavacore
99include $(BUILD_STATIC_LIBRARY)
100
101# Deal with keystores required for security. Note: The path to this file
102# is hardcoded in TrustManagerFactoryImpl.java.
103ALL_PREBUILT += $(TARGET_OUT)/etc/security/cacerts.bks
104$(TARGET_OUT)/etc/security/cacerts.bks : $(LOCAL_PATH)/security/src/main/files/cacerts.bks | $(ACP)
105	$(transform-prebuilt-to-target)
106
107
108#
109# Build for the host.
110#
111
112ifeq ($(WITH_HOST_DALVIK),true)
113
114    include $(CLEAR_VARS)
115
116    # Define the rules.
117    LOCAL_SRC_FILES := $(core_src_files)
118    LOCAL_C_INCLUDES := $(core_c_includes)
119    LOCAL_SHARED_LIBRARIES := $(core_shared_libraries)
120    LOCAL_STATIC_LIBRARIES := $(core_static_libraries)
121    LOCAL_MODULE := libjavacore-host
122    include $(BUILD_HOST_STATIC_LIBRARY)
123
124    # TODO: Figure out cacerts.bks for the host.
125
126endif
127