blob: c182a779e68ab01d4b8b5d6d04856dc7e2cff076 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001#
2# Copyright (C) 2008 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# Users can define base-rules-hook in their buildspec.mk to perform
18# arbitrary operations as each module is included.
19ifdef base-rules-hook
20$(if $(base-rules-hook),)
21endif
22
23###########################################################
24## Common instructions for a generic module.
25###########################################################
26
27LOCAL_MODULE := $(strip $(LOCAL_MODULE))
28ifeq ($(LOCAL_MODULE),)
29 $(error $(LOCAL_PATH): LOCAL_MODULE is not defined)
30endif
31
32LOCAL_IS_HOST_MODULE := $(strip $(LOCAL_IS_HOST_MODULE))
33ifdef LOCAL_IS_HOST_MODULE
34 ifneq ($(LOCAL_IS_HOST_MODULE),true)
35 $(error $(LOCAL_PATH): LOCAL_IS_HOST_MODULE must be "true" or empty, not "$(LOCAL_IS_HOST_MODULE)")
36 endif
37 my_prefix:=HOST_
38 my_host:=host-
39else
40 my_prefix:=TARGET_
41 my_host:=
42endif
43
44###########################################################
45## Validate and define fallbacks for input LOCAL_* variables.
46###########################################################
47
48## Dump a .csv file of all modules and their tags
49#ifneq ($(tag-list-first-time),false)
50#$(shell rm -f tag-list.csv)
51#tag-list-first-time := false
52#endif
53#comma := ,
54#empty :=
55#space := $(empty) $(empty)
56#$(shell echo $(lastword $(filter-out config/% out/%,$(MAKEFILE_LIST))),$(LOCAL_MODULE),$(strip $(LOCAL_MODULE_CLASS)),$(subst $(space),$(comma),$(sort $(LOCAL_MODULE_TAGS))) >> tag-list.csv)
57
58LOCAL_MODULE_TAGS := $(sort $(LOCAL_MODULE_TAGS))
59ifeq (,$(LOCAL_MODULE_TAGS))
60# Modules without tags fall back to user (which is changed to user eng below)
61LOCAL_MODULE_TAGS := user
62#$(warning default tags: $(lastword $(filter-out config/% out/%,$(MAKEFILE_LIST))))
63endif
64
65# Add implicit tags.
66#
67# If the local directory or one of its parents contains a MODULE_LICENSE_GPL
68# file, tag the module as "gnu". Search for "*_GNU*" so that we can also
69# find files like MODULE_LICENSE_GPL_AND_AFL but exclude files like
70# MODULE_LICENSE_LGPL.
71#
72ifneq ($(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*_GPL*),)
73 LOCAL_MODULE_TAGS += gnu
74endif
75
76#
77# If this module is listed on CUSTOM_MODULES, promote it to "user"
78# so that it will be installed in $(TARGET_OUT).
79#
80ifneq (,$(filter $(LOCAL_MODULE),$(CUSTOM_MODULES)))
81 LOCAL_MODULE_TAGS := $(sort $(LOCAL_MODULE_TAGS) user)
82endif
83
84# The definition of should-install-to-system will be different depending
The Android Open Source Project2f312932009-03-09 11:52:11 -070085# on which goal (e.g., sdk or just droid) is being built.
The Android Open Source Project88b60792009-03-03 19:28:42 -080086ifdef LOCAL_IS_HOST_MODULE
87 use_data :=
88else
89 use_data := $(if $(call should-install-to-system,$(LOCAL_MODULE_TAGS)),,_DATA)
90endif
91
92LOCAL_MODULE_CLASS := $(strip $(LOCAL_MODULE_CLASS))
93ifneq ($(words $(LOCAL_MODULE_CLASS)),1)
94 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS must contain exactly one word, not "$(LOCAL_MODULE_CLASS)")
95endif
96
97# Add a tag like "_class@APPS" to this module so that we can filter
98# based on the class.
99LOCAL_MODULE_TAGS += _class@$(LOCAL_MODULE_CLASS)
100
101LOCAL_MODULE_PATH := $(strip $(LOCAL_MODULE_PATH))
102ifeq ($(LOCAL_MODULE_PATH),)
103 LOCAL_MODULE_PATH := $($(my_prefix)OUT$(use_data)_$(LOCAL_MODULE_CLASS))
104 ifeq ($(strip $(LOCAL_MODULE_PATH)),)
105 $(error $(LOCAL_PATH): unhandled LOCAL_MODULE_CLASS "$(LOCAL_MODULE_CLASS)")
106 endif
107endif
108
109ifneq ($(strip $(LOCAL_BUILT_MODULE)$(LOCAL_INSTALLED_MODULE)),)
110 $(error $(LOCAL_PATH): LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE must not be defined by component makefiles)
111endif
112
113# Make sure that this IS_HOST/CLASS/MODULE combination is unique.
114module_id := MODULE.$(if \
115 $(LOCAL_IS_HOST_MODULE),HOST,TARGET).$(LOCAL_MODULE_CLASS).$(LOCAL_MODULE)
116ifdef $(module_id)
117$(error $(LOCAL_PATH): $(module_id) already defined by $($(module_id)))
118endif
119$(module_id) := $(LOCAL_PATH)
120
121intermediates := $(call local-intermediates-dir)
122intermediates.COMMON := $(call local-intermediates-dir,COMMON)
123
124###########################################################
125# Pick a name for the intermediate and final targets
126###########################################################
127LOCAL_MODULE_STEM := $(strip $(LOCAL_MODULE_STEM))
128ifeq ($(LOCAL_MODULE_STEM),)
129 LOCAL_MODULE_STEM := $(LOCAL_MODULE)
130endif
131LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE_STEM)$(LOCAL_MODULE_SUFFIX)
132
133LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))
134ifeq ($(LOCAL_BUILT_MODULE_STEM),)
135 LOCAL_BUILT_MODULE_STEM := $(LOCAL_INSTALLED_MODULE_STEM)
136endif
137
138# OVERRIDE_BUILT_MODULE_PATH is only allowed to be used by the
139# internal SHARED_LIBRARIES build files.
140OVERRIDE_BUILT_MODULE_PATH := $(strip $(OVERRIDE_BUILT_MODULE_PATH))
141ifdef OVERRIDE_BUILT_MODULE_PATH
142 ifneq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES)
143 $(error $(LOCAL_PATH): Illegal use of OVERRIDE_BUILT_MODULE_PATH)
144 endif
145 built_module_path := $(OVERRIDE_BUILT_MODULE_PATH)
146else
147 built_module_path := $(intermediates)
148endif
149LOCAL_BUILT_MODULE := $(built_module_path)/$(LOCAL_BUILT_MODULE_STEM)
150built_module_path :=
151
152# LOCAL_UNINSTALLABLE_MODULE is only allowed to be used by the
153# internal STATIC_LIBRARIES build files.
154LOCAL_UNINSTALLABLE_MODULE := $(strip $(LOCAL_UNINSTALLABLE_MODULE))
155ifdef LOCAL_UNINSTALLABLE_MODULE
156 ifeq (,$(filter $(LOCAL_MODULE_CLASS),JAVA_LIBRARIES STATIC_LIBRARIES))
157 $(error $(LOCAL_PATH): Illegal use of LOCAL_UNINSTALLABLE_MODULE)
158 endif
159else
160 LOCAL_INSTALLED_MODULE := $(LOCAL_MODULE_PATH)/$(LOCAL_MODULE_SUBDIR)$(LOCAL_INSTALLED_MODULE_STEM)
161endif
162
163# Assemble the list of targets to create PRIVATE_ variables for.
164LOCAL_INTERMEDIATE_TARGETS += $(LOCAL_BUILT_MODULE)
165
166
167###########################################################
168## AIDL: Compile .aidl files to .java
169###########################################################
170
171aidl_sources := $(filter %.aidl,$(LOCAL_SRC_FILES))
172
173ifneq ($(strip $(aidl_sources)),)
174
175aidl_java_sources := $(patsubst %.aidl,%.java,$(addprefix $(intermediates.COMMON)/src/, $(aidl_sources)))
176aidl_sources := $(addprefix $(TOP_DIR)$(LOCAL_PATH)/, $(aidl_sources))
177
178$(aidl_java_sources): PRIVATE_AIDL_FLAGS := -b -I$(LOCAL_PATH) -I$(LOCAL_PATH)/src $(addprefix -I,$(LOCAL_AIDL_INCLUDES))
179
180$(aidl_java_sources): $(intermediates.COMMON)/src/%.java: $(TOPDIR)$(LOCAL_PATH)/%.aidl $(PRIVATE_ADDITIONAL_DEPENDENCIES) $(AIDL)
181 $(transform-aidl-to-java)
182-include $(aidl_java_sources:%.java=%.P)
183
184else
185aidl_java_sources :=
186endif
187
188###########################################################
189## Java: Compile .java files to .class
190###########################################################
191#TODO: pull this into java.make once host and target are combined
192
193java_sources := $(addprefix $(TOP_DIR)$(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) $(aidl_java_sources)
194all_java_sources := $(java_sources) $(addprefix $($(my_prefix)OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES)))
195
196## Java resources #########################################
197
198# Look for resource files in any specified directories.
199# Non-java and non-doc files will be picked up as resources
200# and included in the output jar file.
201java_resource_file_groups :=
202
203LOCAL_JAVA_RESOURCE_DIRS := $(strip $(LOCAL_JAVA_RESOURCE_DIRS))
204ifneq ($(LOCAL_JAVA_RESOURCE_DIRS),)
205 # This makes a list of words like
206 # <dir1>::<file1>:<file2> <dir2>::<file1> <dir3>:
207 # where each of the files is relative to the directory it's grouped with.
208 # Directories that don't contain any resource files will result in groups
209 # that end with a colon, and they are stripped out in the next step.
210 java_resource_file_groups += \
211 $(foreach dir,$(LOCAL_JAVA_RESOURCE_DIRS), \
212 $(subst $(space),:,$(strip \
213 $(TOP_DIR)$(LOCAL_PATH)/$(dir): \
214 $(patsubst ./%,%,$(shell cd $(TOP_DIR)$(LOCAL_PATH)/$(dir) && \
215 find . \
216 -type d -a -name ".svn" -prune -o \
217 -type f \
218 -a \! -name "*.java" \
219 -a \! -name "package.html" \
220 -a \! -name "overview.html" \
221 -a \! -name ".*.swp" \
222 -a \! -name ".DS_Store" \
223 -a \! -name "*~" \
224 -print \
225 )) \
226 )) \
227 )
228 java_resource_file_groups := $(filter-out %:,$(java_resource_file_groups))
229endif # LOCAL_JAVA_RESOURCE_DIRS
230
231LOCAL_JAVA_RESOURCE_FILES := $(strip $(LOCAL_JAVA_RESOURCE_FILES))
232ifneq ($(LOCAL_JAVA_RESOURCE_FILES),)
233 java_resource_file_groups += \
234 $(foreach f,$(LOCAL_JAVA_RESOURCE_FILES), \
235 $(patsubst %/,%,$(dir $(f)))::$(notdir $(f)) \
236 )
237endif # LOCAL_JAVA_RESOURCE_FILES
238
239ifdef java_resource_file_groups
240 # The full paths to all resources, used for dependencies.
241 java_resource_sources := \
242 $(foreach group,$(java_resource_file_groups), \
243 $(addprefix $(word 1,$(subst :,$(space),$(group)))/, \
244 $(wordlist 2,9999,$(subst :,$(space),$(group))) \
245 ) \
246 )
247 # The arguments to jar that will include these files in a jar file.
248 extra_jar_args := \
249 $(foreach group,$(java_resource_file_groups), \
250 $(addprefix -C $(word 1,$(subst :,$(space),$(group))) , \
251 $(wordlist 2,9999,$(subst :,$(space),$(group))) \
252 ) \
253 )
254 java_resource_file_groups :=
255else
256 java_resource_sources :=
257 extra_jar_args :=
258endif # java_resource_file_groups
259
260## PRIVATE java vars ######################################
261
262ifneq ($(strip $(all_java_sources)$(all_res_assets)),)
263
264full_static_java_libs := \
265 $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
266 $(call intermediates-dir-for, \
267 JAVA_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/javalib.jar)
268
269$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_INSTALL_DIR := $(dir $(LOCAL_INSTALLED_MODULE))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800270$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates)/classes
271$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates)/src
272$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCES := $(all_java_sources)
273$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_OBJECTS := $(patsubst %.java,%.class,$(LOCAL_SRC_FILES))
274ifeq ($(my_prefix),TARGET_)
275$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(call java-lib-files,core)
276endif
277$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
278$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args)
279$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := $(LOCAL_ASSET_DIR)
280$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_LIBRARIES := $(full_static_java_libs)
281
282# full_java_libs: The list of files that should be used as the classpath.
283# Using this list as a dependency list WILL NOT WORK.
284# full_java_lib_deps: Should be specified as a prerequisite of this module
285# to guarantee that the files in full_java_libs will
286# be up-to-date.
287ifdef LOCAL_IS_HOST_MODULE
288# TODO: make prebuilt java libraries use the same
289# intermediates path pattern as target java libraries.
290full_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,$(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
291full_java_lib_deps := $(full_java_libs)
292else
293full_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
294full_java_lib_deps := $(call java-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
295endif
296full_java_libs += $(full_static_java_libs) $(LOCAL_CLASSPATH)
297full_java_lib_deps += $(full_static_java_libs) $(LOCAL_CLASSPATH)
298
299# This is set by packages that contain instrumentation, allowing them to
300# link against the package they are instrumenting. Currently only one such
301# package is allowed.
302LOCAL_INSTRUMENTATION_FOR := $(strip $(LOCAL_INSTRUMENTATION_FOR))
303ifdef LOCAL_INSTRUMENTATION_FOR
304 ifneq ($(words $(LOCAL_INSTRUMENTATION_FOR)),1)
305 $(error \
306 $(LOCAL_PATH): Multiple LOCAL_INSTRUMENTATION_FOR members defined)
307 endif
308
309 link_instr_intermediates_dir := $(call intermediates-dir-for, \
310 APPS,$(LOCAL_INSTRUMENTATION_FOR))
311 link_instr_intermediates_dir.COMMON := $(call intermediates-dir-for, \
312 APPS,$(LOCAL_INSTRUMENTATION_FOR),,COMMON)
313
314 full_java_libs += $(link_instr_intermediates_dir.COMMON)/classes.jar
315
316 # We can't depend on the .jar file, so we depend on something that
317 # depends on the jar file; the final built package file.
318 full_java_lib_deps += $(link_instr_intermediates_dir)/package.apk
319endif
320
321ifneq ($(strip $(LOCAL_JAR_MANIFEST)),)
322$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST := $(LOCAL_PATH)/$(LOCAL_JAR_MANIFEST)
323else
324$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST :=
325endif
326
327endif
328
329
330###########################################################
331## make clean- targets
332###########################################################
333cleantarget := clean-$(LOCAL_MODULE)
334$(cleantarget) : PRIVATE_MODULE := $(LOCAL_MODULE)
335$(cleantarget) : PRIVATE_CLEAN_FILES := \
336 $(PRIVATE_CLEAN_FILES) \
337 $(LOCAL_BUILT_MODULE) \
338 $(LOCAL_INSTALLED_MODULE) \
339 $(intermediates)
340$(cleantarget)::
341 @echo "Clean: $(PRIVATE_MODULE)"
342 $(hide) rm -rf $(PRIVATE_CLEAN_FILES)
343
344###########################################################
345## Common definitions for module.
346###########################################################
347
348# Propagate local configuration options to this target.
349$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_PATH:=$(LOCAL_PATH)
350$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_POST_PROCESS_COMMAND:= $(LOCAL_POST_PROCESS_COMMAND)
351$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_AAPT_FLAGS:= $(LOCAL_AAPT_FLAGS)
352$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_JAVA_LIBRARIES:= $(LOCAL_JAVA_LIBRARIES)
353#TODO: add this: $(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_ADDITIONAL_DEPENDENCIES:= $(LOCAL_ADDITIONAL_DEPENDENCIES)
354
355$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_ALL_JAVA_LIBRARIES:= $(full_java_libs)
356$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_IS_HOST_MODULE := $(LOCAL_IS_HOST_MODULE)
357$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_HOST:= $(my_host)
358
Dima Zavin46e9bec2009-05-27 19:41:07 -0700359$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_INTERMEDIATES_DIR:= $(intermediates)
360
The Android Open Source Project88b60792009-03-03 19:28:42 -0800361# Tell the module and all of its sub-modules who it is.
362$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_MODULE:= $(LOCAL_MODULE)
363
364# Provide a short-hand for building this module.
365# We name both BUILT and INSTALLED in case
366# LOCAL_UNINSTALLABLE_MODULE is set.
367.PHONY: $(LOCAL_MODULE)
368$(LOCAL_MODULE): $(LOCAL_BUILT_MODULE) $(LOCAL_INSTALLED_MODULE)
369
370###########################################################
371## Module installation rule
372###########################################################
373
374# Some hosts do not have ACP; override the LOCAL version if that's the case.
375ifneq ($(strip $(HOST_ACP_UNAVAILABLE)),)
376 LOCAL_ACP_UNAVAILABLE := $(strip $(HOST_ACP_UNAVAILABLE))
377endif
378
379ifndef LOCAL_UNINSTALLABLE_MODULE
380 # Define a copy rule to install the module.
381 # acp and libraries that it uses can't use acp for
382 # installation; hence, LOCAL_ACP_UNAVAILABLE.
383ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
384$(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE) | $(ACP)
385 @echo "Install: $@"
386 $(copy-file-to-target)
387else
388$(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE)
389 @echo "Install: $@"
390 $(copy-file-to-target-with-cp)
391endif
392
393endif # !LOCAL_UNINSTALLABLE_MODULE
394
395###########################################################
396## Register with ALL_MODULES
397###########################################################
398
399ALL_MODULES += $(LOCAL_MODULE)
400
401# Don't use += on subvars, or else they'll end up being
402# recursively expanded.
403ALL_MODULES.$(LOCAL_MODULE).PATH := \
404 $(ALL_MODULES.$(LOCAL_MODULE).PATH) $(LOCAL_PATH)
405ALL_MODULES.$(LOCAL_MODULE).TAGS := \
406 $(ALL_MODULES.$(LOCAL_MODULE).TAGS) $(LOCAL_MODULE_TAGS)
407ALL_MODULES.$(LOCAL_MODULE).BUILT := \
408 $(ALL_MODULES.$(LOCAL_MODULE).BUILT) $(LOCAL_BUILT_MODULE)
409ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
410 $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(LOCAL_INSTALLED_MODULE)
411ALL_MODULES.$(LOCAL_MODULE).REQUIRED := \
412 $(ALL_MODULES.$(LOCAL_MODULE).REQUIRED) $(LOCAL_REQUIRED_MODULES)
413
414###########################################################
415## Take care of LOCAL_MODULE_TAGS
416###########################################################
417
418# Keep track of all the tags we've seen.
419ALL_MODULE_TAGS := $(sort $(ALL_MODULE_TAGS) $(LOCAL_MODULE_TAGS))
420
421# Add this module to the tag list of each specified tag.
422# Don't use "+=". If the variable hasn't been set with ":=",
423# it will default to recursive expansion.
424$(foreach tag,$(LOCAL_MODULE_TAGS),\
425 $(eval ALL_MODULE_TAGS.$(tag) := \
426 $(ALL_MODULE_TAGS.$(tag)) \
427 $(LOCAL_INSTALLED_MODULE)))
428
429# Add this module name to the tag list of each specified tag.
430$(foreach tag,$(LOCAL_MODULE_TAGS),\
431 $(eval ALL_MODULE_NAME_TAGS.$(tag) += $(LOCAL_MODULE)))
432
433# Always build everything, but only install a subset.
434ALL_BUILT_MODULES += $(LOCAL_BUILT_MODULE)
435
436###########################################################
437## NOTICE files
438###########################################################
439
440include $(BUILD_SYSTEM)/notice_files.mk
441
442#:vi noexpandtab