The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | # |
| 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 |
| 27 | ALL_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. |
| 38 | ALL_MODULES:= |
| 39 | |
| 40 | # Full paths to targets that should be added to the "make droid" |
| 41 | # set of installed targets. |
| 42 | ALL_DEFAULT_INSTALLED_MODULES:= |
| 43 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 44 | # 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. |
| 48 | ALL_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.) |
| 56 | ALL_MODULE_NAME_TAGS:= |
| 57 | |
| 58 | # Full paths to all prebuilt files that will be copied |
| 59 | # (used to make the dependency on acp) |
| 60 | ALL_PREBUILT:= |
| 61 | |
| 62 | # Full path to all files that are made by some tool |
| 63 | ALL_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 |
| 67 | ALL_C_CPP_ETC_OBJECTS:= |
| 68 | |
Iliyan Malchev | b375e71 | 2011-03-08 16:19:48 -0800 | [diff] [blame] | 69 | # The list of dynamic binaries that haven't been stripped/compressed/etc. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 70 | ALL_ORIGINAL_DYNAMIC_BINARIES:= |
| 71 | |
| 72 | # These files go into the SDK |
| 73 | ALL_SDK_FILES:= |
| 74 | |
| 75 | # Files for dalvik. This is often build without building the rest of the OS. |
| 76 | INTERNAL_DALVIK_MODULES:= |
| 77 | |
| 78 | # All findbugs xml files |
| 79 | ALL_FINDBUGS_FILES:= |
| 80 | |
| 81 | ########################################################### |
| 82 | ## Debugging; prints a variable list to stdout |
| 83 | ########################################################### |
| 84 | |
| 85 | # $(1): variable name list, not variable values |
| 86 | define print-vars |
| 87 | $(foreach var,$(1), \ |
| 88 | $(info $(var):) \ |
| 89 | $(foreach word,$($(var)), \ |
| 90 | $(info $(space)$(space)$(word)) \ |
| 91 | ) \ |
| 92 | ) |
| 93 | endef |
| 94 | |
| 95 | ########################################################### |
Joe Onorato | 64d85d0 | 2009-04-09 19:31:12 -0700 | [diff] [blame] | 96 | ## Evaluates to true if the string contains the word true, |
| 97 | ## and empty otherwise |
| 98 | ## $(1): a var to test |
| 99 | ########################################################### |
| 100 | |
| 101 | define true-or-empty |
| 102 | $(filter true, $(1)) |
| 103 | endef |
| 104 | |
| 105 | |
| 106 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 107 | ## Retrieve the directory of the current makefile |
| 108 | ########################################################### |
| 109 | |
| 110 | # Figure out where we are. |
| 111 | define my-dir |
Dave Bort | b392641 | 2009-05-19 16:12:22 -0700 | [diff] [blame] | 112 | $(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 Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 120 | endef |
| 121 | |
| 122 | ########################################################### |
| 123 | ## Retrieve a list of all makefiles immediately below some directory |
| 124 | ########################################################### |
| 125 | |
| 126 | define all-makefiles-under |
| 127 | $(wildcard $(1)/*/Android.mk) |
| 128 | endef |
| 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 |
| 137 | define first-makefiles-under |
Joe Onorato | dc1a728 | 2009-08-04 15:58:26 -0400 | [diff] [blame] | 138 | $(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git \ |
| 139 | --mindepth=2 $(1) Android.mk) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 140 | endef |
| 141 | |
| 142 | ########################################################### |
| 143 | ## Retrieve a list of all makefiles immediately below your directory |
| 144 | ########################################################### |
| 145 | |
| 146 | define all-subdir-makefiles |
| 147 | $(call all-makefiles-under,$(call my-dir)) |
| 148 | endef |
| 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 |
| 156 | define all-named-subdir-makefiles |
Chih-Wei Huang | e73c4bb | 2011-01-16 18:31:29 +0800 | [diff] [blame] | 157 | $(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1)))) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 158 | endef |
| 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 | |
| 166 | define all-java-files-under |
| 167 | $(patsubst ./%,%, \ |
| 168 | $(shell cd $(LOCAL_PATH) ; \ |
| 169 | find $(1) -name "*.java" -and -not -name ".*") \ |
| 170 | ) |
| 171 | endef |
| 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 | |
| 178 | define all-subdir-java-files |
| 179 | $(call all-java-files-under,.) |
| 180 | endef |
| 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 | |
| 188 | define all-c-files-under |
| 189 | $(patsubst ./%,%, \ |
| 190 | $(shell cd $(LOCAL_PATH) ; \ |
| 191 | find $(1) -name "*.c" -and -not -name ".*") \ |
| 192 | ) |
| 193 | endef |
| 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 | |
| 200 | define all-subdir-c-files |
| 201 | $(call all-c-files-under,.) |
| 202 | endef |
| 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 | |
| 210 | define all-Iaidl-files-under |
| 211 | $(patsubst ./%,%, \ |
| 212 | $(shell cd $(LOCAL_PATH) ; \ |
| 213 | find $(1) -name "I*.aidl" -and -not -name ".*") \ |
| 214 | ) |
| 215 | endef |
| 216 | |
| 217 | ########################################################### |
| 218 | ## Find all of the "I*.aidl" files under $(LOCAL_PATH). |
| 219 | ########################################################### |
| 220 | |
| 221 | define all-subdir-Iaidl-files |
| 222 | $(call all-Iaidl-files-under,.) |
| 223 | endef |
| 224 | |
| 225 | ########################################################### |
Bjorn Bringert | a89c990 | 2010-02-02 17:36:20 +0000 | [diff] [blame] | 226 | ## 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 | |
| 231 | define all-logtags-files-under |
| 232 | $(patsubst ./%,%, \ |
| 233 | $(shell cd $(LOCAL_PATH) ; \ |
| 234 | find $(1) -name "*.logtags" -and -not -name ".*") \ |
| 235 | ) |
| 236 | endef |
| 237 | |
| 238 | ########################################################### |
Ying Wang | a5fc87a | 2010-11-02 18:43:16 -0700 | [diff] [blame] | 239 | ## Find all of the .proto files under the named directories. |
| 240 | ## Meant to be used like: |
| 241 | ## SRC_FILES := $(call all-proto-files-under,src) |
| 242 | ########################################################### |
| 243 | |
| 244 | define all-proto-files-under |
| 245 | $(patsubst ./%,%, \ |
| 246 | $(shell cd $(LOCAL_PATH) ; \ |
| 247 | find $(1) -name "*.proto" -and -not -name ".*") \ |
| 248 | ) |
| 249 | endef |
| 250 | |
| 251 | ########################################################### |
Ying Wang | 0bd59a0 | 2010-07-15 17:17:52 -0700 | [diff] [blame] | 252 | ## Find all of the RenderScript files under the named directories. |
| 253 | ## Meant to be used like: |
| 254 | ## SRC_FILES := $(call all-renderscript-files-under,src) |
| 255 | ########################################################### |
| 256 | |
| 257 | define all-renderscript-files-under |
| 258 | $(patsubst ./%,%, \ |
| 259 | $(shell cd $(LOCAL_PATH) ; \ |
| 260 | find $(1) -name "*.rs" -and -not -name ".*") \ |
| 261 | ) |
| 262 | endef |
| 263 | |
| 264 | ########################################################### |
Jean-Baptiste Queru | 0a3cfdc | 2009-12-17 17:47:28 -0800 | [diff] [blame] | 265 | ## Find all of the html files under the named directories. |
| 266 | ## Meant to be used like: |
| 267 | ## SRC_FILES := $(call all-html-files-under,src tests) |
| 268 | ########################################################### |
| 269 | |
| 270 | define all-html-files-under |
| 271 | $(patsubst ./%,%, \ |
| 272 | $(shell cd $(LOCAL_PATH) ; \ |
| 273 | find $(1) -name "*.html" -and -not -name ".*") \ |
| 274 | ) |
| 275 | endef |
| 276 | |
| 277 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 278 | ## Find all of the html files from here. Meant to be used like: |
| 279 | ## SRC_FILES := $(call all-subdir-html-files) |
| 280 | ########################################################### |
| 281 | |
| 282 | define all-subdir-html-files |
Jean-Baptiste Queru | 0a3cfdc | 2009-12-17 17:47:28 -0800 | [diff] [blame] | 283 | $(call all-html-files-under,.) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 284 | endef |
| 285 | |
| 286 | ########################################################### |
| 287 | ## Find all of the files matching pattern |
| 288 | ## SRC_FILES := $(call find-subdir-files, <pattern>) |
| 289 | ########################################################### |
| 290 | |
| 291 | define find-subdir-files |
| 292 | $(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find $(1))) |
| 293 | endef |
| 294 | |
| 295 | ########################################################### |
| 296 | # find the files in the subdirectory $1 of LOCAL_DIR |
| 297 | # matching pattern $2, filtering out files $3 |
| 298 | # e.g. |
| 299 | # SRC_FILES += $(call find-subdir-subdir-files, \ |
| 300 | # css, *.cpp, DontWantThis.cpp) |
| 301 | ########################################################### |
| 302 | |
| 303 | define find-subdir-subdir-files |
| 304 | $(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \ |
| 305 | $(LOCAL_PATH) ; find $(1) -maxdepth 1 -name $(2)))) |
| 306 | endef |
| 307 | |
| 308 | ########################################################### |
| 309 | ## Find all of the files matching pattern |
| 310 | ## SRC_FILES := $(call all-subdir-java-files) |
| 311 | ########################################################### |
| 312 | |
| 313 | define find-subdir-assets |
| 314 | $(if $(1),$(patsubst ./%,%, \ |
Ying Wang | 6ab5d6a | 2011-08-10 16:05:51 -0700 | [diff] [blame] | 315 | $(shell if [ -d $(1) ] ; then cd $(1) ; find ./ -not -name '.*' -and -type f -and -not -type l ; fi)), \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 316 | $(warning Empty argument supplied to find-subdir-assets) \ |
| 317 | ) |
| 318 | endef |
| 319 | |
| 320 | ########################################################### |
| 321 | ## Find various file types in a list of directories relative to $(LOCAL_PATH) |
| 322 | ########################################################### |
| 323 | |
| 324 | define find-other-java-files |
| 325 | $(call find-subdir-files,$(1) -name "*.java" -and -not -name ".*") |
| 326 | endef |
| 327 | |
| 328 | define find-other-html-files |
| 329 | $(call find-subdir-files,$(1) -name "*.html" -and -not -name ".*") |
| 330 | endef |
| 331 | |
| 332 | ########################################################### |
| 333 | ## Scan through each directory of $(1) looking for files |
| 334 | ## that match $(2) using $(wildcard). Useful for seeing if |
| 335 | ## a given directory or one of its parents contains |
| 336 | ## a particular file. Returns the first match found, |
| 337 | ## starting furthest from the root. |
| 338 | ########################################################### |
| 339 | |
| 340 | define find-parent-file |
| 341 | $(strip \ |
Ying Wang | a67ce69 | 2011-03-03 13:29:38 -0800 | [diff] [blame] | 342 | $(eval _fpf := $(wildcard $(foreach f, $(2), $(strip $(1))/$(f)))) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 343 | $(if $(_fpf),$(_fpf), \ |
| 344 | $(if $(filter-out ./ .,$(1)), \ |
| 345 | $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \ |
| 346 | ) \ |
| 347 | ) \ |
| 348 | ) |
| 349 | endef |
| 350 | |
| 351 | ########################################################### |
| 352 | ## Function we can evaluate to introduce a dynamic dependency |
| 353 | ########################################################### |
| 354 | |
| 355 | define add-dependency |
| 356 | $(1): $(2) |
| 357 | endef |
| 358 | |
| 359 | ########################################################### |
| 360 | ## Set up the dependencies for a prebuilt target |
| 361 | ## $(call add-prebuilt-file, srcfile, [targetclass]) |
| 362 | ########################################################### |
| 363 | |
| 364 | define add-prebuilt-file |
| 365 | $(eval $(include-prebuilt)) |
| 366 | endef |
| 367 | |
| 368 | define include-prebuilt |
| 369 | include $$(CLEAR_VARS) |
| 370 | LOCAL_SRC_FILES := $(1) |
| 371 | LOCAL_BUILT_MODULE_STEM := $(1) |
| 372 | LOCAL_MODULE_SUFFIX := $$(suffix $(1)) |
| 373 | LOCAL_MODULE := $$(basename $(1)) |
| 374 | LOCAL_MODULE_CLASS := $(2) |
| 375 | include $$(BUILD_PREBUILT) |
| 376 | endef |
| 377 | |
| 378 | ########################################################### |
| 379 | ## do multiple prebuilts |
| 380 | ## $(call target class, files ...) |
| 381 | ########################################################### |
| 382 | |
| 383 | define add-prebuilt-files |
| 384 | $(foreach f,$(2),$(call add-prebuilt-file,$f,$(1))) |
| 385 | endef |
| 386 | |
| 387 | |
| 388 | |
| 389 | ########################################################### |
| 390 | ## The intermediates directory. Where object files go for |
| 391 | ## a given target. We could technically get away without |
| 392 | ## the "_intermediates" suffix on the directory, but it's |
| 393 | ## nice to be able to grep for that string to find out if |
| 394 | ## anyone's abusing the system. |
| 395 | ########################################################### |
| 396 | |
| 397 | # $(1): target class, like "APPS" |
| 398 | # $(2): target name, like "NotePad" |
| 399 | # $(3): if non-empty, this is a HOST target. |
| 400 | # $(4): if non-empty, force the intermediates to be COMMON |
| 401 | define intermediates-dir-for |
| 402 | $(strip \ |
| 403 | $(eval _idfClass := $(strip $(1))) \ |
| 404 | $(if $(_idfClass),, \ |
| 405 | $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \ |
| 406 | $(eval _idfName := $(strip $(2))) \ |
| 407 | $(if $(_idfName),, \ |
| 408 | $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \ |
| 409 | $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \ |
Ying Wang | a83940f | 2010-09-24 18:09:04 -0700 | [diff] [blame] | 410 | $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 411 | $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \ |
| 412 | , \ |
| 413 | $(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \ |
| 414 | ) \ |
| 415 | $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \ |
| 416 | ) |
| 417 | endef |
| 418 | |
| 419 | # Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE |
| 420 | # to determine the intermediates directory. |
| 421 | # |
| 422 | # $(1): if non-empty, force the intermediates to be COMMON |
| 423 | define local-intermediates-dir |
| 424 | $(strip \ |
| 425 | $(if $(strip $(LOCAL_MODULE_CLASS)),, \ |
| 426 | $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \ |
| 427 | $(if $(strip $(LOCAL_MODULE)),, \ |
| 428 | $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \ |
| 429 | $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \ |
| 430 | ) |
| 431 | endef |
| 432 | |
| 433 | ########################################################### |
| 434 | ## Convert "path/to/libXXX.so" to "-lXXX". |
| 435 | ## Any "path/to/libXXX.a" elements pass through unchanged. |
| 436 | ########################################################### |
| 437 | |
| 438 | define normalize-libraries |
| 439 | $(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\ |
| 440 | $(filter-out %.so,$(1)) |
| 441 | endef |
| 442 | |
| 443 | # TODO: change users to call the common version. |
| 444 | define normalize-host-libraries |
| 445 | $(call normalize-libraries,$(1)) |
| 446 | endef |
| 447 | |
| 448 | define normalize-target-libraries |
| 449 | $(call normalize-libraries,$(1)) |
| 450 | endef |
| 451 | |
| 452 | ########################################################### |
| 453 | ## Convert a list of short module names (e.g., "framework", "Browser") |
| 454 | ## into the list of files that are built for those modules. |
| 455 | ## NOTE: this won't return reliable results until after all |
| 456 | ## sub-makefiles have been included. |
| 457 | ## $(1): target list |
| 458 | ########################################################### |
| 459 | |
| 460 | define module-built-files |
| 461 | $(foreach module,$(1),$(ALL_MODULES.$(module).BUILT)) |
| 462 | endef |
| 463 | |
| 464 | ########################################################### |
| 465 | ## Convert a list of short modules names (e.g., "framework", "Browser") |
| 466 | ## into the list of files that are installed for those modules. |
| 467 | ## NOTE: this won't return reliable results until after all |
| 468 | ## sub-makefiles have been included. |
| 469 | ## $(1): target list |
| 470 | ########################################################### |
| 471 | |
| 472 | define module-installed-files |
| 473 | $(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED)) |
| 474 | endef |
| 475 | |
| 476 | ########################################################### |
Joe Onorato | 64d85d0 | 2009-04-09 19:31:12 -0700 | [diff] [blame] | 477 | ## Convert a list of short modules names (e.g., "framework", "Browser") |
| 478 | ## into the list of files that should be used when linking |
| 479 | ## against that module as a public API. |
| 480 | ## TODO: Allow this for more than JAVA_LIBRARIES modules |
| 481 | ## NOTE: this won't return reliable results until after all |
| 482 | ## sub-makefiles have been included. |
| 483 | ## $(1): target list |
| 484 | ########################################################### |
| 485 | |
| 486 | define module-stubs-files |
| 487 | $(foreach module,$(1),$(ALL_MODULES.$(module).STUBS)) |
| 488 | endef |
| 489 | |
| 490 | ########################################################### |
| 491 | ## Evaluates to the timestamp file for a doc module, which |
| 492 | ## is the dependency that should be used. |
| 493 | ## $(1): doc module |
| 494 | ########################################################### |
| 495 | |
| 496 | define doc-timestamp-for |
| 497 | $(OUT_DOCS)/$(strip $(1))-timestamp |
| 498 | endef |
| 499 | |
| 500 | |
| 501 | ########################################################### |
Ying Wang | 912f828 | 2010-09-28 17:27:56 -0700 | [diff] [blame] | 502 | ## Convert "core ext framework" to "out/.../javalib.jar ..." |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 503 | ## $(1): library list |
| 504 | ## $(2): Non-empty if IS_HOST_MODULE |
| 505 | ########################################################### |
| 506 | |
| 507 | # $(1): library name |
| 508 | # $(2): Non-empty if IS_HOST_MODULE |
| 509 | define _java-lib-dir |
| 510 | $(call intermediates-dir-for, \ |
Ying Wang | 912f828 | 2010-09-28 17:27:56 -0700 | [diff] [blame] | 511 | JAVA_LIBRARIES,$(1),$(2),COMMON) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 512 | endef |
| 513 | |
| 514 | # $(1): library name |
| 515 | # $(2): Non-empty if IS_HOST_MODULE |
| 516 | define _java-lib-full-classes.jar |
Ying Wang | 912f828 | 2010-09-28 17:27:56 -0700 | [diff] [blame] | 517 | $(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 518 | endef |
| 519 | |
| 520 | # $(1): library name list |
| 521 | # $(2): Non-empty if IS_HOST_MODULE |
| 522 | define java-lib-files |
| 523 | $(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2))) |
| 524 | endef |
| 525 | |
| 526 | # $(1): library name |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 527 | # $(2): Non-empty if IS_HOST_MODULE |
| 528 | define _java-lib-full-dep |
Ying Wang | 912f828 | 2010-09-28 17:27:56 -0700 | [diff] [blame] | 529 | $(call _java-lib-dir,$(1),$(2))/javalib$(COMMON_JAVA_PACKAGE_SUFFIX) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 530 | endef |
| 531 | |
| 532 | # $(1): library name list |
| 533 | # $(2): Non-empty if IS_HOST_MODULE |
| 534 | define java-lib-deps |
| 535 | $(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2))) |
| 536 | endef |
| 537 | |
| 538 | ########################################################### |
Joe Onorato | 8dc8faa | 2010-09-14 13:09:48 -0400 | [diff] [blame] | 539 | ## Run rot13 on a string |
| 540 | ## $(1): the string. Must be one line. |
| 541 | ########################################################### |
| 542 | define rot13 |
| 543 | $(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M') |
| 544 | endef |
| 545 | |
| 546 | |
| 547 | ########################################################### |
| 548 | ## Returns true if $(1) and $(2) are equal. Returns |
| 549 | ## the empty string if they are not equal. |
| 550 | ########################################################### |
| 551 | define streq |
| 552 | $(strip $(if $(strip $(1)),\ |
| 553 | $(if $(strip $(2)),\ |
| 554 | $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \ |
| 555 | ),\ |
| 556 | $(if $(strip $(2)),\ |
| 557 | ,\ |
| 558 | true)\ |
| 559 | )) |
| 560 | endef |
| 561 | |
| 562 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 563 | ## Convert "a b c" into "a:b:c" |
| 564 | ########################################################### |
| 565 | |
| 566 | empty := |
| 567 | space := $(empty) $(empty) |
| 568 | |
| 569 | define normalize-path-list |
| 570 | $(subst $(space),:,$(strip $(1))) |
| 571 | endef |
| 572 | |
| 573 | ########################################################### |
Joe Onorato | 64d85d0 | 2009-04-09 19:31:12 -0700 | [diff] [blame] | 574 | ## Read the word out of a colon-separated list of words. |
| 575 | ## This has the same behavior as the built-in function |
| 576 | ## $(word n,str). |
| 577 | ## |
| 578 | ## The individual words may not contain spaces. |
| 579 | ## |
| 580 | ## $(1): 1 based index |
| 581 | ## $(2): value of the form a:b:c... |
| 582 | ########################################################### |
| 583 | |
| 584 | define word-colon |
| 585 | $(word $(1),$(subst :,$(space),$(2))) |
| 586 | endef |
| 587 | |
| 588 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 589 | ## Convert "a=b c= d e = f" into "a=b c=d e=f" |
| 590 | ## |
| 591 | ## $(1): list to collapse |
| 592 | ## $(2): if set, separator word; usually "=", ":", or ":=" |
| 593 | ## Defaults to "=" if not set. |
| 594 | ########################################################### |
| 595 | |
| 596 | define collapse-pairs |
| 597 | $(eval _cpSEP := $(strip $(if $(2),$(2),=)))\ |
| 598 | $(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \ |
| 599 | $(subst $(_cpSEP), $(_cpSEP) ,$(1)))) |
| 600 | endef |
| 601 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 602 | ########################################################### |
Ying Wang | 7e8d442 | 2011-06-17 17:05:35 -0700 | [diff] [blame] | 603 | ## Given a list of pairs, if multiple pairs have the same |
| 604 | ## first components, keep only the first pair. |
| 605 | ## |
| 606 | ## $(1): list of pairs |
| 607 | ## $(2): the separator word, such as ":", "=", etc. |
| 608 | define uniq-pairs-by-first-component |
| 609 | $(eval _upbfc_fc_set :=)\ |
| 610 | $(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\ |
| 611 | $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\ |
| 612 | $(eval _upbfc_fc_set += $(_first)))))\ |
| 613 | $(eval _upbfc_fc_set :=)\ |
| 614 | $(eval _first:=) |
| 615 | endef |
| 616 | |
| 617 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 618 | ## MODULE_TAG set operations |
| 619 | ########################################################### |
| 620 | |
| 621 | # Given a list of tags, return the targets that specify |
| 622 | # any of those tags. |
| 623 | # $(1): tag list |
| 624 | define modules-for-tag-list |
| 625 | $(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag)))) |
| 626 | endef |
| 627 | |
| 628 | # Same as modules-for-tag-list, but operates on |
| 629 | # ALL_MODULE_NAME_TAGS. |
| 630 | # $(1): tag list |
| 631 | define module-names-for-tag-list |
| 632 | $(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag)))) |
| 633 | endef |
| 634 | |
| 635 | # Given an accept and reject list, find the matching |
| 636 | # set of targets. If a target has multiple tags and |
| 637 | # any of them are rejected, the target is rejected. |
| 638 | # Reject overrides accept. |
| 639 | # $(1): list of tags to accept |
| 640 | # $(2): list of tags to reject |
| 641 | #TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS)) |
Jean-Baptiste Queru | 75127b7 | 2010-01-07 11:44:22 -0800 | [diff] [blame] | 642 | #TODO(jbq): as of 20100106 nobody uses the second parameter |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 643 | define get-tagged-modules |
| 644 | $(filter-out \ |
| 645 | $(call modules-for-tag-list,$(2)), \ |
| 646 | $(call modules-for-tag-list,$(1))) |
| 647 | endef |
| 648 | |
Joe Onorato | 64d85d0 | 2009-04-09 19:31:12 -0700 | [diff] [blame] | 649 | ########################################################### |
| 650 | ## Append a leaf to a base path. Properly deals with |
| 651 | ## base paths ending in /. |
| 652 | ## |
| 653 | ## $(1): base path |
| 654 | ## $(2): leaf path |
| 655 | ########################################################### |
| 656 | |
| 657 | define append-path |
| 658 | $(subst //,/,$(1)/$(2)) |
| 659 | endef |
| 660 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 661 | |
| 662 | ########################################################### |
| 663 | ## Package filtering |
| 664 | ########################################################### |
| 665 | |
| 666 | # Given a list of installed modules (short or long names) |
| 667 | # return a list of the packages (yes, .apk packages, not |
| 668 | # modules in general) that are overridden by this list and, |
| 669 | # therefore, should not be installed. |
| 670 | # $(1): mixed list of installed modules |
| 671 | # TODO: This is fragile; find a reliable way to get this information. |
| 672 | define _get-package-overrides |
| 673 | $(eval ### Discard any words containing slashes, unless they end in .apk, \ |
| 674 | ### in which case trim off the directory component and the suffix. \ |
| 675 | ### If there are no slashes, keep the entire word.) |
| 676 | $(eval _gpo_names := $(subst /,@@@ @@@,$(1))) |
| 677 | $(eval _gpo_names := \ |
| 678 | $(filter %.apk,$(_gpo_names)) \ |
| 679 | $(filter-out %@@@ @@@%,$(_gpo_names))) |
| 680 | $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names))) |
| 681 | $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names))) |
| 682 | |
| 683 | $(eval ### Remove any remaining words that contain dots.) |
| 684 | $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names))) |
| 685 | $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names))) |
| 686 | |
| 687 | $(eval ### Now we have a list of any words that could possibly refer to \ |
| 688 | ### packages, although there may be words that do not. Only \ |
| 689 | ### real packages will be present under PACKAGES.*, though.) |
| 690 | $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES)) |
| 691 | endef |
| 692 | |
| 693 | define get-package-overrides |
| 694 | $(strip $(sort $(call _get-package-overrides,$(1)))) |
| 695 | endef |
| 696 | |
| 697 | ########################################################### |
| 698 | ## Output the command lines, or not |
| 699 | ########################################################### |
| 700 | |
| 701 | ifeq ($(strip $(SHOW_COMMANDS)),) |
| 702 | define pretty |
| 703 | @echo $1 |
| 704 | endef |
| 705 | hide := @ |
| 706 | else |
| 707 | define pretty |
| 708 | endef |
| 709 | hide := |
| 710 | endif |
| 711 | |
| 712 | ########################################################### |
| 713 | ## Dump the variables that are associated with targets |
| 714 | ########################################################### |
| 715 | |
| 716 | define dump-module-variables |
| 717 | @echo all_dependencies=$^ |
| 718 | @echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS); |
| 719 | @echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS); |
| 720 | @echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS); |
| 721 | @echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS); |
| 722 | @echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES); |
| 723 | @echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS); |
| 724 | @echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS); |
| 725 | @echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS); |
| 726 | @echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS); |
| 727 | @echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS); |
Brian Carlstrom | f184a0f | 2010-02-01 11:13:32 -0800 | [diff] [blame] | 728 | @echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 729 | @echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES); |
| 730 | @echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES); |
| 731 | @echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES); |
| 732 | @echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES); |
| 733 | @echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS); |
Jeff Brown | 703e7c6 | 2011-02-04 20:15:00 -0800 | [diff] [blame] | 734 | @echo PRIVATE_NO_CRT=$(PRIVATE_NO_CRT); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 735 | endef |
| 736 | |
| 737 | ########################################################### |
| 738 | ## Commands for using sed to replace given variable values |
| 739 | ########################################################### |
| 740 | |
| 741 | define transform-variables |
| 742 | @mkdir -p $(dir $@) |
| 743 | @echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<" |
| 744 | $(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@ |
| 745 | $(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi |
| 746 | endef |
| 747 | |
| 748 | |
| 749 | ########################################################### |
| 750 | ## Commands for munging the dependency files GCC generates |
| 751 | ########################################################### |
| 752 | |
| 753 | define transform-d-to-p |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 754 | $(hide) cp $(@:%.o=%.d) $(@:%.o=%.P); \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 755 | sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ |
| 756 | -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ |
| 757 | rm -f $(@:%.o=%.d) |
| 758 | endef |
| 759 | |
| 760 | ########################################################### |
| 761 | ## Commands for running lex |
| 762 | ########################################################### |
| 763 | |
| 764 | define transform-l-to-cpp |
| 765 | @mkdir -p $(dir $@) |
| 766 | @echo "Lex: $(PRIVATE_MODULE) <= $<" |
| 767 | $(hide) $(LEX) -o$@ $< |
| 768 | endef |
| 769 | |
| 770 | ########################################################### |
| 771 | ## Commands for running yacc |
| 772 | ## |
| 773 | ## Because the extension of c++ files can change, the |
| 774 | ## extension must be specified in $1. |
| 775 | ## E.g, "$(call transform-y-to-cpp,.cpp)" |
| 776 | ########################################################### |
| 777 | |
| 778 | define transform-y-to-cpp |
| 779 | @mkdir -p $(dir $@) |
| 780 | @echo "Yacc: $(PRIVATE_MODULE) <= $<" |
| 781 | $(YACC) $(PRIVATE_YACCFLAGS) -o $@ $< |
| 782 | touch $(@:$1=$(YACC_HEADER_SUFFIX)) |
| 783 | echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h) |
| 784 | echo '#define '$(@F:$1=_h) >> $(@:$1=.h) |
| 785 | cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h) |
| 786 | echo '#endif' >> $(@:$1=.h) |
| 787 | rm -f $(@:$1=$(YACC_HEADER_SUFFIX)) |
| 788 | endef |
| 789 | |
Ying Wang | 0bd59a0 | 2010-07-15 17:17:52 -0700 | [diff] [blame] | 790 | ########################################################### |
| 791 | ## Commands to compile RenderScript |
| 792 | ########################################################### |
Ying Wang | 0bd59a0 | 2010-07-15 17:17:52 -0700 | [diff] [blame] | 793 | |
| 794 | define transform-renderscripts-to-java-and-bc |
| 795 | @echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)" |
| 796 | $(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR) |
| 797 | $(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw |
| 798 | $(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src |
Ying Wang | 7d83ef8 | 2011-05-25 17:16:22 -0700 | [diff] [blame] | 799 | $(hide) $(PRIVATE_RS_CC) \ |
Ying Wang | ebfddaa | 2010-07-30 18:37:29 -0700 | [diff] [blame] | 800 | -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \ |
| 801 | -p $(PRIVATE_RS_OUTPUT_DIR)/src \ |
Ying Wang | 24e1c01 | 2010-10-07 18:57:57 -0700 | [diff] [blame] | 802 | -d $(PRIVATE_RS_OUTPUT_DIR) \ |
| 803 | -a $@ -MD \ |
Stephen Hines | c963eae | 2011-08-10 13:53:05 -0700 | [diff] [blame] | 804 | $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \ |
Ying Wang | 5128027 | 2010-09-01 13:28:52 -0700 | [diff] [blame] | 805 | $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \ |
Ying Wang | ebfddaa | 2010-07-30 18:37:29 -0700 | [diff] [blame] | 806 | $(PRIVATE_RS_SOURCE_FILES) |
Shih-wei Liao | c656030 | 2010-10-23 03:07:13 -0700 | [diff] [blame] | 807 | #$(hide) $(LLVM_RS_LINK) \ |
| 808 | # $(PRIVATE_RS_OUTPUT_DIR)/res/raw/*.bc |
Ying Wang | 0bd59a0 | 2010-07-15 17:17:52 -0700 | [diff] [blame] | 809 | $(hide) mkdir -p $(dir $@) |
| 810 | $(hide) touch $@ |
| 811 | endef |
| 812 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 813 | |
| 814 | ########################################################### |
| 815 | ## Commands for running aidl |
| 816 | ########################################################### |
| 817 | |
| 818 | define transform-aidl-to-java |
| 819 | @mkdir -p $(dir $@) |
| 820 | @echo "Aidl: $(PRIVATE_MODULE) <= $<" |
| 821 | $(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@ |
| 822 | endef |
| 823 | #$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@ |
| 824 | |
| 825 | |
Doug Zongker | 9bd4962 | 2009-11-30 14:28:59 -0800 | [diff] [blame] | 826 | ########################################################### |
| 827 | ## Commands for running java-event-log-tags.py |
| 828 | ########################################################### |
| 829 | |
| 830 | define transform-logtags-to-java |
| 831 | @mkdir -p $(dir $@) |
| 832 | @echo "logtags: $@ <= $<" |
Doug Zongker | abfbbe2 | 2010-02-16 14:32:08 -0800 | [diff] [blame] | 833 | $(hide) $(JAVATAGS) -o $@ $^ |
Doug Zongker | 9bd4962 | 2009-11-30 14:28:59 -0800 | [diff] [blame] | 834 | endef |
| 835 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 836 | |
| 837 | ########################################################### |
Ying Wang | a5fc87a | 2010-11-02 18:43:16 -0700 | [diff] [blame] | 838 | ## Commands for running protoc to compile .proto into .java |
| 839 | ########################################################### |
| 840 | |
| 841 | define transform-proto-to-java |
| 842 | @mkdir -p $(dir $@) |
| 843 | @echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)" |
| 844 | @rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR) |
| 845 | @mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR) |
| 846 | $(hide) $(PROTOC) \ |
| 847 | $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \ |
| 848 | $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)=$(PRIVATE_PROTO_JAVA_OUTPUT_DIR) \ |
Ying Wang | 33c0d95 | 2010-11-05 11:30:58 -0700 | [diff] [blame] | 849 | $(PRIVATE_PROTOC_FLAGS) \ |
Ying Wang | a5fc87a | 2010-11-02 18:43:16 -0700 | [diff] [blame] | 850 | $(PRIVATE_PROTO_SRC_FILES) |
| 851 | $(hide) touch $@ |
| 852 | endef |
| 853 | |
| 854 | ###################################################################### |
| 855 | ## Commands for running protoc to compile .proto into .pb.cc and .pb.h |
| 856 | ###################################################################### |
| 857 | define transform-proto-to-cc |
| 858 | @mkdir -p $(dir $@) |
| 859 | @echo "Protoc: $@ <= $<" |
| 860 | $(hide) $(PROTOC) \ |
| 861 | $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \ |
Ying Wang | 33c0d95 | 2010-11-05 11:30:58 -0700 | [diff] [blame] | 862 | $(PRIVATE_PROTOC_FLAGS) \ |
Ying Wang | a5fc87a | 2010-11-02 18:43:16 -0700 | [diff] [blame] | 863 | --cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $< |
| 864 | endef |
| 865 | |
| 866 | |
| 867 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 868 | ## Commands for running gcc to compile a C++ file |
| 869 | ########################################################### |
| 870 | |
| 871 | define transform-cpp-to-o |
| 872 | @mkdir -p $(dir $@) |
| 873 | @echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<" |
| 874 | $(hide) $(PRIVATE_CXX) \ |
Ying Wang | ddbcad8 | 2011-04-18 11:45:44 -0700 | [diff] [blame] | 875 | $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ |
Ying Wang | 4761e56 | 2011-04-12 11:06:35 -0700 | [diff] [blame] | 876 | $(addprefix -isystem ,\ |
| 877 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
| 878 | $(filter-out $(PRIVATE_C_INCLUDES), \ |
Ying Wang | ddbcad8 | 2011-04-18 11:45:44 -0700 | [diff] [blame] | 879 | $(PRIVATE_TARGET_PROJECT_INCLUDES) \ |
Ying Wang | 4761e56 | 2011-04-12 11:06:35 -0700 | [diff] [blame] | 880 | $(PRIVATE_TARGET_C_INCLUDES)))) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 881 | -c \ |
| 882 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 883 | $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ |
| 884 | $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 885 | $(PRIVATE_ARM_CFLAGS) \ |
| 886 | ) \ |
Doug Kwan | 9a8ecf9 | 2011-05-10 21:50:58 -0700 | [diff] [blame] | 887 | $(PRIVATE_RTTI_FLAG) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 888 | $(PRIVATE_CFLAGS) \ |
| 889 | $(PRIVATE_CPPFLAGS) \ |
| 890 | $(PRIVATE_DEBUG_CFLAGS) \ |
| 891 | -MD -o $@ $< |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 892 | $(transform-d-to-p) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 893 | endef |
| 894 | |
| 895 | |
| 896 | ########################################################### |
| 897 | ## Commands for running gcc to compile a C file |
| 898 | ########################################################### |
| 899 | |
| 900 | # $(1): extra flags |
| 901 | define transform-c-or-s-to-o-no-deps |
| 902 | @mkdir -p $(dir $@) |
| 903 | $(hide) $(PRIVATE_CC) \ |
Ying Wang | ddbcad8 | 2011-04-18 11:45:44 -0700 | [diff] [blame] | 904 | $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ |
Ying Wang | 4761e56 | 2011-04-12 11:06:35 -0700 | [diff] [blame] | 905 | $(addprefix -isystem ,\ |
| 906 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
| 907 | $(filter-out $(PRIVATE_C_INCLUDES), \ |
Ying Wang | ddbcad8 | 2011-04-18 11:45:44 -0700 | [diff] [blame] | 908 | $(PRIVATE_TARGET_PROJECT_INCLUDES) \ |
Ying Wang | 4761e56 | 2011-04-12 11:06:35 -0700 | [diff] [blame] | 909 | $(PRIVATE_TARGET_C_INCLUDES)))) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 910 | -c \ |
| 911 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 912 | $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 913 | $(PRIVATE_ARM_CFLAGS) \ |
| 914 | ) \ |
| 915 | $(PRIVATE_CFLAGS) \ |
| 916 | $(1) \ |
| 917 | $(PRIVATE_DEBUG_CFLAGS) \ |
| 918 | -MD -o $@ $< |
| 919 | endef |
| 920 | |
| 921 | define transform-c-to-o-no-deps |
| 922 | @echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<" |
| 923 | $(call transform-c-or-s-to-o-no-deps, ) |
| 924 | endef |
| 925 | |
| 926 | define transform-s-to-o-no-deps |
| 927 | @echo "target asm: $(PRIVATE_MODULE) <= $<" |
| 928 | $(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS)) |
| 929 | endef |
| 930 | |
| 931 | define transform-c-to-o |
| 932 | $(transform-c-to-o-no-deps) |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 933 | $(transform-d-to-p) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 934 | endef |
| 935 | |
| 936 | define transform-s-to-o |
| 937 | $(transform-s-to-o-no-deps) |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 938 | $(transform-d-to-p) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 939 | endef |
| 940 | |
| 941 | ########################################################### |
David 'Digit' Turner | 5dbb529 | 2009-05-14 16:00:09 +0200 | [diff] [blame] | 942 | ## Commands for running gcc to compile an Objective-C file |
| 943 | ## This should never happen for target builds but this |
| 944 | ## will error at build time. |
| 945 | ########################################################### |
| 946 | |
| 947 | define transform-m-to-o-no-deps |
| 948 | @echo "target ObjC: $(PRIVATE_MODULE) <= $<" |
| 949 | $(call transform-c-or-s-to-o-no-deps) |
| 950 | endef |
| 951 | |
| 952 | define transform-m-to-o |
| 953 | $(transform-m-to-o-no-deps) |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 954 | $(transform-d-to-p) |
David 'Digit' Turner | 5dbb529 | 2009-05-14 16:00:09 +0200 | [diff] [blame] | 955 | endef |
| 956 | |
| 957 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 958 | ## Commands for running gcc to compile a host C++ file |
| 959 | ########################################################### |
| 960 | |
| 961 | define transform-host-cpp-to-o |
| 962 | @mkdir -p $(dir $@) |
| 963 | @echo "host C++: $(PRIVATE_MODULE) <= $<" |
| 964 | $(hide) $(PRIVATE_CXX) \ |
Ying Wang | ddbcad8 | 2011-04-18 11:45:44 -0700 | [diff] [blame] | 965 | $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ |
| 966 | $(addprefix -isystem ,\ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 967 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
Ying Wang | ddbcad8 | 2011-04-18 11:45:44 -0700 | [diff] [blame] | 968 | $(filter-out $(PRIVATE_C_INCLUDES), \ |
| 969 | $(HOST_PROJECT_INCLUDES) \ |
| 970 | $(HOST_C_INCLUDES)))) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 971 | -c \ |
| 972 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
| 973 | $(HOST_GLOBAL_CFLAGS) \ |
| 974 | $(HOST_GLOBAL_CPPFLAGS) \ |
| 975 | ) \ |
| 976 | $(PRIVATE_CFLAGS) \ |
| 977 | $(PRIVATE_CPPFLAGS) \ |
| 978 | $(PRIVATE_DEBUG_CFLAGS) \ |
| 979 | -MD -o $@ $< |
| 980 | $(transform-d-to-p) |
| 981 | endef |
| 982 | |
| 983 | |
| 984 | ########################################################### |
| 985 | ## Commands for running gcc to compile a host C file |
| 986 | ########################################################### |
| 987 | |
| 988 | # $(1): extra flags |
| 989 | define transform-host-c-or-s-to-o-no-deps |
| 990 | @mkdir -p $(dir $@) |
| 991 | $(hide) $(PRIVATE_CC) \ |
Ying Wang | ddbcad8 | 2011-04-18 11:45:44 -0700 | [diff] [blame] | 992 | $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ |
| 993 | $(addprefix -isystem ,\ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 994 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
Ying Wang | ddbcad8 | 2011-04-18 11:45:44 -0700 | [diff] [blame] | 995 | $(filter-out $(PRIVATE_C_INCLUDES), \ |
| 996 | $(HOST_PROJECT_INCLUDES) \ |
| 997 | $(HOST_C_INCLUDES)))) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 998 | -c \ |
| 999 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
| 1000 | $(HOST_GLOBAL_CFLAGS) \ |
| 1001 | ) \ |
| 1002 | $(PRIVATE_CFLAGS) \ |
| 1003 | $(1) \ |
| 1004 | $(PRIVATE_DEBUG_CFLAGS) \ |
| 1005 | -MD -o $@ $< |
| 1006 | endef |
| 1007 | |
| 1008 | define transform-host-c-to-o-no-deps |
| 1009 | @echo "host C: $(PRIVATE_MODULE) <= $<" |
| 1010 | $(call transform-host-c-or-s-to-o-no-deps, ) |
| 1011 | endef |
| 1012 | |
| 1013 | define transform-host-s-to-o-no-deps |
| 1014 | @echo "host asm: $(PRIVATE_MODULE) <= $<" |
| 1015 | $(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS)) |
| 1016 | endef |
| 1017 | |
| 1018 | define transform-host-c-to-o |
| 1019 | $(transform-host-c-to-o-no-deps) |
| 1020 | $(transform-d-to-p) |
| 1021 | endef |
| 1022 | |
| 1023 | define transform-host-s-to-o |
| 1024 | $(transform-host-s-to-o-no-deps) |
| 1025 | $(transform-d-to-p) |
| 1026 | endef |
| 1027 | |
| 1028 | ########################################################### |
David 'Digit' Turner | 5dbb529 | 2009-05-14 16:00:09 +0200 | [diff] [blame] | 1029 | ## Commands for running gcc to compile a host Objective-C file |
| 1030 | ########################################################### |
| 1031 | |
| 1032 | define transform-host-m-to-o-no-deps |
| 1033 | @echo "host ObjC: $(PRIVATE_MODULE) <= $<" |
| 1034 | $(call transform-host-c-or-s-to-o-no-deps) |
| 1035 | endef |
| 1036 | |
David 'Digit' Turner | 5ca286d | 2011-02-11 16:19:31 +0100 | [diff] [blame] | 1037 | define transform-host-m-to-o |
David 'Digit' Turner | 5dbb529 | 2009-05-14 16:00:09 +0200 | [diff] [blame] | 1038 | $(transform-host-m-to-o-no-deps) |
| 1039 | $(transform-d-to-p) |
| 1040 | endef |
| 1041 | |
| 1042 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1043 | ## Commands for running ar |
| 1044 | ########################################################### |
| 1045 | |
Ying Wang | e4b24eb | 2010-05-27 11:55:39 -0700 | [diff] [blame] | 1046 | define _concat-if-arg2-not-empty |
| 1047 | $(if $(2),$(hide) $(1) $(2)) |
| 1048 | endef |
| 1049 | |
| 1050 | # Split long argument list into smaller groups and call the command repeatedly |
| 1051 | # |
| 1052 | # $(1): the command without arguments |
| 1053 | # $(2): the arguments |
| 1054 | define split-long-arguments |
| 1055 | $(call _concat-if-arg2-not-empty,$(1),$(wordlist 1,500,$(2))) |
| 1056 | $(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2))) |
| 1057 | $(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2))) |
| 1058 | $(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2))) |
| 1059 | $(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2))) |
| 1060 | $(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2))) |
| 1061 | $(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2))) |
| 1062 | endef |
| 1063 | |
Ying Wang | a02d3d9 | 2011-01-27 18:48:00 -0800 | [diff] [blame] | 1064 | # $(1): the full path of the source static library. |
| 1065 | define _extract-and-include-single-target-whole-static-lib |
| 1066 | @echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]" |
| 1067 | $(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ |
| 1068 | rm -rf $$ldir; \ |
| 1069 | mkdir -p $$ldir; \ |
| 1070 | filelist=; \ |
| 1071 | for f in `$(TARGET_AR) t $(1)`; do \ |
| 1072 | $(TARGET_AR) p $(1) $$f > $$ldir/$$f; \ |
| 1073 | filelist="$$filelist $$ldir/$$f"; \ |
| 1074 | done ; \ |
| 1075 | $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist |
| 1076 | |
| 1077 | endef |
| 1078 | |
Dan Bornstein | 3d02eac | 2009-10-21 11:12:56 -0700 | [diff] [blame] | 1079 | define extract-and-include-target-whole-static-libs |
Dima Zavin | 46e9bec | 2009-05-27 19:41:07 -0700 | [diff] [blame] | 1080 | $(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \ |
Ying Wang | a02d3d9 | 2011-01-27 18:48:00 -0800 | [diff] [blame] | 1081 | $(call _extract-and-include-single-target-whole-static-lib, $(lib))) |
Dima Zavin | 46e9bec | 2009-05-27 19:41:07 -0700 | [diff] [blame] | 1082 | endef |
| 1083 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1084 | # Explicitly delete the archive first so that ar doesn't |
| 1085 | # try to add to an existing archive. |
| 1086 | define transform-o-to-static-lib |
| 1087 | @mkdir -p $(dir $@) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1088 | @rm -f $@ |
Dan Bornstein | 3d02eac | 2009-10-21 11:12:56 -0700 | [diff] [blame] | 1089 | $(extract-and-include-target-whole-static-libs) |
Dima Zavin | 46e9bec | 2009-05-27 19:41:07 -0700 | [diff] [blame] | 1090 | @echo "target StaticLib: $(PRIVATE_MODULE) ($@)" |
Ying Wang | e4b24eb | 2010-05-27 11:55:39 -0700 | [diff] [blame] | 1091 | $(call split-long-arguments,$(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1092 | endef |
| 1093 | |
| 1094 | ########################################################### |
| 1095 | ## Commands for running host ar |
| 1096 | ########################################################### |
| 1097 | |
Ying Wang | a02d3d9 | 2011-01-27 18:48:00 -0800 | [diff] [blame] | 1098 | # $(1): the full path of the source static library. |
| 1099 | define _extract-and-include-single-host-whole-static-lib |
| 1100 | @echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]" |
| 1101 | $(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ |
| 1102 | rm -rf $$ldir; \ |
| 1103 | mkdir -p $$ldir; \ |
| 1104 | filelist=; \ |
| 1105 | for f in `$(HOST_AR) t $(1) | grep '\.o$$'`; do \ |
| 1106 | $(HOST_AR) p $(1) $$f > $$ldir/$$f; \ |
| 1107 | filelist="$$filelist $$ldir/$$f"; \ |
| 1108 | done ; \ |
| 1109 | $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist |
| 1110 | |
| 1111 | endef |
| 1112 | |
Dan Bornstein | 3d02eac | 2009-10-21 11:12:56 -0700 | [diff] [blame] | 1113 | define extract-and-include-host-whole-static-libs |
| 1114 | $(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \ |
Ying Wang | a02d3d9 | 2011-01-27 18:48:00 -0800 | [diff] [blame] | 1115 | $(call _extract-and-include-single-host-whole-static-lib, $(lib))) |
Dan Bornstein | 3d02eac | 2009-10-21 11:12:56 -0700 | [diff] [blame] | 1116 | endef |
| 1117 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1118 | # Explicitly delete the archive first so that ar doesn't |
| 1119 | # try to add to an existing archive. |
| 1120 | define transform-host-o-to-static-lib |
| 1121 | @mkdir -p $(dir $@) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1122 | @rm -f $@ |
Dan Bornstein | 3d02eac | 2009-10-21 11:12:56 -0700 | [diff] [blame] | 1123 | $(extract-and-include-host-whole-static-libs) |
Dan Bornstein | 6bffc91 | 2009-10-15 13:01:36 -0700 | [diff] [blame] | 1124 | @echo "host StaticLib: $(PRIVATE_MODULE) ($@)" |
Ying Wang | e4b24eb | 2010-05-27 11:55:39 -0700 | [diff] [blame] | 1125 | $(call split-long-arguments,$(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1126 | endef |
| 1127 | |
| 1128 | |
| 1129 | ########################################################### |
| 1130 | ## Commands for running gcc to link a shared library or package |
| 1131 | ########################################################### |
| 1132 | |
| 1133 | # ld just seems to be so finicky with command order that we allow |
| 1134 | # it to be overriden en-masse see combo/linux-arm.make for an example. |
| 1135 | ifneq ($(HOST_CUSTOM_LD_COMMAND),true) |
| 1136 | define transform-host-o-to-shared-lib-inner |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1137 | $(hide) $(PRIVATE_CXX) \ |
Ying Wang | 80e6cce | 2011-01-24 23:25:36 -0800 | [diff] [blame] | 1138 | -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1139 | -Wl,-rpath,\$$ORIGIN/../lib \ |
| 1140 | -shared -Wl,-soname,$(notdir $@) \ |
| 1141 | $(PRIVATE_LDFLAGS) \ |
| 1142 | $(HOST_GLOBAL_LD_DIRS) \ |
| 1143 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
| 1144 | $(HOST_GLOBAL_LDFLAGS) \ |
| 1145 | ) \ |
| 1146 | $(PRIVATE_ALL_OBJECTS) \ |
| 1147 | -Wl,--whole-archive \ |
| 1148 | $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ |
| 1149 | -Wl,--no-whole-archive \ |
Ying Wang | fcdabd4 | 2011-04-25 14:22:41 -0700 | [diff] [blame] | 1150 | $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1151 | $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ |
Ying Wang | fcdabd4 | 2011-04-25 14:22:41 -0700 | [diff] [blame] | 1152 | $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1153 | $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ |
| 1154 | -o $@ \ |
| 1155 | $(PRIVATE_LDLIBS) |
| 1156 | endef |
| 1157 | endif |
| 1158 | |
| 1159 | define transform-host-o-to-shared-lib |
| 1160 | @mkdir -p $(dir $@) |
| 1161 | @echo "host SharedLib: $(PRIVATE_MODULE) ($@)" |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1162 | $(transform-host-o-to-shared-lib-inner) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1163 | endef |
| 1164 | |
| 1165 | define transform-host-o-to-package |
| 1166 | @mkdir -p $(dir $@) |
| 1167 | @echo "host Package: $(PRIVATE_MODULE) ($@)" |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1168 | $(transform-host-o-to-shared-lib-inner) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1169 | endef |
| 1170 | |
| 1171 | |
| 1172 | ########################################################### |
| 1173 | ## Commands for running gcc to link a shared library or package |
| 1174 | ########################################################### |
| 1175 | |
| 1176 | #echo >$@.vers "{"; \ |
| 1177 | #echo >>$@.vers " global:"; \ |
| 1178 | #$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \ |
| 1179 | #echo >>$@.vers " local:"; \ |
| 1180 | #echo >>$@.vers " *;"; \ |
| 1181 | #echo >>$@.vers "};"; \ |
| 1182 | |
| 1183 | # -Wl,--version-script=$@.vers \ |
| 1184 | |
| 1185 | # ld just seems to be so finicky with command order that we allow |
| 1186 | # it to be overriden en-masse see combo/linux-arm.make for an example. |
| 1187 | ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) |
| 1188 | define transform-o-to-shared-lib-inner |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1189 | $(hide) $(PRIVATE_CXX) \ |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 1190 | $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1191 | -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \ |
| 1192 | -Wl,-rpath,\$$ORIGIN/../lib \ |
| 1193 | -shared -Wl,-soname,$(notdir $@) \ |
| 1194 | $(PRIVATE_LDFLAGS) \ |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 1195 | $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1196 | $(PRIVATE_ALL_OBJECTS) \ |
| 1197 | -Wl,--whole-archive \ |
Ying Wang | 80e6cce | 2011-01-24 23:25:36 -0800 | [diff] [blame] | 1198 | $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1199 | -Wl,--no-whole-archive \ |
Ying Wang | fcdabd4 | 2011-04-25 14:22:41 -0700 | [diff] [blame] | 1200 | $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1201 | $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ |
Ying Wang | fcdabd4 | 2011-04-25 14:22:41 -0700 | [diff] [blame] | 1202 | $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1203 | $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ |
| 1204 | -o $@ \ |
| 1205 | $(PRIVATE_LDLIBS) |
| 1206 | endef |
| 1207 | endif |
| 1208 | |
| 1209 | define transform-o-to-shared-lib |
| 1210 | @mkdir -p $(dir $@) |
| 1211 | @echo "target SharedLib: $(PRIVATE_MODULE) ($@)" |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1212 | $(transform-o-to-shared-lib-inner) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1213 | endef |
| 1214 | |
| 1215 | define transform-o-to-package |
| 1216 | @mkdir -p $(dir $@) |
| 1217 | @echo "target Package: $(PRIVATE_MODULE) ($@)" |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1218 | $(transform-o-to-shared-lib-inner) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1219 | endef |
| 1220 | |
| 1221 | |
| 1222 | ########################################################### |
| 1223 | ## Commands for filtering a target executable or library |
| 1224 | ########################################################### |
| 1225 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1226 | define transform-to-stripped |
| 1227 | @mkdir -p $(dir $@) |
| 1228 | @echo "target Strip: $(PRIVATE_MODULE) ($@)" |
Bruce Beare | 45ac434 | 2010-06-24 14:02:00 -0700 | [diff] [blame] | 1229 | $(hide) $(TARGET_STRIP_COMMAND) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1230 | endef |
| 1231 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1232 | |
| 1233 | ########################################################### |
| 1234 | ## Commands for running gcc to link an executable |
| 1235 | ########################################################### |
| 1236 | |
| 1237 | ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) |
| 1238 | define transform-o-to-executable-inner |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1239 | $(hide) $(PRIVATE_CXX) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1240 | $(TARGET_GLOBAL_LDFLAGS) \ |
| 1241 | -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \ |
| 1242 | $(TARGET_GLOBAL_LD_DIRS) \ |
| 1243 | -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \ |
| 1244 | -Wl,-rpath,\$$ORIGIN/../lib \ |
| 1245 | $(PRIVATE_LDFLAGS) \ |
| 1246 | $(TARGET_GLOBAL_LD_DIRS) \ |
| 1247 | $(PRIVATE_ALL_OBJECTS) \ |
| 1248 | -Wl,--whole-archive \ |
| 1249 | $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ |
| 1250 | -Wl,--no-whole-archive \ |
Ying Wang | fcdabd4 | 2011-04-25 14:22:41 -0700 | [diff] [blame] | 1251 | $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1252 | $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ |
Ying Wang | fcdabd4 | 2011-04-25 14:22:41 -0700 | [diff] [blame] | 1253 | $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1254 | $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ |
| 1255 | -o $@ \ |
| 1256 | $(PRIVATE_LDLIBS) |
| 1257 | endef |
| 1258 | endif |
| 1259 | |
| 1260 | define transform-o-to-executable |
| 1261 | @mkdir -p $(dir $@) |
| 1262 | @echo "target Executable: $(PRIVATE_MODULE) ($@)" |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1263 | $(transform-o-to-executable-inner) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1264 | endef |
| 1265 | |
| 1266 | |
| 1267 | ########################################################### |
| 1268 | ## Commands for running gcc to link a statically linked |
| 1269 | ## executable. In practice, we only use this on arm, so |
| 1270 | ## the other platforms don't have the |
| 1271 | ## transform-o-to-static-executable defined |
| 1272 | ########################################################### |
| 1273 | |
| 1274 | ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) |
| 1275 | define transform-o-to-static-executable-inner |
| 1276 | endef |
| 1277 | endif |
| 1278 | |
| 1279 | define transform-o-to-static-executable |
| 1280 | @mkdir -p $(dir $@) |
| 1281 | @echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)" |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1282 | $(transform-o-to-static-executable-inner) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1283 | endef |
| 1284 | |
| 1285 | |
| 1286 | ########################################################### |
| 1287 | ## Commands for running gcc to link a host executable |
| 1288 | ########################################################### |
| 1289 | |
| 1290 | ifneq ($(HOST_CUSTOM_LD_COMMAND),true) |
| 1291 | define transform-host-o-to-executable-inner |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1292 | $(hide) $(PRIVATE_CXX) \ |
Ying Wang | 80e6cce | 2011-01-24 23:25:36 -0800 | [diff] [blame] | 1293 | -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1294 | -Wl,-rpath,\$$ORIGIN/../lib \ |
| 1295 | $(HOST_GLOBAL_LD_DIRS) \ |
| 1296 | $(PRIVATE_LDFLAGS) \ |
| 1297 | $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ |
| 1298 | $(HOST_GLOBAL_LDFLAGS) \ |
| 1299 | ) \ |
| 1300 | $(PRIVATE_ALL_OBJECTS) \ |
| 1301 | -Wl,--whole-archive \ |
| 1302 | $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ |
| 1303 | -Wl,--no-whole-archive \ |
Ying Wang | fcdabd4 | 2011-04-25 14:22:41 -0700 | [diff] [blame] | 1304 | $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1305 | $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ |
Ying Wang | fcdabd4 | 2011-04-25 14:22:41 -0700 | [diff] [blame] | 1306 | $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1307 | $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ |
| 1308 | -o $@ \ |
| 1309 | $(PRIVATE_LDLIBS) |
| 1310 | endef |
| 1311 | endif |
| 1312 | |
| 1313 | define transform-host-o-to-executable |
| 1314 | @mkdir -p $(dir $@) |
| 1315 | @echo "host Executable: $(PRIVATE_MODULE) ($@)" |
Ying Wang | 3a7e4cc | 2011-01-28 14:14:47 -0800 | [diff] [blame] | 1316 | $(transform-host-o-to-executable-inner) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1317 | endef |
| 1318 | |
| 1319 | |
| 1320 | ########################################################### |
| 1321 | ## Commands for running javac to make .class files |
| 1322 | ########################################################### |
| 1323 | |
| 1324 | #@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)" |
| 1325 | #@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')" |
| 1326 | |
| 1327 | # TODO: Right now we generate the asset resources twice, first as part |
| 1328 | # of generating the Java classes, then at the end when packaging the final |
| 1329 | # assets. This should be changed to do one of two things: (1) Don't generate |
| 1330 | # any resource files the first time, only create classes during that stage; |
| 1331 | # or (2) Don't use the -c flag with the second stage, instead taking the |
| 1332 | # resource files from the first stage as additional input. My original intent |
| 1333 | # was to use approach (2), but this requires a little more work in the tool. |
| 1334 | # Maybe we should just use approach (1). |
| 1335 | |
| 1336 | # This rule creates the R.java and Manifest.java files, both of which |
Ying Wang | 4f1ab92 | 2011-03-15 13:19:30 -0700 | [diff] [blame] | 1337 | # are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1338 | define create-resource-java-files |
| 1339 | @mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR) |
| 1340 | @mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) |
Ying Wang | c61d593 | 2010-03-10 16:02:42 -0800 | [diff] [blame] | 1341 | $(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \ |
Ying Wang | 4f1ab92 | 2011-03-15 13:19:30 -0700 | [diff] [blame] | 1342 | $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1343 | $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \ |
| 1344 | $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ |
| 1345 | $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \ |
| 1346 | $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ |
| 1347 | $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ |
Dianne Hackborn | 9bd5404 | 2009-05-15 18:01:20 -0700 | [diff] [blame] | 1348 | $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ |
Joe Onorato | 2daa2b3 | 2009-08-30 13:39:24 -0700 | [diff] [blame] | 1349 | $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \ |
Ying Wang | bb9c230 | 2011-04-08 17:27:35 -0700 | [diff] [blame] | 1350 | $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ |
| 1351 | $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ |
Ying Wang | 1ae607a | 2010-06-23 13:34:22 -0700 | [diff] [blame] | 1352 | $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \ |
Ying Wang | 8f5069b | 2010-06-29 11:08:13 -0700 | [diff] [blame] | 1353 | $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \ |
Ying Wang | 8c25482 | 2010-03-16 16:13:56 -0700 | [diff] [blame] | 1354 | $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ |
Ying Wang | 3dae0ee | 2010-09-02 15:41:01 -0700 | [diff] [blame] | 1355 | $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1356 | endef |
| 1357 | |
| 1358 | ifeq ($(HOST_OS),windows) |
| 1359 | xlint_unchecked := |
| 1360 | else |
Jeffrey Chyan | 7adbf97 | 2010-07-07 13:42:19 -0500 | [diff] [blame] | 1361 | xlint_unchecked := -Xlint:unchecked |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1362 | endif |
| 1363 | |
Brian Carlstrom | bb7c6d8 | 2011-04-01 15:45:58 -0700 | [diff] [blame] | 1364 | ifeq (true, $(ENABLE_INCREMENTALJAVAC)) |
| 1365 | incremental_dex := --incremental |
| 1366 | else |
| 1367 | incremental_dex := |
| 1368 | endif |
| 1369 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1370 | # emit-line, <word list>, <output file> |
| 1371 | define emit-line |
| 1372 | $(if $(1),echo -n '$(strip $(1)) ' >> $(2)) |
| 1373 | endef |
| 1374 | |
| 1375 | # dump-words-to-file, <word list>, <output file> |
| 1376 | define dump-words-to-file |
| 1377 | @rm -f $(2) |
| 1378 | @$(call emit-line,$(wordlist 1,200,$(1)),$(2)) |
| 1379 | @$(call emit-line,$(wordlist 201,400,$(1)),$(2)) |
| 1380 | @$(call emit-line,$(wordlist 401,600,$(1)),$(2)) |
| 1381 | @$(call emit-line,$(wordlist 601,800,$(1)),$(2)) |
| 1382 | @$(call emit-line,$(wordlist 801,1000,$(1)),$(2)) |
| 1383 | @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2)) |
| 1384 | @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2)) |
| 1385 | @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2)) |
| 1386 | @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2)) |
| 1387 | @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2)) |
| 1388 | @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2)) |
| 1389 | @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2)) |
| 1390 | @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2)) |
| 1391 | @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2)) |
| 1392 | @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2)) |
| 1393 | @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2)) |
| 1394 | @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2)) |
| 1395 | @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2)) |
| 1396 | @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2)) |
| 1397 | @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2)) |
Jesse Wilson | 72c941a | 2010-05-04 16:33:49 -0700 | [diff] [blame] | 1398 | @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2)) |
| 1399 | @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2)) |
| 1400 | @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2)) |
| 1401 | @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2)) |
| 1402 | @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2)) |
| 1403 | @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1))))) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1404 | endef |
| 1405 | |
| 1406 | # For a list of jar files, unzip them to a specified directory, |
| 1407 | # but make sure that no META-INF files come along for the ride. |
| 1408 | # |
| 1409 | # $(1): files to unzip |
| 1410 | # $(2): destination directory |
| 1411 | define unzip-jar-files |
| 1412 | $(hide) for f in $(1); \ |
| 1413 | do \ |
| 1414 | if [ ! -f $$f ]; then \ |
| 1415 | echo Missing file $$f; \ |
| 1416 | exit 1; \ |
| 1417 | fi; \ |
Sriram Raman | f1a55f8 | 2009-06-09 15:08:29 -0700 | [diff] [blame] | 1418 | unzip -qo $$f -d $(2); \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1419 | (cd $(2) && rm -rf META-INF); \ |
| 1420 | done |
| 1421 | endef |
| 1422 | |
Brian Carlstrom | 7826951 | 2010-12-10 12:10:24 -0800 | [diff] [blame] | 1423 | # Common definition to invoke javac on the host and target. |
| 1424 | # |
| 1425 | # Some historical notes: |
| 1426 | # - below we write the list of java files to java-source-list to avoid argument |
| 1427 | # list length problems with Cygwin |
| 1428 | # - we filter out duplicate java file names because eclipse's compiler |
| 1429 | # doesn't like them. |
| 1430 | # |
| 1431 | # $(1): javac |
| 1432 | # $(2): bootclasspath |
| 1433 | define compile-java |
Joe Onorato | 64d85d0 | 2009-04-09 19:31:12 -0700 | [diff] [blame] | 1434 | $(hide) rm -f $@ |
| 1435 | $(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) |
Brian Carlstrom | 7826951 | 2010-12-10 12:10:24 -0800 | [diff] [blame] | 1436 | $(hide) mkdir -p $(dir $@) |
Joe Onorato | 64d85d0 | 2009-04-09 19:31:12 -0700 | [diff] [blame] | 1437 | $(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) |
Brian Carlstrom | 7826951 | 2010-12-10 12:10:24 -0800 | [diff] [blame] | 1438 | $(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)) |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 1439 | $(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list) |
Joe Onorato | 64d85d0 | 2009-04-09 19:31:12 -0700 | [diff] [blame] | 1440 | $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 1441 | find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1442 | fi |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 1443 | $(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \ |
| 1444 | | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq |
Joe Onorato | 149dd91 | 2011-05-31 18:21:07 -0700 | [diff] [blame] | 1445 | $(hide) $(1) -encoding UTF-8 \ |
Brian Carlstrom | 7826951 | 2010-12-10 12:10:24 -0800 | [diff] [blame] | 1446 | $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \ |
| 1447 | $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \ |
| 1448 | $(2) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1449 | $(addprefix -classpath ,$(strip \ |
| 1450 | $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \ |
Brian Carlstrom | 7826951 | 2010-12-10 12:10:24 -0800 | [diff] [blame] | 1451 | $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1452 | -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ |
Brian Carlstrom | 7826951 | 2010-12-10 12:10:24 -0800 | [diff] [blame] | 1453 | $(PRIVATE_JAVACFLAGS) \ |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 1454 | \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1455 | || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 1456 | $(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list |
| 1457 | $(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1458 | $(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \ |
| 1459 | $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) . |
Brian Carlstrom | 7826951 | 2010-12-10 12:10:24 -0800 | [diff] [blame] | 1460 | endef |
| 1461 | |
| 1462 | define transform-java-to-classes.jar |
| 1463 | @echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" |
| 1464 | $(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH)) |
Joe Onorato | 64d85d0 | 2009-04-09 19:31:12 -0700 | [diff] [blame] | 1465 | $(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1466 | endef |
| 1467 | |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 1468 | # Override the above definitions if we want to do incremetal javac |
| 1469 | ifeq (true, $(ENABLE_INCREMENTALJAVAC)) |
| 1470 | define compile-java |
| 1471 | $(hide) mkdir -p $(dir $@) |
| 1472 | $(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) |
| 1473 | $(hide) touch $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp |
| 1474 | $(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)) |
| 1475 | $(hide) if [ -e $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp ] ; then \ |
| 1476 | newerFlag=$$(echo -n "-newer $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp") ; \ |
| 1477 | fi ; \ |
| 1478 | find $(PRIVATE_JAVA_SOURCES) $$newerFlag > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list ; \ |
| 1479 | if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ |
| 1480 | find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' $$newerFlag >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \ |
| 1481 | fi |
| 1482 | $(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \ |
| 1483 | | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq |
| 1484 | @echo "(Incremental) build source files:" |
| 1485 | @cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq |
| 1486 | $(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ |
Joe Onorato | 149dd91 | 2011-05-31 18:21:07 -0700 | [diff] [blame] | 1487 | $(1) -encoding UTF-8 \ |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 1488 | $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \ |
| 1489 | $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \ |
| 1490 | $(2) \ |
| 1491 | $(addprefix -classpath ,$(strip \ |
| 1492 | $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES) $(PRIVATE_CLASS_INTERMEDIATES_DIR)))) \ |
| 1493 | $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \ |
| 1494 | -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ |
| 1495 | $(PRIVATE_JAVACFLAGS) \ |
| 1496 | \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \ |
| 1497 | || ( exit 41 ) \ |
| 1498 | fi |
| 1499 | $(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list |
| 1500 | $(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq |
| 1501 | $(hide) rm -f $@ |
| 1502 | $(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \ |
| 1503 | $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) . |
| 1504 | $(hide) mv $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp |
| 1505 | endef |
| 1506 | |
| 1507 | define transform-java-to-classes.jar |
| 1508 | @echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" |
| 1509 | $(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH)) |
| 1510 | endef |
| 1511 | endif # ENABLE_INCREMENTALJAVAC |
| 1512 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1513 | define transform-classes.jar-to-emma |
| 1514 | $(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \ |
Guang Zhu | 155afe3 | 2010-03-10 15:48:03 -0800 | [diff] [blame] | 1515 | $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \ |
Guang Zhu | 9cd3d8c | 2010-06-15 13:31:25 -0700 | [diff] [blame] | 1516 | $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1517 | endef |
| 1518 | |
| 1519 | #TODO: use a smaller -Xmx value for most libraries; |
| 1520 | # only core.jar and framework.jar need a heap this big. |
Raphael | f6ff4c5 | 2009-08-18 14:43:32 -0700 | [diff] [blame] | 1521 | # Avoid the memory arguments on Windows, dx fails to load for some reason with them. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1522 | define transform-classes.jar-to-dex |
| 1523 | @echo "target Dex: $(PRIVATE_MODULE)" |
| 1524 | @mkdir -p $(dir $@) |
Raphael | f6ff4c5 | 2009-08-18 14:43:32 -0700 | [diff] [blame] | 1525 | $(hide) $(DX) \ |
| 1526 | $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1536M) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1527 | --dex --output=$@ \ |
Brian Carlstrom | bb7c6d8 | 2011-04-01 15:45:58 -0700 | [diff] [blame] | 1528 | $(incremental_dex) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1529 | $(if $(NO_OPTIMIZE_DX), \ |
| 1530 | --no-optimize) \ |
| 1531 | $(if $(GENERATE_DEX_DEBUG), \ |
| 1532 | --debug --verbose \ |
| 1533 | --dump-to=$(@:.dex=.lst) \ |
| 1534 | --dump-width=1000) \ |
| 1535 | $(PRIVATE_DX_FLAGS) \ |
| 1536 | $< |
| 1537 | endef |
| 1538 | |
| 1539 | # Create a mostly-empty .jar file that we'll add to later. |
| 1540 | # The MacOS jar tool doesn't like creating empty jar files, |
| 1541 | # so we need to give it something. |
| 1542 | define create-empty-package |
| 1543 | @mkdir -p $(dir $@) |
| 1544 | $(hide) touch $(dir $@)/dummy |
| 1545 | $(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy) |
| 1546 | $(hide) zip -qd $@ dummy |
| 1547 | $(hide) rm $(dir $@)/dummy |
| 1548 | endef |
| 1549 | |
| 1550 | #TODO: we kinda want to build different asset packages for |
| 1551 | # different configurations, then combine them later (or something). |
| 1552 | # Per-locale, etc. |
| 1553 | # A list of dynamic and static parameters; build layers for |
| 1554 | # dynamic params that lay over the static ones. |
| 1555 | #TODO: update the manifest to point to the package file |
Dianne Hackborn | 9bd5404 | 2009-05-15 18:01:20 -0700 | [diff] [blame] | 1556 | #Note that the version numbers are given to aapt as simple default |
| 1557 | #values; applications can override these by explicitly stating |
| 1558 | #them in their manifest. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1559 | define add-assets-to-package |
Ying Wang | c61d593 | 2010-03-10 16:02:42 -0800 | [diff] [blame] | 1560 | $(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \ |
Ying Wang | 4f1ab92 | 2011-03-15 13:19:30 -0700 | [diff] [blame] | 1561 | $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \ |
Dianne Hackborn | a0f464a | 2011-10-14 19:37:57 -0700 | [diff] [blame^] | 1562 | $(addprefix --preferred-configurations , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1563 | $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ |
| 1564 | $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ |
| 1565 | $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ |
| 1566 | $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ |
Ying Wang | bb9c230 | 2011-04-08 17:27:35 -0700 | [diff] [blame] | 1567 | $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ |
| 1568 | $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ |
Joe Onorato | 700b88e | 2010-10-05 17:33:58 -0400 | [diff] [blame] | 1569 | $(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS)) \ |
Ying Wang | 1ae607a | 2010-06-23 13:34:22 -0700 | [diff] [blame] | 1570 | $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \ |
Ying Wang | 8f5069b | 2010-06-29 11:08:13 -0700 | [diff] [blame] | 1571 | $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \ |
Jeff Hamilton | bb67d21 | 2010-02-05 22:36:42 -0600 | [diff] [blame] | 1572 | $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ |
Ying Wang | 3dae0ee | 2010-09-02 15:41:01 -0700 | [diff] [blame] | 1573 | $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1574 | -F $@ |
| 1575 | endef |
| 1576 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1577 | define add-jni-shared-libs-to-package |
| 1578 | $(hide) rm -rf $(dir $@)lib |
Jack Palevich | a0ab29b | 2010-06-18 15:38:07 +0800 | [diff] [blame] | 1579 | $(hide) mkdir -p $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI) |
| 1580 | $(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1581 | $(hide) (cd $(dir $@) && zip -r $(notdir $@) lib) |
| 1582 | $(hide) rm -rf $(dir $@)lib |
| 1583 | endef |
| 1584 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1585 | #TODO: update the manifest to point to the dex file |
| 1586 | define add-dex-to-package |
Ying Wang | 957fea5 | 2010-09-23 11:48:38 -0700 | [diff] [blame] | 1587 | $(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\ |
| 1588 | $(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE),\ |
| 1589 | $(eval _adtp_classes.dex := $(dir $(PRIVATE_DEX_FILE))/classes.dex)\ |
| 1590 | $(hide) cp $(PRIVATE_DEX_FILE) $(_adtp_classes.dex) && \ |
| 1591 | $(AAPT) add -k $@ $(_adtp_classes.dex) && \ |
| 1592 | rm -f $(_adtp_classes.dex)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1593 | endef |
| 1594 | |
| 1595 | define add-java-resources-to-package |
Ying Wang | 194a8ec | 2011-06-06 14:34:52 -0700 | [diff] [blame] | 1596 | $(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(dir $@)jar-arg-list) |
| 1597 | $(hide) jar uf $@ @$(dir $@)jar-arg-list |
| 1598 | @rm -f $(dir $@)jar-arg-list |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1599 | endef |
| 1600 | |
| 1601 | # Sign a package using the specified key/cert. |
| 1602 | # |
| 1603 | define sign-package |
| 1604 | $(hide) mv $@ $@.unsigned |
| 1605 | $(hide) java -jar $(SIGNAPK_JAR) \ |
| 1606 | $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) $@.unsigned $@.signed |
| 1607 | $(hide) mv $@.signed $@ |
| 1608 | endef |
| 1609 | |
| 1610 | # Align STORED entries of a package on 4-byte boundaries |
| 1611 | # to make them easier to mmap. |
| 1612 | # |
| 1613 | define align-package |
| 1614 | $(hide) mv $@ $@.unaligned |
| 1615 | $(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned |
| 1616 | $(hide) mv $@.aligned $@ |
| 1617 | endef |
| 1618 | |
| 1619 | define install-dex-debug |
| 1620 | $(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \ |
| 1621 | mkdir -p $(TOP)/dalvik/DEBUG-FILES; \ |
| 1622 | $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \ |
| 1623 | $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \ |
| 1624 | fi |
| 1625 | $(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \ |
| 1626 | mkdir -p $(TOP)/dalvik/DEBUG-FILES; \ |
| 1627 | $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \ |
| 1628 | $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \ |
| 1629 | fi |
| 1630 | endef |
| 1631 | |
| 1632 | # TODO(joeo): If we can ever upgrade to post 3.81 make and get the |
| 1633 | # new prebuilt rules to work, we should change this to copy the |
| 1634 | # resources to the out directory and then copy the resources. |
| 1635 | |
Brian Carlstrom | 7826951 | 2010-12-10 12:10:24 -0800 | [diff] [blame] | 1636 | # Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR |
| 1637 | # in transform-java-to-classes for the sake of vm-tests. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1638 | define transform-host-java-to-package |
| 1639 | @echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 1640 | $(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH)) |
Ying Wang | 194a8ec | 2011-06-06 14:34:52 -0700 | [diff] [blame] | 1641 | $(if $(PRIVATE_EXTRA_JAR_ARGS), $(call add-java-resources-to-package)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1642 | endef |
| 1643 | |
| 1644 | ########################################################### |
| 1645 | ## Obfuscate a jar file |
| 1646 | ########################################################### |
| 1647 | |
| 1648 | # PRIVATE_KEEP_FILE is a file containing a list of classes |
| 1649 | # PRIVATE_INTERMEDIATES_DIR is a directory we can use for temporary files |
| 1650 | # The module using this must depend on |
| 1651 | # $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar |
| 1652 | define obfuscate-jar |
| 1653 | @echo "Obfuscate jar: $(notdir $@) ($@)" |
| 1654 | @mkdir -p $(dir $@) |
| 1655 | @rm -f $@ |
| 1656 | @mkdir -p $(PRIVATE_INTERMEDIATES_DIR) |
| 1657 | $(hide) sed -e 's/^/-keep class /' < $(PRIVATE_KEEP_FILE) > \ |
| 1658 | $(PRIVATE_INTERMEDIATES_DIR)/keep.pro |
| 1659 | $(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \ |
| 1660 | -injars $< \ |
| 1661 | -outjars $@ \ |
| 1662 | -target 1.5 \ |
| 1663 | -dontnote -dontwarn \ |
| 1664 | -printmapping $(PRIVATE_INTERMEDIATES_DIR)/out.map \ |
| 1665 | -forceprocessing \ |
| 1666 | -renamesourcefileattribute SourceFile \ |
| 1667 | -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod \ |
| 1668 | -repackageclasses \ |
| 1669 | -keepclassmembers "class * { public protected *; }" \ |
| 1670 | @$(PRIVATE_INTERMEDIATES_DIR)/keep.pro |
| 1671 | endef |
| 1672 | |
| 1673 | ########################################################### |
| 1674 | ## Commands for copying files |
| 1675 | ########################################################### |
| 1676 | |
| 1677 | # Define a rule to copy a header. Used via $(eval) by copy_headers.make. |
| 1678 | # $(1): source header |
| 1679 | # $(2): destination header |
| 1680 | define copy-one-header |
| 1681 | $(2): $(1) |
| 1682 | @echo "Header: $$@" |
| 1683 | $$(copy-file-to-new-target-with-cp) |
| 1684 | endef |
| 1685 | |
| 1686 | # Define a rule to copy a file. For use via $(eval). |
| 1687 | # $(1): source file |
| 1688 | # $(2): destination file |
| 1689 | define copy-one-file |
| 1690 | $(2): $(1) | $(ACP) |
| 1691 | @echo "Copy: $$@" |
| 1692 | $$(copy-file-to-target) |
| 1693 | endef |
| 1694 | |
| 1695 | # The -t option to acp and the -p option to cp is |
| 1696 | # required for OSX. OSX has a ridiculous restriction |
| 1697 | # where it's an error for a .a file's modification time |
| 1698 | # to disagree with an internal timestamp, and this |
| 1699 | # macro is used to install .a files (among other things). |
| 1700 | |
| 1701 | # Copy a single file from one place to another, |
| 1702 | # preserving permissions and overwriting any existing |
| 1703 | # file. |
Ying Wang | 84ed6fa | 2011-01-18 17:21:20 -0800 | [diff] [blame] | 1704 | # We disable the "-t" option for acp can not handle |
| 1705 | # high resolution timestamp correctly on file systems like ext4. |
| 1706 | # Therefore copy-file-to-target is the same as copy-file-to-new-target. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1707 | define copy-file-to-target |
| 1708 | @mkdir -p $(dir $@) |
Ying Wang | 84ed6fa | 2011-01-18 17:21:20 -0800 | [diff] [blame] | 1709 | $(hide) $(ACP) -fp $< $@ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1710 | endef |
| 1711 | |
| 1712 | # The same as copy-file-to-target, but use the local |
| 1713 | # cp command instead of acp. |
| 1714 | define copy-file-to-target-with-cp |
| 1715 | @mkdir -p $(dir $@) |
| 1716 | $(hide) cp -fp $< $@ |
| 1717 | endef |
| 1718 | |
Dianne Hackborn | 9c0c4b7 | 2009-08-11 19:16:46 -0700 | [diff] [blame] | 1719 | # The same as copy-file-to-target, but use the zipalign tool to do so. |
| 1720 | define copy-file-to-target-with-zipalign |
| 1721 | @mkdir -p $(dir $@) |
| 1722 | $(hide) $(ZIPALIGN) -f 4 $< $@ |
| 1723 | endef |
| 1724 | |
Doug Zongker | 1046d20 | 2009-08-06 13:02:19 -0700 | [diff] [blame] | 1725 | # The same as copy-file-to-target, but strip out "# comment"-style |
| 1726 | # comments (for config files and such). |
| 1727 | define copy-file-to-target-strip-comments |
| 1728 | @mkdir -p $(dir $@) |
| 1729 | $(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@ |
| 1730 | endef |
| 1731 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1732 | # The same as copy-file-to-target, but don't preserve |
| 1733 | # the old modification time. |
| 1734 | define copy-file-to-new-target |
| 1735 | @mkdir -p $(dir $@) |
| 1736 | $(hide) $(ACP) -fp $< $@ |
| 1737 | endef |
| 1738 | |
| 1739 | # The same as copy-file-to-new-target, but use the local |
| 1740 | # cp command instead of acp. |
| 1741 | define copy-file-to-new-target-with-cp |
| 1742 | @mkdir -p $(dir $@) |
| 1743 | $(hide) cp -f $< $@ |
| 1744 | endef |
| 1745 | |
| 1746 | # Copy a prebuilt file to a target location. |
| 1747 | define transform-prebuilt-to-target |
| 1748 | @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)" |
| 1749 | $(copy-file-to-target) |
| 1750 | endef |
| 1751 | |
Dianne Hackborn | 9c0c4b7 | 2009-08-11 19:16:46 -0700 | [diff] [blame] | 1752 | # Copy a prebuilt file to a target location, using zipalign on it. |
| 1753 | define transform-prebuilt-to-target-with-zipalign |
| 1754 | @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)" |
| 1755 | $(copy-file-to-target-with-zipalign) |
| 1756 | endef |
| 1757 | |
Doug Zongker | 1046d20 | 2009-08-06 13:02:19 -0700 | [diff] [blame] | 1758 | # Copy a prebuilt file to a target location, stripping "# comment" comments. |
| 1759 | define transform-prebuilt-to-target-strip-comments |
| 1760 | @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)" |
| 1761 | $(copy-file-to-target-strip-comments) |
| 1762 | endef |
| 1763 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1764 | ########################################################### |
| 1765 | ## On some platforms (MacOS), after copying a static |
| 1766 | ## library, ranlib must be run to update an internal |
| 1767 | ## timestamp!?!?! |
| 1768 | ########################################################### |
| 1769 | |
| 1770 | ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true) |
| 1771 | define transform-host-ranlib-copy-hack |
| 1772 | $(hide) ranlib $@ || true |
| 1773 | endef |
| 1774 | else |
| 1775 | define transform-host-ranlib-copy-hack |
Patrick Scott | 0e27dff | 2010-05-07 08:37:11 -0400 | [diff] [blame] | 1776 | @true |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1777 | endef |
| 1778 | endif |
| 1779 | |
| 1780 | ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true) |
| 1781 | define transform-ranlib-copy-hack |
| 1782 | $(hide) ranlib $@ |
| 1783 | endef |
| 1784 | else |
| 1785 | define transform-ranlib-copy-hack |
Patrick Scott | 0e27dff | 2010-05-07 08:37:11 -0400 | [diff] [blame] | 1786 | @true |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1787 | endef |
| 1788 | endif |
| 1789 | |
| 1790 | |
| 1791 | ########################################################### |
Ying Wang | 3b2bdf1 | 2010-02-01 09:51:23 -0800 | [diff] [blame] | 1792 | ## Commands to call Proguard |
| 1793 | ########################################################### |
| 1794 | |
| 1795 | # Command to copy the file with acp, if proguard is disabled. |
| 1796 | define proguard-disabled-commands |
| 1797 | @echo Copying: $@ |
Ying Wang | 84ed6fa | 2011-01-18 17:21:20 -0800 | [diff] [blame] | 1798 | $(hide) $(ACP) -fp $< $@ |
Ying Wang | 3b2bdf1 | 2010-02-01 09:51:23 -0800 | [diff] [blame] | 1799 | endef |
| 1800 | |
| 1801 | # Command to call Proguard |
| 1802 | # $(1): extra flags for instrumentation. |
| 1803 | define proguard-enabled-commands |
| 1804 | @echo Proguard: $@ |
| 1805 | $(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) $(1) |
| 1806 | endef |
| 1807 | |
| 1808 | # Figure out the proguard dictionary file of the module that is instrumentationed for. |
| 1809 | define get-instrumentation-proguard-flags |
| 1810 | $(if $(PRIVATE_INSTRUMENTATION_FOR),$(if $(ALL_MODULES.$(PRIVATE_INSTRUMENTATION_FOR).PROGUARD_ENABLED),-applymapping $(call intermediates-dir-for,APPS,$(PRIVATE_INSTRUMENTATION_FOR),,COMMON)/proguard_dictionary)) |
| 1811 | endef |
| 1812 | |
| 1813 | define transform-jar-to-proguard |
| 1814 | $(eval _instrumentation_proguard_flags:=$(call get-instrumentation-proguard-flags)) |
| 1815 | $(eval _enable_proguard:=$(PRIVATE_PROGUARD_ENABLED)$(_instrumentation_proguard_flags)) |
| 1816 | $(if $(_enable_proguard),$(call proguard-enabled-commands,$(_instrumentation_proguard_flags)),$(call proguard-disabled-commands)) |
| 1817 | $(eval _instrumentation_proguard_flags:=) |
| 1818 | $(eval _enable_proguard:=) |
| 1819 | endef |
| 1820 | |
| 1821 | |
| 1822 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1823 | ## Stuff source generated from one-off tools |
| 1824 | ########################################################### |
| 1825 | |
| 1826 | define transform-generated-source |
| 1827 | @echo "target Generated: $(PRIVATE_MODULE) <= $<" |
| 1828 | @mkdir -p $(dir $@) |
| 1829 | $(hide) $(PRIVATE_CUSTOM_TOOL) |
| 1830 | endef |
| 1831 | |
| 1832 | |
| 1833 | ########################################################### |
| 1834 | ## Assertions about attributes of the target |
| 1835 | ########################################################### |
| 1836 | |
| 1837 | # $(1): The file to check |
| 1838 | ifndef get-file-size |
| 1839 | $(error HOST_OS must define get-file-size) |
| 1840 | endif |
| 1841 | |
Doug Zongker | 4647f12 | 2009-07-02 09:00:54 -0700 | [diff] [blame] | 1842 | # Convert a partition data size (eg, as reported in /proc/mtd) to the |
| 1843 | # size of the image used to flash that partition (which includes a |
Lars Svensson | 9cb8c28 | 2010-12-06 15:24:58 +0100 | [diff] [blame] | 1844 | # spare area for each page). |
Doug Zongker | 4647f12 | 2009-07-02 09:00:54 -0700 | [diff] [blame] | 1845 | # $(1): the partition data size |
| 1846 | define image-size-from-data-size |
Ying Wang | 4a2ecaf | 2011-02-09 17:24:27 -0800 | [diff] [blame] | 1847 | $(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \ |
| 1848 | ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\ |
| 1849 | $(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\ |
| 1850 | $(eval _isfds_value :=)) |
Doug Zongker | 4647f12 | 2009-07-02 09:00:54 -0700 | [diff] [blame] | 1851 | endef |
| 1852 | |
| 1853 | # $(1): The file(s) to check (often $@) |
| 1854 | # $(2): The maximum total image size, in decimal bytes |
Doug Zongker | 6dd2ae0 | 2009-08-25 17:23:57 -0700 | [diff] [blame] | 1855 | # $(3): the type of filesystem "yaffs" or "raw" |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1856 | # |
| 1857 | # If $(2) is empty, evaluates to "true" |
| 1858 | # |
| 1859 | # Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks) |
| 1860 | # is left over after the image has been flashed. Round the 1% up to the |
| 1861 | # next whole flash block size. |
| 1862 | define assert-max-file-size |
| 1863 | $(if $(2), \ |
Doug Zongker | 742fa57 | 2009-07-08 12:09:04 -0700 | [diff] [blame] | 1864 | size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \ |
| 1865 | total=$$(( $$( echo "$$size" ) )); \ |
Doug Zongker | 4647f12 | 2009-07-02 09:00:54 -0700 | [diff] [blame] | 1866 | printname=$$(echo -n "$(1)" | tr " " +); \ |
| 1867 | echo "$$printname total size is $$total"; \ |
| 1868 | img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \ |
Doug Zongker | 6dd2ae0 | 2009-08-25 17:23:57 -0700 | [diff] [blame] | 1869 | if [ "$(3)" == "yaffs" ]; then \ |
Doug Zongker | 93d9ff4 | 2009-09-14 17:46:41 -0700 | [diff] [blame] | 1870 | reservedblocks=8; \ |
Doug Zongker | 6dd2ae0 | 2009-08-25 17:23:57 -0700 | [diff] [blame] | 1871 | else \ |
Doug Zongker | 4ac1ba6 | 2009-08-25 20:38:50 -0700 | [diff] [blame] | 1872 | reservedblocks=0; \ |
Doug Zongker | 6dd2ae0 | 2009-08-25 17:23:57 -0700 | [diff] [blame] | 1873 | fi; \ |
Doug Zongker | 4647f12 | 2009-07-02 09:00:54 -0700 | [diff] [blame] | 1874 | twoblocks=$$((img_blocksize * 2)); \ |
| 1875 | onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \ |
Doug Zongker | 6dd2ae0 | 2009-08-25 17:23:57 -0700 | [diff] [blame] | 1876 | reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \ |
| 1877 | reservedblocks * img_blocksize)); \ |
Doug Zongker | 4647f12 | 2009-07-02 09:00:54 -0700 | [diff] [blame] | 1878 | maxsize=$$(($(2) - reserve)); \ |
| 1879 | if [ "$$total" -gt "$$maxsize" ]; then \ |
| 1880 | echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \ |
| 1881 | false; \ |
Doug Zongker | 742fa57 | 2009-07-08 12:09:04 -0700 | [diff] [blame] | 1882 | elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \ |
Doug Zongker | 4647f12 | 2009-07-02 09:00:54 -0700 | [diff] [blame] | 1883 | echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1884 | fi \ |
| 1885 | , \ |
| 1886 | true \ |
| 1887 | ) |
| 1888 | endef |
| 1889 | |
Doug Zongker | 8510a1e | 2009-08-07 16:38:08 -0700 | [diff] [blame] | 1890 | # Like assert-max-file-size, but the second argument is a partition |
| 1891 | # size, which we'll convert to a max image size before checking it |
| 1892 | # against the files. |
| 1893 | # |
| 1894 | # $(1): The file(s) to check (often $@) |
| 1895 | # $(2): The partition size. |
| 1896 | define assert-max-image-size |
| 1897 | $(if $(2), \ |
| 1898 | $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \ |
| 1899 | true) |
| 1900 | endef |
| 1901 | |
Doug Zongker | e01100c | 2009-06-19 17:12:18 -0700 | [diff] [blame] | 1902 | |
| 1903 | ########################################################### |
| 1904 | ## Define device-specific radio files |
| 1905 | ########################################################### |
| 1906 | |
| 1907 | # Copy a radio image file to the output location, and add it to |
| 1908 | # INSTALLED_RADIOIMAGE_TARGET. |
| 1909 | # $(1): filename |
| 1910 | define add-radio-file |
Doug Zongker | 1483360 | 2010-02-02 13:12:04 -0800 | [diff] [blame] | 1911 | $(eval $(call add-radio-file-internal,$(1),$(notdir $(1)))) |
Doug Zongker | e01100c | 2009-06-19 17:12:18 -0700 | [diff] [blame] | 1912 | endef |
| 1913 | define add-radio-file-internal |
Doug Zongker | 1483360 | 2010-02-02 13:12:04 -0800 | [diff] [blame] | 1914 | INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2) |
Doug Zongker | 1483360 | 2010-02-02 13:12:04 -0800 | [diff] [blame] | 1915 | $$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP) |
Doug Zongker | e01100c | 2009-06-19 17:12:18 -0700 | [diff] [blame] | 1916 | $$(transform-prebuilt-to-target) |
| 1917 | endef |
| 1918 | |
| 1919 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1920 | ########################################################### |
Joe Onorato | 899e62a | 2010-02-04 17:37:21 -0800 | [diff] [blame] | 1921 | # Override the package defined in $(1), setting the |
| 1922 | # variables listed below differently. |
| 1923 | # |
| 1924 | # $(1): The makefile to override (relative to the source |
| 1925 | # tree root) |
| 1926 | # $(2): Old LOCAL_PACKAGE_NAME value. |
| 1927 | # $(3): New LOCAL_PACKAGE_NAME value. |
Ying Wang | 3dae0ee | 2010-09-02 15:41:01 -0700 | [diff] [blame] | 1928 | # $(4): New LOCAL_MANIFEST_PACKAGE_NAME value. |
| 1929 | # $(5): New LOCAL_CERTIFICATE value. |
| 1930 | # $(6): New LOCAL_INSTRUMENTATION_FOR value. |
| 1931 | # $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value. |
Joe Onorato | 899e62a | 2010-02-04 17:37:21 -0800 | [diff] [blame] | 1932 | # |
| 1933 | # Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in |
| 1934 | # clear_vars.mk. |
| 1935 | ########################################################### |
| 1936 | define inherit-package |
Ying Wang | 3dae0ee | 2010-09-02 15:41:01 -0700 | [diff] [blame] | 1937 | $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7))) |
Joe Onorato | 899e62a | 2010-02-04 17:37:21 -0800 | [diff] [blame] | 1938 | endef |
| 1939 | |
| 1940 | define inherit-package-internal |
| 1941 | LOCAL_PACKAGE_OVERRIDES \ |
Ying Wang | 3dae0ee | 2010-09-02 15:41:01 -0700 | [diff] [blame] | 1942 | := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES) |
Joe Onorato | 899e62a | 2010-02-04 17:37:21 -0800 | [diff] [blame] | 1943 | include $(1) |
| 1944 | LOCAL_PACKAGE_OVERRIDES \ |
| 1945 | := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES)) |
| 1946 | endef |
| 1947 | |
| 1948 | # To be used with inherit-package above |
| 1949 | # Evalutes to true if the package was overridden |
| 1950 | define set-inherited-package-variables |
| 1951 | $(strip $(call set-inherited-package-variables-internal)) |
| 1952 | endef |
| 1953 | |
| 1954 | define keep-or-override |
| 1955 | $(eval $(1) := $(if $(2),$(2),$($(1)))) |
| 1956 | endef |
| 1957 | |
| 1958 | define set-inherited-package-variables-internal |
| 1959 | $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES)))) |
| 1960 | $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES)))) |
| 1961 | $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \ |
| 1962 | $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \ |
| 1963 | $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \ |
Ying Wang | 3dae0ee | 2010-09-02 15:41:01 -0700 | [diff] [blame] | 1964 | $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \ |
| 1965 | $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \ |
| 1966 | $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \ |
Joe Onorato | 899e62a | 2010-02-04 17:37:21 -0800 | [diff] [blame] | 1967 | $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \ |
| 1968 | true \ |
| 1969 | ,) |
| 1970 | endef |
| 1971 | |
| 1972 | |
| 1973 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1974 | ## Other includes |
| 1975 | ########################################################### |
| 1976 | |
| 1977 | # ----------------------------------------------------------------- |
| 1978 | # Rules and functions to help copy important files to DIST_DIR |
| 1979 | # when requested. |
| 1980 | include $(BUILD_SYSTEM)/distdir.mk |
| 1981 | |
Jean-Baptiste Queru | 4074f23 | 2010-09-03 16:32:58 -0700 | [diff] [blame] | 1982 | # ----------------------------------------------------------------- |
| 1983 | # The modules allowed to use a user tag |
| 1984 | include $(BUILD_SYSTEM)/user_tags.mk |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1985 | |
| 1986 | # broken: |
| 1987 | # $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file))) |
| 1988 | |
| 1989 | ########################################################### |
| 1990 | ## Misc notes |
| 1991 | ########################################################### |
| 1992 | |
| 1993 | #DEPDIR = .deps |
| 1994 | #df = $(DEPDIR)/$(*F) |
| 1995 | |
| 1996 | #SRCS = foo.c bar.c ... |
| 1997 | |
| 1998 | #%.o : %.c |
| 1999 | # @$(MAKEDEPEND); \ |
| 2000 | # cp $(df).d $(df).P; \ |
| 2001 | # sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ |
| 2002 | # -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \ |
| 2003 | # rm -f $(df).d |
| 2004 | # $(COMPILE.c) -o $@ $< |
| 2005 | |
| 2006 | #-include $(SRCS:%.c=$(DEPDIR)/%.P) |
| 2007 | |
| 2008 | |
| 2009 | #%.o : %.c |
| 2010 | # $(COMPILE.c) -MD -o $@ $< |
| 2011 | # @cp $*.d $*.P; \ |
| 2012 | # sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ |
| 2013 | # -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \ |
| 2014 | # rm -f $*.d |