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