blob: 780d8fbdc6653fcdfdf45c15eb47fe3836927b04 [file] [log] [blame]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001#
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##
18## Common build system definitions. Mostly standard
19## commands for building various types of targets, which
20## are used by others to construct the final targets.
21##
22
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070023# These are variables we use to collect overall lists
24# of things being processed.
25
26# Full paths to all of the documentation
27ALL_DOCS:=
28
29# The short names of all of the targets in the system.
30# For each element of ALL_MODULES, two other variables
31# are defined:
32# $(ALL_MODULES.$(target)).BUILT
33# $(ALL_MODULES.$(target)).INSTALLED
34# The BUILT variable contains LOCAL_BUILT_MODULE for that
35# target, and the INSTALLED variable contains the LOCAL_INSTALLED_MODULE.
36# Some targets may have multiple files listed in the BUILT and INSTALLED
37# sub-variables.
38ALL_MODULES:=
39
40# Full paths to targets that should be added to the "make droid"
41# set of installed targets.
42ALL_DEFAULT_INSTALLED_MODULES:=
43
44# Full paths to all targets that will be built.
45ALL_BUILT_MODULES:=
46
47# The list of tags that have been defined by
48# LOCAL_MODULE_TAGS. Each word in this variable maps
49# to a corresponding ALL_MODULE_TAGS.<tagname> variable
50# that contains all of the INSTALLED_MODULEs with that tag.
51ALL_MODULE_TAGS:=
52
53# Similar to ALL_MODULE_TAGS, but contains the short names
54# of all targets for a particular tag. The top-level variable
55# won't have the list of tags; ust ALL_MODULE_TAGS to get
56# the list of all known tags. (This means that this variable
57# will always be empty; it's just here as a placeholder for
58# its sub-variables.)
59ALL_MODULE_NAME_TAGS:=
60
61# Full paths to all prebuilt files that will be copied
62# (used to make the dependency on acp)
63ALL_PREBUILT:=
64
65# Full path to all files that are made by some tool
66ALL_GENERATED_SOURCES:=
67
68# Full path to all asm, C, C++, lex and yacc generated C files.
69# These all have an order-only dependency on the copied headers
70ALL_C_CPP_ETC_OBJECTS:=
71
72# The list of dynamic binaries that haven't been stripped/compressed/prelinked.
73ALL_ORIGINAL_DYNAMIC_BINARIES:=
74
75# These files go into the SDK
76ALL_SDK_FILES:=
77
78# Files for dalvik. This is often build without building the rest of the OS.
79INTERNAL_DALVIK_MODULES:=
80
81# All findbugs xml files
82ALL_FINDBUGS_FILES:=
83
84###########################################################
85## Debugging; prints a variable list to stdout
86###########################################################
87
88# $(1): variable name list, not variable values
89define print-vars
90$(foreach var,$(1), \
91 $(info $(var):) \
92 $(foreach word,$($(var)), \
93 $(info $(space)$(space)$(word)) \
94 ) \
95 )
96endef
97
98###########################################################
99## Retrieve the directory of the current makefile
100###########################################################
101
102# Figure out where we are.
103define my-dir
104$(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST),$(MAKEFILE_LIST))))
105endef
106
107###########################################################
108## Retrieve a list of all makefiles immediately below some directory
109###########################################################
110
111define all-makefiles-under
112$(wildcard $(1)/*/Android.mk)
113endef
114
115###########################################################
116## Look under a directory for makefiles that don't have parent
117## makefiles.
118###########################################################
119
120# $(1): directory to search under
121# Ignores $(1)/Android.mk
122define first-makefiles-under
123$(shell build/tools/findleaves.sh --mindepth=2 $(1) Android.mk)
124endef
125
126###########################################################
127## Retrieve a list of all makefiles immediately below your directory
128###########################################################
129
130define all-subdir-makefiles
131$(call all-makefiles-under,$(call my-dir))
132endef
133
134###########################################################
135## Look in the named list of directories for makefiles,
136## relative to the current directory.
137###########################################################
138
139# $(1): List of directories to look for under this directory
140define all-named-subdir-makefiles
141$(wildcard $(addsuffix /Android.mk, $(addprefix $(my-dir)/,$(1))))
142endef
143
144###########################################################
145## Find all of the java files under the named directories.
146## Meant to be used like:
147## SRC_FILES := $(call all-java-files-under,src tests)
148###########################################################
149
150define all-java-files-under
151$(patsubst ./%,%, \
152 $(shell cd $(LOCAL_PATH) ; \
153 find $(1) -name "*.java" -and -not -name ".*") \
154 )
155endef
156
157###########################################################
158## Find all of the java files from here. Meant to be used like:
159## SRC_FILES := $(call all-subdir-java-files)
160###########################################################
161
162define all-subdir-java-files
163$(call all-java-files-under,.)
164endef
165
166###########################################################
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800167## Find all of the c files under the named directories.
168## Meant to be used like:
169## SRC_FILES := $(call all-c-files-under,src tests)
170###########################################################
171
172define all-c-files-under
173$(patsubst ./%,%, \
174 $(shell cd $(LOCAL_PATH) ; \
175 find $(1) -name "*.c" -and -not -name ".*") \
176 )
177endef
178
179###########################################################
180## Find all of the c files from here. Meant to be used like:
181## SRC_FILES := $(call all-subdir-c-files)
182###########################################################
183
184define all-subdir-c-files
185$(call all-c-files-under,.)
186endef
187
188###########################################################
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700189## Find all files named "I*.aidl" under the named directories,
190## which must be relative to $(LOCAL_PATH). The returned list
191## is relative to $(LOCAL_PATH).
192###########################################################
193
194define all-Iaidl-files-under
195$(patsubst ./%,%, \
196 $(shell cd $(LOCAL_PATH) ; \
197 find $(1) -name "I*.aidl" -and -not -name ".*") \
198 )
199endef
200
201###########################################################
202## Find all of the "I*.aidl" files under $(LOCAL_PATH).
203###########################################################
204
205define all-subdir-Iaidl-files
206$(call all-Iaidl-files-under,.)
207endef
208
209###########################################################
210## Find all of the html files from here. Meant to be used like:
211## SRC_FILES := $(call all-subdir-html-files)
212###########################################################
213
214define all-subdir-html-files
215$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find . -name "*.html"))
216endef
217
218###########################################################
219## Find all of the files matching pattern
220## SRC_FILES := $(call find-subdir-files, <pattern>)
221###########################################################
222
223define find-subdir-files
224$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find $(1)))
225endef
226
227###########################################################
228# find the files in the subdirectory $1 of LOCAL_DIR
229# matching pattern $2, filtering out files $3
230# e.g.
231# SRC_FILES += $(call find-subdir-subdir-files, \
232# css, *.cpp, DontWantThis.cpp)
233###########################################################
234
235define find-subdir-subdir-files
236$(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
237 $(LOCAL_PATH) ; find $(1) -maxdepth 1 -name $(2))))
238endef
239
240###########################################################
241## Find all of the files matching pattern
242## SRC_FILES := $(call all-subdir-java-files)
243###########################################################
244
245define find-subdir-assets
The Android Open Source Project66339ad2009-01-15 16:12:07 -0800246$(if $(1),\
247 $(patsubst ./%,%, $(foreach dir,$(1),\
248 $(shell if [ -d $(dir) ] ; then\
249 cd $(dir) ; find ./ -type f -and -not -type l ;\
250 fi \
251 ) \
252 )) \
253, \
254 $(warning Empty argument supplied to find-subdir-assets) \
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255)
256endef
257
258###########################################################
259## Find various file types in a list of directories relative to $(LOCAL_PATH)
260###########################################################
261
262define find-other-java-files
263 $(call find-subdir-files,$(1) -name "*.java" -and -not -name ".*")
264endef
265
266define find-other-html-files
267 $(call find-subdir-files,$(1) -name "*.html" -and -not -name ".*")
268endef
269
270###########################################################
271## Scan through each directory of $(1) looking for files
272## that match $(2) using $(wildcard). Useful for seeing if
273## a given directory or one of its parents contains
274## a particular file. Returns the first match found,
275## starting furthest from the root.
276###########################################################
277
278define find-parent-file
279$(strip \
280 $(eval _fpf := $(wildcard $(strip $(1))/$(strip $(2)))) \
281 $(if $(_fpf),$(_fpf), \
282 $(if $(filter-out ./ .,$(1)), \
283 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
284 ) \
285 ) \
286)
287endef
288
289###########################################################
290## Function we can evaluate to introduce a dynamic dependency
291###########################################################
292
293define add-dependency
294$(1): $(2)
295endef
296
297###########################################################
298## Set up the dependencies for a prebuilt target
299## $(call add-prebuilt-file, srcfile, [targetclass])
300###########################################################
301
302define add-prebuilt-file
303 $(eval $(include-prebuilt))
304endef
305
306define include-prebuilt
307 include $$(CLEAR_VARS)
308 LOCAL_SRC_FILES := $(1)
309 LOCAL_BUILT_MODULE_STEM := $(1)
310 LOCAL_MODULE_SUFFIX := $$(suffix $(1))
311 LOCAL_MODULE := $$(basename $(1))
312 LOCAL_MODULE_CLASS := $(2)
313 include $$(BUILD_PREBUILT)
314endef
315
316###########################################################
317## do multiple prebuilts
318## $(call target class, files ...)
319###########################################################
320
321define add-prebuilt-files
322 $(foreach f,$(2),$(call add-prebuilt-file,$f,$(1)))
323endef
324
325
326
327###########################################################
328## The intermediates directory. Where object files go for
329## a given target. We could technically get away without
330## the "_intermediates" suffix on the directory, but it's
331## nice to be able to grep for that string to find out if
332## anyone's abusing the system.
333###########################################################
334
335# $(1): target class, like "APPS"
336# $(2): target name, like "NotePad"
337# $(3): if non-empty, this is a HOST target.
338# $(4): if non-empty, force the intermediates to be COMMON
339define intermediates-dir-for
340$(strip \
341 $(eval _idfClass := $(strip $(1))) \
342 $(if $(_idfClass),, \
343 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
344 $(eval _idfName := $(strip $(2))) \
345 $(if $(_idfName),, \
346 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
347 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
348 $(if $(filter $(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
349 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
350 , \
351 $(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
352 ) \
353 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
354)
355endef
356
357# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
358# to determine the intermediates directory.
359#
360# $(1): if non-empty, force the intermediates to be COMMON
361define local-intermediates-dir
362$(strip \
363 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
364 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
365 $(if $(strip $(LOCAL_MODULE)),, \
366 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
367 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
368)
369endef
370
371###########################################################
372## Convert "path/to/libXXX.so" to "-lXXX".
373## Any "path/to/libXXX.a" elements pass through unchanged.
374###########################################################
375
376define normalize-libraries
377$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
378$(filter-out %.so,$(1))
379endef
380
381# TODO: change users to call the common version.
382define normalize-host-libraries
383$(call normalize-libraries,$(1))
384endef
385
386define normalize-target-libraries
387$(call normalize-libraries,$(1))
388endef
389
390###########################################################
391## Convert a list of short module names (e.g., "framework", "Browser")
392## into the list of files that are built for those modules.
393## NOTE: this won't return reliable results until after all
394## sub-makefiles have been included.
395## $(1): target list
396###########################################################
397
398define module-built-files
399$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
400endef
401
402###########################################################
403## Convert a list of short modules names (e.g., "framework", "Browser")
404## into the list of files that are installed for those modules.
405## NOTE: this won't return reliable results until after all
406## sub-makefiles have been included.
407## $(1): target list
408###########################################################
409
410define module-installed-files
411$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
412endef
413
414###########################################################
415## Convert "framework framework-res ext" to "out/.../javalib.jar ..."
416## This lets us treat framework-res as a normal library.
417## $(1): library list
418## $(2): Non-empty if IS_HOST_MODULE
419###########################################################
420
421# $(1): library name
422# $(2): Non-empty if IS_HOST_MODULE
423define _java-lib-dir
424$(call intermediates-dir-for, \
425 $(if $(filter framework-res,$(1)),APPS,JAVA_LIBRARIES),$(1),$(2))
426endef
427
428# $(1): library name
429define _java-lib-classes.jar
430$(if $(filter framework-res,$(1)),package$(COMMON_ANDROID_PACKAGE_SUFFIX),classes$(COMMON_JAVA_PACKAGE_SUFFIX))
431endef
432
433# $(1): library name
434# $(2): Non-empty if IS_HOST_MODULE
435define _java-lib-full-classes.jar
436$(call _java-lib-dir,$(1),$(2))/$(call _java-lib-classes.jar,$(1))
437endef
438
439# $(1): library name list
440# $(2): Non-empty if IS_HOST_MODULE
441define java-lib-files
442$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
443endef
444
445# $(1): library name
446define _java-lib-dep
447$(if $(filter framework-res,$(1)),package$(COMMON_ANDROID_PACKAGE_SUFFIX),javalib$(COMMON_JAVA_PACKAGE_SUFFIX))
448endef
449
450# $(1): library name
451# $(2): Non-empty if IS_HOST_MODULE
452define _java-lib-full-dep
453$(call _java-lib-dir,$(1),$(2))/$(call _java-lib-dep,$(1))
454endef
455
456# $(1): library name list
457# $(2): Non-empty if IS_HOST_MODULE
458define java-lib-deps
459$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
460endef
461
462###########################################################
463## Convert "a b c" into "a:b:c"
464###########################################################
465
466empty :=
467space := $(empty) $(empty)
468
469define normalize-path-list
470$(subst $(space),:,$(strip $(1)))
471endef
472
473###########################################################
474## Convert "a=b c= d e = f" into "a=b c=d e=f"
475##
476## $(1): list to collapse
477## $(2): if set, separator word; usually "=", ":", or ":="
478## Defaults to "=" if not set.
479###########################################################
480
481define collapse-pairs
482$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
483$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
484 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
485endef
486
487
488###########################################################
489## MODULE_TAG set operations
490###########################################################
491
492# Given a list of tags, return the targets that specify
493# any of those tags.
494# $(1): tag list
495define modules-for-tag-list
496$(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag))))
497endef
498
499# Same as modules-for-tag-list, but operates on
500# ALL_MODULE_NAME_TAGS.
501# $(1): tag list
502define module-names-for-tag-list
503$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
504endef
505
506# Given an accept and reject list, find the matching
507# set of targets. If a target has multiple tags and
508# any of them are rejected, the target is rejected.
509# Reject overrides accept.
510# $(1): list of tags to accept
511# $(2): list of tags to reject
512#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
513define get-tagged-modules
514$(filter-out \
515 $(call modules-for-tag-list,$(2)), \
516 $(call modules-for-tag-list,$(1)))
517endef
518
519
520###########################################################
521## Package filtering
522###########################################################
523
524# Given a list of installed modules (short or long names)
525# return a list of the packages (yes, .apk packages, not
526# modules in general) that are overridden by this list and,
527# therefore, should not be installed.
528# $(1): mixed list of installed modules
529# TODO: This is fragile; find a reliable way to get this information.
530define _get-package-overrides
531 $(eval ### Discard any words containing slashes, unless they end in .apk, \
532 ### in which case trim off the directory component and the suffix. \
533 ### If there are no slashes, keep the entire word.)
534 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
535 $(eval _gpo_names := \
536 $(filter %.apk,$(_gpo_names)) \
537 $(filter-out %@@@ @@@%,$(_gpo_names)))
538 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
539 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
540
541 $(eval ### Remove any remaining words that contain dots.)
542 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
543 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
544
545 $(eval ### Now we have a list of any words that could possibly refer to \
546 ### packages, although there may be words that do not. Only \
547 ### real packages will be present under PACKAGES.*, though.)
548 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
549endef
550
551define get-package-overrides
552$(strip $(sort $(call _get-package-overrides,$(1))))
553endef
554
555###########################################################
556## Output the command lines, or not
557###########################################################
558
559ifeq ($(strip $(SHOW_COMMANDS)),)
560define pretty
561@echo $1
562endef
563hide := @
564else
565define pretty
566endef
567hide :=
568endif
569
570###########################################################
571## Dump the variables that are associated with targets
572###########################################################
573
574define dump-module-variables
575@echo all_dependencies=$^
576@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
577@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
578@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
579@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
580@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
581@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
582@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
583@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
584@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
585@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
586@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
587@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
588@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
589@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
590@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
591endef
592
593###########################################################
594## Commands for using sed to replace given variable values
595###########################################################
596
597define transform-variables
598@mkdir -p $(dir $@)
599@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
600$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
601$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
602endef
603
604
605###########################################################
606## Commands for munging the dependency files GCC generates
607###########################################################
608
609define transform-d-to-p
610@cp $(@:%.o=%.d) $(@:%.o=%.P); \
611 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
612 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
613 rm -f $(@:%.o=%.d)
614endef
615
616###########################################################
617## Commands for running lex
618###########################################################
619
620define transform-l-to-cpp
621@mkdir -p $(dir $@)
622@echo "Lex: $(PRIVATE_MODULE) <= $<"
623$(hide) $(LEX) -o$@ $<
624endef
625
626###########################################################
627## Commands for running yacc
628##
629## Because the extension of c++ files can change, the
630## extension must be specified in $1.
631## E.g, "$(call transform-y-to-cpp,.cpp)"
632###########################################################
633
634define transform-y-to-cpp
635@mkdir -p $(dir $@)
636@echo "Yacc: $(PRIVATE_MODULE) <= $<"
637$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
638touch $(@:$1=$(YACC_HEADER_SUFFIX))
639echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
640echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
641cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
642echo '#endif' >> $(@:$1=.h)
643rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
644endef
645
646
647###########################################################
648## Commands for running aidl
649###########################################################
650
651define transform-aidl-to-java
652@mkdir -p $(dir $@)
653@echo "Aidl: $(PRIVATE_MODULE) <= $<"
654$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
655endef
656#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
657
658
659
660###########################################################
661## Commands for running gcc to compile a C++ file
662###########################################################
663
664define transform-cpp-to-o
665@mkdir -p $(dir $@)
666@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
667$(hide) $(PRIVATE_CXX) \
668 $(foreach incdir, \
669 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
670 $(TARGET_PROJECT_INCLUDES) \
671 $(TARGET_C_INCLUDES) \
672 ) \
673 $(PRIVATE_C_INCLUDES) \
674 , \
675 -I $(incdir) \
676 ) \
677 -c \
678 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
679 $(TARGET_GLOBAL_CFLAGS) \
680 $(TARGET_GLOBAL_CPPFLAGS) \
681 $(PRIVATE_ARM_CFLAGS) \
682 ) \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800683 -fno-rtti \
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700684 $(PRIVATE_CFLAGS) \
685 $(PRIVATE_CPPFLAGS) \
686 $(PRIVATE_DEBUG_CFLAGS) \
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700687 -MD -o $@ $<
688$(hide) $(transform-d-to-p)
689endef
690
691
692###########################################################
693## Commands for running gcc to compile a C file
694###########################################################
695
696# $(1): extra flags
697define transform-c-or-s-to-o-no-deps
698@mkdir -p $(dir $@)
699$(hide) $(PRIVATE_CC) \
700 $(foreach incdir, \
701 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
702 $(TARGET_PROJECT_INCLUDES) \
703 $(TARGET_C_INCLUDES) \
704 ) \
705 $(PRIVATE_C_INCLUDES) \
706 , \
707 -I $(incdir) \
708 ) \
709 -c \
710 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
711 $(TARGET_GLOBAL_CFLAGS) \
712 $(PRIVATE_ARM_CFLAGS) \
713 ) \
714 $(PRIVATE_CFLAGS) \
715 $(1) \
716 $(PRIVATE_DEBUG_CFLAGS) \
717 -MD -o $@ $<
718endef
719
720define transform-c-to-o-no-deps
721@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
722$(call transform-c-or-s-to-o-no-deps, )
723endef
724
725define transform-s-to-o-no-deps
726@echo "target asm: $(PRIVATE_MODULE) <= $<"
727$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
728endef
729
730define transform-c-to-o
731$(transform-c-to-o-no-deps)
732$(hide) $(transform-d-to-p)
733endef
734
735define transform-s-to-o
736$(transform-s-to-o-no-deps)
737$(hide) $(transform-d-to-p)
738endef
739
740###########################################################
741## Commands for running gcc to compile a host C++ file
742###########################################################
743
744define transform-host-cpp-to-o
745@mkdir -p $(dir $@)
746@echo "host C++: $(PRIVATE_MODULE) <= $<"
747$(hide) $(PRIVATE_CXX) \
748 $(foreach incdir, \
749 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
750 $(HOST_PROJECT_INCLUDES) \
751 $(HOST_C_INCLUDES) \
752 ) \
753 $(PRIVATE_C_INCLUDES) \
754 , \
755 -I $(incdir) \
756 ) \
757 -c \
758 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
759 $(HOST_GLOBAL_CFLAGS) \
760 $(HOST_GLOBAL_CPPFLAGS) \
761 ) \
762 $(PRIVATE_CFLAGS) \
763 $(PRIVATE_CPPFLAGS) \
764 $(PRIVATE_DEBUG_CFLAGS) \
765 -MD -o $@ $<
766$(transform-d-to-p)
767endef
768
769
770###########################################################
771## Commands for running gcc to compile a host C file
772###########################################################
773
774# $(1): extra flags
775define transform-host-c-or-s-to-o-no-deps
776@mkdir -p $(dir $@)
777$(hide) $(PRIVATE_CC) \
778 $(foreach incdir, \
779 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
780 $(HOST_PROJECT_INCLUDES) \
781 $(HOST_C_INCLUDES) \
782 ) \
783 $(PRIVATE_C_INCLUDES) \
784 , \
785 -I $(incdir) \
786 ) \
787 -c \
788 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
789 $(HOST_GLOBAL_CFLAGS) \
790 ) \
791 $(PRIVATE_CFLAGS) \
792 $(1) \
793 $(PRIVATE_DEBUG_CFLAGS) \
794 -MD -o $@ $<
795endef
796
797define transform-host-c-to-o-no-deps
798@echo "host C: $(PRIVATE_MODULE) <= $<"
799$(call transform-host-c-or-s-to-o-no-deps, )
800endef
801
802define transform-host-s-to-o-no-deps
803@echo "host asm: $(PRIVATE_MODULE) <= $<"
804$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
805endef
806
807define transform-host-c-to-o
808$(transform-host-c-to-o-no-deps)
809$(transform-d-to-p)
810endef
811
812define transform-host-s-to-o
813$(transform-host-s-to-o-no-deps)
814$(transform-d-to-p)
815endef
816
817###########################################################
818## Commands for running ar
819###########################################################
820
821# Explicitly delete the archive first so that ar doesn't
822# try to add to an existing archive.
823define transform-o-to-static-lib
824@mkdir -p $(dir $@)
825@echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
826@rm -f $@
827$(hide) $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $^
828endef
829
830###########################################################
831## Commands for running host ar
832###########################################################
833
834# Explicitly delete the archive first so that ar doesn't
835# try to add to an existing archive.
836define transform-host-o-to-static-lib
837@mkdir -p $(dir $@)
838@echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
839@rm -f $@
840$(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $^
841endef
842
843
844###########################################################
845## Commands for running gcc to link a shared library or package
846###########################################################
847
848# ld just seems to be so finicky with command order that we allow
849# it to be overriden en-masse see combo/linux-arm.make for an example.
850ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
851define transform-host-o-to-shared-lib-inner
852$(HOST_CXX) \
853 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
854 -Wl,-rpath,\$$ORIGIN/../lib \
855 -shared -Wl,-soname,$(notdir $@) \
856 $(PRIVATE_LDFLAGS) \
857 $(HOST_GLOBAL_LD_DIRS) \
858 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
859 $(HOST_GLOBAL_LDFLAGS) \
860 ) \
861 $(PRIVATE_ALL_OBJECTS) \
862 -Wl,--whole-archive \
863 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
864 -Wl,--no-whole-archive \
865 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
866 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
867 -o $@ \
868 $(PRIVATE_LDLIBS)
869endef
870endif
871
872define transform-host-o-to-shared-lib
873@mkdir -p $(dir $@)
874@echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
875$(hide) $(transform-host-o-to-shared-lib-inner)
876endef
877
878define transform-host-o-to-package
879@mkdir -p $(dir $@)
880@echo "host Package: $(PRIVATE_MODULE) ($@)"
881$(hide) $(transform-host-o-to-shared-lib-inner)
882endef
883
884
885###########################################################
886## Commands for running gcc to link a shared library or package
887###########################################################
888
889#echo >$@.vers "{"; \
890#echo >>$@.vers " global:"; \
891#$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \
892#echo >>$@.vers " local:"; \
893#echo >>$@.vers " *;"; \
894#echo >>$@.vers "};"; \
895
896# -Wl,--version-script=$@.vers \
897
898# ld just seems to be so finicky with command order that we allow
899# it to be overriden en-masse see combo/linux-arm.make for an example.
900ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
901define transform-o-to-shared-lib-inner
902$(TARGET_CXX) \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800903 $(TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700904 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
905 -Wl,-rpath,\$$ORIGIN/../lib \
906 -shared -Wl,-soname,$(notdir $@) \
907 $(PRIVATE_LDFLAGS) \
908 $(TARGET_GLOBAL_LD_DIRS) \
909 $(PRIVATE_ALL_OBJECTS) \
910 -Wl,--whole-archive \
911 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
912 -Wl,--no-whole-archive \
913 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
914 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
915 -o $@ \
916 $(PRIVATE_LDLIBS)
917endef
918endif
919
920define transform-o-to-shared-lib
921@mkdir -p $(dir $@)
922@echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
923$(hide) $(transform-o-to-shared-lib-inner)
924endef
925
926define transform-o-to-package
927@mkdir -p $(dir $@)
928@echo "target Package: $(PRIVATE_MODULE) ($@)"
929$(hide) $(transform-o-to-shared-lib-inner)
930endef
931
932
933###########################################################
934## Commands for filtering a target executable or library
935###########################################################
936
937# Because of bug 743462 ("Prelinked image magic gets stripped
938# by arm-elf-objcopy"), we have to use soslim to strip target
939# binaries.
940define transform-to-stripped
941@mkdir -p $(dir $@)
942@echo "target Strip: $(PRIVATE_MODULE) ($@)"
943$(hide) $(SOSLIM) --strip --shady --quiet $< --outfile $@
944endef
945
946define transform-to-prelinked
947@mkdir -p $(dir $@)
948@echo "target Prelink: $(PRIVATE_MODULE) ($@)"
949$(hide) $(APRIORI) \
950 --prelinkmap $(TARGET_PRELINKER_MAP) \
951 --locals-only \
952 --quiet \
953 $< \
954 --output $@
955endef
956
957
958###########################################################
959## Commands for running gcc to link an executable
960###########################################################
961
962ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
963define transform-o-to-executable-inner
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800964$(TARGET_CXX) \
965 $(TARGET_GLOBAL_LDFLAGS) \
966 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 $(TARGET_GLOBAL_LD_DIRS) \
968 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
969 -Wl,-rpath,\$$ORIGIN/../lib \
970 $(PRIVATE_LDFLAGS) \
971 $(TARGET_GLOBAL_LD_DIRS) \
972 $(PRIVATE_ALL_OBJECTS) \
973 -Wl,--whole-archive \
974 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
975 -Wl,--no-whole-archive \
976 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
977 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
978 -o $@ \
979 $(PRIVATE_LDLIBS)
980endef
981endif
982
983define transform-o-to-executable
984@mkdir -p $(dir $@)
985@echo "target Executable: $(PRIVATE_MODULE) ($@)"
986$(hide) $(transform-o-to-executable-inner)
987endef
988
989
990###########################################################
991## Commands for running gcc to link a statically linked
992## executable. In practice, we only use this on arm, so
993## the other platforms don't have the
994## transform-o-to-static-executable defined
995###########################################################
996
997ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
998define transform-o-to-static-executable-inner
999endef
1000endif
1001
1002define transform-o-to-static-executable
1003@mkdir -p $(dir $@)
1004@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
1005$(hide) $(transform-o-to-static-executable-inner)
1006endef
1007
1008
1009###########################################################
1010## Commands for running gcc to link a host executable
1011###########################################################
1012
1013ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1014define transform-host-o-to-executable-inner
1015$(HOST_CXX) \
1016 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1017 -Wl,-rpath,\$$ORIGIN/../lib \
1018 $(HOST_GLOBAL_LD_DIRS) \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001019 $(PRIVATE_LDFLAGS) \
1020 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1021 $(HOST_GLOBAL_LDFLAGS) \
1022 ) \
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001023 $(PRIVATE_ALL_OBJECTS) \
1024 -Wl,--whole-archive \
1025 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1026 -Wl,--no-whole-archive \
1027 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1028 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1029 -o $@ \
1030 $(PRIVATE_LDLIBS)
1031endef
1032endif
1033
1034define transform-host-o-to-executable
1035@mkdir -p $(dir $@)
1036@echo "host Executable: $(PRIVATE_MODULE) ($@)"
1037$(hide) $(transform-host-o-to-executable-inner)
1038endef
1039
1040
1041###########################################################
1042## Commands for running javac to make .class files
1043###########################################################
1044
1045#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)"
1046#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')"
1047
1048# TODO: Right now we generate the asset resources twice, first as part
1049# of generating the Java classes, then at the end when packaging the final
1050# assets. This should be changed to do one of two things: (1) Don't generate
1051# any resource files the first time, only create classes during that stage;
1052# or (2) Don't use the -c flag with the second stage, instead taking the
1053# resource files from the first stage as additional input. My original intent
1054# was to use approach (2), but this requires a little more work in the tool.
1055# Maybe we should just use approach (1).
1056
1057# This rule creates the R.java and Manifest.java files, both of which
1058# are PRODUCT-neutral. Don't pass PRODUCT_AAPT_CONFIG to this invocation.
1059define create-resource-java-files
1060@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1061@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
1062$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m -z \
1063 $(eval # PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
1064 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1065 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1066 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1067 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1068 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1069 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES))
1070endef
1071
1072ifeq ($(HOST_OS),windows)
1073xlint_unchecked :=
1074else
1075#xlint_unchecked := -Xlint:unchecked
1076endif
1077
1078# emit-line, <word list>, <output file>
1079define emit-line
1080 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1081endef
1082
1083# dump-words-to-file, <word list>, <output file>
1084define dump-words-to-file
1085 @rm -f $(2)
1086 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1087 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1088 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1089 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1090 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1091 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1092 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1093 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1094 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1095 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1096 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1097 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1098 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1099 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1100 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1101 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1102 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1103 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1104 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1105 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
1106 @$(if $(wordlist 4001,4002,$(1)),$(error Too many words ($(words $(1)))))
1107endef
1108
1109# For a list of jar files, unzip them to a specified directory,
1110# but make sure that no META-INF files come along for the ride.
1111#
1112# $(1): files to unzip
1113# $(2): destination directory
1114define unzip-jar-files
1115 $(hide) for f in $(1); \
1116 do \
1117 if [ ! -f $$f ]; then \
1118 echo Missing file $$f; \
1119 exit 1; \
1120 fi; \
1121 unzip -q $$f -d $(2); \
1122 (cd $(2) && rm -rf META-INF); \
1123 done
1124endef
1125
1126# below we write the list of java files to java-source-list to avoid argument list length problems with Cygwin
1127# we filter out duplicate java file names because eclipse's compiler doesn't like them.
1128define transform-java-to-classes.jar
1129@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1130@rm -f $@
1131@rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1132@mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1133$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1134 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
1135$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
1136@if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1137 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
1138fi
1139$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
1140 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1141$(hide) $(TARGET_JAVAC) -encoding ascii $(PRIVATE_BOOTCLASSPATH) \
1142 $(addprefix -classpath ,$(strip \
1143 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
The Android Open Source Project66339ad2009-01-15 16:12:07 -08001144 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) $(xlint_unchecked) \
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001145 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1146 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
1147 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
1148@ rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
1149@ rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1150@mkdir -p $(dir $@)
1151$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1152 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1153@rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1154endef
1155
The Android Open Source Project66339ad2009-01-15 16:12:07 -08001156define transform-classes.jar-to-emma
1157$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
1158 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR)
1159endef
1160
The Android Open Source Project4f85cc52009-01-09 17:50:54 -08001161#TODO: use a smaller -Xmx value for most libraries;
1162# only core.jar and framework.jar need a heap this big.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001163define transform-classes.jar-to-dex
1164@echo "target Dex: $(PRIVATE_MODULE)"
1165@mkdir -p $(dir $@)
1166$(hide) $(DX) -JXms16M \
The Android Open Source Project4f85cc52009-01-09 17:50:54 -08001167 -JXmx1536M \
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001168 --dex --output=$@ \
1169 $(if $(NO_OPTIMIZE_DX), \
1170 --no-optimize) \
1171 $(if $(GENERATE_DEX_DEBUG), \
1172 --debug --verbose \
1173 --dump-to=$(@:.dex=.lst) \
1174 --dump-width=1000) \
1175 $(PRIVATE_DX_FLAGS) \
1176 $<
1177endef
1178
1179# Create a mostly-empty .jar file that we'll add to later.
1180# The MacOS jar tool doesn't like creating empty jar files,
1181# so we need to give it something.
1182define create-empty-package
1183@mkdir -p $(dir $@)
1184$(hide) touch $(dir $@)/dummy
1185$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy)
1186$(hide) zip -qd $@ dummy
1187$(hide) rm $(dir $@)/dummy
1188endef
1189
1190#TODO: we kinda want to build different asset packages for
1191# different configurations, then combine them later (or something).
1192# Per-locale, etc.
1193# A list of dynamic and static parameters; build layers for
1194# dynamic params that lay over the static ones.
1195#TODO: update the manifest to point to the package file
1196define add-assets-to-package
1197$(hide) $(AAPT) package -z -u $(PRIVATE_AAPT_FLAGS) \
1198 $(addprefix -c , $(PRODUCT_AAPT_CONFIG)) \
1199 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1200 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1201 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1202 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
1203 -F $@
1204endef
1205
1206#TODO: Allow library directory to be specified based on the target
1207# CPU and ABI instead of being hard coded as armeabi.
1208define add-jni-shared-libs-to-package
1209$(hide) rm -rf $(dir $@)lib
1210$(hide) mkdir -p $(dir $@)lib/armeabi
1211$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/armeabi
1212$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib)
1213$(hide) rm -rf $(dir $@)lib
1214endef
1215
1216#TODO: use aapt instead of zip, once it supports junking the path
1217# (so adding "xxx/yyy/classes.dex" appears as "classes.dex")
1218#TODO: update the manifest to point to the dex file
1219define add-dex-to-package
1220$(hide) zip -qj $@ $(PRIVATE_DEX_FILE)
1221endef
1222
1223define add-java-resources-to-package
1224$(hide) jar uf $@ $(PRIVATE_EXTRA_JAR_ARGS)
1225endef
1226
1227# Sign a package using the specified key/cert.
1228#
1229define sign-package
1230$(hide) mv $@ $@.unsigned
1231$(hide) java -jar $(SIGNAPK_JAR) \
1232 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) $@.unsigned $@.signed
1233$(hide) mv $@.signed $@
1234endef
1235
1236# Align STORED entries of a package on 4-byte boundaries
1237# to make them easier to mmap.
1238#
1239define align-package
1240$(hide) mv $@ $@.unaligned
1241$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned
1242$(hide) mv $@.aligned $@
1243endef
1244
1245define install-dex-debug
1246$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
1247 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1248 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
1249 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
1250 fi
1251$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
1252 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1253 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
1254 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
1255 fi
1256endef
1257
1258# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
1259# new prebuilt rules to work, we should change this to copy the
1260# resources to the out directory and then copy the resources.
1261
1262# Note: not using aapt tool for this because we aren't making
1263# an android package for the host.
1264define transform-host-java-to-package
1265@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1266@rm -f $@
1267@rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1268@mkdir -p $(dir $@)
1269@mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1270$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1271 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
1272$(hide) $(HOST_JAVAC) -encoding ascii -g \
1273 $(xlint_unchecked) \
1274 $(addprefix -classpath ,$(strip \
1275 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
1276 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) $(PRIVATE_JAVA_SOURCES) || \
1277 ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
1278$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1279 $@ $(PRIVATE_JAR_MANIFEST) $(PRIVATE_EXTRA_JAR_ARGS) \
1280 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1281endef
1282
1283###########################################################
1284## Obfuscate a jar file
1285###########################################################
1286
1287# PRIVATE_KEEP_FILE is a file containing a list of classes
1288# PRIVATE_INTERMEDIATES_DIR is a directory we can use for temporary files
1289# The module using this must depend on
1290# $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar
1291define obfuscate-jar
1292@echo "Obfuscate jar: $(notdir $@) ($@)"
1293@mkdir -p $(dir $@)
1294@rm -f $@
1295@mkdir -p $(PRIVATE_INTERMEDIATES_DIR)
1296$(hide) sed -e 's/^/-keep class /' < $(PRIVATE_KEEP_FILE) > \
1297 $(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1298$(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \
1299 -injars $< \
1300 -outjars $@ \
1301 -target 1.5 \
1302 -dontnote -dontwarn \
1303 -printmapping $(PRIVATE_INTERMEDIATES_DIR)/out.map \
1304 -forceprocessing \
1305 -renamesourcefileattribute SourceFile \
1306 -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod \
1307 -repackageclasses \
1308 -keepclassmembers "class * { public protected *; }" \
1309 @$(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1310endef
1311
1312###########################################################
1313## Commands for copying files
1314###########################################################
1315
1316# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
1317# $(1): source header
1318# $(2): destination header
1319define copy-one-header
1320$(2): $(1)
1321 @echo "Header: $$@"
1322 $$(copy-file-to-new-target-with-cp)
1323endef
1324
1325# Define a rule to copy a file. For use via $(eval).
1326# $(1): source file
1327# $(2): destination file
1328define copy-one-file
1329$(2): $(1) | $(ACP)
1330 @echo "Copy: $$@"
1331 $$(copy-file-to-target)
1332endef
1333
1334# The -t option to acp and the -p option to cp is
1335# required for OSX. OSX has a ridiculous restriction
1336# where it's an error for a .a file's modification time
1337# to disagree with an internal timestamp, and this
1338# macro is used to install .a files (among other things).
1339
1340# Copy a single file from one place to another,
1341# preserving permissions and overwriting any existing
1342# file.
1343define copy-file-to-target
1344@mkdir -p $(dir $@)
1345$(hide) $(ACP) -fpt $< $@
1346endef
1347
1348# The same as copy-file-to-target, but use the local
1349# cp command instead of acp.
1350define copy-file-to-target-with-cp
1351@mkdir -p $(dir $@)
1352$(hide) cp -fp $< $@
1353endef
1354
1355# The same as copy-file-to-target, but don't preserve
1356# the old modification time.
1357define copy-file-to-new-target
1358@mkdir -p $(dir $@)
1359$(hide) $(ACP) -fp $< $@
1360endef
1361
1362# The same as copy-file-to-new-target, but use the local
1363# cp command instead of acp.
1364define copy-file-to-new-target-with-cp
1365@mkdir -p $(dir $@)
1366$(hide) cp -f $< $@
1367endef
1368
1369# Copy a prebuilt file to a target location.
1370define transform-prebuilt-to-target
1371@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1372$(copy-file-to-target)
1373endef
1374
1375
1376###########################################################
1377## On some platforms (MacOS), after copying a static
1378## library, ranlib must be run to update an internal
1379## timestamp!?!?!
1380###########################################################
1381
1382ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true)
1383define transform-host-ranlib-copy-hack
1384 $(hide) ranlib $@ || true
1385endef
1386else
1387define transform-host-ranlib-copy-hack
1388true
1389endef
1390endif
1391
1392ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true)
1393define transform-ranlib-copy-hack
1394 $(hide) ranlib $@
1395endef
1396else
1397define transform-ranlib-copy-hack
1398true
1399endef
1400endif
1401
1402
1403###########################################################
1404## Stuff source generated from one-off tools
1405###########################################################
1406
1407define transform-generated-source
1408@echo "target Generated: $(PRIVATE_MODULE) <= $<"
1409@mkdir -p $(dir $@)
1410$(hide) $(PRIVATE_CUSTOM_TOOL)
1411endef
1412
1413
1414###########################################################
1415## Assertions about attributes of the target
1416###########################################################
1417
1418# $(1): The file to check
1419ifndef get-file-size
1420$(error HOST_OS must define get-file-size)
1421endif
1422
1423# $(1): The file to check (often $@)
1424# $(2): The maximum size, in decimal bytes
1425#
1426# If $(2) is empty, evaluates to "true"
1427#
1428# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
1429# is left over after the image has been flashed. Round the 1% up to the
1430# next whole flash block size.
1431define assert-max-file-size
1432$(if $(2), \
1433 fileSize=`$(call get-file-size,$(1))`; \
1434 maxSize=$(2); \
1435 onePct=`expr "(" $$maxSize + 99 ")" / 100`; \
1436 onePct=`expr "(" "(" $$onePct + $(BOARD_FLASH_BLOCK_SIZE) - 1 ")" / \
1437 $(BOARD_FLASH_BLOCK_SIZE) ")" "*" $(BOARD_FLASH_BLOCK_SIZE)`; \
1438 reserve=`expr 2 "*" $(BOARD_FLASH_BLOCK_SIZE)`; \
1439 if [ "$$onePct" -gt "$$reserve" ]; then \
1440 reserve="$$onePct"; \
1441 fi; \
1442 maxSize=`expr $$maxSize - $$reserve`; \
1443 if [ "$$fileSize" -gt "$$maxSize" ]; then \
1444 echo "error: $(1) too large ($$fileSize > [$(2) - $$reserve])"; \
1445 false; \
1446 fi \
1447 , \
1448 true \
1449 )
1450endef
1451
1452###########################################################
1453## Other includes
1454###########################################################
1455
1456# -----------------------------------------------------------------
1457# Rules and functions to help copy important files to DIST_DIR
1458# when requested.
1459include $(BUILD_SYSTEM)/distdir.mk
1460
1461
1462# broken:
1463# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
1464
1465###########################################################
1466## Misc notes
1467###########################################################
1468
1469#DEPDIR = .deps
1470#df = $(DEPDIR)/$(*F)
1471
1472#SRCS = foo.c bar.c ...
1473
1474#%.o : %.c
1475# @$(MAKEDEPEND); \
1476# cp $(df).d $(df).P; \
1477# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1478# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
1479# rm -f $(df).d
1480# $(COMPILE.c) -o $@ $<
1481
1482#-include $(SRCS:%.c=$(DEPDIR)/%.P)
1483
1484
1485#%.o : %.c
1486# $(COMPILE.c) -MD -o $@ $<
1487# @cp $*.d $*.P; \
1488# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1489# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
1490# rm -f $*.d
The Android Open Source Project66339ad2009-01-15 16:12:07 -08001491