definitions.mk revision bafbfe8866f1016cc9c651d9e9ead21a0b7eb16e
1# Copyright (C) 2009 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# 15# Common definitions for the Android NDK build system 16# 17 18# We use the GNU Make Standard Library 19include $(NDK_ROOT)/build/gmsl/gmsl 20 21# If NDK_TRACE is enabled then calls to the library functions are 22# traced to stdout using warning messages with their arguments 23 24ifdef NDK_TRACE 25__ndk_tr1 = $(warning $0('$1')) 26__ndk_tr2 = $(warning $0('$1','$2')) 27__ndk_tr3 = $(warning $0('$1','$2','$3')) 28else 29__ndk_tr1 := 30__ndk_tr2 := 31__ndk_tr3 := 32endif 33 34# ----------------------------------------------------------------------------- 35# Macro : empty 36# Returns : an empty macro 37# Usage : $(empty) 38# ----------------------------------------------------------------------------- 39empty := 40 41# ----------------------------------------------------------------------------- 42# Macro : space 43# Returns : a single space 44# Usage : $(space) 45# ----------------------------------------------------------------------------- 46space := $(empty) $(empty) 47 48# ----------------------------------------------------------------------------- 49# Function : last2 50# Arguments: a list 51# Returns : the penultimate (next-to-last) element of a list 52# Usage : $(call last2, <LIST>) 53# ----------------------------------------------------------------------------- 54last2 = $(word $(words $1), x $1) 55 56# ----------------------------------------------------------------------------- 57# Function : last3 58# Arguments: a list 59# Returns : the antepenultimate (second-next-to-last) element of a list 60# Usage : $(call last3, <LIST>) 61# ----------------------------------------------------------------------------- 62last3 = $(word $(words $1), x x $1) 63 64# ----------------------------------------------------------------------------- 65# Function : remove-duplicates 66# Arguments: a list 67# Returns : the list with duplicate items removed, order is preserved. 68# Usage : $(call remove-duplicates, <LIST>) 69# Note : This is equivalent to the 'uniq' function provided by GMSL, 70# however this implementation is non-recursive and *much* 71# faster. It will also not explode the stack with a lot of 72# items like 'uniq' does. 73# ----------------------------------------------------------------------------- 74remove-duplicates = $(strip \ 75 $(eval __uniq_ret :=) \ 76 $(foreach __uniq_item,$1,\ 77 $(if $(findstring $(__uniq_item),$(__uniq_ret)),,\ 78 $(eval __uniq_ret += $(__uniq_item))\ 79 )\ 80 )\ 81 $(__uniq_ret)) 82 83# ----------------------------------------------------------------------------- 84# Macro : this-makefile 85# Returns : the name of the current Makefile in the inclusion stack 86# Usage : $(this-makefile) 87# ----------------------------------------------------------------------------- 88this-makefile = $(lastword $(MAKEFILE_LIST)) 89 90# ----------------------------------------------------------------------------- 91# Macro : local-makefile 92# Returns : the name of the last parsed Android.mk file 93# Usage : $(local-makefile) 94# ----------------------------------------------------------------------------- 95local-makefile = $(lastword $(filter %Android.mk,$(MAKEFILE_LIST))) 96 97# ----------------------------------------------------------------------------- 98# Function : assert-defined 99# Arguments: 1: list of variable names 100# Returns : None 101# Usage : $(call assert-defined, VAR1 VAR2 VAR3...) 102# Rationale: Checks that all variables listed in $1 are defined, or abort the 103# build 104# ----------------------------------------------------------------------------- 105assert-defined = $(foreach __varname,$(strip $1),\ 106 $(if $(strip $($(__varname))),,\ 107 $(call __ndk_error, Assertion failure: $(__varname) is not defined)\ 108 )\ 109) 110 111# ----------------------------------------------------------------------------- 112# Function : clear-vars 113# Arguments: 1: list of variable names 114# 2: file where the variable should be defined 115# Returns : None 116# Usage : $(call clear-vars, VAR1 VAR2 VAR3...) 117# Rationale: Clears/undefines all variables in argument list 118# ----------------------------------------------------------------------------- 119clear-vars = $(foreach __varname,$1,$(eval $(__varname) := $(empty))) 120 121# ----------------------------------------------------------------------------- 122# Function : check-required-vars 123# Arguments: 1: list of variable names 124# 2: file where the variable(s) should be defined 125# Returns : None 126# Usage : $(call check-required-vars, VAR1 VAR2 VAR3..., <file>) 127# Rationale: Checks that all required vars listed in $1 were defined by $2 128# or abort the build with an error 129# ----------------------------------------------------------------------------- 130check-required-vars = $(foreach __varname,$1,\ 131 $(if $(strip $($(__varname))),,\ 132 $(call __ndk_info, Required variable $(__varname) is not defined by $2)\ 133 $(call __ndk_error,Aborting)\ 134 )\ 135) 136 137# ----------------------------------------------------------------------------- 138# Function : host-path 139# Arguments: 1: file path 140# Returns : file path, as understood by the host file system 141# Usage : $(call host-path,<path>) 142# Rationale: This function is used to translate Cygwin paths into 143# Windows-specific ones. On other platforms, it will just 144# return its argument. 145# ----------------------------------------------------------------------------- 146ifeq ($(HOST_OS),windows) 147host-path = $(if $(strip $1),$(call cygwin-to-host-path,$1)) 148else 149host-path = $1 150endif 151 152# ----------------------------------------------------------------------------- 153# Function : host-c-includes 154# Arguments: 1: list of file paths (e.g. "foo bar") 155# Returns : list of include compiler options (e.g. "-Ifoo -Ibar") 156# Usage : $(call host-c-includes,<paths>) 157# Rationale: This function is used to translate Cygwin paths into 158# Windows-specific ones. On other platforms, it will just 159# return its argument. 160# ----------------------------------------------------------------------------- 161ifeq ($(HOST_OS),windows) 162host-c-includes = $(patsubst %,-I%,$(call host-path,$1)) 163else 164host-c-includes = $(1:%=-I%) 165endif 166 167 168# ----------------------------------------------------------------------------- 169# Function : link-whole-archives 170# Arguments: 1: list of whole static libraries 171# Returns : linker flags to use the whole static libraries 172# Usage : $(call link-whole-archives,<libraries>) 173# Rationale: This function is used to put the list of whole static libraries 174# inside a -Wl,--whole-archive ... -Wl,--no-whole-archive block. 175# If the list is empty, it returns an empty string. 176# This function also calls host-path to translate the library 177# paths. 178# ----------------------------------------------------------------------------- 179link-whole-archives = $(if $(strip $1),$(call link-whole-archive-flags,$1)) 180link-whole-archive-flags = -Wl,--whole-archive $(call host-path,$1) -Wl,--no-whole-archive 181 182# ============================================================================= 183# 184# Modules database 185# 186# The following declarations are used to manage the list of modules 187# defined in application's Android.mk files. 188# 189# Technical note: 190# We use __ndk_modules to hold the list of all modules corresponding 191# to a given application. 192# 193# For each module 'foo', __ndk_modules.foo.<field> is used 194# to store module-specific information. 195# 196# type -> type of module (e.g. 'static', 'shared', ...) 197# depends -> list of other modules this module depends on 198# 199# Also, LOCAL_XXXX values defined for a module are recorded in XXXX, e.g.: 200# 201# PATH -> recorded LOCAL_PATH for the module 202# CFLAGS -> recorded LOCAL_CFLAGS for the module 203# ... 204# 205# Some of these are created by build scripts like BUILD_STATIC_LIBRARY: 206# 207# MAKEFILE -> The Android.mk where the module is defined. 208# LDFLAGS -> Final linker flags 209# OBJECTS -> List of module objects 210# BUILT_MODULE -> location of module built file (e.g. obj/<app>/<abi>/libfoo.so) 211# 212# Note that some modules are never installed (e.g. static libraries). 213# 214# ============================================================================= 215 216# The list of LOCAL_XXXX variables that are recorded for each module definition 217# These are documented by docs/ANDROID-MK.TXT. Exception is LOCAL_MODULE 218# 219modules-LOCALS := \ 220 MODULE \ 221 MODULE_FILENAME \ 222 PATH \ 223 SRC_FILES \ 224 CPP_EXTENSION \ 225 C_INCLUDES \ 226 CFLAGS \ 227 CXXFLAGS \ 228 CPPFLAGS \ 229 STATIC_LIBRARIES \ 230 WHOLE_STATIC_LIBRARIES \ 231 SHARED_LIBRARIES \ 232 LDLIBS \ 233 ALLOW_UNDEFINED_SYMBOLS \ 234 ARM_MODE \ 235 ARM_NEON \ 236 DISABLE_NO_EXECUTE \ 237 EXPORT_CFLAGS \ 238 EXPORT_CPPFLAGS \ 239 EXPORT_LDLIBS \ 240 EXPORT_C_INCLUDES \ 241 FILTER_ASM \ 242 243# The following are generated by the build scripts themselves 244 245# LOCAL_MAKEFILE will contain the path to the Android.mk defining the module 246modules-LOCALS += MAKEFILE 247 248# LOCAL_LDFLAGS will contain the set of final linker flags for the module 249modules-LOCALS += LDFLAGS 250 251# LOCAL_OBJECTS will contain the list of object files generated from the 252# module's sources, if any. 253modules-LOCALS += OBJECTS 254 255# LOCAL_BUILT_MODULE will contain the location of the symbolic version of 256# the generated module (i.e. the one containing all symbols used during 257# native debugging). It is generally under $PROJECT/obj/local/ 258modules-LOCALS += BUILT_MODULE 259 260# LOCAL_OBJS_DIR will contain the location where the object files for 261# this module will be stored. Usually $PROJECT/obj/local/<module>/obj 262modules-LOCALS += OBJS_DIR 263 264# LOCAL_INSTALLED will contain the location of the installed version 265# of the module. Usually $PROJECT/libs/<abi>/<prefix><module><suffix> 266# where <prefix> and <suffix> depend on the module class. 267modules-LOCALS += INSTALLED 268 269# LOCAL_MODULE_CLASS will contain the type of the module 270# (e.g. STATIC_LIBRARY, SHARED_LIBRARY, etc...) 271modules-LOCALS += MODULE_CLASS 272 273# the list of managed fields per module 274modules-fields = depends \ 275 $(modules-LOCALS) 276 277# ----------------------------------------------------------------------------- 278# Function : modules-clear 279# Arguments: None 280# Returns : None 281# Usage : $(call modules-clear) 282# Rationale: clears the list of defined modules known by the build system 283# ----------------------------------------------------------------------------- 284modules-clear = \ 285 $(foreach __mod,$(__ndk_modules),\ 286 $(foreach __field,$(modules-fields),\ 287 $(eval __ndk_modules.$(__mod).$(__field) := $(empty))\ 288 )\ 289 )\ 290 $(eval __ndk_modules := $(empty_set)) \ 291 $(eval __ndk_top_modules := $(empty)) \ 292 $(eval __ndk_import_list := $(empty)) \ 293 $(eval __ndk_import_depth := $(empty)) 294 295# ----------------------------------------------------------------------------- 296# Function : modules-get-list 297# Arguments: None 298# Returns : The list of all recorded modules 299# Usage : $(call modules-get-list) 300# ----------------------------------------------------------------------------- 301modules-get-list = $(__ndk_modules) 302 303# ----------------------------------------------------------------------------- 304# Function : modules-get-top-list 305# Arguments: None 306# Returns : The list of all recorded non-imported modules 307# Usage : $(call modules-get-top-list) 308# ----------------------------------------------------------------------------- 309modules-get-top-list = $(__ndk_top_modules) 310 311# ----------------------------------------------------------------------------- 312# Function : module-add 313# Arguments: 1: module name 314# Returns : None 315# Usage : $(call module-add,<modulename>) 316# Rationale: add a new module. If it is already defined, print an error message 317# and abort. This will record all LOCAL_XXX variables for the module. 318# ----------------------------------------------------------------------------- 319module-add = \ 320 $(call assert-defined,LOCAL_MAKEFILE LOCAL_BUILT_MODULE LOCAL_OBJS_DIR LOCAL_MODULE_CLASS)\ 321 $(if $(call set_is_member,$(__ndk_modules),$1),\ 322 $(call __ndk_info,Trying to define local module '$1' in $(LOCAL_MAKEFILE).)\ 323 $(call __ndk_info,But this module was already defined by $(__ndk_modules.$1.MAKEFILE).)\ 324 $(call __ndk_error,Aborting.)\ 325 )\ 326 $(eval __ndk_modules := $(call set_insert,$(__ndk_modules),$1))\ 327 $(if $(strip $(__ndk_import_depth)),,\ 328 $(eval __ndk_top_modules := $(call set_insert,$(__ndk_top_modules),$1))\ 329 )\ 330 $(if $(call module-class-is-installable,$(LOCAL_MODULE_CLASS)),\ 331 $(eval LOCAL_INSTALLED := $(NDK_APP_DST_DIR)/$(notdir $(LOCAL_BUILT_MODULE)))\ 332 )\ 333 $(foreach __local,$(modules-LOCALS),\ 334 $(eval __ndk_modules.$1.$(__local) := $(LOCAL_$(__local)))\ 335 ) 336 337 338# Retrieve the class of module $1 339module-get-class = $(__ndk_modules.$1.MODULE_CLASS) 340 341# Retrieve built location of module $1 342module-get-built = $(__ndk_modules.$1.BUILT_MODULE) 343 344# Returns $(true) is module $1 is installable 345# An installable module is one that will be copied to $PROJECT/libs/<abi>/ 346# (e.g. shared libraries). 347# 348module-is-installable = $(call module-class-is-installable,$(call module-get-class,$1)) 349 350# Returns $(true) if module $1 is prebuilt 351# A prebuilt module is one declared with BUILD_PREBUILT_SHARED_LIBRARY or 352# BUILD_PREBUILT_STATIC_LIBRARY 353# 354module-is-prebuilt = $(call module-class-is-prebuilt,$(call module-get-class,$1)) 355 356# ----------------------------------------------------------------------------- 357# Function : module-get-export 358# Arguments: 1: module name 359# 2: export variable name without LOCAL_EXPORT_ prefix (e.g. 'CFLAGS') 360# Returns : Exported value 361# Usage : $(call module-get-export,<modulename>,<varname>) 362# Rationale: Return the recorded value of LOCAL_EXPORT_$2, if any, for module $1 363# ----------------------------------------------------------------------------- 364module-get-export = $(__ndk_modules.$1.EXPORT_$2) 365 366# ----------------------------------------------------------------------------- 367# Function : module-get-listed-export 368# Arguments: 1: list of module names 369# 2: export variable name without LOCAL_EXPORT_ prefix (e.g. 'CFLAGS') 370# Returns : Exported values 371# Usage : $(call module-get-listed-export,<module-list>,<varname>) 372# Rationale: Return the recorded value of LOCAL_EXPORT_$2, if any, for modules 373# listed in $1. 374# ----------------------------------------------------------------------------- 375module-get-listed-export = $(strip \ 376 $(foreach __listed_module,$1,\ 377 $(call module-get-export,$(__listed_module),$2)\ 378 )) 379 380# ----------------------------------------------------------------------------- 381# Function : modules-restore-locals 382# Arguments: 1: module name 383# Returns : None 384# Usage : $(call module-restore-locals,<modulename>) 385# Rationale: Restore the recorded LOCAL_XXX definitions for a given module. 386# ----------------------------------------------------------------------------- 387module-restore-locals = \ 388 $(foreach __local,$(modules-LOCALS),\ 389 $(eval LOCAL_$(__local) := $(__ndk_modules.$1.$(__local)))\ 390 ) 391 392# Dump all module information. Only use this for debugging 393modules-dump-database = \ 394 $(info Modules: $(__ndk_modules)) \ 395 $(foreach __mod,$(__ndk_modules),\ 396 $(info $(space)$(space)$(__mod):)\ 397 $(foreach __field,$(modules-fields),\ 398 $(info $(space)$(space)$(space)$(space)$(__field): $(__ndk_modules.$(__mod).$(__field)))\ 399 )\ 400 )\ 401 $(info --- end of modules list) 402 403 404# ----------------------------------------------------------------------------- 405# Function : module-add-static-depends 406# Arguments: 1: module name 407# 2: list/set of static library modules this module depends on. 408# Returns : None 409# Usage : $(call module-add-static-depends,<modulename>,<list of module names>) 410# Rationale: Record that a module depends on a set of static libraries. 411# Use module-get-static-dependencies to retrieve final list. 412# ----------------------------------------------------------------------------- 413module-add-static-depends = \ 414 $(call module-add-depends-any,$1,$2,depends) \ 415 416# ----------------------------------------------------------------------------- 417# Function : module-add-shared-depends 418# Arguments: 1: module name 419# 2: list/set of shared library modules this module depends on. 420# Returns : None 421# Usage : $(call module-add-shared-depends,<modulename>,<list of module names>) 422# Rationale: Record that a module depends on a set of shared libraries. 423# Use modulge-get-shared-dependencies to retrieve final list. 424# ----------------------------------------------------------------------------- 425module-add-shared-depends = \ 426 $(call module-add-depends-any,$1,$2,depends) \ 427 428# Used internally by module-add-static-depends and module-add-shared-depends 429# NOTE: this function must not modify the existing dependency order when new depends are added. 430# 431module-add-depends-any = \ 432 $(eval __ndk_modules.$1.$3 += $(filter-out $(__ndk_modules.$1.$3),$(call strip-lib-prefix,$2))) 433 434# Used to recompute all dependencies once all module information has been recorded. 435# 436modules-compute-dependencies = \ 437 $(foreach __module,$(__ndk_modules),\ 438 $(call module-compute-depends,$(__module))\ 439 ) 440 441module-compute-depends = \ 442 $(call module-add-static-depends,$1,$(__ndk_modules.$1.STATIC_LIBRARIES))\ 443 $(call module-add-static-depends,$1,$(__ndk_modules.$1.WHOLE_STATIC_LIBRARIES))\ 444 $(call module-add-shared-depends,$1,$(__ndk_modules.$1.SHARED_LIBRARIES))\ 445 446module-get-installed = $(__ndk_modules.$1.INSTALLED) 447 448# ----------------------------------------------------------------------------- 449# Function : modules-get-all-dependencies 450# Arguments: 1: list of module names 451# Returns : List of all the modules $1 depends on transitively. 452# Usage : $(call modules-all-get-dependencies,<list of module names>) 453# Rationale: This computes the closure of all module dependencies starting from $1 454# ----------------------------------------------------------------------------- 455module-get-all-dependencies = \ 456 $(strip $(call modules-get-closure,$1,depends)) 457 458modules-get-closure = \ 459 $(eval __closure_deps := $(strip $1)) \ 460 $(eval __closure_wq := $(__closure_deps)) \ 461 $(eval __closure_field := $(strip $2)) \ 462 $(call modules-closure)\ 463 $(__closure_deps) 464 465# Used internally by modules-get-dependencies 466# Note the tricky use of conditional recursion to work around the fact that 467# the GNU Make language does not have any conditional looping construct 468# like 'while'. 469# 470modules-closure = \ 471 $(eval __closure_mod := $(call first,$(__closure_wq))) \ 472 $(eval __closure_wq := $(call rest,$(__closure_wq))) \ 473 $(eval __closure_new := $(filter-out $(__closure_deps),$(__ndk_modules.$(__closure_mod).$(__closure_field))))\ 474 $(eval __closure_deps += $(__closure_new)) \ 475 $(eval __closure_wq := $(strip $(__closure_wq) $(__closure_new)))\ 476 $(if $(__closure_wq),$(call modules-closure)) \ 477 478# Return the C++ extension of a given module 479# 480module-get-cpp-extension = $(strip \ 481 $(if $(__ndk_modules.$1.CPP_EXTENSION),\ 482 $(__ndk_modules.$1.CPP_EXTENSION),\ 483 .cpp\ 484 )) 485 486# Return the list of C++ sources of a given module 487# 488module-get-c++-sources = \ 489 $(filter %$(call module-get-cpp-extension,$1),$(__ndk_modules.$1.SRC_FILES)) 490 491# Returns true if a module has C++ sources 492# 493module-has-c++ = $(strip $(call module-get-c++-sources,$1)) 494 495# Add C++ dependencies to any module that has C++ sources. 496# $1: list of C++ runtime static libraries (if any) 497# $2: list of C++ runtime shared libraries (if any) 498# 499modules-add-c++-dependencies = \ 500 $(foreach __module,$(__ndk_modules),\ 501 $(if $(call module-has-c++,$(__module)),\ 502 $(call ndk_log,Module '$(__module)' has C++ sources)\ 503 $(call module-add-c++-deps,$(__module),$1,$2),\ 504 )\ 505 ) 506 507# Add standard C++ dependencies to a given module 508# 509# $1: module name 510# $2: list of C++ runtime static libraries (if any) 511# $3: list of C++ runtime shared libraries (if any) 512# 513module-add-c++-deps = \ 514 $(eval __ndk_modules.$1.STATIC_LIBRARIES += $(2))\ 515 $(eval __ndk_modules.$1.SHARED_LIBRARIES += $(3)) 516 517 518# ============================================================================= 519# 520# Utility functions 521# 522# ============================================================================= 523 524# ----------------------------------------------------------------------------- 525# Function : parent-dir 526# Arguments: 1: path 527# Returns : Parent dir or path of $1, with final separator removed. 528# ----------------------------------------------------------------------------- 529parent-dir = $(patsubst %/,%,$(dir $1)) 530 531 532# ----------------------------------------------------------------------------- 533# Function : pretty-dir 534# Arguments: 1: path 535# Returns : Remove NDK_PROJECT_PATH prefix from a given path. This can be 536# used to perform pretty-printing for logs. 537# ----------------------------------------------------------------------------- 538pretty-dir = $(patsubst $(NDK_ROOT)/%,<NDK>/%,\ 539 $(patsubst $(NDK_PROJECT_PATH)/%,%,$1)) 540 541# ----------------------------------------------------------------------------- 542# Function : check-user-define 543# Arguments: 1: name of variable that must be defined by the user 544# 2: name of Makefile where the variable should be defined 545# 3: name/description of the Makefile where the check is done, which 546# must be included by $2 547# Returns : None 548# ----------------------------------------------------------------------------- 549check-user-define = $(if $(strip $($1)),,\ 550 $(call __ndk_error,Missing $1 before including $3 in $2)) 551 552# ----------------------------------------------------------------------------- 553# This is used to check that LOCAL_MODULE is properly defined by an Android.mk 554# file before including one of the $(BUILD_SHARED_LIBRARY), etc... files. 555# 556# Function : check-user-LOCAL_MODULE 557# Arguments: 1: name/description of the included build Makefile where the 558# check is done 559# Returns : None 560# Usage : $(call check-user-LOCAL_MODULE, BUILD_SHARED_LIBRARY) 561# ----------------------------------------------------------------------------- 562check-defined-LOCAL_MODULE = \ 563 $(call check-user-define,LOCAL_MODULE,$(local-makefile),$(1)) \ 564 $(if $(call seq,$(words $(LOCAL_MODULE)),1),,\ 565 $(call __ndk_info,LOCAL_MODULE definition in $(local-makefile) must not contain space)\ 566 $(call __ndk_error,Please correct error. Aborting)\ 567 ) 568 569# ----------------------------------------------------------------------------- 570# This is used to check that LOCAL_MODULE_FILENAME, if defined, is correct. 571# 572# Function : check-user-LOCAL_MODULE_FILENAME 573# Returns : None 574# Usage : $(call check-user-LOCAL_MODULE_FILENAME) 575# ----------------------------------------------------------------------------- 576check-LOCAL_MODULE_FILENAME = \ 577 $(if $(strip $(LOCAL_MODULE_FILENAME)),\ 578 $(if $(call seq,$(words $(LOCAL_MODULE_FILENAME)),1),,\ 579 $(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain spaces)\ 580 $(call __ndk_error,Plase correct error. Aborting)\ 581 )\ 582 $(if $(filter %.a %.so,$(LOCAL_MODULE_FILENAME)),\ 583 $(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_MODULE_FILENAME should not include file extensions)\ 584 )\ 585 ) 586 587# ----------------------------------------------------------------------------- 588# Function : handle-module-filename 589# Arguments : 1: default file prefix 590# 2: file suffix 591# Returns : None 592# Usage : $(call handle-module-filename,<prefix>,<suffix>) 593# Rationale : To be used to check and or set the module's filename through 594# the LOCAL_MODULE_FILENAME variable. 595# ----------------------------------------------------------------------------- 596handle-module-filename = $(eval $(call ev-handle-module-filename,$1,$2)) 597 598# 599# Check that LOCAL_MODULE_FILENAME is properly defined 600# - with one single item 601# - without a library file extension 602# - with no directory separators 603# 604define ev-check-module-filename 605ifneq (1,$$(words $$(LOCAL_MODULE_FILENAME))) 606 $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain any space) 607 $$(call __ndk_error,Aborting) 608endif 609ifneq (,$$(filter %.a %.so,$$(LOCAL_MODULE_FILENAME))) 610 $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain a file extension) 611 $$(call __ndk_error,Aborting) 612endif 613ifneq (1,$$(words $$(subst /, ,$$(LOCAL_MODULE_FILENAME)))) 614 $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain directory separators) 615 $$(call __ndk_error,Aborting) 616endif 617endef 618 619# 620# Check the definition of LOCAL_MODULE_FILENAME. If none exists, 621# infer it from the LOCAL_MODULE name. 622# 623# $1: default file prefix 624# $2: default file suffix 625# 626define ev-handle-module-filename 627LOCAL_MODULE_FILENAME := $$(strip $$(LOCAL_MODULE_FILENAME)) 628ifndef LOCAL_MODULE_FILENAME 629 LOCAL_MODULE_FILENAME := $1$$(LOCAL_MODULE) 630endif 631$$(eval $$(call ev-check-module-filename)) 632LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME)$2 633endef 634 635handle-prebuilt-module-filename = $(eval $(call ev-handle-prebuilt-module-filename,$1)) 636 637# 638# Check the definition of LOCAL_MODULE_FILENAME for a _prebuilt_ module. 639# If none exists, infer it from $(LOCAL_SRC_FILES) 640# 641# $1: default file suffix 642# 643define ev-handle-prebuilt-module-filename 644LOCAL_MODULE_FILENAME := $$(strip $$(LOCAL_MODULE_FILENAME)) 645ifndef LOCAL_MODULE_FILENAME 646 LOCAL_MODULE_FILENAME := $$(notdir $(LOCAL_SRC_FILES)) 647 LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%.a=%) 648 LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%.so=%) 649endif 650LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME)$1 651$$(eval $$(call ev-check-module-filename)) 652endef 653 654 655# ----------------------------------------------------------------------------- 656# Function : handle-module-built 657# Returns : None 658# Usage : $(call handle-module-built) 659# Rationale : To be used to automatically compute the location of the generated 660# binary file, and the directory where to place its object files. 661# ----------------------------------------------------------------------------- 662handle-module-built = \ 663 $(eval LOCAL_BUILT_MODULE := $(TARGET_OUT)/$(LOCAL_MODULE_FILENAME))\ 664 $(eval LOCAL_OBJS_DIR := $(TARGET_OBJS)/$(LOCAL_MODULE)) 665 666# ----------------------------------------------------------------------------- 667# Strip any 'lib' prefix in front of a given string. 668# 669# Function : strip-lib-prefix 670# Arguments: 1: module name 671# Returns : module name, without any 'lib' prefix if any 672# Usage : $(call strip-lib-prefix,$(LOCAL_MODULE)) 673# ----------------------------------------------------------------------------- 674strip-lib-prefix = $(1:lib%=%) 675 676# ----------------------------------------------------------------------------- 677# This is used to strip any lib prefix from LOCAL_MODULE, then check that 678# the corresponding module name is not already defined. 679# 680# Function : check-user-LOCAL_MODULE 681# Arguments: 1: path of Android.mk where this LOCAL_MODULE is defined 682# Returns : None 683# Usage : $(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE)) 684# ----------------------------------------------------------------------------- 685check-LOCAL_MODULE = \ 686 $(eval LOCAL_MODULE := $$(call strip-lib-prefix,$$(LOCAL_MODULE))) 687 688# ----------------------------------------------------------------------------- 689# Macro : my-dir 690# Returns : the directory of the current Makefile 691# Usage : $(my-dir) 692# ----------------------------------------------------------------------------- 693my-dir = $(call parent-dir,$(lastword $(MAKEFILE_LIST))) 694 695# ----------------------------------------------------------------------------- 696# Function : all-makefiles-under 697# Arguments: 1: directory path 698# Returns : a list of all makefiles immediately below some directory 699# Usage : $(call all-makefiles-under, <some path>) 700# ----------------------------------------------------------------------------- 701all-makefiles-under = $(wildcard $1/*/Android.mk) 702 703# ----------------------------------------------------------------------------- 704# Macro : all-subdir-makefiles 705# Returns : list of all makefiles in subdirectories of the current Makefile's 706# location 707# Usage : $(all-subdir-makefiles) 708# ----------------------------------------------------------------------------- 709all-subdir-makefiles = $(call all-makefiles-under,$(call my-dir)) 710 711# ============================================================================= 712# 713# Source file tagging support. 714# 715# Each source file listed in LOCAL_SRC_FILES can have any number of 716# 'tags' associated to it. A tag name must not contain space, and its 717# usage can vary. 718# 719# For example, the 'debug' tag is used to sources that must be built 720# in debug mode, the 'arm' tag is used for sources that must be built 721# using the 32-bit instruction set on ARM platforms, and 'neon' is used 722# for sources that must be built with ARM Advanced SIMD (a.k.a. NEON) 723# support. 724# 725# More tags might be introduced in the future. 726# 727# LOCAL_SRC_TAGS contains the list of all tags used (initially empty) 728# LOCAL_SRC_FILES contains the list of all source files. 729# LOCAL_SRC_TAG.<tagname> contains the set of source file names tagged 730# with <tagname> 731# LOCAL_SRC_FILES_TAGS.<filename> contains the set of tags for a given 732# source file name 733# 734# Tags are processed by a toolchain-specific function (e.g. TARGET-compute-cflags) 735# which will call various functions to compute source-file specific settings. 736# These are currently stored as: 737# 738# LOCAL_SRC_FILES_TARGET_CFLAGS.<filename> contains the list of 739# target-specific C compiler flags used to compile a given 740# source file. This is set by the function TARGET-set-cflags 741# defined in the toolchain's setup.mk script. 742# 743# LOCAL_SRC_FILES_TEXT.<filename> contains the 'text' that will be 744# displayed along the label of the build output line. For example 745# 'thumb' or 'arm ' with ARM-based toolchains. 746# 747# ============================================================================= 748 749# ----------------------------------------------------------------------------- 750# Macro : clear-all-src-tags 751# Returns : remove all source file tags and associated data. 752# Usage : $(clear-all-src-tags) 753# ----------------------------------------------------------------------------- 754clear-all-src-tags = \ 755$(foreach __tag,$(LOCAL_SRC_TAGS), \ 756 $(eval LOCAL_SRC_TAG.$(__tag) := $(empty)) \ 757) \ 758$(foreach __src,$(LOCAL_SRC_FILES), \ 759 $(eval LOCAL_SRC_FILES_TAGS.$(__src) := $(empty)) \ 760 $(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) := $(empty)) \ 761 $(eval LOCAL_SRC_FILES_TEXT.$(__src) := $(empty)) \ 762) \ 763$(eval LOCAL_SRC_TAGS := $(empty_set)) 764 765# ----------------------------------------------------------------------------- 766# Macro : tag-src-files 767# Arguments: 1: list of source files to tag 768# 2: tag name (must not contain space) 769# Usage : $(call tag-src-files,<list-of-source-files>,<tagname>) 770# Rationale: Add a tag to a list of source files 771# ----------------------------------------------------------------------------- 772tag-src-files = \ 773$(eval LOCAL_SRC_TAGS := $(call set_insert,$2,$(LOCAL_SRC_TAGS))) \ 774$(eval LOCAL_SRC_TAG.$2 := $(call set_union,$1,$(LOCAL_SRC_TAG.$2))) \ 775$(foreach __src,$1, \ 776 $(eval LOCAL_SRC_FILES_TAGS.$(__src) += $2) \ 777) 778 779# ----------------------------------------------------------------------------- 780# Macro : get-src-files-with-tag 781# Arguments: 1: tag name 782# Usage : $(call get-src-files-with-tag,<tagname>) 783# Return : The list of source file names that have been tagged with <tagname> 784# ----------------------------------------------------------------------------- 785get-src-files-with-tag = $(LOCAL_SRC_TAG.$1) 786 787# ----------------------------------------------------------------------------- 788# Macro : get-src-files-without-tag 789# Arguments: 1: tag name 790# Usage : $(call get-src-files-without-tag,<tagname>) 791# Return : The list of source file names that have NOT been tagged with <tagname> 792# ----------------------------------------------------------------------------- 793get-src-files-without-tag = $(filter-out $(LOCAL_SRC_TAG.$1),$(LOCAL_SRC_FILES)) 794 795# ----------------------------------------------------------------------------- 796# Macro : set-src-files-target-cflags 797# Arguments: 1: list of source files 798# 2: list of compiler flags 799# Usage : $(call set-src-files-target-cflags,<sources>,<flags>) 800# Rationale: Set or replace the set of compiler flags that will be applied 801# when building a given set of source files. This function should 802# normally be called from the toolchain-specific function that 803# computes all compiler flags for all source files. 804# ----------------------------------------------------------------------------- 805set-src-files-target-cflags = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) := $2)) 806 807# ----------------------------------------------------------------------------- 808# Macro : add-src-files-target-cflags 809# Arguments: 1: list of source files 810# 2: list of compiler flags 811# Usage : $(call add-src-files-target-cflags,<sources>,<flags>) 812# Rationale: A variant of set-src-files-target-cflags that can be used 813# to append, instead of replace, compiler flags for specific 814# source files. 815# ----------------------------------------------------------------------------- 816add-src-files-target-cflags = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) += $2)) 817 818# ----------------------------------------------------------------------------- 819# Macro : get-src-file-target-cflags 820# Arguments: 1: single source file name 821# Usage : $(call get-src-file-target-cflags,<source>) 822# Rationale: Return the set of target-specific compiler flags that must be 823# applied to a given source file. These must be set prior to this 824# call using set-src-files-target-cflags or add-src-files-target-cflags 825# ----------------------------------------------------------------------------- 826get-src-file-target-cflags = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$1) 827 828# ----------------------------------------------------------------------------- 829# Macro : set-src-files-text 830# Arguments: 1: list of source files 831# 2: text 832# Usage : $(call set-src-files-text,<sources>,<text>) 833# Rationale: Set or replace the 'text' associated to a set of source files. 834# The text is a very short string that complements the build 835# label. For example, it will be either 'thumb' or 'arm ' for 836# ARM-based toolchains. This function must be called by the 837# toolchain-specific functions that processes all source files. 838# ----------------------------------------------------------------------------- 839set-src-files-text = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TEXT.$(__src) := $2)) 840 841# ----------------------------------------------------------------------------- 842# Macro : get-src-file-text 843# Arguments: 1: single source file 844# Usage : $(call get-src-file-text,<source>) 845# Rationale: Return the 'text' associated to a given source file when 846# set-src-files-text was called. 847# ----------------------------------------------------------------------------- 848get-src-file-text = $(LOCAL_SRC_FILES_TEXT.$1) 849 850# This should only be called for debugging the source files tagging system 851dump-src-file-tags = \ 852$(info LOCAL_SRC_TAGS := $(LOCAL_SRC_TAGS)) \ 853$(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES)) \ 854$(foreach __tag,$(LOCAL_SRC_TAGS),$(info LOCAL_SRC_TAG.$(__tag) = $(LOCAL_SRC_TAG.$(__tag)))) \ 855$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TAGS.$(__src) = $(LOCAL_SRC_FILES_TAGS.$(__src)))) \ 856$(info WITH arm = $(call get-src-files-with-tag,arm)) \ 857$(info WITHOUT arm = $(call get-src-files-without-tag,arm)) \ 858$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src)))) \ 859$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TEXT.$(__src) = $(LOCAL_SRC_FILES_TEXT.$(__src)))) \ 860 861 862# ============================================================================= 863# 864# Application.mk support 865# 866# ============================================================================= 867 868# the list of variables that *must* be defined in Application.mk files 869NDK_APP_VARS_REQUIRED := 870 871# the list of variables that *may* be defined in Application.mk files 872NDK_APP_VARS_OPTIONAL := APP_OPTIM APP_CPPFLAGS APP_CFLAGS APP_CXXFLAGS \ 873 APP_PLATFORM APP_BUILD_SCRIPT APP_ABI APP_MODULES \ 874 APP_PROJECT_PATH APP_STL 875 876# the list of all variables that may appear in an Application.mk file 877# or defined by the build scripts. 878NDK_APP_VARS := $(NDK_APP_VARS_REQUIRED) \ 879 $(NDK_APP_VARS_OPTIONAL) \ 880 APP_DEBUG \ 881 APP_DEBUGGABLE \ 882 APP_MANIFEST 883 884# ============================================================================= 885# 886# Android.mk support 887# 888# ============================================================================= 889 890# ============================================================================= 891# 892# Build commands support 893# 894# ============================================================================= 895 896# ----------------------------------------------------------------------------- 897# Macro : hide 898# Returns : nothing 899# Usage : $(hide)<make commands> 900# Rationale: To be used as a prefix for Make build commands to hide them 901# by default during the build. To show them, set V=1 in your 902# environment or command-line. 903# 904# For example: 905# 906# foo.o: foo.c 907# -->|$(hide) <build-commands> 908# 909# Where '-->|' stands for a single tab character. 910# 911# ----------------------------------------------------------------------------- 912ifeq ($(V),1) 913hide = $(empty) 914else 915hide = @ 916endif 917 918# cmd-convert-deps 919# 920# Commands used to copy/convert the .d.org depency file generated by the 921# compiler into its final .d version. 922# 923# On windows, this myst convert the Windows paths to a format that our 924# Cygwin-based GNU Make can understand (i.e. C:/Foo => /cygdrive/c/Foo) 925# 926# On other platforms, this simply renames the file. 927# 928# NOTE: In certain cases, no dependency file will be generated by the 929# compiler (e.g. when compiling an assembly file as foo.s) 930# 931ifeq ($(HOST_OS),windows) 932cmd-convert-deps = \ 933 ( if [ -f "$1.org" ]; then \ 934 $(HOST_AWK) -f $(BUILD_AWK)/convert-deps-to-cygwin.awk $1.org > $1 && \ 935 rm -f $1.org; \ 936 fi ) 937else 938cmd-convert-deps = \ 939 ( if [ -f "$1.org" ]; then \ 940 rm -f $1 && \ 941 mv $1.org $1; \ 942 fi ) 943endif 944 945# This assumes that many variables have been pre-defined: 946# _SRC: source file 947# _OBJ: destination file 948# _CC: 'compiler' command 949# _FLAGS: 'compiler' flags 950# _TEXT: Display text (e.g. "Compile++ thumb", must be EXACTLY 15 chars long) 951# 952define ev-build-file 953$$(_OBJ): PRIVATE_SRC := $$(_SRC) 954$$(_OBJ): PRIVATE_OBJ := $$(_OBJ) 955$$(_OBJ): PRIVATE_DEPS := $$(call host-path,$$(_OBJ).d) 956$$(_OBJ): PRIVATE_MODULE := $$(LOCAL_MODULE) 957$$(_OBJ): PRIVATE_TEXT := "$$(_TEXT)" 958$$(_OBJ): PRIVATE_CC := $$(_CC) 959$$(_OBJ): PRIVATE_CFLAGS := $$(_FLAGS) 960$$(_OBJ): $$(_SRC) $$(LOCAL_MAKEFILE) $$(NDK_APP_APPLICATION_MK) 961 @mkdir -p $$(dir $$(PRIVATE_OBJ)) 962 @echo "$$(PRIVATE_TEXT) : $$(PRIVATE_MODULE) <= $$(notdir $$(PRIVATE_SRC))" 963 $(hide) $$(PRIVATE_CC) -MMD -MP -MF $$(PRIVATE_DEPS).org $$(PRIVATE_CFLAGS) $$(call host-path,$$(PRIVATE_SRC)) -o $$(call host-path,$$(PRIVATE_OBJ)) && \ 964 $$(call cmd-convert-deps,$$(PRIVATE_DEPS)) 965endef 966 967# This assumes the same things than ev-build-file, but will handle 968# the definition of LOCAL_FILTER_ASM as well. 969define ev-build-source-file 970LOCAL_DEPENDENCY_DIRS += $$(dir $$(_OBJ)) 971ifndef LOCAL_FILTER_ASM 972 # Trivial case: Directly generate an object file 973 $$(eval $$(call ev-build-file)) 974else 975 # This is where things get hairy, we first transform 976 # the source into an assembler file, send it to the 977 # filter, then generate a final object file from it. 978 # 979 980 # First, remember the original settings and compute 981 # the location of our temporary files. 982 # 983 _ORG_SRC := $$(_SRC) 984 _ORG_OBJ := $$(_OBJ) 985 _ORG_FLAGS := $$(_FLAGS) 986 _ORG_TEXT := $$(_TEXT) 987 988 _OBJ_ASM_ORIGINAL := $$(patsubst %.o,%.s,$$(_ORG_OBJ)) 989 _OBJ_ASM_FILTERED := $$(patsubst %.o,%.filtered.s,$$(_ORG_OBJ)) 990 991 # If the source file is a plain assembler file, we're going to 992 # use it directly in our filter. 993 ifneq (,$$(filter %.s,$$(_SRC))) 994 _OBJ_ASM_ORIGINAL := $$(_SRC) 995 endif 996 997 #$$(info SRC=$$(_SRC) OBJ=$$(_OBJ) OBJ_ORIGINAL=$$(_OBJ_ASM_ORIGINAL) OBJ_FILTERED=$$(_OBJ_ASM_FILTERED)) 998 999 # We need to transform the source into an assembly file, instead of 1000 # an object. The proper way to do that depends on the file extension. 1001 # 1002 # For C and C++ source files, simply replace the -c by an -S in the 1003 # compilation command (this forces the compiler to generate an 1004 # assembly file). 1005 # 1006 # For assembler templates (which end in .S), replace the -c with -E 1007 # to send it to the preprocessor instead. 1008 # 1009 # Don't do anything for plain assembly files (which end in .s) 1010 # 1011 ifeq (,$$(filter %.s,$$(_SRC))) 1012 _OBJ := $$(_OBJ_ASM_ORIGINAL) 1013 ifneq (,$$(filter %.S,$$(_SRC))) 1014 _FLAGS := $$(patsubst -c,-E,$$(_ORG_FLAGS)) 1015 else 1016 _FLAGS := $$(patsubst -c,-S,$$(_ORG_FLAGS)) 1017 endif 1018 $$(eval $$(call ev-build-file)) 1019 endif 1020 1021 # Next, process the assembly file with the filter 1022 $$(_OBJ_ASM_FILTERED): PRIVATE_SRC := $$(_OBJ_ASM_ORIGINAL) 1023 $$(_OBJ_ASM_FILTERED): PRIVATE_DST := $$(_OBJ_ASM_FILTERED) 1024 $$(_OBJ_ASM_FILTERED): PRIVATE_FILTER := $$(LOCAL_FILTER_ASM) 1025 $$(_OBJ_ASM_FILTERED): PRIVATE_MODULE := $$(LOCAL_MODULE) 1026 $$(_OBJ_ASM_FILTERED): $$(_OBJ_ASM_ORIGINAL) 1027 @echo "AsmFilter : $$(PRIVATE_MODULE) <= $$(notdir $$(PRIVATE_SRC))" 1028 $(hide) $$(PRIVATE_FILTER) $$(PRIVATE_SRC) $$(PRIVATE_DST) 1029 1030 # Then, generate the final object, we need to keep assembler-specific 1031 # flags which look like -Wa,<option>: 1032 _SRC := $$(_OBJ_ASM_FILTERED) 1033 _OBJ := $$(_ORG_OBJ) 1034 _FLAGS := $$(filter -Wa%,$$(_ORG_FLAGS)) -c 1035 _TEXT := "Assembly " 1036 $$(eval $$(call ev-build-file)) 1037endif 1038endef 1039 1040# ----------------------------------------------------------------------------- 1041# Template : ev-compile-c-source 1042# Arguments : 1: single C source file name (relative to LOCAL_PATH) 1043# 2: target object file (without path) 1044# Returns : None 1045# Usage : $(eval $(call ev-compile-c-source,<srcfile>,<objfile>) 1046# Rationale : Internal template evaluated by compile-c-source and 1047# compile-s-source 1048# ----------------------------------------------------------------------------- 1049define ev-compile-c-source 1050_SRC:=$$(LOCAL_PATH)/$(1) 1051_OBJ:=$$(LOCAL_OBJS_DIR)/$(2) 1052 1053_FLAGS := $$($$(my)CFLAGS) \ 1054 $$(call get-src-file-target-cflags,$(1)) \ 1055 $$(call host-c-includes,$$(LOCAL_C_INCLUDES) $$(LOCAL_PATH)) \ 1056 $$(LOCAL_CFLAGS) \ 1057 $$(NDK_APP_CFLAGS) \ 1058 $$(call host-c-includes,$$($(my)C_INCLUDES)) \ 1059 -c \ 1060 1061_TEXT := "Compile $$(call get-src-file-text,$1)" 1062_CC := $$(TARGET_CC) 1063 1064$$(eval $$(call ev-build-source-file)) 1065endef 1066 1067# ----------------------------------------------------------------------------- 1068# Function : compile-c-source 1069# Arguments : 1: single C source file name (relative to LOCAL_PATH) 1070# Returns : None 1071# Usage : $(call compile-c-source,<srcfile>) 1072# Rationale : Setup everything required to build a single C source file 1073# ----------------------------------------------------------------------------- 1074compile-c-source = $(eval $(call ev-compile-c-source,$1,$(1:%.c=%.o))) 1075 1076# ----------------------------------------------------------------------------- 1077# Function : compile-s-source 1078# Arguments : 1: single Assembly source file name (relative to LOCAL_PATH) 1079# Returns : None 1080# Usage : $(call compile-s-source,<srcfile>) 1081# Rationale : Setup everything required to build a single Assembly source file 1082# ----------------------------------------------------------------------------- 1083compile-s-source = $(eval $(call ev-compile-c-source,$1,$(patsubst %.s,%.o,$(patsubst %.S,%.o,$1)))) 1084 1085 1086# ----------------------------------------------------------------------------- 1087# Template : ev-compile-cpp-source 1088# Arguments : 1: single C++ source file name (relative to LOCAL_PATH) 1089# 2: target object file (without path) 1090# Returns : None 1091# Usage : $(eval $(call ev-compile-cpp-source,<srcfile>,<objfile>) 1092# Rationale : Internal template evaluated by compile-cpp-source 1093# ----------------------------------------------------------------------------- 1094 1095define ev-compile-cpp-source 1096_SRC:=$$(LOCAL_PATH)/$(1) 1097_OBJ:=$$(LOCAL_OBJS_DIR)/$(2) 1098_FLAGS := $$($$(my)CXXFLAGS) \ 1099 $$(call get-src-file-target-cflags,$(1)) \ 1100 $$(call host-c-includes, $$(LOCAL_C_INCLUDES) $$(LOCAL_PATH)) \ 1101 $$(LOCAL_CFLAGS) \ 1102 $$(LOCAL_CPPFLAGS) \ 1103 $$(LOCAL_CXXFLAGS) \ 1104 $$(NDK_APP_CFLAGS) \ 1105 $$(NDK_APP_CPPFLAGS) \ 1106 $$(NDK_APP_CXXFLAGS) \ 1107 $$(call host-c-includes,$$($(my)C_INCLUDES)) \ 1108 -c \ 1109 1110_CC := $$($$(my)CXX) 1111_TEXT := "Compile++ $$(call get-src-file-text,$1)" 1112 1113$$(eval $$(call ev-build-source-file)) 1114endef 1115 1116# ----------------------------------------------------------------------------- 1117# Function : compile-cpp-source 1118# Arguments : 1: single C++ source file name (relative to LOCAL_PATH) 1119# Returns : None 1120# Usage : $(call compile-c-source,<srcfile>) 1121# Rationale : Setup everything required to build a single C++ source file 1122# ----------------------------------------------------------------------------- 1123compile-cpp-source = $(eval $(call ev-compile-cpp-source,$1,$(1:%$(LOCAL_CPP_EXTENSION)=%.o))) 1124 1125# ----------------------------------------------------------------------------- 1126# Command : cmd-install-file 1127# Arguments : 1: source file 1128# 2: destination file 1129# Returns : None 1130# Usage : $(call cmd-install-file,<srcfile>,<dstfile>) 1131# Rationale : To be used as a Make build command to copy/install a file to 1132# a given location. 1133# ----------------------------------------------------------------------------- 1134define cmd-install-file 1135@mkdir -p $(dir $2) 1136$(hide) cp -fp $1 $2 1137endef 1138 1139 1140# 1141# Module imports 1142# 1143 1144# Initialize import list 1145import-init = $(eval __ndk_import_dirs :=) 1146 1147# Add an optional single directory to the list of import paths 1148# 1149import-add-path-optional = \ 1150 $(if $(strip $(wildcard $1)),\ 1151 $(call ndk_log,Adding import directory: $1)\ 1152 $(eval __ndk_import_dirs += $1)\ 1153 )\ 1154 1155# Add a directory to the list of import paths 1156# This will warn if the directory does not exist 1157# 1158import-add-path = \ 1159 $(if $(strip $(wildcard $1)),\ 1160 $(call ndk_log,Adding import directory: $1)\ 1161 $(eval __ndk_import_dirs += $1)\ 1162 ,\ 1163 $(call __ndk_info,WARNING: Ignoring unknown import directory: $1)\ 1164 )\ 1165 1166import-find-module = $(strip \ 1167 $(eval __imported_module :=)\ 1168 $(foreach __import_dir,$(__ndk_import_dirs),\ 1169 $(if $(__imported_module),,\ 1170 $(call ndk_log, Probing $(__import_dir)/$1/Android.mk)\ 1171 $(if $(strip $(wildcard $(__import_dir)/$1/Android.mk)),\ 1172 $(eval __imported_module := $(__import_dir)/$1)\ 1173 )\ 1174 )\ 1175 )\ 1176 $(__imported_module)\ 1177 ) 1178 1179# described in docs/IMPORT-MODULE.TXT 1180# $1: tag name for the lookup 1181# 1182# Small technical note on __ndk_import_depth: we use this variable to 1183# record the depth of recursive import-module calls. The variable is 1184# initially empty, and we append a "x" to it each time import-module is 1185# called. I.e. for three recursive calls to import-module, we would get 1186# the values: 1187# 1188# first call: x 1189# second call: xx 1190# third call: xxx 1191# 1192# This is used in module-add to add the top-level modules (i.e. those 1193# that are not added with import-module) to __ndk_top_modules, corresponding 1194# to the default list of wanted modules (see setup-toolchain.mk). 1195# 1196import-module = \ 1197 $(eval __import_tag := $(strip $1))\ 1198 $(if $(call seq,$(words $(__import_tag)),1),,\ 1199 $(call __ndk_info,$(call local-makefile): Cannot import module with spaces in tag: '$(__import_tag)')\ 1200 )\ 1201 $(if $(call set_is_member,$(__ndk_import_list),$(__import_tag)),\ 1202 $(call ndk_log,Skipping duplicate import for module with tag '$(__import_tag)')\ 1203 ,\ 1204 $(call ndk_log,Looking for imported module with tag '$(__import_tag)')\ 1205 $(eval __imported_path := $(call import-find-module,$(__import_tag)))\ 1206 $(if $(__imported_path),\ 1207 $(call ndk_log, Found in $(__imported_path))\ 1208 $(eval __ndk_import_depth := $(__ndk_import_depth)x) \ 1209 $(eval __ndk_import_list := $(call set_insert,$(__ndk_import_list),$(__import_tag)))\ 1210 $(eval include $(__imported_path)/Android.mk)\ 1211 $(eval __ndk_import_depth := $(__ndk_import_depth:%x=%))\ 1212 ,\ 1213 $(call __ndk_info,$(call local-makefile): Cannot find module with tag '$(__import_tag)' in import path)\ 1214 $(call __ndk_info,Are you sure your NDK_MODULE_PATH variable is properly defined ?)\ 1215 $(call __ndk_info,The following directories were searched:)\ 1216 $(for __import_dir,$(__ndk_import_dirs),\ 1217 $(call __ndk_info, $(__import_dir))\ 1218 )\ 1219 $(call __ndk_error,Aborting.)\ 1220 )\ 1221 ) 1222 1223# Only used for debugging 1224# 1225import-debug = \ 1226 $(info IMPORT DIRECTORIES:)\ 1227 $(foreach __dir,$(__ndk_import_dirs),\ 1228 $(info -- $(__dir))\ 1229 )\ 1230 1231# 1232# Module classes 1233# 1234NDK_MODULE_CLASSES := 1235 1236# Register a new module class 1237# $1: class name (e.g. STATIC_LIBRARY) 1238# $2: optional file prefix (e.g. 'lib') 1239# $3: optional file suffix (e.g. '.so') 1240# 1241module-class-register = \ 1242 $(eval NDK_MODULE_CLASSES += $1) \ 1243 $(eval NDK_MODULE_CLASS.$1.FILE_PREFIX := $2) \ 1244 $(eval NDK_MODULE_CLASS.$1.FILE_SUFFIX := $3) \ 1245 $(eval NDK_MODULE_CLASS.$1.INSTALLABLE := $(false)) \ 1246 1247# Same a module-class-register, for installable modules 1248# 1249# An installable module is one that will be copied to $PROJECT/libs/<abi>/ 1250# during the NDK build. 1251# 1252# $1: class name 1253# $2: optional file prefix 1254# $3: optional file suffix 1255# 1256module-class-register-installable = \ 1257 $(call module-class-register,$1,$2,$3) \ 1258 $(eval NDK_MODULE_CLASS.$1.INSTALLABLE := $(true)) 1259 1260module-class-set-prebuilt = \ 1261 $(eval NDK_MODULE_CLASS.$1.PREBUILT := $(true)) 1262 1263# Returns $(true) if $1 is a valid/registered LOCAL_MODULE_CLASS value 1264# 1265module-class-check = $(call set_is_member,$(NDK_MODULE_CLASSES),$1) 1266 1267# Returns $(true) if $1 corresponds to an installable module class 1268# 1269module-class-is-installable = $(if $(NDK_MODULE_CLASS.$1.INSTALLABLE),$(true),$(false)) 1270 1271# Returns $(true) if $1 corresponds to an installable module class 1272# 1273module-class-is-prebuilt = $(if $(NDK_MODULE_CLASS.$1.PREBUILT),$(true),$(false)) 1274 1275# 1276# Register valid module classes 1277# 1278 1279# static libraries: 1280# <foo> -> lib<foo>.a by default 1281$(call module-class-register,STATIC_LIBRARY,lib,.a) 1282 1283# shared libraries: 1284# <foo> -> lib<foo>.so 1285# a shared library is installable. 1286$(call module-class-register-installable,SHARED_LIBRARY,lib,.so) 1287 1288# executable 1289# <foo> -> <foo> 1290# an executable is installable. 1291$(call module-class-register-installable,EXECUTABLE,,) 1292 1293# prebuilt shared library 1294# <foo> -> <foo> (we assume it is already well-named) 1295# it is installable 1296$(call module-class-register-installable,PREBUILT_SHARED_LIBRARY,,) 1297$(call module-class-set-prebuilt,PREBUILT_SHARED_LIBRARY) 1298 1299# prebuilt static library 1300# <foo> -> <foo> (we assume it is already well-named) 1301$(call module-class-register,PREBUILT_STATIC_LIBRARY,,) 1302$(call module-class-set-prebuilt,PREBUILT_STATIC_LIBRARY) 1303 1304# 1305# C++ STL support 1306# 1307 1308# The list of registered STL implementations we support 1309NDK_STL_LIST := 1310 1311# Used internally to register a given STL implementation, see below. 1312# 1313# $1: STL name as it appears in APP_STL (e.g. system) 1314# $2: STL module name (e.g. cxx-stl/system) 1315# $3: list of static libraries all modules will depend on 1316# $4: list of shared libraries all modules will depend on 1317# 1318ndk-stl-register = \ 1319 $(eval __ndk_stl := $(strip $1)) \ 1320 $(eval NDK_STL_LIST += $(__ndk_stl)) \ 1321 $(eval NDK_STL.$(__ndk_stl).IMPORT_MODULE := $(strip $2)) \ 1322 $(eval NDK_STL.$(__ndk_stl).STATIC_LIBS := $(strip $3)) \ 1323 $(eval NDK_STL.$(__ndk_stl).SHARED_LIBS := $(strip $4)) 1324 1325# Called to check that the value of APP_STL is a valid one. 1326# $1: STL name as it apperas in APP_STL (e.g. 'system') 1327# 1328ndk-stl-check = \ 1329 $(if $(call set_is_member,$(NDK_STL_LIST),$1),,\ 1330 $(call __ndk_info,Invalid APP_STL value: $1)\ 1331 $(call __ndk_info,Please use one of the following instead: $(NDK_STL_LIST))\ 1332 $(call __ndk_error,Aborting)) 1333 1334# Called before the top-level Android.mk is parsed to 1335# select the STL implementation. 1336# $1: STL name as it appears in APP_STL (e.g. system) 1337# 1338ndk-stl-select = \ 1339 $(call import-module,$(NDK_STL.$1.IMPORT_MODULE)) 1340 1341# Called after all Android.mk files are parsed to add 1342# proper STL dependencies to every C++ module. 1343# $1: STL name as it appears in APP_STL (e.g. system) 1344# 1345ndk-stl-add-dependencies = \ 1346 $(call modules-add-c++-dependencies,\ 1347 $(NDK_STL.$1.STATIC_LIBS),\ 1348 $(NDK_STL.$1.SHARED_LIBS)) 1349 1350# 1351# 1352 1353# Register the 'system' STL implementation 1354# 1355$(call ndk-stl-register,\ 1356 system,\ 1357 cxx-stl/system,\ 1358 libstdc++,\ 1359 ) 1360 1361# Register the 'stlport_static' STL implementation 1362# 1363$(call ndk-stl-register,\ 1364 stlport_static,\ 1365 cxx-stl/stlport,\ 1366 stlport_static,\ 1367 ) 1368 1369# Register the 'stlport_shared' STL implementation 1370# 1371$(call ndk-stl-register,\ 1372 stlport_shared,\ 1373 cxx-stl/stlport,\ 1374 ,\ 1375 stlport_shared\ 1376 ) 1377 1378# Register the 'gnustl_static' STL implementation 1379# 1380$(call ndk-stl-register,\ 1381 gnustl_static,\ 1382 cxx-stl/gnu-libstdc++,\ 1383 gnustl_static,\ 1384 \ 1385 ) 1386