blob: 87e90135bfdc8e836373e5af1062f69e98ca0f72 [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)) \
384 $(if $(filter $(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
385 $(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###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800476## Convert "framework framework-res ext" to "out/.../javalib.jar ..."
477## This lets us treat framework-res as a normal library.
478## $(1): library list
479## $(2): Non-empty if IS_HOST_MODULE
480###########################################################
481
482# $(1): library name
483# $(2): Non-empty if IS_HOST_MODULE
484define _java-lib-dir
485$(call intermediates-dir-for, \
486 $(if $(filter framework-res,$(1)),APPS,JAVA_LIBRARIES),$(1),$(2))
487endef
488
489# $(1): library name
490define _java-lib-classes.jar
491$(if $(filter framework-res,$(1)),package$(COMMON_ANDROID_PACKAGE_SUFFIX),classes$(COMMON_JAVA_PACKAGE_SUFFIX))
492endef
493
494# $(1): library name
495# $(2): Non-empty if IS_HOST_MODULE
496define _java-lib-full-classes.jar
497$(call _java-lib-dir,$(1),$(2))/$(call _java-lib-classes.jar,$(1))
498endef
499
500# $(1): library name list
501# $(2): Non-empty if IS_HOST_MODULE
502define java-lib-files
503$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
504endef
505
506# $(1): library name
507define _java-lib-dep
508$(if $(filter framework-res,$(1)),package$(COMMON_ANDROID_PACKAGE_SUFFIX),javalib$(COMMON_JAVA_PACKAGE_SUFFIX))
509endef
510
511# $(1): library name
512# $(2): Non-empty if IS_HOST_MODULE
513define _java-lib-full-dep
514$(call _java-lib-dir,$(1),$(2))/$(call _java-lib-dep,$(1))
515endef
516
517# $(1): library name list
518# $(2): Non-empty if IS_HOST_MODULE
519define java-lib-deps
520$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
521endef
522
523###########################################################
524## Convert "a b c" into "a:b:c"
525###########################################################
526
527empty :=
528space := $(empty) $(empty)
529
530define normalize-path-list
531$(subst $(space),:,$(strip $(1)))
532endef
533
534###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700535## Read the word out of a colon-separated list of words.
536## This has the same behavior as the built-in function
537## $(word n,str).
538##
539## The individual words may not contain spaces.
540##
541## $(1): 1 based index
542## $(2): value of the form a:b:c...
543###########################################################
544
545define word-colon
546$(word $(1),$(subst :,$(space),$(2)))
547endef
548
549###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800550## Convert "a=b c= d e = f" into "a=b c=d e=f"
551##
552## $(1): list to collapse
553## $(2): if set, separator word; usually "=", ":", or ":="
554## Defaults to "=" if not set.
555###########################################################
556
557define collapse-pairs
558$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
559$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
560 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
561endef
562
The Android Open Source Project88b60792009-03-03 19:28:42 -0800563###########################################################
564## MODULE_TAG set operations
565###########################################################
566
567# Given a list of tags, return the targets that specify
568# any of those tags.
569# $(1): tag list
570define modules-for-tag-list
571$(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag))))
572endef
573
574# Same as modules-for-tag-list, but operates on
575# ALL_MODULE_NAME_TAGS.
576# $(1): tag list
577define module-names-for-tag-list
578$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
579endef
580
581# Given an accept and reject list, find the matching
582# set of targets. If a target has multiple tags and
583# any of them are rejected, the target is rejected.
584# Reject overrides accept.
585# $(1): list of tags to accept
586# $(2): list of tags to reject
587#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800588#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800589define get-tagged-modules
590$(filter-out \
591 $(call modules-for-tag-list,$(2)), \
592 $(call modules-for-tag-list,$(1)))
593endef
594
Joe Onorato64d85d02009-04-09 19:31:12 -0700595###########################################################
596## Append a leaf to a base path. Properly deals with
597## base paths ending in /.
598##
599## $(1): base path
600## $(2): leaf path
601###########################################################
602
603define append-path
604$(subst //,/,$(1)/$(2))
605endef
606
The Android Open Source Project88b60792009-03-03 19:28:42 -0800607
608###########################################################
609## Package filtering
610###########################################################
611
612# Given a list of installed modules (short or long names)
613# return a list of the packages (yes, .apk packages, not
614# modules in general) that are overridden by this list and,
615# therefore, should not be installed.
616# $(1): mixed list of installed modules
617# TODO: This is fragile; find a reliable way to get this information.
618define _get-package-overrides
619 $(eval ### Discard any words containing slashes, unless they end in .apk, \
620 ### in which case trim off the directory component and the suffix. \
621 ### If there are no slashes, keep the entire word.)
622 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
623 $(eval _gpo_names := \
624 $(filter %.apk,$(_gpo_names)) \
625 $(filter-out %@@@ @@@%,$(_gpo_names)))
626 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
627 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
628
629 $(eval ### Remove any remaining words that contain dots.)
630 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
631 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
632
633 $(eval ### Now we have a list of any words that could possibly refer to \
634 ### packages, although there may be words that do not. Only \
635 ### real packages will be present under PACKAGES.*, though.)
636 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
637endef
638
639define get-package-overrides
640$(strip $(sort $(call _get-package-overrides,$(1))))
641endef
642
643###########################################################
644## Output the command lines, or not
645###########################################################
646
647ifeq ($(strip $(SHOW_COMMANDS)),)
648define pretty
649@echo $1
650endef
651hide := @
652else
653define pretty
654endef
655hide :=
656endif
657
658###########################################################
659## Dump the variables that are associated with targets
660###########################################################
661
662define dump-module-variables
663@echo all_dependencies=$^
664@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
665@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
666@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
667@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
668@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
669@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
670@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
671@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
672@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
673@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
Brian Carlstromf184a0f2010-02-01 11:13:32 -0800674@echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800675@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
676@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
677@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
678@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
679@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
680endef
681
682###########################################################
683## Commands for using sed to replace given variable values
684###########################################################
685
686define transform-variables
687@mkdir -p $(dir $@)
688@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
689$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
690$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
691endef
692
693
694###########################################################
695## Commands for munging the dependency files GCC generates
696###########################################################
697
698define transform-d-to-p
699@cp $(@:%.o=%.d) $(@:%.o=%.P); \
700 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
701 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
702 rm -f $(@:%.o=%.d)
703endef
704
705###########################################################
706## Commands for running lex
707###########################################################
708
709define transform-l-to-cpp
710@mkdir -p $(dir $@)
711@echo "Lex: $(PRIVATE_MODULE) <= $<"
712$(hide) $(LEX) -o$@ $<
713endef
714
715###########################################################
716## Commands for running yacc
717##
718## Because the extension of c++ files can change, the
719## extension must be specified in $1.
720## E.g, "$(call transform-y-to-cpp,.cpp)"
721###########################################################
722
723define transform-y-to-cpp
724@mkdir -p $(dir $@)
725@echo "Yacc: $(PRIVATE_MODULE) <= $<"
726$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
727touch $(@:$1=$(YACC_HEADER_SUFFIX))
728echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
729echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
730cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
731echo '#endif' >> $(@:$1=.h)
732rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
733endef
734
735
736###########################################################
737## Commands for running aidl
738###########################################################
739
740define transform-aidl-to-java
741@mkdir -p $(dir $@)
742@echo "Aidl: $(PRIVATE_MODULE) <= $<"
743$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
744endef
745#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
746
747
Doug Zongker9bd49622009-11-30 14:28:59 -0800748###########################################################
749## Commands for running java-event-log-tags.py
750###########################################################
751
752define transform-logtags-to-java
753@mkdir -p $(dir $@)
754@echo "logtags: $@ <= $<"
Doug Zongkerabfbbe22010-02-16 14:32:08 -0800755$(hide) $(JAVATAGS) -o $@ $^
Doug Zongker9bd49622009-11-30 14:28:59 -0800756endef
757
The Android Open Source Project88b60792009-03-03 19:28:42 -0800758
759###########################################################
760## Commands for running gcc to compile a C++ file
761###########################################################
762
763define transform-cpp-to-o
764@mkdir -p $(dir $@)
765@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
766$(hide) $(PRIVATE_CXX) \
767 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500768 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800769 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700770 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
771 $(PRIVATE_TARGET_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800772 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800773 , \
774 -I $(incdir) \
775 ) \
776 -c \
777 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700778 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
779 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800780 $(PRIVATE_ARM_CFLAGS) \
781 ) \
782 -fno-rtti \
783 $(PRIVATE_CFLAGS) \
784 $(PRIVATE_CPPFLAGS) \
785 $(PRIVATE_DEBUG_CFLAGS) \
786 -MD -o $@ $<
787$(hide) $(transform-d-to-p)
788endef
789
790
791###########################################################
792## Commands for running gcc to compile a C file
793###########################################################
794
795# $(1): extra flags
796define transform-c-or-s-to-o-no-deps
797@mkdir -p $(dir $@)
798$(hide) $(PRIVATE_CC) \
799 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500800 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800801 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700802 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
803 $(PRIVATE_TARGET_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800804 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800805 , \
806 -I $(incdir) \
807 ) \
808 -c \
809 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700810 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800811 $(PRIVATE_ARM_CFLAGS) \
812 ) \
813 $(PRIVATE_CFLAGS) \
814 $(1) \
815 $(PRIVATE_DEBUG_CFLAGS) \
816 -MD -o $@ $<
817endef
818
819define transform-c-to-o-no-deps
820@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
821$(call transform-c-or-s-to-o-no-deps, )
822endef
823
824define transform-s-to-o-no-deps
825@echo "target asm: $(PRIVATE_MODULE) <= $<"
826$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
827endef
828
829define transform-c-to-o
830$(transform-c-to-o-no-deps)
831$(hide) $(transform-d-to-p)
832endef
833
834define transform-s-to-o
835$(transform-s-to-o-no-deps)
836$(hide) $(transform-d-to-p)
837endef
838
839###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200840## Commands for running gcc to compile an Objective-C file
841## This should never happen for target builds but this
842## will error at build time.
843###########################################################
844
845define transform-m-to-o-no-deps
846@echo "target ObjC: $(PRIVATE_MODULE) <= $<"
847$(call transform-c-or-s-to-o-no-deps)
848endef
849
850define transform-m-to-o
851$(transform-m-to-o-no-deps)
852$(hide) $(transform-d-to-p)
853endef
854
855###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800856## Commands for running gcc to compile a host C++ file
857###########################################################
858
859define transform-host-cpp-to-o
860@mkdir -p $(dir $@)
861@echo "host C++: $(PRIVATE_MODULE) <= $<"
862$(hide) $(PRIVATE_CXX) \
863 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500864 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800865 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
866 $(HOST_PROJECT_INCLUDES) \
867 $(HOST_C_INCLUDES) \
868 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800869 , \
870 -I $(incdir) \
871 ) \
872 -c \
873 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
874 $(HOST_GLOBAL_CFLAGS) \
875 $(HOST_GLOBAL_CPPFLAGS) \
876 ) \
877 $(PRIVATE_CFLAGS) \
878 $(PRIVATE_CPPFLAGS) \
879 $(PRIVATE_DEBUG_CFLAGS) \
880 -MD -o $@ $<
881$(transform-d-to-p)
882endef
883
884
885###########################################################
886## Commands for running gcc to compile a host C file
887###########################################################
888
889# $(1): extra flags
890define transform-host-c-or-s-to-o-no-deps
891@mkdir -p $(dir $@)
892$(hide) $(PRIVATE_CC) \
893 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500894 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800895 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
896 $(HOST_PROJECT_INCLUDES) \
897 $(HOST_C_INCLUDES) \
898 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800899 , \
900 -I $(incdir) \
901 ) \
902 -c \
903 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
904 $(HOST_GLOBAL_CFLAGS) \
905 ) \
906 $(PRIVATE_CFLAGS) \
907 $(1) \
908 $(PRIVATE_DEBUG_CFLAGS) \
909 -MD -o $@ $<
910endef
911
912define transform-host-c-to-o-no-deps
913@echo "host C: $(PRIVATE_MODULE) <= $<"
914$(call transform-host-c-or-s-to-o-no-deps, )
915endef
916
917define transform-host-s-to-o-no-deps
918@echo "host asm: $(PRIVATE_MODULE) <= $<"
919$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
920endef
921
922define transform-host-c-to-o
923$(transform-host-c-to-o-no-deps)
924$(transform-d-to-p)
925endef
926
927define transform-host-s-to-o
928$(transform-host-s-to-o-no-deps)
929$(transform-d-to-p)
930endef
931
932###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200933## Commands for running gcc to compile a host Objective-C file
934###########################################################
935
936define transform-host-m-to-o-no-deps
937@echo "host ObjC: $(PRIVATE_MODULE) <= $<"
938$(call transform-host-c-or-s-to-o-no-deps)
939endef
940
941define tranform-host-m-to-o
942$(transform-host-m-to-o-no-deps)
943$(transform-d-to-p)
944endef
945
946###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800947## Commands for running ar
948###########################################################
949
Ying Wange4b24eb2010-05-27 11:55:39 -0700950define _concat-if-arg2-not-empty
951$(if $(2),$(hide) $(1) $(2))
952endef
953
954# Split long argument list into smaller groups and call the command repeatedly
955#
956# $(1): the command without arguments
957# $(2): the arguments
958define split-long-arguments
959$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1,500,$(2)))
960$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
961$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
962$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
963$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
964$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
965$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
966endef
967
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700968define extract-and-include-target-whole-static-libs
Dima Zavin46e9bec2009-05-27 19:41:07 -0700969$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Colin Cross9ca21642010-05-04 15:42:22 -0700970 $(hide) echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
Dima Zavin46e9bec2009-05-27 19:41:07 -0700971 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
972 rm -rf $$ldir; \
973 mkdir -p $$ldir; \
974 filelist=; \
975 for f in `$(TARGET_AR) t $(lib)`; do \
976 $(TARGET_AR) p $(lib) $$f > $$ldir/$$f; \
977 filelist="$$filelist $$ldir/$$f"; \
978 done ; \
979 $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
980)
981endef
982
The Android Open Source Project88b60792009-03-03 19:28:42 -0800983# Explicitly delete the archive first so that ar doesn't
984# try to add to an existing archive.
985define transform-o-to-static-lib
986@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800987@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700988$(extract-and-include-target-whole-static-libs)
Dima Zavin46e9bec2009-05-27 19:41:07 -0700989@echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
Ying Wange4b24eb2010-05-27 11:55:39 -0700990$(call split-long-arguments,$(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800991endef
992
993###########################################################
994## Commands for running host ar
995###########################################################
996
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700997define extract-and-include-host-whole-static-libs
998$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Ying Wange4b24eb2010-05-27 11:55:39 -0700999 $(hide) echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001000 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
1001 rm -rf $$ldir; \
1002 mkdir -p $$ldir; \
1003 filelist=; \
Dan Bornstein6581fed2009-10-22 13:14:41 -07001004 for f in `$(HOST_AR) t $(lib) | grep '\.o$$'`; do \
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001005 $(HOST_AR) p $(lib) $$f > $$ldir/$$f; \
1006 filelist="$$filelist $$ldir/$$f"; \
1007 done ; \
1008 $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
1009)
1010endef
1011
The Android Open Source Project88b60792009-03-03 19:28:42 -08001012# Explicitly delete the archive first so that ar doesn't
1013# try to add to an existing archive.
1014define transform-host-o-to-static-lib
1015@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001016@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001017$(extract-and-include-host-whole-static-libs)
Dan Bornstein6bffc912009-10-15 13:01:36 -07001018@echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
Ying Wange4b24eb2010-05-27 11:55:39 -07001019$(call split-long-arguments,$(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001020endef
1021
1022
1023###########################################################
1024## Commands for running gcc to link a shared library or package
1025###########################################################
1026
1027# ld just seems to be so finicky with command order that we allow
1028# it to be overriden en-masse see combo/linux-arm.make for an example.
1029ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1030define transform-host-o-to-shared-lib-inner
1031$(HOST_CXX) \
1032 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1033 -Wl,-rpath,\$$ORIGIN/../lib \
1034 -shared -Wl,-soname,$(notdir $@) \
1035 $(PRIVATE_LDFLAGS) \
1036 $(HOST_GLOBAL_LD_DIRS) \
1037 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1038 $(HOST_GLOBAL_LDFLAGS) \
1039 ) \
1040 $(PRIVATE_ALL_OBJECTS) \
1041 -Wl,--whole-archive \
1042 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1043 -Wl,--no-whole-archive \
1044 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1045 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1046 -o $@ \
1047 $(PRIVATE_LDLIBS)
1048endef
1049endif
1050
1051define transform-host-o-to-shared-lib
1052@mkdir -p $(dir $@)
1053@echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
1054$(hide) $(transform-host-o-to-shared-lib-inner)
1055endef
1056
1057define transform-host-o-to-package
1058@mkdir -p $(dir $@)
1059@echo "host Package: $(PRIVATE_MODULE) ($@)"
1060$(hide) $(transform-host-o-to-shared-lib-inner)
1061endef
1062
1063
1064###########################################################
1065## Commands for running gcc to link a shared library or package
1066###########################################################
1067
1068#echo >$@.vers "{"; \
1069#echo >>$@.vers " global:"; \
1070#$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \
1071#echo >>$@.vers " local:"; \
1072#echo >>$@.vers " *;"; \
1073#echo >>$@.vers "};"; \
1074
1075# -Wl,--version-script=$@.vers \
1076
1077# ld just seems to be so finicky with command order that we allow
1078# it to be overriden en-masse see combo/linux-arm.make for an example.
1079ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1080define transform-o-to-shared-lib-inner
1081$(TARGET_CXX) \
Ying Wang1a081002010-07-13 14:55:47 -07001082 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001083 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1084 -Wl,-rpath,\$$ORIGIN/../lib \
1085 -shared -Wl,-soname,$(notdir $@) \
1086 $(PRIVATE_LDFLAGS) \
Ying Wang1a081002010-07-13 14:55:47 -07001087 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001088 $(PRIVATE_ALL_OBJECTS) \
1089 -Wl,--whole-archive \
1090 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1091 -Wl,--no-whole-archive \
1092 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1093 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1094 -o $@ \
1095 $(PRIVATE_LDLIBS)
1096endef
1097endif
1098
1099define transform-o-to-shared-lib
1100@mkdir -p $(dir $@)
1101@echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
1102$(hide) $(transform-o-to-shared-lib-inner)
1103endef
1104
1105define transform-o-to-package
1106@mkdir -p $(dir $@)
1107@echo "target Package: $(PRIVATE_MODULE) ($@)"
1108$(hide) $(transform-o-to-shared-lib-inner)
1109endef
1110
1111
1112###########################################################
1113## Commands for filtering a target executable or library
1114###########################################################
1115
The Android Open Source Project88b60792009-03-03 19:28:42 -08001116define transform-to-stripped
1117@mkdir -p $(dir $@)
1118@echo "target Strip: $(PRIVATE_MODULE) ($@)"
Bruce Beare45ac4342010-06-24 14:02:00 -07001119$(hide) $(TARGET_STRIP_COMMAND)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001120endef
1121
1122define transform-to-prelinked
1123@mkdir -p $(dir $@)
1124@echo "target Prelink: $(PRIVATE_MODULE) ($@)"
1125$(hide) $(APRIORI) \
1126 --prelinkmap $(TARGET_PRELINKER_MAP) \
1127 --locals-only \
1128 --quiet \
1129 $< \
1130 --output $@
1131endef
1132
1133
1134###########################################################
1135## Commands for running gcc to link an executable
1136###########################################################
1137
1138ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1139define transform-o-to-executable-inner
1140$(TARGET_CXX) \
1141 $(TARGET_GLOBAL_LDFLAGS) \
1142 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1143 $(TARGET_GLOBAL_LD_DIRS) \
1144 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1145 -Wl,-rpath,\$$ORIGIN/../lib \
1146 $(PRIVATE_LDFLAGS) \
1147 $(TARGET_GLOBAL_LD_DIRS) \
1148 $(PRIVATE_ALL_OBJECTS) \
1149 -Wl,--whole-archive \
1150 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1151 -Wl,--no-whole-archive \
1152 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1153 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1154 -o $@ \
1155 $(PRIVATE_LDLIBS)
1156endef
1157endif
1158
1159define transform-o-to-executable
1160@mkdir -p $(dir $@)
1161@echo "target Executable: $(PRIVATE_MODULE) ($@)"
1162$(hide) $(transform-o-to-executable-inner)
1163endef
1164
1165
1166###########################################################
1167## Commands for running gcc to link a statically linked
1168## executable. In practice, we only use this on arm, so
1169## the other platforms don't have the
1170## transform-o-to-static-executable defined
1171###########################################################
1172
1173ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1174define transform-o-to-static-executable-inner
1175endef
1176endif
1177
1178define transform-o-to-static-executable
1179@mkdir -p $(dir $@)
1180@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
1181$(hide) $(transform-o-to-static-executable-inner)
1182endef
1183
1184
1185###########################################################
1186## Commands for running gcc to link a host executable
1187###########################################################
1188
1189ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1190define transform-host-o-to-executable-inner
1191$(HOST_CXX) \
1192 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1193 -Wl,-rpath,\$$ORIGIN/../lib \
1194 $(HOST_GLOBAL_LD_DIRS) \
1195 $(PRIVATE_LDFLAGS) \
1196 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1197 $(HOST_GLOBAL_LDFLAGS) \
1198 ) \
1199 $(PRIVATE_ALL_OBJECTS) \
1200 -Wl,--whole-archive \
1201 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1202 -Wl,--no-whole-archive \
1203 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1204 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1205 -o $@ \
1206 $(PRIVATE_LDLIBS)
1207endef
1208endif
1209
1210define transform-host-o-to-executable
1211@mkdir -p $(dir $@)
1212@echo "host Executable: $(PRIVATE_MODULE) ($@)"
1213$(hide) $(transform-host-o-to-executable-inner)
1214endef
1215
1216
1217###########################################################
1218## Commands for running javac to make .class files
1219###########################################################
1220
1221#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)"
1222#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')"
1223
1224# TODO: Right now we generate the asset resources twice, first as part
1225# of generating the Java classes, then at the end when packaging the final
1226# assets. This should be changed to do one of two things: (1) Don't generate
1227# any resource files the first time, only create classes during that stage;
1228# or (2) Don't use the -c flag with the second stage, instead taking the
1229# resource files from the first stage as additional input. My original intent
1230# was to use approach (2), but this requires a little more work in the tool.
1231# Maybe we should just use approach (1).
1232
1233# This rule creates the R.java and Manifest.java files, both of which
1234# are PRODUCT-neutral. Don't pass PRODUCT_AAPT_CONFIG to this invocation.
1235define create-resource-java-files
1236@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1237@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08001238$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001239 $(eval # PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
1240 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1241 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1242 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1243 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1244 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001245 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07001246 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001247 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1248 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001249 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07001250 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Ying Wang8c254822010-03-16 16:13:56 -07001251 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
1252 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_INSTRUMENTATION_FOR_PACKAGE_NAME))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001253endef
1254
1255ifeq ($(HOST_OS),windows)
1256xlint_unchecked :=
1257else
1258#xlint_unchecked := -Xlint:unchecked
1259endif
1260
1261# emit-line, <word list>, <output file>
1262define emit-line
1263 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1264endef
1265
1266# dump-words-to-file, <word list>, <output file>
1267define dump-words-to-file
1268 @rm -f $(2)
1269 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1270 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1271 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1272 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1273 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1274 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1275 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1276 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1277 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1278 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1279 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1280 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1281 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1282 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1283 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1284 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1285 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1286 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1287 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1288 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
Jesse Wilson72c941a2010-05-04 16:33:49 -07001289 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2))
1290 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2))
1291 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2))
1292 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2))
1293 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2))
1294 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001295endef
1296
1297# For a list of jar files, unzip them to a specified directory,
1298# but make sure that no META-INF files come along for the ride.
1299#
1300# $(1): files to unzip
1301# $(2): destination directory
1302define unzip-jar-files
1303 $(hide) for f in $(1); \
1304 do \
1305 if [ ! -f $$f ]; then \
1306 echo Missing file $$f; \
1307 exit 1; \
1308 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07001309 unzip -qo $$f -d $(2); \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001310 (cd $(2) && rm -rf META-INF); \
1311 done
1312endef
1313
Joe Onorato64d85d02009-04-09 19:31:12 -07001314# below we write the list of java files to java-source-list to avoid argument
1315# list length problems with Cygwin we filter out duplicate java file names
1316# because eclipse's compiler doesn't like them.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001317define transform-java-to-classes.jar
1318@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Joe Onorato64d85d02009-04-09 19:31:12 -07001319$(hide) rm -f $@
1320$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1321$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001322$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1323 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
Joe Onoratoe334d252009-07-17 15:33:40 -04001324$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07001325$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Joe Onoratoe334d252009-07-17 15:33:40 -04001326 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 -08001327fi
Joe Onoratoe334d252009-07-17 15:33:40 -04001328$(hide) tr ' ' '\n' < $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list \
1329 | sort -u > $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
The Android Open Source Project88b60792009-03-03 19:28:42 -08001330$(hide) $(TARGET_JAVAC) -encoding ascii $(PRIVATE_BOOTCLASSPATH) \
1331 $(addprefix -classpath ,$(strip \
1332 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Brian Carlstromf184a0f2010-02-01 11:13:32 -08001333 $(PRIVATE_JAVACFLAGS) $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) $(xlint_unchecked) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001334 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Joe Onoratoe334d252009-07-17 15:33:40 -04001335 \@$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001336 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
Joe Onoratoe334d252009-07-17 15:33:40 -04001337$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list
1338$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
Joe Onorato64d85d02009-04-09 19:31:12 -07001339$(hide) mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001340$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1341 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
Joe Onorato64d85d02009-04-09 19:31:12 -07001342$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001343endef
1344
1345define transform-classes.jar-to-emma
1346$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu155afe32010-03-10 15:48:03 -08001347 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07001348 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001349endef
1350
1351#TODO: use a smaller -Xmx value for most libraries;
1352# only core.jar and framework.jar need a heap this big.
Raphaelf6ff4c52009-08-18 14:43:32 -07001353# 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 -08001354define transform-classes.jar-to-dex
1355@echo "target Dex: $(PRIVATE_MODULE)"
1356@mkdir -p $(dir $@)
Raphaelf6ff4c52009-08-18 14:43:32 -07001357$(hide) $(DX) \
1358 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1536M) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001359 --dex --output=$@ \
1360 $(if $(NO_OPTIMIZE_DX), \
1361 --no-optimize) \
1362 $(if $(GENERATE_DEX_DEBUG), \
1363 --debug --verbose \
1364 --dump-to=$(@:.dex=.lst) \
1365 --dump-width=1000) \
1366 $(PRIVATE_DX_FLAGS) \
1367 $<
1368endef
1369
1370# Create a mostly-empty .jar file that we'll add to later.
1371# The MacOS jar tool doesn't like creating empty jar files,
1372# so we need to give it something.
1373define create-empty-package
1374@mkdir -p $(dir $@)
1375$(hide) touch $(dir $@)/dummy
1376$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy)
1377$(hide) zip -qd $@ dummy
1378$(hide) rm $(dir $@)/dummy
1379endef
1380
1381#TODO: we kinda want to build different asset packages for
1382# different configurations, then combine them later (or something).
1383# Per-locale, etc.
1384# A list of dynamic and static parameters; build layers for
1385# dynamic params that lay over the static ones.
1386#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001387#Note that the version numbers are given to aapt as simple default
1388#values; applications can override these by explicitly stating
1389#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001390define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08001391$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001392 $(addprefix -c , $(PRODUCT_AAPT_CONFIG)) \
1393 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1394 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1395 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1396 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001397 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1398 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001399 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07001400 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06001401 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang8c254822010-03-16 16:13:56 -07001402 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_INSTRUMENTATION_FOR_PACKAGE_NAME)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001403 -F $@
1404endef
1405
The Android Open Source Project88b60792009-03-03 19:28:42 -08001406define add-jni-shared-libs-to-package
1407$(hide) rm -rf $(dir $@)lib
Jack Palevicha0ab29b2010-06-18 15:38:07 +08001408$(hide) mkdir -p $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)
1409$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001410$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib)
1411$(hide) rm -rf $(dir $@)lib
1412endef
1413
The Android Open Source Project88b60792009-03-03 19:28:42 -08001414#TODO: update the manifest to point to the dex file
1415define add-dex-to-package
Doug Zongker9e4374b2009-10-09 12:11:30 -07001416$(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001417endef
1418
1419define add-java-resources-to-package
1420$(hide) jar uf $@ $(PRIVATE_EXTRA_JAR_ARGS)
1421endef
1422
1423# Sign a package using the specified key/cert.
1424#
1425define sign-package
1426$(hide) mv $@ $@.unsigned
1427$(hide) java -jar $(SIGNAPK_JAR) \
1428 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) $@.unsigned $@.signed
1429$(hide) mv $@.signed $@
1430endef
1431
1432# Align STORED entries of a package on 4-byte boundaries
1433# to make them easier to mmap.
1434#
1435define align-package
1436$(hide) mv $@ $@.unaligned
1437$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned
1438$(hide) mv $@.aligned $@
1439endef
1440
1441define install-dex-debug
1442$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
1443 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1444 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
1445 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
1446 fi
1447$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
1448 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1449 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
1450 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
1451 fi
1452endef
1453
1454# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
1455# new prebuilt rules to work, we should change this to copy the
1456# resources to the out directory and then copy the resources.
1457
1458# Note: not using aapt tool for this because we aren't making
1459# an android package for the host.
1460define transform-host-java-to-package
1461@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1462@rm -f $@
1463@rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1464@mkdir -p $(dir $@)
1465@mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1466$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1467 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
1468$(call dump-words-to-file,$(sort\
1469 $(PRIVATE_JAVA_SOURCES)),\
Joe Onorato483d9242009-06-18 13:11:58 -07001470 $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001471$(hide) $(HOST_JAVAC) -encoding ascii -g \
Brian Carlstromf184a0f2010-02-01 11:13:32 -08001472 $(PRIVATE_JAVACFLAGS) $(xlint_unchecked) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001473 $(addprefix -classpath ,$(strip \
1474 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
1475 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR)\
Joe Onorato483d9242009-06-18 13:11:58 -07001476 \@$(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq || \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001477 ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
Joe Onorato483d9242009-06-18 13:11:58 -07001478$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list
1479$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq
The Android Open Source Project88b60792009-03-03 19:28:42 -08001480$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1481 $@ $(PRIVATE_JAR_MANIFEST) $(PRIVATE_EXTRA_JAR_ARGS) \
1482 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1483endef
1484
1485###########################################################
1486## Obfuscate a jar file
1487###########################################################
1488
1489# PRIVATE_KEEP_FILE is a file containing a list of classes
1490# PRIVATE_INTERMEDIATES_DIR is a directory we can use for temporary files
1491# The module using this must depend on
1492# $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar
1493define obfuscate-jar
1494@echo "Obfuscate jar: $(notdir $@) ($@)"
1495@mkdir -p $(dir $@)
1496@rm -f $@
1497@mkdir -p $(PRIVATE_INTERMEDIATES_DIR)
1498$(hide) sed -e 's/^/-keep class /' < $(PRIVATE_KEEP_FILE) > \
1499 $(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1500$(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \
1501 -injars $< \
1502 -outjars $@ \
1503 -target 1.5 \
1504 -dontnote -dontwarn \
1505 -printmapping $(PRIVATE_INTERMEDIATES_DIR)/out.map \
1506 -forceprocessing \
1507 -renamesourcefileattribute SourceFile \
1508 -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod \
1509 -repackageclasses \
1510 -keepclassmembers "class * { public protected *; }" \
1511 @$(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1512endef
1513
1514###########################################################
1515## Commands for copying files
1516###########################################################
1517
1518# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
1519# $(1): source header
1520# $(2): destination header
1521define copy-one-header
1522$(2): $(1)
1523 @echo "Header: $$@"
1524 $$(copy-file-to-new-target-with-cp)
1525endef
1526
1527# Define a rule to copy a file. For use via $(eval).
1528# $(1): source file
1529# $(2): destination file
1530define copy-one-file
1531$(2): $(1) | $(ACP)
1532 @echo "Copy: $$@"
1533 $$(copy-file-to-target)
1534endef
1535
1536# The -t option to acp and the -p option to cp is
1537# required for OSX. OSX has a ridiculous restriction
1538# where it's an error for a .a file's modification time
1539# to disagree with an internal timestamp, and this
1540# macro is used to install .a files (among other things).
1541
1542# Copy a single file from one place to another,
1543# preserving permissions and overwriting any existing
1544# file.
1545define copy-file-to-target
1546@mkdir -p $(dir $@)
1547$(hide) $(ACP) -fpt $< $@
1548endef
1549
1550# The same as copy-file-to-target, but use the local
1551# cp command instead of acp.
1552define copy-file-to-target-with-cp
1553@mkdir -p $(dir $@)
1554$(hide) cp -fp $< $@
1555endef
1556
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001557# The same as copy-file-to-target, but use the zipalign tool to do so.
1558define copy-file-to-target-with-zipalign
1559@mkdir -p $(dir $@)
1560$(hide) $(ZIPALIGN) -f 4 $< $@
1561endef
1562
Doug Zongker1046d202009-08-06 13:02:19 -07001563# The same as copy-file-to-target, but strip out "# comment"-style
1564# comments (for config files and such).
1565define copy-file-to-target-strip-comments
1566@mkdir -p $(dir $@)
1567$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
1568endef
1569
The Android Open Source Project88b60792009-03-03 19:28:42 -08001570# The same as copy-file-to-target, but don't preserve
1571# the old modification time.
1572define copy-file-to-new-target
1573@mkdir -p $(dir $@)
1574$(hide) $(ACP) -fp $< $@
1575endef
1576
1577# The same as copy-file-to-new-target, but use the local
1578# cp command instead of acp.
1579define copy-file-to-new-target-with-cp
1580@mkdir -p $(dir $@)
1581$(hide) cp -f $< $@
1582endef
1583
1584# Copy a prebuilt file to a target location.
1585define transform-prebuilt-to-target
1586@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1587$(copy-file-to-target)
1588endef
1589
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001590# Copy a prebuilt file to a target location, using zipalign on it.
1591define transform-prebuilt-to-target-with-zipalign
1592@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
1593$(copy-file-to-target-with-zipalign)
1594endef
1595
Doug Zongker1046d202009-08-06 13:02:19 -07001596# Copy a prebuilt file to a target location, stripping "# comment" comments.
1597define transform-prebuilt-to-target-strip-comments
1598@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1599$(copy-file-to-target-strip-comments)
1600endef
1601
The Android Open Source Project88b60792009-03-03 19:28:42 -08001602###########################################################
1603## On some platforms (MacOS), after copying a static
1604## library, ranlib must be run to update an internal
1605## timestamp!?!?!
1606###########################################################
1607
1608ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true)
1609define transform-host-ranlib-copy-hack
1610 $(hide) ranlib $@ || true
1611endef
1612else
1613define transform-host-ranlib-copy-hack
Patrick Scott0e27dff2010-05-07 08:37:11 -04001614@true
The Android Open Source Project88b60792009-03-03 19:28:42 -08001615endef
1616endif
1617
1618ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true)
1619define transform-ranlib-copy-hack
1620 $(hide) ranlib $@
1621endef
1622else
1623define transform-ranlib-copy-hack
Patrick Scott0e27dff2010-05-07 08:37:11 -04001624@true
The Android Open Source Project88b60792009-03-03 19:28:42 -08001625endef
1626endif
1627
1628
1629###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08001630## Commands to call Proguard
1631###########################################################
1632
1633# Command to copy the file with acp, if proguard is disabled.
1634define proguard-disabled-commands
1635@echo Copying: $@
1636$(hide) $(ACP) $< $@
1637endef
1638
1639# Command to call Proguard
1640# $(1): extra flags for instrumentation.
1641define proguard-enabled-commands
1642@echo Proguard: $@
1643$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) $(1)
1644endef
1645
1646# Figure out the proguard dictionary file of the module that is instrumentationed for.
1647define get-instrumentation-proguard-flags
1648$(if $(PRIVATE_INSTRUMENTATION_FOR),$(if $(ALL_MODULES.$(PRIVATE_INSTRUMENTATION_FOR).PROGUARD_ENABLED),-applymapping $(call intermediates-dir-for,APPS,$(PRIVATE_INSTRUMENTATION_FOR),,COMMON)/proguard_dictionary))
1649endef
1650
1651define transform-jar-to-proguard
1652$(eval _instrumentation_proguard_flags:=$(call get-instrumentation-proguard-flags))
1653$(eval _enable_proguard:=$(PRIVATE_PROGUARD_ENABLED)$(_instrumentation_proguard_flags))
1654$(if $(_enable_proguard),$(call proguard-enabled-commands,$(_instrumentation_proguard_flags)),$(call proguard-disabled-commands))
1655$(eval _instrumentation_proguard_flags:=)
1656$(eval _enable_proguard:=)
1657endef
1658
1659
1660###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001661## Stuff source generated from one-off tools
1662###########################################################
1663
1664define transform-generated-source
1665@echo "target Generated: $(PRIVATE_MODULE) <= $<"
1666@mkdir -p $(dir $@)
1667$(hide) $(PRIVATE_CUSTOM_TOOL)
1668endef
1669
1670
1671###########################################################
1672## Assertions about attributes of the target
1673###########################################################
1674
1675# $(1): The file to check
1676ifndef get-file-size
1677$(error HOST_OS must define get-file-size)
1678endif
1679
Doug Zongker4647f122009-07-02 09:00:54 -07001680# Convert a partition data size (eg, as reported in /proc/mtd) to the
1681# size of the image used to flash that partition (which includes a
1682# 64-byte spare area for each 2048-byte page).
1683# $(1): the partition data size
1684define image-size-from-data-size
1685$(shell echo $$(($(1) / 2048 * (2048+64))))
1686endef
1687
1688# $(1): The file(s) to check (often $@)
1689# $(2): The maximum total image size, in decimal bytes
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001690# $(3): the type of filesystem "yaffs" or "raw"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001691#
1692# If $(2) is empty, evaluates to "true"
1693#
1694# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
1695# is left over after the image has been flashed. Round the 1% up to the
1696# next whole flash block size.
1697define assert-max-file-size
1698$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07001699 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
1700 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07001701 printname=$$(echo -n "$(1)" | tr " " +); \
1702 echo "$$printname total size is $$total"; \
1703 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001704 if [ "$(3)" == "yaffs" ]; then \
Doug Zongker93d9ff42009-09-14 17:46:41 -07001705 reservedblocks=8; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001706 else \
Doug Zongker4ac1ba62009-08-25 20:38:50 -07001707 reservedblocks=0; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001708 fi; \
Doug Zongker4647f122009-07-02 09:00:54 -07001709 twoblocks=$$((img_blocksize * 2)); \
1710 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001711 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \
1712 reservedblocks * img_blocksize)); \
Doug Zongker4647f122009-07-02 09:00:54 -07001713 maxsize=$$(($(2) - reserve)); \
1714 if [ "$$total" -gt "$$maxsize" ]; then \
1715 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
1716 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07001717 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07001718 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001719 fi \
1720 , \
1721 true \
1722 )
1723endef
1724
Doug Zongker8510a1e2009-08-07 16:38:08 -07001725# Like assert-max-file-size, but the second argument is a partition
1726# size, which we'll convert to a max image size before checking it
1727# against the files.
1728#
1729# $(1): The file(s) to check (often $@)
1730# $(2): The partition size.
1731define assert-max-image-size
1732$(if $(2), \
1733 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \
1734 true)
1735endef
1736
Doug Zongkere01100c2009-06-19 17:12:18 -07001737
1738###########################################################
1739## Define device-specific radio files
1740###########################################################
1741
1742# Copy a radio image file to the output location, and add it to
1743# INSTALLED_RADIOIMAGE_TARGET.
1744# $(1): filename
1745define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08001746 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07001747endef
1748define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08001749INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
1750ALL_PREBUILT += $$(PRODUCT_OUT)/$(2)
1751$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
Doug Zongkere01100c2009-06-19 17:12:18 -07001752 $$(transform-prebuilt-to-target)
1753endef
1754
1755
The Android Open Source Project88b60792009-03-03 19:28:42 -08001756###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08001757# Override the package defined in $(1), setting the
1758# variables listed below differently.
1759#
1760# $(1): The makefile to override (relative to the source
1761# tree root)
1762# $(2): Old LOCAL_PACKAGE_NAME value.
1763# $(3): New LOCAL_PACKAGE_NAME value.
1764# $(4): New LOCALE_MANIFEST_PACKAGE_NAME value.
Ying Wang8c254822010-03-16 16:13:56 -07001765# $(5): New LOCAL_INSTRUMENTATION_FOR_PACKAGE_NAME value.
1766# $(6): New LOCAL_CERTIFICATE value.
Joe Onorato899e62a2010-02-04 17:37:21 -08001767#
1768# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
1769# clear_vars.mk.
1770###########################################################
1771define inherit-package
Ying Wangba16a892010-06-02 13:24:36 -07001772 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6)))
Joe Onorato899e62a2010-02-04 17:37:21 -08001773endef
1774
1775define inherit-package-internal
1776 LOCAL_PACKAGE_OVERRIDES \
Ying Wang8c254822010-03-16 16:13:56 -07001777 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||$(strip $(6)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08001778 include $(1)
1779 LOCAL_PACKAGE_OVERRIDES \
1780 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
1781endef
1782
1783# To be used with inherit-package above
1784# Evalutes to true if the package was overridden
1785define set-inherited-package-variables
1786$(strip $(call set-inherited-package-variables-internal))
1787endef
1788
1789define keep-or-override
1790$(eval $(1) := $(if $(2),$(2),$($(1))))
1791endef
1792
1793define set-inherited-package-variables-internal
1794 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
1795 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
1796 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
1797 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
1798 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang8c254822010-03-16 16:13:56 -07001799 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR_PACKAGE_NAME,$(patsubst &&%,%,$(word 5,$(_o)))) \
1800 $(call keep-or-override,LOCAL_CERTIFICATE,$(word 6,$(_o))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08001801 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
1802 true \
1803 ,)
1804endef
1805
1806
1807###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001808## Other includes
1809###########################################################
1810
1811# -----------------------------------------------------------------
1812# Rules and functions to help copy important files to DIST_DIR
1813# when requested.
1814include $(BUILD_SYSTEM)/distdir.mk
1815
1816
1817# broken:
1818# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
1819
1820###########################################################
1821## Misc notes
1822###########################################################
1823
1824#DEPDIR = .deps
1825#df = $(DEPDIR)/$(*F)
1826
1827#SRCS = foo.c bar.c ...
1828
1829#%.o : %.c
1830# @$(MAKEDEPEND); \
1831# cp $(df).d $(df).P; \
1832# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1833# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
1834# rm -f $(df).d
1835# $(COMPILE.c) -o $@ $<
1836
1837#-include $(SRCS:%.c=$(DEPDIR)/%.P)
1838
1839
1840#%.o : %.c
1841# $(COMPILE.c) -MD -o $@ $<
1842# @cp $*.d $*.P; \
1843# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1844# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
1845# rm -f $*.d