blob: 6f7d2a33245820a1c55a3e2977a1dabd70086cf2 [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##
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
23# 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
The Android Open Source Project88b60792009-03-03 19:28:42 -080044# The list of tags that have been defined by
45# LOCAL_MODULE_TAGS. Each word in this variable maps
46# to a corresponding ALL_MODULE_TAGS.<tagname> variable
47# that contains all of the INSTALLED_MODULEs with that tag.
48ALL_MODULE_TAGS:=
49
50# Similar to ALL_MODULE_TAGS, but contains the short names
51# of all targets for a particular tag. The top-level variable
52# won't have the list of tags; ust ALL_MODULE_TAGS to get
53# the list of all known tags. (This means that this variable
54# will always be empty; it's just here as a placeholder for
55# its sub-variables.)
56ALL_MODULE_NAME_TAGS:=
57
58# Full paths to all prebuilt files that will be copied
59# (used to make the dependency on acp)
60ALL_PREBUILT:=
61
62# Full path to all files that are made by some tool
63ALL_GENERATED_SOURCES:=
64
65# Full path to all asm, C, C++, lex and yacc generated C files.
66# These all have an order-only dependency on the copied headers
67ALL_C_CPP_ETC_OBJECTS:=
68
69# The list of dynamic binaries that haven't been stripped/compressed/prelinked.
70ALL_ORIGINAL_DYNAMIC_BINARIES:=
71
72# These files go into the SDK
73ALL_SDK_FILES:=
74
75# Files for dalvik. This is often build without building the rest of the OS.
76INTERNAL_DALVIK_MODULES:=
77
78# All findbugs xml files
79ALL_FINDBUGS_FILES:=
80
81###########################################################
82## Debugging; prints a variable list to stdout
83###########################################################
84
85# $(1): variable name list, not variable values
86define print-vars
87$(foreach var,$(1), \
88 $(info $(var):) \
89 $(foreach word,$($(var)), \
90 $(info $(space)$(space)$(word)) \
91 ) \
92 )
93endef
94
95###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -070096## Evaluates to true if the string contains the word true,
97## and empty otherwise
98## $(1): a var to test
99###########################################################
100
101define true-or-empty
102$(filter true, $(1))
103endef
104
105
106###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800107## Retrieve the directory of the current makefile
108###########################################################
109
110# Figure out where we are.
111define my-dir
Dave Bortb3926412009-05-19 16:12:22 -0700112$(strip \
113 $(eval md_file_ := $$(lastword $$(MAKEFILE_LIST))) \
114 $(if $(filter $(CLEAR_VARS),$(md_file_)), \
115 $(error LOCAL_PATH must be set before including $$(CLEAR_VARS)) \
116 , \
117 $(patsubst %/,%,$(dir $(md_file_))) \
118 ) \
119 )
The Android Open Source Project88b60792009-03-03 19:28:42 -0800120endef
121
122###########################################################
123## Retrieve a list of all makefiles immediately below some directory
124###########################################################
125
126define all-makefiles-under
127$(wildcard $(1)/*/Android.mk)
128endef
129
130###########################################################
131## Look under a directory for makefiles that don't have parent
132## makefiles.
133###########################################################
134
135# $(1): directory to search under
136# Ignores $(1)/Android.mk
137define first-makefiles-under
Joe Onoratodc1a7282009-08-04 15:58:26 -0400138$(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git \
139 --mindepth=2 $(1) Android.mk)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800140endef
141
142###########################################################
143## Retrieve a list of all makefiles immediately below your directory
144###########################################################
145
146define all-subdir-makefiles
147$(call all-makefiles-under,$(call my-dir))
148endef
149
150###########################################################
151## Look in the named list of directories for makefiles,
152## relative to the current directory.
153###########################################################
154
155# $(1): List of directories to look for under this directory
156define all-named-subdir-makefiles
157$(wildcard $(addsuffix /Android.mk, $(addprefix $(my-dir)/,$(1))))
158endef
159
160###########################################################
161## Find all of the java files under the named directories.
162## Meant to be used like:
163## SRC_FILES := $(call all-java-files-under,src tests)
164###########################################################
165
166define all-java-files-under
167$(patsubst ./%,%, \
168 $(shell cd $(LOCAL_PATH) ; \
169 find $(1) -name "*.java" -and -not -name ".*") \
170 )
171endef
172
173###########################################################
174## Find all of the java files from here. Meant to be used like:
175## SRC_FILES := $(call all-subdir-java-files)
176###########################################################
177
178define all-subdir-java-files
179$(call all-java-files-under,.)
180endef
181
182###########################################################
183## Find all of the c files under the named directories.
184## Meant to be used like:
185## SRC_FILES := $(call all-c-files-under,src tests)
186###########################################################
187
188define all-c-files-under
189$(patsubst ./%,%, \
190 $(shell cd $(LOCAL_PATH) ; \
191 find $(1) -name "*.c" -and -not -name ".*") \
192 )
193endef
194
195###########################################################
196## Find all of the c files from here. Meant to be used like:
197## SRC_FILES := $(call all-subdir-c-files)
198###########################################################
199
200define all-subdir-c-files
201$(call all-c-files-under,.)
202endef
203
204###########################################################
205## Find all files named "I*.aidl" under the named directories,
206## which must be relative to $(LOCAL_PATH). The returned list
207## is relative to $(LOCAL_PATH).
208###########################################################
209
210define all-Iaidl-files-under
211$(patsubst ./%,%, \
212 $(shell cd $(LOCAL_PATH) ; \
213 find $(1) -name "I*.aidl" -and -not -name ".*") \
214 )
215endef
216
217###########################################################
218## Find all of the "I*.aidl" files under $(LOCAL_PATH).
219###########################################################
220
221define all-subdir-Iaidl-files
222$(call all-Iaidl-files-under,.)
223endef
224
225###########################################################
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000226## Find all of the logtags files under the named directories.
227## Meant to be used like:
228## SRC_FILES := $(call all-logtags-files-under,src)
229###########################################################
230
231define all-logtags-files-under
232$(patsubst ./%,%, \
233 $(shell cd $(LOCAL_PATH) ; \
234 find $(1) -name "*.logtags" -and -not -name ".*") \
235 )
236endef
237
238###########################################################
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800239## Find all of the html files under the named directories.
240## Meant to be used like:
241## SRC_FILES := $(call all-html-files-under,src tests)
242###########################################################
243
244define all-html-files-under
245$(patsubst ./%,%, \
246 $(shell cd $(LOCAL_PATH) ; \
247 find $(1) -name "*.html" -and -not -name ".*") \
248 )
249endef
250
251###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800252## Find all of the html files from here. Meant to be used like:
253## SRC_FILES := $(call all-subdir-html-files)
254###########################################################
255
256define all-subdir-html-files
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800257$(call all-html-files-under,.)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800258endef
259
260###########################################################
261## Find all of the files matching pattern
262## SRC_FILES := $(call find-subdir-files, <pattern>)
263###########################################################
264
265define find-subdir-files
266$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find $(1)))
267endef
268
269###########################################################
270# find the files in the subdirectory $1 of LOCAL_DIR
271# matching pattern $2, filtering out files $3
272# e.g.
273# SRC_FILES += $(call find-subdir-subdir-files, \
274# css, *.cpp, DontWantThis.cpp)
275###########################################################
276
277define find-subdir-subdir-files
278$(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
279 $(LOCAL_PATH) ; find $(1) -maxdepth 1 -name $(2))))
280endef
281
282###########################################################
283## Find all of the files matching pattern
284## SRC_FILES := $(call all-subdir-java-files)
285###########################################################
286
287define find-subdir-assets
288$(if $(1),$(patsubst ./%,%, \
289 $(shell if [ -d $(1) ] ; then cd $(1) ; find ./ -type f -and -not -type l ; fi)), \
290 $(warning Empty argument supplied to find-subdir-assets) \
291)
292endef
293
294###########################################################
295## Find various file types in a list of directories relative to $(LOCAL_PATH)
296###########################################################
297
298define find-other-java-files
299 $(call find-subdir-files,$(1) -name "*.java" -and -not -name ".*")
300endef
301
302define find-other-html-files
303 $(call find-subdir-files,$(1) -name "*.html" -and -not -name ".*")
304endef
305
306###########################################################
307## Scan through each directory of $(1) looking for files
308## that match $(2) using $(wildcard). Useful for seeing if
309## a given directory or one of its parents contains
310## a particular file. Returns the first match found,
311## starting furthest from the root.
312###########################################################
313
314define find-parent-file
315$(strip \
316 $(eval _fpf := $(wildcard $(strip $(1))/$(strip $(2)))) \
317 $(if $(_fpf),$(_fpf), \
318 $(if $(filter-out ./ .,$(1)), \
319 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
320 ) \
321 ) \
322)
323endef
324
325###########################################################
326## Function we can evaluate to introduce a dynamic dependency
327###########################################################
328
329define add-dependency
330$(1): $(2)
331endef
332
333###########################################################
334## Set up the dependencies for a prebuilt target
335## $(call add-prebuilt-file, srcfile, [targetclass])
336###########################################################
337
338define add-prebuilt-file
339 $(eval $(include-prebuilt))
340endef
341
342define include-prebuilt
343 include $$(CLEAR_VARS)
344 LOCAL_SRC_FILES := $(1)
345 LOCAL_BUILT_MODULE_STEM := $(1)
346 LOCAL_MODULE_SUFFIX := $$(suffix $(1))
347 LOCAL_MODULE := $$(basename $(1))
348 LOCAL_MODULE_CLASS := $(2)
349 include $$(BUILD_PREBUILT)
350endef
351
352###########################################################
353## do multiple prebuilts
354## $(call target class, files ...)
355###########################################################
356
357define add-prebuilt-files
358 $(foreach f,$(2),$(call add-prebuilt-file,$f,$(1)))
359endef
360
361
362
363###########################################################
364## The intermediates directory. Where object files go for
365## a given target. We could technically get away without
366## the "_intermediates" suffix on the directory, but it's
367## nice to be able to grep for that string to find out if
368## anyone's abusing the system.
369###########################################################
370
371# $(1): target class, like "APPS"
372# $(2): target name, like "NotePad"
373# $(3): if non-empty, this is a HOST target.
374# $(4): if non-empty, force the intermediates to be COMMON
375define intermediates-dir-for
376$(strip \
377 $(eval _idfClass := $(strip $(1))) \
378 $(if $(_idfClass),, \
379 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
380 $(eval _idfName := $(strip $(2))) \
381 $(if $(_idfName),, \
382 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
383 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
Ying Wanga83940f2010-09-24 18:09:04 -0700384 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800385 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
386 , \
387 $(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
388 ) \
389 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
390)
391endef
392
393# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
394# to determine the intermediates directory.
395#
396# $(1): if non-empty, force the intermediates to be COMMON
397define local-intermediates-dir
398$(strip \
399 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
400 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
401 $(if $(strip $(LOCAL_MODULE)),, \
402 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
403 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
404)
405endef
406
407###########################################################
408## Convert "path/to/libXXX.so" to "-lXXX".
409## Any "path/to/libXXX.a" elements pass through unchanged.
410###########################################################
411
412define normalize-libraries
413$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
414$(filter-out %.so,$(1))
415endef
416
417# TODO: change users to call the common version.
418define normalize-host-libraries
419$(call normalize-libraries,$(1))
420endef
421
422define normalize-target-libraries
423$(call normalize-libraries,$(1))
424endef
425
426###########################################################
427## Convert a list of short module names (e.g., "framework", "Browser")
428## into the list of files that are built for those modules.
429## NOTE: this won't return reliable results until after all
430## sub-makefiles have been included.
431## $(1): target list
432###########################################################
433
434define module-built-files
435$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
436endef
437
438###########################################################
439## Convert a list of short modules names (e.g., "framework", "Browser")
440## into the list of files that are installed for those modules.
441## NOTE: this won't return reliable results until after all
442## sub-makefiles have been included.
443## $(1): target list
444###########################################################
445
446define module-installed-files
447$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
448endef
449
450###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700451## Convert a list of short modules names (e.g., "framework", "Browser")
452## into the list of files that should be used when linking
453## against that module as a public API.
454## TODO: Allow this for more than JAVA_LIBRARIES modules
455## NOTE: this won't return reliable results until after all
456## sub-makefiles have been included.
457## $(1): target list
458###########################################################
459
460define module-stubs-files
461$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
462endef
463
464###########################################################
465## Evaluates to the timestamp file for a doc module, which
466## is the dependency that should be used.
467## $(1): doc module
468###########################################################
469
470define doc-timestamp-for
471$(OUT_DOCS)/$(strip $(1))-timestamp
472endef
473
474
475###########################################################
Ying Wang912f8282010-09-28 17:27:56 -0700476## Convert "core ext framework" to "out/.../javalib.jar ..."
The Android Open Source Project88b60792009-03-03 19:28:42 -0800477## $(1): library list
478## $(2): Non-empty if IS_HOST_MODULE
479###########################################################
480
481# $(1): library name
482# $(2): Non-empty if IS_HOST_MODULE
483define _java-lib-dir
484$(call intermediates-dir-for, \
Ying Wang912f8282010-09-28 17:27:56 -0700485 JAVA_LIBRARIES,$(1),$(2),COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800486endef
487
488# $(1): library name
489# $(2): Non-empty if IS_HOST_MODULE
490define _java-lib-full-classes.jar
Ying Wang912f8282010-09-28 17:27:56 -0700491$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800492endef
493
494# $(1): library name list
495# $(2): Non-empty if IS_HOST_MODULE
496define java-lib-files
497$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
498endef
499
500# $(1): library name
The Android Open Source Project88b60792009-03-03 19:28:42 -0800501# $(2): Non-empty if IS_HOST_MODULE
502define _java-lib-full-dep
Ying Wang912f8282010-09-28 17:27:56 -0700503$(call _java-lib-dir,$(1),$(2))/javalib$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800504endef
505
506# $(1): library name list
507# $(2): Non-empty if IS_HOST_MODULE
508define java-lib-deps
509$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
510endef
511
512###########################################################
513## Convert "a b c" into "a:b:c"
514###########################################################
515
516empty :=
517space := $(empty) $(empty)
518
519define normalize-path-list
520$(subst $(space),:,$(strip $(1)))
521endef
522
523###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700524## Read the word out of a colon-separated list of words.
525## This has the same behavior as the built-in function
526## $(word n,str).
527##
528## The individual words may not contain spaces.
529##
530## $(1): 1 based index
531## $(2): value of the form a:b:c...
532###########################################################
533
534define word-colon
535$(word $(1),$(subst :,$(space),$(2)))
536endef
537
538###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800539## Convert "a=b c= d e = f" into "a=b c=d e=f"
540##
541## $(1): list to collapse
542## $(2): if set, separator word; usually "=", ":", or ":="
543## Defaults to "=" if not set.
544###########################################################
545
546define collapse-pairs
547$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
548$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
549 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
550endef
551
The Android Open Source Project88b60792009-03-03 19:28:42 -0800552###########################################################
553## MODULE_TAG set operations
554###########################################################
555
556# Given a list of tags, return the targets that specify
557# any of those tags.
558# $(1): tag list
559define modules-for-tag-list
560$(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag))))
561endef
562
563# Same as modules-for-tag-list, but operates on
564# ALL_MODULE_NAME_TAGS.
565# $(1): tag list
566define module-names-for-tag-list
567$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
568endef
569
570# Given an accept and reject list, find the matching
571# set of targets. If a target has multiple tags and
572# any of them are rejected, the target is rejected.
573# Reject overrides accept.
574# $(1): list of tags to accept
575# $(2): list of tags to reject
576#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800577#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800578define get-tagged-modules
579$(filter-out \
580 $(call modules-for-tag-list,$(2)), \
581 $(call modules-for-tag-list,$(1)))
582endef
583
Joe Onorato64d85d02009-04-09 19:31:12 -0700584###########################################################
585## Append a leaf to a base path. Properly deals with
586## base paths ending in /.
587##
588## $(1): base path
589## $(2): leaf path
590###########################################################
591
592define append-path
593$(subst //,/,$(1)/$(2))
594endef
595
The Android Open Source Project88b60792009-03-03 19:28:42 -0800596
597###########################################################
598## Package filtering
599###########################################################
600
601# Given a list of installed modules (short or long names)
602# return a list of the packages (yes, .apk packages, not
603# modules in general) that are overridden by this list and,
604# therefore, should not be installed.
605# $(1): mixed list of installed modules
606# TODO: This is fragile; find a reliable way to get this information.
607define _get-package-overrides
608 $(eval ### Discard any words containing slashes, unless they end in .apk, \
609 ### in which case trim off the directory component and the suffix. \
610 ### If there are no slashes, keep the entire word.)
611 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
612 $(eval _gpo_names := \
613 $(filter %.apk,$(_gpo_names)) \
614 $(filter-out %@@@ @@@%,$(_gpo_names)))
615 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
616 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
617
618 $(eval ### Remove any remaining words that contain dots.)
619 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
620 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
621
622 $(eval ### Now we have a list of any words that could possibly refer to \
623 ### packages, although there may be words that do not. Only \
624 ### real packages will be present under PACKAGES.*, though.)
625 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
626endef
627
628define get-package-overrides
629$(strip $(sort $(call _get-package-overrides,$(1))))
630endef
631
632###########################################################
633## Output the command lines, or not
634###########################################################
635
636ifeq ($(strip $(SHOW_COMMANDS)),)
637define pretty
638@echo $1
639endef
640hide := @
641else
642define pretty
643endef
644hide :=
645endif
646
647###########################################################
648## Dump the variables that are associated with targets
649###########################################################
650
651define dump-module-variables
652@echo all_dependencies=$^
653@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
654@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
655@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
656@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
657@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
658@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
659@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
660@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
661@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
662@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
Brian Carlstromf184a0f2010-02-01 11:13:32 -0800663@echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800664@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
665@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
666@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
667@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
668@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
669endef
670
671###########################################################
672## Commands for using sed to replace given variable values
673###########################################################
674
675define transform-variables
676@mkdir -p $(dir $@)
677@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
678$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
679$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
680endef
681
682
683###########################################################
684## Commands for munging the dependency files GCC generates
685###########################################################
686
687define transform-d-to-p
688@cp $(@:%.o=%.d) $(@:%.o=%.P); \
689 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
690 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
691 rm -f $(@:%.o=%.d)
692endef
693
694###########################################################
695## Commands for running lex
696###########################################################
697
698define transform-l-to-cpp
699@mkdir -p $(dir $@)
700@echo "Lex: $(PRIVATE_MODULE) <= $<"
701$(hide) $(LEX) -o$@ $<
702endef
703
704###########################################################
705## Commands for running yacc
706##
707## Because the extension of c++ files can change, the
708## extension must be specified in $1.
709## E.g, "$(call transform-y-to-cpp,.cpp)"
710###########################################################
711
712define transform-y-to-cpp
713@mkdir -p $(dir $@)
714@echo "Yacc: $(PRIVATE_MODULE) <= $<"
715$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
716touch $(@:$1=$(YACC_HEADER_SUFFIX))
717echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
718echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
719cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
720echo '#endif' >> $(@:$1=.h)
721rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
722endef
723
724
725###########################################################
726## Commands for running aidl
727###########################################################
728
729define transform-aidl-to-java
730@mkdir -p $(dir $@)
731@echo "Aidl: $(PRIVATE_MODULE) <= $<"
732$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
733endef
734#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
735
736
Doug Zongker9bd49622009-11-30 14:28:59 -0800737###########################################################
738## Commands for running java-event-log-tags.py
739###########################################################
740
741define transform-logtags-to-java
742@mkdir -p $(dir $@)
743@echo "logtags: $@ <= $<"
Doug Zongkerabfbbe22010-02-16 14:32:08 -0800744$(hide) $(JAVATAGS) -o $@ $^
Doug Zongker9bd49622009-11-30 14:28:59 -0800745endef
746
The Android Open Source Project88b60792009-03-03 19:28:42 -0800747
748###########################################################
749## Commands for running gcc to compile a C++ file
750###########################################################
751
752define transform-cpp-to-o
753@mkdir -p $(dir $@)
754@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
755$(hide) $(PRIVATE_CXX) \
756 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500757 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800758 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700759 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
760 $(PRIVATE_TARGET_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800761 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800762 , \
763 -I $(incdir) \
764 ) \
765 -c \
766 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700767 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
768 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800769 $(PRIVATE_ARM_CFLAGS) \
770 ) \
771 -fno-rtti \
772 $(PRIVATE_CFLAGS) \
773 $(PRIVATE_CPPFLAGS) \
774 $(PRIVATE_DEBUG_CFLAGS) \
775 -MD -o $@ $<
776$(hide) $(transform-d-to-p)
777endef
778
779
780###########################################################
781## Commands for running gcc to compile a C file
782###########################################################
783
784# $(1): extra flags
785define transform-c-or-s-to-o-no-deps
786@mkdir -p $(dir $@)
787$(hide) $(PRIVATE_CC) \
788 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500789 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800790 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700791 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
792 $(PRIVATE_TARGET_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800793 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800794 , \
795 -I $(incdir) \
796 ) \
797 -c \
798 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700799 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800800 $(PRIVATE_ARM_CFLAGS) \
801 ) \
802 $(PRIVATE_CFLAGS) \
803 $(1) \
804 $(PRIVATE_DEBUG_CFLAGS) \
805 -MD -o $@ $<
806endef
807
808define transform-c-to-o-no-deps
809@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
810$(call transform-c-or-s-to-o-no-deps, )
811endef
812
813define transform-s-to-o-no-deps
814@echo "target asm: $(PRIVATE_MODULE) <= $<"
815$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
816endef
817
818define transform-c-to-o
819$(transform-c-to-o-no-deps)
820$(hide) $(transform-d-to-p)
821endef
822
823define transform-s-to-o
824$(transform-s-to-o-no-deps)
825$(hide) $(transform-d-to-p)
826endef
827
828###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200829## Commands for running gcc to compile an Objective-C file
830## This should never happen for target builds but this
831## will error at build time.
832###########################################################
833
834define transform-m-to-o-no-deps
835@echo "target ObjC: $(PRIVATE_MODULE) <= $<"
836$(call transform-c-or-s-to-o-no-deps)
837endef
838
839define transform-m-to-o
840$(transform-m-to-o-no-deps)
841$(hide) $(transform-d-to-p)
842endef
843
844###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800845## Commands for running gcc to compile a host C++ file
846###########################################################
847
848define transform-host-cpp-to-o
849@mkdir -p $(dir $@)
850@echo "host C++: $(PRIVATE_MODULE) <= $<"
851$(hide) $(PRIVATE_CXX) \
852 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500853 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800854 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
855 $(HOST_PROJECT_INCLUDES) \
856 $(HOST_C_INCLUDES) \
857 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800858 , \
859 -I $(incdir) \
860 ) \
861 -c \
862 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
863 $(HOST_GLOBAL_CFLAGS) \
864 $(HOST_GLOBAL_CPPFLAGS) \
865 ) \
866 $(PRIVATE_CFLAGS) \
867 $(PRIVATE_CPPFLAGS) \
868 $(PRIVATE_DEBUG_CFLAGS) \
869 -MD -o $@ $<
870$(transform-d-to-p)
871endef
872
873
874###########################################################
875## Commands for running gcc to compile a host C file
876###########################################################
877
878# $(1): extra flags
879define transform-host-c-or-s-to-o-no-deps
880@mkdir -p $(dir $@)
881$(hide) $(PRIVATE_CC) \
882 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500883 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800884 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
885 $(HOST_PROJECT_INCLUDES) \
886 $(HOST_C_INCLUDES) \
887 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800888 , \
889 -I $(incdir) \
890 ) \
891 -c \
892 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
893 $(HOST_GLOBAL_CFLAGS) \
894 ) \
895 $(PRIVATE_CFLAGS) \
896 $(1) \
897 $(PRIVATE_DEBUG_CFLAGS) \
898 -MD -o $@ $<
899endef
900
901define transform-host-c-to-o-no-deps
902@echo "host C: $(PRIVATE_MODULE) <= $<"
903$(call transform-host-c-or-s-to-o-no-deps, )
904endef
905
906define transform-host-s-to-o-no-deps
907@echo "host asm: $(PRIVATE_MODULE) <= $<"
908$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
909endef
910
911define transform-host-c-to-o
912$(transform-host-c-to-o-no-deps)
913$(transform-d-to-p)
914endef
915
916define transform-host-s-to-o
917$(transform-host-s-to-o-no-deps)
918$(transform-d-to-p)
919endef
920
921###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200922## Commands for running gcc to compile a host Objective-C file
923###########################################################
924
925define transform-host-m-to-o-no-deps
926@echo "host ObjC: $(PRIVATE_MODULE) <= $<"
927$(call transform-host-c-or-s-to-o-no-deps)
928endef
929
930define tranform-host-m-to-o
931$(transform-host-m-to-o-no-deps)
932$(transform-d-to-p)
933endef
934
935###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800936## Commands for running ar
937###########################################################
938
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700939define extract-and-include-target-whole-static-libs
Dima Zavin46e9bec2009-05-27 19:41:07 -0700940$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Colin Cross9ca21642010-05-04 15:42:22 -0700941 $(hide) echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
Dima Zavin46e9bec2009-05-27 19:41:07 -0700942 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
943 rm -rf $$ldir; \
944 mkdir -p $$ldir; \
945 filelist=; \
946 for f in `$(TARGET_AR) t $(lib)`; do \
947 $(TARGET_AR) p $(lib) $$f > $$ldir/$$f; \
948 filelist="$$filelist $$ldir/$$f"; \
949 done ; \
950 $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
951)
952endef
953
The Android Open Source Project88b60792009-03-03 19:28:42 -0800954# Explicitly delete the archive first so that ar doesn't
955# try to add to an existing archive.
956define transform-o-to-static-lib
957@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800958@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700959$(extract-and-include-target-whole-static-libs)
Dima Zavin46e9bec2009-05-27 19:41:07 -0700960@echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
Colin Cross9ca21642010-05-04 15:42:22 -0700961$(hide) echo $(filter %.o, $^) | \
962 xargs $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@
The Android Open Source Project88b60792009-03-03 19:28:42 -0800963endef
964
965###########################################################
966## Commands for running host ar
967###########################################################
968
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700969define extract-and-include-host-whole-static-libs
970$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
971 @echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
972 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
973 rm -rf $$ldir; \
974 mkdir -p $$ldir; \
975 filelist=; \
Dan Bornstein6581fed2009-10-22 13:14:41 -0700976 for f in `$(HOST_AR) t $(lib) | grep '\.o$$'`; do \
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700977 $(HOST_AR) p $(lib) $$f > $$ldir/$$f; \
978 filelist="$$filelist $$ldir/$$f"; \
979 done ; \
980 $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
981)
982endef
983
The Android Open Source Project88b60792009-03-03 19:28:42 -0800984# Explicitly delete the archive first so that ar doesn't
985# try to add to an existing archive.
986define transform-host-o-to-static-lib
987@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800988@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700989$(extract-and-include-host-whole-static-libs)
Dan Bornstein6bffc912009-10-15 13:01:36 -0700990@echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700991echo $(filter %.o, $^) | \
992 xargs $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@
The Android Open Source Project88b60792009-03-03 19:28:42 -0800993endef
994
995
996###########################################################
997## Commands for running gcc to link a shared library or package
998###########################################################
999
1000# ld just seems to be so finicky with command order that we allow
1001# it to be overriden en-masse see combo/linux-arm.make for an example.
1002ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1003define transform-host-o-to-shared-lib-inner
1004$(HOST_CXX) \
1005 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1006 -Wl,-rpath,\$$ORIGIN/../lib \
1007 -shared -Wl,-soname,$(notdir $@) \
1008 $(PRIVATE_LDFLAGS) \
1009 $(HOST_GLOBAL_LD_DIRS) \
1010 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1011 $(HOST_GLOBAL_LDFLAGS) \
1012 ) \
1013 $(PRIVATE_ALL_OBJECTS) \
1014 -Wl,--whole-archive \
1015 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1016 -Wl,--no-whole-archive \
1017 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1018 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1019 -o $@ \
1020 $(PRIVATE_LDLIBS)
1021endef
1022endif
1023
1024define transform-host-o-to-shared-lib
1025@mkdir -p $(dir $@)
1026@echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
1027$(hide) $(transform-host-o-to-shared-lib-inner)
1028endef
1029
1030define transform-host-o-to-package
1031@mkdir -p $(dir $@)
1032@echo "host Package: $(PRIVATE_MODULE) ($@)"
1033$(hide) $(transform-host-o-to-shared-lib-inner)
1034endef
1035
1036
1037###########################################################
1038## Commands for running gcc to link a shared library or package
1039###########################################################
1040
1041#echo >$@.vers "{"; \
1042#echo >>$@.vers " global:"; \
1043#$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \
1044#echo >>$@.vers " local:"; \
1045#echo >>$@.vers " *;"; \
1046#echo >>$@.vers "};"; \
1047
1048# -Wl,--version-script=$@.vers \
1049
1050# ld just seems to be so finicky with command order that we allow
1051# it to be overriden en-masse see combo/linux-arm.make for an example.
1052ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1053define transform-o-to-shared-lib-inner
1054$(TARGET_CXX) \
Ying Wang1a081002010-07-13 14:55:47 -07001055 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001056 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1057 -Wl,-rpath,\$$ORIGIN/../lib \
1058 -shared -Wl,-soname,$(notdir $@) \
1059 $(PRIVATE_LDFLAGS) \
Ying Wang1a081002010-07-13 14:55:47 -07001060 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001061 $(PRIVATE_ALL_OBJECTS) \
1062 -Wl,--whole-archive \
1063 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1064 -Wl,--no-whole-archive \
1065 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1066 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1067 -o $@ \
1068 $(PRIVATE_LDLIBS)
1069endef
1070endif
1071
1072define transform-o-to-shared-lib
1073@mkdir -p $(dir $@)
1074@echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
1075$(hide) $(transform-o-to-shared-lib-inner)
1076endef
1077
1078define transform-o-to-package
1079@mkdir -p $(dir $@)
1080@echo "target Package: $(PRIVATE_MODULE) ($@)"
1081$(hide) $(transform-o-to-shared-lib-inner)
1082endef
1083
1084
1085###########################################################
1086## Commands for filtering a target executable or library
1087###########################################################
1088
1089# Because of bug 743462 ("Prelinked image magic gets stripped
1090# by arm-elf-objcopy"), we have to use soslim to strip target
1091# binaries.
1092define transform-to-stripped
1093@mkdir -p $(dir $@)
1094@echo "target Strip: $(PRIVATE_MODULE) ($@)"
1095$(hide) $(SOSLIM) --strip --shady --quiet $< --outfile $@
1096endef
1097
1098define transform-to-prelinked
1099@mkdir -p $(dir $@)
1100@echo "target Prelink: $(PRIVATE_MODULE) ($@)"
1101$(hide) $(APRIORI) \
1102 --prelinkmap $(TARGET_PRELINKER_MAP) \
1103 --locals-only \
1104 --quiet \
1105 $< \
1106 --output $@
1107endef
1108
1109
1110###########################################################
1111## Commands for running gcc to link an executable
1112###########################################################
1113
1114ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1115define transform-o-to-executable-inner
1116$(TARGET_CXX) \
1117 $(TARGET_GLOBAL_LDFLAGS) \
1118 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1119 $(TARGET_GLOBAL_LD_DIRS) \
1120 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1121 -Wl,-rpath,\$$ORIGIN/../lib \
1122 $(PRIVATE_LDFLAGS) \
1123 $(TARGET_GLOBAL_LD_DIRS) \
1124 $(PRIVATE_ALL_OBJECTS) \
1125 -Wl,--whole-archive \
1126 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1127 -Wl,--no-whole-archive \
1128 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1129 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1130 -o $@ \
1131 $(PRIVATE_LDLIBS)
1132endef
1133endif
1134
1135define transform-o-to-executable
1136@mkdir -p $(dir $@)
1137@echo "target Executable: $(PRIVATE_MODULE) ($@)"
1138$(hide) $(transform-o-to-executable-inner)
1139endef
1140
1141
1142###########################################################
1143## Commands for running gcc to link a statically linked
1144## executable. In practice, we only use this on arm, so
1145## the other platforms don't have the
1146## transform-o-to-static-executable defined
1147###########################################################
1148
1149ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1150define transform-o-to-static-executable-inner
1151endef
1152endif
1153
1154define transform-o-to-static-executable
1155@mkdir -p $(dir $@)
1156@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
1157$(hide) $(transform-o-to-static-executable-inner)
1158endef
1159
1160
1161###########################################################
1162## Commands for running gcc to link a host executable
1163###########################################################
1164
1165ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1166define transform-host-o-to-executable-inner
1167$(HOST_CXX) \
1168 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1169 -Wl,-rpath,\$$ORIGIN/../lib \
1170 $(HOST_GLOBAL_LD_DIRS) \
1171 $(PRIVATE_LDFLAGS) \
1172 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1173 $(HOST_GLOBAL_LDFLAGS) \
1174 ) \
1175 $(PRIVATE_ALL_OBJECTS) \
1176 -Wl,--whole-archive \
1177 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1178 -Wl,--no-whole-archive \
1179 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1180 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1181 -o $@ \
1182 $(PRIVATE_LDLIBS)
1183endef
1184endif
1185
1186define transform-host-o-to-executable
1187@mkdir -p $(dir $@)
1188@echo "host Executable: $(PRIVATE_MODULE) ($@)"
1189$(hide) $(transform-host-o-to-executable-inner)
1190endef
1191
1192
1193###########################################################
1194## Commands for running javac to make .class files
1195###########################################################
1196
1197#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)"
1198#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')"
1199
1200# TODO: Right now we generate the asset resources twice, first as part
1201# of generating the Java classes, then at the end when packaging the final
1202# assets. This should be changed to do one of two things: (1) Don't generate
1203# any resource files the first time, only create classes during that stage;
1204# or (2) Don't use the -c flag with the second stage, instead taking the
1205# resource files from the first stage as additional input. My original intent
1206# was to use approach (2), but this requires a little more work in the tool.
1207# Maybe we should just use approach (1).
1208
1209# This rule creates the R.java and Manifest.java files, both of which
1210# are PRODUCT-neutral. Don't pass PRODUCT_AAPT_CONFIG to this invocation.
1211define create-resource-java-files
1212@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1213@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08001214$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001215 $(eval # PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
1216 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1217 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1218 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1219 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1220 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001221 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07001222 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001223 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1224 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001225 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
1226 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION))) \
Ying Wang8c254822010-03-16 16:13:56 -07001227 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001228 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001229endef
1230
1231ifeq ($(HOST_OS),windows)
1232xlint_unchecked :=
1233else
1234#xlint_unchecked := -Xlint:unchecked
1235endif
1236
1237# emit-line, <word list>, <output file>
1238define emit-line
1239 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1240endef
1241
1242# dump-words-to-file, <word list>, <output file>
1243define dump-words-to-file
1244 @rm -f $(2)
1245 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1246 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1247 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1248 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1249 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1250 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1251 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1252 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1253 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1254 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1255 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1256 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1257 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1258 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1259 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1260 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1261 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1262 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1263 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1264 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
1265 @$(if $(wordlist 4001,4002,$(1)),$(error Too many words ($(words $(1)))))
1266endef
1267
1268# For a list of jar files, unzip them to a specified directory,
1269# but make sure that no META-INF files come along for the ride.
1270#
1271# $(1): files to unzip
1272# $(2): destination directory
1273define unzip-jar-files
1274 $(hide) for f in $(1); \
1275 do \
1276 if [ ! -f $$f ]; then \
1277 echo Missing file $$f; \
1278 exit 1; \
1279 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07001280 unzip -qo $$f -d $(2); \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001281 (cd $(2) && rm -rf META-INF); \
1282 done
1283endef
1284
Joe Onorato64d85d02009-04-09 19:31:12 -07001285# below we write the list of java files to java-source-list to avoid argument
1286# list length problems with Cygwin we filter out duplicate java file names
1287# because eclipse's compiler doesn't like them.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001288define transform-java-to-classes.jar
1289@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Joe Onorato64d85d02009-04-09 19:31:12 -07001290$(hide) rm -f $@
1291$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1292$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001293$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1294 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
Joe Onoratoe334d252009-07-17 15:33:40 -04001295$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07001296$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Joe Onoratoe334d252009-07-17 15:33:40 -04001297 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001298fi
Joe Onoratoe334d252009-07-17 15:33:40 -04001299$(hide) tr ' ' '\n' < $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list \
1300 | sort -u > $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
The Android Open Source Project88b60792009-03-03 19:28:42 -08001301$(hide) $(TARGET_JAVAC) -encoding ascii $(PRIVATE_BOOTCLASSPATH) \
1302 $(addprefix -classpath ,$(strip \
1303 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Brian Carlstromf184a0f2010-02-01 11:13:32 -08001304 $(PRIVATE_JAVACFLAGS) $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) $(xlint_unchecked) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001305 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Joe Onoratoe334d252009-07-17 15:33:40 -04001306 \@$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001307 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
Joe Onoratoe334d252009-07-17 15:33:40 -04001308$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list
1309$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
Joe Onorato64d85d02009-04-09 19:31:12 -07001310$(hide) mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001311$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1312 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
Joe Onorato64d85d02009-04-09 19:31:12 -07001313$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001314endef
1315
1316define transform-classes.jar-to-emma
1317$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu18b75562010-05-13 16:46:21 -07001318 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07001319 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001320endef
1321
1322#TODO: use a smaller -Xmx value for most libraries;
1323# only core.jar and framework.jar need a heap this big.
Raphaelf6ff4c52009-08-18 14:43:32 -07001324# Avoid the memory arguments on Windows, dx fails to load for some reason with them.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001325define transform-classes.jar-to-dex
1326@echo "target Dex: $(PRIVATE_MODULE)"
1327@mkdir -p $(dir $@)
Raphaelf6ff4c52009-08-18 14:43:32 -07001328$(hide) $(DX) \
1329 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1536M) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001330 --dex --output=$@ \
1331 $(if $(NO_OPTIMIZE_DX), \
1332 --no-optimize) \
1333 $(if $(GENERATE_DEX_DEBUG), \
1334 --debug --verbose \
1335 --dump-to=$(@:.dex=.lst) \
1336 --dump-width=1000) \
1337 $(PRIVATE_DX_FLAGS) \
1338 $<
1339endef
1340
1341# Create a mostly-empty .jar file that we'll add to later.
1342# The MacOS jar tool doesn't like creating empty jar files,
1343# so we need to give it something.
1344define create-empty-package
1345@mkdir -p $(dir $@)
1346$(hide) touch $(dir $@)/dummy
1347$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy)
1348$(hide) zip -qd $@ dummy
1349$(hide) rm $(dir $@)/dummy
1350endef
1351
1352#TODO: we kinda want to build different asset packages for
1353# different configurations, then combine them later (or something).
1354# Per-locale, etc.
1355# A list of dynamic and static parameters; build layers for
1356# dynamic params that lay over the static ones.
1357#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001358#Note that the version numbers are given to aapt as simple default
1359#values; applications can override these by explicitly stating
1360#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001361define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08001362$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001363 $(addprefix -c , $(PRODUCT_AAPT_CONFIG)) \
1364 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1365 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1366 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1367 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001368 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1369 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001370 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
1371 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION))) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06001372 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001373 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374 -F $@
1375endef
1376
The Android Open Source Project88b60792009-03-03 19:28:42 -08001377define add-jni-shared-libs-to-package
1378$(hide) rm -rf $(dir $@)lib
Bruce Beare5b9f19e2010-05-05 09:47:16 -07001379$(hide) mkdir -p $(dir $@)lib/$(TARGET_CPU_ABI)
1380$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(TARGET_CPU_ABI)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001381$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib)
1382$(hide) rm -rf $(dir $@)lib
1383endef
1384
The Android Open Source Project88b60792009-03-03 19:28:42 -08001385#TODO: update the manifest to point to the dex file
1386define add-dex-to-package
Ying Wang957fea52010-09-23 11:48:38 -07001387$(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\
1388$(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE),\
1389$(eval _adtp_classes.dex := $(dir $(PRIVATE_DEX_FILE))/classes.dex)\
1390$(hide) cp $(PRIVATE_DEX_FILE) $(_adtp_classes.dex) && \
1391$(AAPT) add -k $@ $(_adtp_classes.dex) && \
1392rm -f $(_adtp_classes.dex))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001393endef
1394
1395define add-java-resources-to-package
1396$(hide) jar uf $@ $(PRIVATE_EXTRA_JAR_ARGS)
1397endef
1398
1399# Sign a package using the specified key/cert.
1400#
1401define sign-package
1402$(hide) mv $@ $@.unsigned
1403$(hide) java -jar $(SIGNAPK_JAR) \
1404 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) $@.unsigned $@.signed
1405$(hide) mv $@.signed $@
1406endef
1407
1408# Align STORED entries of a package on 4-byte boundaries
1409# to make them easier to mmap.
1410#
1411define align-package
1412$(hide) mv $@ $@.unaligned
1413$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned
1414$(hide) mv $@.aligned $@
1415endef
1416
1417define install-dex-debug
1418$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
1419 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1420 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
1421 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
1422 fi
1423$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
1424 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1425 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
1426 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
1427 fi
1428endef
1429
1430# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
1431# new prebuilt rules to work, we should change this to copy the
1432# resources to the out directory and then copy the resources.
1433
1434# Note: not using aapt tool for this because we aren't making
1435# an android package for the host.
1436define transform-host-java-to-package
1437@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1438@rm -f $@
1439@rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1440@mkdir -p $(dir $@)
1441@mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1442$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1443 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
1444$(call dump-words-to-file,$(sort\
1445 $(PRIVATE_JAVA_SOURCES)),\
Joe Onorato483d9242009-06-18 13:11:58 -07001446 $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001447$(hide) $(HOST_JAVAC) -encoding ascii -g \
Brian Carlstromf184a0f2010-02-01 11:13:32 -08001448 $(PRIVATE_JAVACFLAGS) $(xlint_unchecked) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001449 $(addprefix -classpath ,$(strip \
1450 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
1451 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR)\
Joe Onorato483d9242009-06-18 13:11:58 -07001452 \@$(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq || \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001453 ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
Joe Onorato483d9242009-06-18 13:11:58 -07001454$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list
1455$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq
The Android Open Source Project88b60792009-03-03 19:28:42 -08001456$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1457 $@ $(PRIVATE_JAR_MANIFEST) $(PRIVATE_EXTRA_JAR_ARGS) \
1458 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1459endef
1460
1461###########################################################
1462## Obfuscate a jar file
1463###########################################################
1464
1465# PRIVATE_KEEP_FILE is a file containing a list of classes
1466# PRIVATE_INTERMEDIATES_DIR is a directory we can use for temporary files
1467# The module using this must depend on
1468# $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar
1469define obfuscate-jar
1470@echo "Obfuscate jar: $(notdir $@) ($@)"
1471@mkdir -p $(dir $@)
1472@rm -f $@
1473@mkdir -p $(PRIVATE_INTERMEDIATES_DIR)
1474$(hide) sed -e 's/^/-keep class /' < $(PRIVATE_KEEP_FILE) > \
1475 $(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1476$(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \
1477 -injars $< \
1478 -outjars $@ \
1479 -target 1.5 \
1480 -dontnote -dontwarn \
1481 -printmapping $(PRIVATE_INTERMEDIATES_DIR)/out.map \
1482 -forceprocessing \
1483 -renamesourcefileattribute SourceFile \
1484 -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod \
1485 -repackageclasses \
1486 -keepclassmembers "class * { public protected *; }" \
1487 @$(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1488endef
1489
1490###########################################################
1491## Commands for copying files
1492###########################################################
1493
1494# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
1495# $(1): source header
1496# $(2): destination header
1497define copy-one-header
1498$(2): $(1)
1499 @echo "Header: $$@"
1500 $$(copy-file-to-new-target-with-cp)
1501endef
1502
1503# Define a rule to copy a file. For use via $(eval).
1504# $(1): source file
1505# $(2): destination file
1506define copy-one-file
1507$(2): $(1) | $(ACP)
1508 @echo "Copy: $$@"
1509 $$(copy-file-to-target)
1510endef
1511
1512# The -t option to acp and the -p option to cp is
1513# required for OSX. OSX has a ridiculous restriction
1514# where it's an error for a .a file's modification time
1515# to disagree with an internal timestamp, and this
1516# macro is used to install .a files (among other things).
1517
1518# Copy a single file from one place to another,
1519# preserving permissions and overwriting any existing
1520# file.
1521define copy-file-to-target
1522@mkdir -p $(dir $@)
1523$(hide) $(ACP) -fpt $< $@
1524endef
1525
1526# The same as copy-file-to-target, but use the local
1527# cp command instead of acp.
1528define copy-file-to-target-with-cp
1529@mkdir -p $(dir $@)
1530$(hide) cp -fp $< $@
1531endef
1532
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001533# The same as copy-file-to-target, but use the zipalign tool to do so.
1534define copy-file-to-target-with-zipalign
1535@mkdir -p $(dir $@)
1536$(hide) $(ZIPALIGN) -f 4 $< $@
1537endef
1538
Doug Zongker1046d202009-08-06 13:02:19 -07001539# The same as copy-file-to-target, but strip out "# comment"-style
1540# comments (for config files and such).
1541define copy-file-to-target-strip-comments
1542@mkdir -p $(dir $@)
1543$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
1544endef
1545
The Android Open Source Project88b60792009-03-03 19:28:42 -08001546# The same as copy-file-to-target, but don't preserve
1547# the old modification time.
1548define copy-file-to-new-target
1549@mkdir -p $(dir $@)
1550$(hide) $(ACP) -fp $< $@
1551endef
1552
1553# The same as copy-file-to-new-target, but use the local
1554# cp command instead of acp.
1555define copy-file-to-new-target-with-cp
1556@mkdir -p $(dir $@)
1557$(hide) cp -f $< $@
1558endef
1559
1560# Copy a prebuilt file to a target location.
1561define transform-prebuilt-to-target
1562@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1563$(copy-file-to-target)
1564endef
1565
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001566# Copy a prebuilt file to a target location, using zipalign on it.
1567define transform-prebuilt-to-target-with-zipalign
1568@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
1569$(copy-file-to-target-with-zipalign)
1570endef
1571
Doug Zongker1046d202009-08-06 13:02:19 -07001572# Copy a prebuilt file to a target location, stripping "# comment" comments.
1573define transform-prebuilt-to-target-strip-comments
1574@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1575$(copy-file-to-target-strip-comments)
1576endef
1577
The Android Open Source Project88b60792009-03-03 19:28:42 -08001578###########################################################
1579## On some platforms (MacOS), after copying a static
1580## library, ranlib must be run to update an internal
1581## timestamp!?!?!
1582###########################################################
1583
1584ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true)
1585define transform-host-ranlib-copy-hack
1586 $(hide) ranlib $@ || true
1587endef
1588else
1589define transform-host-ranlib-copy-hack
1590true
1591endef
1592endif
1593
1594ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true)
1595define transform-ranlib-copy-hack
1596 $(hide) ranlib $@
1597endef
1598else
1599define transform-ranlib-copy-hack
1600true
1601endef
1602endif
1603
1604
1605###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08001606## Commands to call Proguard
1607###########################################################
1608
1609# Command to copy the file with acp, if proguard is disabled.
1610define proguard-disabled-commands
1611@echo Copying: $@
1612$(hide) $(ACP) $< $@
1613endef
1614
1615# Command to call Proguard
1616# $(1): extra flags for instrumentation.
1617define proguard-enabled-commands
1618@echo Proguard: $@
1619$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) $(1)
1620endef
1621
1622# Figure out the proguard dictionary file of the module that is instrumentationed for.
1623define get-instrumentation-proguard-flags
1624$(if $(PRIVATE_INSTRUMENTATION_FOR),$(if $(ALL_MODULES.$(PRIVATE_INSTRUMENTATION_FOR).PROGUARD_ENABLED),-applymapping $(call intermediates-dir-for,APPS,$(PRIVATE_INSTRUMENTATION_FOR),,COMMON)/proguard_dictionary))
1625endef
1626
1627define transform-jar-to-proguard
1628$(eval _instrumentation_proguard_flags:=$(call get-instrumentation-proguard-flags))
1629$(eval _enable_proguard:=$(PRIVATE_PROGUARD_ENABLED)$(_instrumentation_proguard_flags))
1630$(if $(_enable_proguard),$(call proguard-enabled-commands,$(_instrumentation_proguard_flags)),$(call proguard-disabled-commands))
1631$(eval _instrumentation_proguard_flags:=)
1632$(eval _enable_proguard:=)
1633endef
1634
1635
1636###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001637## Stuff source generated from one-off tools
1638###########################################################
1639
1640define transform-generated-source
1641@echo "target Generated: $(PRIVATE_MODULE) <= $<"
1642@mkdir -p $(dir $@)
1643$(hide) $(PRIVATE_CUSTOM_TOOL)
1644endef
1645
1646
1647###########################################################
1648## Assertions about attributes of the target
1649###########################################################
1650
1651# $(1): The file to check
1652ifndef get-file-size
1653$(error HOST_OS must define get-file-size)
1654endif
1655
Doug Zongker4647f122009-07-02 09:00:54 -07001656# Convert a partition data size (eg, as reported in /proc/mtd) to the
1657# size of the image used to flash that partition (which includes a
1658# 64-byte spare area for each 2048-byte page).
1659# $(1): the partition data size
1660define image-size-from-data-size
1661$(shell echo $$(($(1) / 2048 * (2048+64))))
1662endef
1663
1664# $(1): The file(s) to check (often $@)
1665# $(2): The maximum total image size, in decimal bytes
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001666# $(3): the type of filesystem "yaffs" or "raw"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001667#
1668# If $(2) is empty, evaluates to "true"
1669#
1670# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
1671# is left over after the image has been flashed. Round the 1% up to the
1672# next whole flash block size.
1673define assert-max-file-size
1674$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07001675 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
1676 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07001677 printname=$$(echo -n "$(1)" | tr " " +); \
1678 echo "$$printname total size is $$total"; \
1679 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001680 if [ "$(3)" == "yaffs" ]; then \
Doug Zongker93d9ff42009-09-14 17:46:41 -07001681 reservedblocks=8; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001682 else \
Doug Zongker4ac1ba62009-08-25 20:38:50 -07001683 reservedblocks=0; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001684 fi; \
Doug Zongker4647f122009-07-02 09:00:54 -07001685 twoblocks=$$((img_blocksize * 2)); \
1686 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001687 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \
1688 reservedblocks * img_blocksize)); \
Doug Zongker4647f122009-07-02 09:00:54 -07001689 maxsize=$$(($(2) - reserve)); \
1690 if [ "$$total" -gt "$$maxsize" ]; then \
1691 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
1692 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07001693 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07001694 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001695 fi \
1696 , \
1697 true \
1698 )
1699endef
1700
Doug Zongker8510a1e2009-08-07 16:38:08 -07001701# Like assert-max-file-size, but the second argument is a partition
1702# size, which we'll convert to a max image size before checking it
1703# against the files.
1704#
1705# $(1): The file(s) to check (often $@)
1706# $(2): The partition size.
1707define assert-max-image-size
1708$(if $(2), \
1709 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \
1710 true)
1711endef
1712
Doug Zongkere01100c2009-06-19 17:12:18 -07001713
1714###########################################################
1715## Define device-specific radio files
1716###########################################################
1717
1718# Copy a radio image file to the output location, and add it to
1719# INSTALLED_RADIOIMAGE_TARGET.
1720# $(1): filename
1721define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08001722 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07001723endef
1724define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08001725INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
1726ALL_PREBUILT += $$(PRODUCT_OUT)/$(2)
1727$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
Doug Zongkere01100c2009-06-19 17:12:18 -07001728 $$(transform-prebuilt-to-target)
1729endef
1730
1731
The Android Open Source Project88b60792009-03-03 19:28:42 -08001732###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08001733# Override the package defined in $(1), setting the
1734# variables listed below differently.
1735#
1736# $(1): The makefile to override (relative to the source
1737# tree root)
1738# $(2): Old LOCAL_PACKAGE_NAME value.
1739# $(3): New LOCAL_PACKAGE_NAME value.
Ying Wang3dae0ee2010-09-02 15:41:01 -07001740# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
1741# $(5): New LOCAL_CERTIFICATE value.
1742# $(6): New LOCAL_INSTRUMENTATION_FOR value.
1743# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
Joe Onorato899e62a2010-02-04 17:37:21 -08001744#
1745# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
1746# clear_vars.mk.
1747###########################################################
1748define inherit-package
Ying Wang3dae0ee2010-09-02 15:41:01 -07001749 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
Joe Onorato899e62a2010-02-04 17:37:21 -08001750endef
1751
1752define inherit-package-internal
1753 LOCAL_PACKAGE_OVERRIDES \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001754 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08001755 include $(1)
1756 LOCAL_PACKAGE_OVERRIDES \
1757 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
1758endef
1759
1760# To be used with inherit-package above
1761# Evalutes to true if the package was overridden
1762define set-inherited-package-variables
1763$(strip $(call set-inherited-package-variables-internal))
1764endef
1765
1766define keep-or-override
1767$(eval $(1) := $(if $(2),$(2),$($(1))))
1768endef
1769
1770define set-inherited-package-variables-internal
1771 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
1772 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
1773 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
1774 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
1775 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001776 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
1777 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
1778 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08001779 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
1780 true \
1781 ,)
1782endef
1783
1784
1785###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001786## Other includes
1787###########################################################
1788
1789# -----------------------------------------------------------------
1790# Rules and functions to help copy important files to DIST_DIR
1791# when requested.
1792include $(BUILD_SYSTEM)/distdir.mk
1793
Jean-Baptiste Queru39de4322010-09-03 16:32:58 -07001794# -----------------------------------------------------------------
1795# The modules allowed to use a user tag
1796include $(BUILD_SYSTEM)/user_tags.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -08001797
1798# broken:
1799# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
1800
1801###########################################################
1802## Misc notes
1803###########################################################
1804
1805#DEPDIR = .deps
1806#df = $(DEPDIR)/$(*F)
1807
1808#SRCS = foo.c bar.c ...
1809
1810#%.o : %.c
1811# @$(MAKEDEPEND); \
1812# cp $(df).d $(df).P; \
1813# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1814# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
1815# rm -f $(df).d
1816# $(COMPILE.c) -o $@ $<
1817
1818#-include $(SRCS:%.c=$(DEPDIR)/%.P)
1819
1820
1821#%.o : %.c
1822# $(COMPILE.c) -MD -o $@ $<
1823# @cp $*.d $*.P; \
1824# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1825# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
1826# rm -f $*.d