1 # Copyright (C) 2008 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 16 # Check that LOCAL_MODULE is defined, then restore its LOCAL_XXXX values 17 $(call assert-defined,LOCAL_MODULE) 18 $(call module-restore-locals,$(LOCAL_MODULE)) 19 20 # For now, only support target (device-specific modules). 21 # We may want to introduce support for host modules in the future 22 # but that is too experimental for now. 23 # 24 my := TARGET_ 25 26 # LOCAL_MAKEFILE must also exist and name the Android.mk that 27 # included the module build script. 28 # 29 $(call assert-defined,LOCAL_MAKEFILE LOCAL_BUILD_SCRIPT LOCAL_BUILT_MODULE) 30 31 # A list of LOCAL_XXX variables that are ignored for static libraries. 32 # Print a warning if they are present inside a module definition to let 33 # the user know this won't do what he/she expects. 34 not_in_static_libs := \ 35 LOCAL_LDFLAGS \ 36 LOCAL_LDLIBS \ 37 LOCAL_ALLOW_UNDEFINED_SYMBOLS 38 39 ifeq ($(call module-get-class,$(LOCAL_MODULE)),STATIC_LIBRARY) 40 $(foreach _notvar,$(not_in_static_libs),\ 41 $(if $(strip $($(_notvar))),\ 42 $(call __ndk_info,WARNING:$(LOCAL_MAKEFILE):$(LOCAL_MODULE): $(_notvar) is always ignored for static libraries)\ 43 )\ 44 ) 45 endif 46 47 # Some developers like to add library names (e.g. -lfoo) to LOCAL_LDLIBS 48 # and LOCAL_LDFLAGS directly. This is very fragile and can lead to broken 49 # builds and other nasty surprises, because it doesn't tell ndk-build 50 # that the corresponding module depends on these files. Emit a warning 51 # when we detect this case. 52 libs_in_ldflags := $(filter -l% %.so %.a,$(LOCAL_LDLIBS) $(LOCAL_LDFLAGS)) 53 54 # Remove the system libraries we know about from the warning, it's ok 55 # (and actually expected) to link them with -l<name>. 56 system_libs := \ 57 android \ 58 c \ 59 dl \ 60 jnigraphics \ 61 log \ 62 m \ 63 m_hard \ 64 stdc++ \ 65 z \ 66 EGL \ 67 GLESv1_CM \ 68 GLESv2 \ 69 GLESv3 \ 70 OpenSLES \ 71 OpenMAXAL \ 72 bcc \ 73 bcinfo \ 74 cutils \ 75 gui \ 76 RScpp \ 77 RScpp_static \ 78 RS \ 79 ui \ 80 utils \ 81 atomic 82 83 libs_in_ldflags := $(filter-out $(addprefix -l,$(system_libs)), $(libs_in_ldflags)) 84 85 ifneq (,$(strip $(libs_in_ldflags))) 86 $(call __ndk_info,WARNING:$(LOCAL_MAKEFILE):$(LOCAL_MODULE): non-system libraries in linker flags: $(libs_in_ldflags)) 87 $(call __ndk_info, This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES) 88 $(call __ndk_info, or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the) 89 $(call __ndk_info, current module) 90 endif 91 92 include $(BUILD_SYSTEM)/import-locals.mk 93 94 # Check for LOCAL_THIN_ARCHIVE / APP_THIN_ARCHIVE and print a warning if 95 # it is defined for non-static library modules. 96 thin_archive := $(strip $(LOCAL_THIN_ARCHIVE)) 97 ifdef thin_archive 98 ifneq (STATIC_LIBRARY,$(call module-get-class,$(LOCAL_MODULE))) 99 $(call __ndk_info,WARNING:$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_THIN_ARCHIVE is for building static libraries) 100 endif 101 endif 102 103 ifndef thin_archive 104 thin_archive := $(strip $(NDK_APP_THIN_ARCHIVE)) 105 endif 106 # Print a warning if the value is not 'true', 'false' or empty. 107 ifneq (,$(filter-out true false,$(thin_archive))) 108 $(call __ndk_info,WARNING:$(LOCAL_MAKEFILE):$(LOCAL_MODULE): Invalid LOCAL_THIN_ARCHIVE value '$(thin_archive)' ignored!) 109 thin_archive := 110 endif 111 112 # 113 # Ensure that 'make <module>' and 'make clean-<module>' work 114 # 115 .PHONY: $(LOCAL_MODULE) 116 $(LOCAL_MODULE): $(LOCAL_BUILT_MODULE) 117 118 cleantarget := clean-$(LOCAL_MODULE)-$(TARGET_ARCH_ABI) 119 .PHONY: $(cleantarget) 120 clean: $(cleantarget) 121 122 $(cleantarget): PRIVATE_ABI := $(TARGET_ARCH_ABI) 123 $(cleantarget): PRIVATE_MODULE := $(LOCAL_MODULE) 124 ifneq ($(LOCAL_BUILT_MODULE_NOT_COPIED),true) 125 $(cleantarget): PRIVATE_CLEAN_FILES := $(LOCAL_BUILT_MODULE) \ 126 $($(my)OBJS) 127 else 128 $(cleantarget): PRIVATE_CLEAN_FILES := $($(my)OBJS) 129 endif 130 $(cleantarget):: 131 $(call host-echo-build-step,$(PRIVATE_ABI),Clean) "$(PRIVATE_MODULE) [$(PRIVATE_ABI)]" 132 $(hide) $(call host-rmdir,$(PRIVATE_CLEAN_FILES)) 133 134 ifeq ($(NDK_APP_DEBUGGABLE),true) 135 $(NDK_APP_GDBSETUP): PRIVATE_SRC_DIRS += $(LOCAL_C_INCLUDES) $(LOCAL_PATH) 136 endif 137 138 # list of generated object files 139 LOCAL_OBJECTS := 140 141 # list of generated object files from RS files, subset of LOCAL_OBJECTS 142 LOCAL_RS_OBJECTS := 143 144 # always define ANDROID when building binaries 145 # 146 LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS) 147 148 # 149 # Add the default system shared libraries to the build 150 # 151 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 152 LOCAL_SHARED_LIBRARIES += $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES) 153 else 154 LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 155 endif 156 157 # 158 # Check LOCAL_CPP_EXTENSION 159 # 160 bad_cpp_extensions := $(strip $(filter-out .%,$(LOCAL_CPP_EXTENSION))) 161 ifdef bad_cpp_extensions 162 $(call __ndk_info,WARNING: Invalid LOCAL_CPP_EXTENSION values: $(bad_cpp_extensions)) 163 LOCAL_CPP_EXTENSION := $(filter $(bad_cpp_extensions),$(LOCAL_CPP_EXTENSIONS)) 164 endif 165 LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) 166 ifeq ($(LOCAL_CPP_EXTENSION),) 167 # Match the default GCC C++ extensions. 168 LOCAL_CPP_EXTENSION := $(default-c++-extensions) 169 endif 170 LOCAL_RS_EXTENSION := $(default-rs-extensions) 171 172 # 173 # If LOCAL_ALLOW_UNDEFINED_SYMBOLS is not true, the linker will allow the generation 174 # of a binary that uses undefined symbols. 175 # 176 ifneq ($(LOCAL_ALLOW_UNDEFINED_SYMBOLS),true) 177 LOCAL_LDFLAGS += $($(my)NO_UNDEFINED_LDFLAGS) 178 endif 179 180 # Toolchain by default disallows generated code running from the heap and stack. 181 # If LOCAL_DISABLE_NO_EXECUTE is true, we allow that 182 # 183 ifeq ($(LOCAL_DISABLE_NO_EXECUTE),true) 184 LOCAL_CFLAGS += $($(my)DISABLE_NO_EXECUTE_CFLAGS) 185 LOCAL_LDFLAGS += $($(my)DISABLE_NO_EXECUTE_LDFLAGS) 186 else 187 LOCAL_CFLAGS += $($(my)NO_EXECUTE_CFLAGS) 188 LOCAL_LDFLAGS += $($(my)NO_EXECUTE_LDFLAGS) 189 endif 190 191 # Toolchain by default provides relro and GOT protections. 192 # If LOCAL_DISABLE_RELRO is true, we disable the protections. 193 # 194 ifeq ($(LOCAL_DISABLE_RELRO),true) 195 LOCAL_LDFLAGS += $($(my)DISABLE_RELRO_LDFLAGS) 196 else 197 LOCAL_LDFLAGS += $($(my)RELRO_LDFLAGS) 198 endif 199 200 # By default, we protect against format string vulnerabilities 201 # If LOCAL_DISABLE_FORMAT_STRING_CHECKS is true, we disable the protections. 202 ifeq ($(LOCAL_DISABLE_FORMAT_STRING_CHECKS),true) 203 LOCAL_CFLAGS += $($(my)DISABLE_FORMAT_STRING_CFLAGS) 204 else 205 LOCAL_CFLAGS += $($(my)FORMAT_STRING_CFLAGS) 206 endif 207 208 # enable PIE for executable beyond certain API level, unless "-static" 209 ifneq (,$(filter true,$(NDK_APP_PIE) $(TARGET_PIE))) 210 ifeq ($(call module-get-class,$(LOCAL_MODULE)),EXECUTABLE) 211 ifeq (,$(filter -static,$(TARGET_LDFLAGS) $(LOCAL_LDFLAGS) $(NDK_APP_LDFLAGS))) 212 LOCAL_CFLAGS += -fPIE 213 LOCAL_LDFLAGS += -fPIE -pie 214 endif 215 endif 216 endif 217 218 # 219 # The original Android build system allows you to use the .arm prefix 220 # to a source file name to indicate that it should be defined in either 221 # 'thumb' or 'arm' mode, depending on the value of LOCAL_ARM_MODE 222 # 223 # First, check LOCAL_ARM_MODE, it should be empty, 'thumb' or 'arm' 224 # We make the default 'thumb' 225 # 226 LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE)) 227 ifdef LOCAL_ARM_MODE 228 ifneq ($(words $(LOCAL_ARM_MODE)),1) 229 $(call __ndk_info, LOCAL_ARM_MODE in $(LOCAL_MAKEFILE) must be one word, not '$(LOCAL_ARM_MODE)') 230 $(call __ndk_error, Aborting) 231 endif 232 # check that LOCAL_ARM_MODE is defined to either 'arm' or 'thumb' 233 $(if $(filter-out thumb arm, $(LOCAL_ARM_MODE)),\ 234 $(call __ndk_info, LOCAL_ARM_MODE must be defined to either 'arm' or 'thumb' in $(LOCAL_MAKEFILE) not '$(LOCAL_ARM_MODE)')\ 235 $(call __ndk_error, Aborting)\ 236 ) 237 endif 238 239 # As a special case, the original Android build system 240 # allows one to specify that certain source files can be 241 # forced to build in ARM mode by using a '.arm' suffix 242 # after the extension, e.g. 243 # 244 # LOCAL_SRC_FILES := foo.c.arm 245 # 246 # to build source file $(LOCAL_PATH)/foo.c as ARM 247 # 248 249 $(call clear-all-src-tags) 250 251 # As a special extension, the NDK also supports the .neon extension suffix 252 # to indicate that a single file can be compiled with ARM NEON support 253 # We must support both foo.c.neon and foo.c.arm.neon here 254 # 255 # Also, if LOCAL_ARM_NEON is set to 'true', force Neon mode for all source 256 # files 257 # 258 259 neon_sources := $(filter %.neon,$(LOCAL_SRC_FILES)) 260 neon_sources := $(neon_sources:%.neon=%) 261 262 LOCAL_ARM_NEON := $(strip $(LOCAL_ARM_NEON)) 263 ifdef LOCAL_ARM_NEON 264 $(if $(filter-out true false,$(LOCAL_ARM_NEON)),\ 265 $(call __ndk_info,LOCAL_ARM_NEON must be defined either to 'true' or 'false' in $(LOCAL_MAKEFILE), not '$(LOCAL_ARM_NEON)')\ 266 $(call __ndk_error,Aborting) \ 267 ) 268 endif 269 ifeq ($(LOCAL_ARM_NEON),true) 270 neon_sources += $(LOCAL_SRC_FILES:%.neon=%) 271 # tag the precompiled header with 'neon' tag if it exists 272 ifneq (,$(LOCAL_PCH)) 273 $(call tag-src-files,$(LOCAL_PCH),neon) 274 endif 275 endif 276 277 neon_sources := $(strip $(neon_sources)) 278 ifdef neon_sources 279 ifeq ($(filter $(TARGET_ARCH_ABI), armeabi-v7a armeabi-v7a-hard x86),) 280 $(call __ndk_info,NEON support is only possible for armeabi-v7a ABI, its variant armeabi-v7a-hard and x86 ABI) 281 $(call __ndk_info,Please add checks against TARGET_ARCH_ABI in $(LOCAL_MAKEFILE)) 282 $(call __ndk_error,Aborting) 283 endif 284 $(call tag-src-files,$(neon_sources:%.arm=%),neon) 285 endif 286 287 LOCAL_SRC_FILES := $(LOCAL_SRC_FILES:%.neon=%) 288 289 # strip the .arm suffix from LOCAL_SRC_FILES 290 # and tag the relevant sources with the 'arm' tag 291 # 292 arm_sources := $(filter %.arm,$(LOCAL_SRC_FILES)) 293 arm_sources := $(arm_sources:%.arm=%) 294 thumb_sources := $(filter-out %.arm,$(LOCAL_SRC_FILES)) 295 LOCAL_SRC_FILES := $(LOCAL_SRC_FILES:%.arm=%) 296 297 ifeq ($(LOCAL_ARM_MODE),arm) 298 arm_sources := $(LOCAL_SRC_FILES) 299 # tag the precompiled header with 'arm' tag if it exists 300 ifneq (,$(LOCAL_PCH)) 301 $(call tag-src-files,$(LOCAL_PCH),arm) 302 endif 303 endif 304 ifeq ($(LOCAL_ARM_MODE),thumb) 305 arm_sources := $(empty) 306 endif 307 $(call tag-src-files,$(arm_sources),arm) 308 309 # tag debug if APP_OPTIM is 'debug' 310 # 311 ifeq ($(APP_OPTIM),debug) 312 $(call tag-src-files,$(LOCAL_SRC_FILES),debug) 313 ifneq (,$(LOCAL_PCH)) 314 $(call tag-src-files,$(LOCAL_PCH),debug) 315 endif 316 endif 317 318 # add PCH to LOCAL_SRC_FILES so that TARGET-process-src-files-tags could process it 319 ifneq (,$(LOCAL_PCH)) 320 LOCAL_SRC_FILES += $(LOCAL_PCH) 321 endif 322 323 # Process all source file tags to determine toolchain-specific 324 # target compiler flags, and text. 325 # 326 $(call TARGET-process-src-files-tags) 327 328 # now remove PCH from LOCAL_SRC_FILES to prevent getting NDK warning about 329 # unsupported source file extensions 330 ifneq (,$(LOCAL_PCH)) 331 LOCAL_SRC_FILES := $(filter-out $(LOCAL_PCH),$(LOCAL_SRC_FILES)) 332 endif 333 334 # only call dump-src-file-tags during debugging 335 #$(dump-src-file-tags) 336 337 LOCAL_DEPENDENCY_DIRS := 338 339 # all_source_patterns contains the list of filename patterns that correspond 340 # to source files recognized by our build system 341 ifeq ($(TARGET_ARCH_ABI),x86) 342 all_source_extensions := .c .s .S .asm $(LOCAL_CPP_EXTENSION) $(LOCAL_RS_EXTENSION) 343 else 344 all_source_extensions := .c .s .S $(LOCAL_CPP_EXTENSION) $(LOCAL_RS_EXTENSION) 345 endif 346 all_source_patterns := $(foreach _ext,$(all_source_extensions),%$(_ext)) 347 all_cpp_patterns := $(foreach _ext,$(LOCAL_CPP_EXTENSION),%$(_ext)) 348 all_rs_patterns := $(foreach _ext,$(LOCAL_RS_EXTENSION),%$(_ext)) 349 350 unknown_sources := $(strip $(filter-out $(all_source_patterns),$(LOCAL_SRC_FILES))) 351 ifdef unknown_sources 352 $(call __ndk_info,WARNING: Unsupported source file extensions in $(LOCAL_MAKEFILE) for module $(LOCAL_MODULE)) 353 $(call __ndk_info, $(unknown_sources)) 354 endif 355 356 # LOCAL_OBJECTS will list all object files corresponding to the sources 357 # listed in LOCAL_SRC_FILES, in the *same* order. 358 # 359 LOCAL_OBJECTS := $(LOCAL_SRC_FILES) 360 $(foreach _ext,$(all_source_extensions),\ 361 $(eval LOCAL_OBJECTS := $$(LOCAL_OBJECTS:%$(_ext)=%$$(TARGET_OBJ_EXTENSION)))\ 362 ) 363 LOCAL_OBJECTS := $(filter %$(TARGET_OBJ_EXTENSION),$(LOCAL_OBJECTS)) 364 LOCAL_OBJECTS := $(subst ../,__/,$(LOCAL_OBJECTS)) 365 LOCAL_OBJECTS := $(subst :,_,$(LOCAL_OBJECTS)) 366 LOCAL_OBJECTS := $(foreach _obj,$(LOCAL_OBJECTS),$(LOCAL_OBJS_DIR)/$(_obj)) 367 368 LOCAL_RS_OBJECTS := $(filter $(all_rs_patterns),$(LOCAL_SRC_FILES)) 369 $(foreach _ext,$(LOCAL_RS_EXTENSION),\ 370 $(eval LOCAL_RS_OBJECTS := $$(LOCAL_RS_OBJECTS:%$(_ext)=%$$(TARGET_OBJ_EXTENSION)))\ 371 ) 372 LOCAL_RS_OBJECTS := $(filter %$(TARGET_OBJ_EXTENSION),$(LOCAL_RS_OBJECTS)) 373 LOCAL_RS_OBJECTS := $(subst ../,__/,$(LOCAL_RS_OBJECTS)) 374 LOCAL_RS_OBJECTS := $(subst :,_,$(LOCAL_RS_OBJECTS)) 375 LOCAL_RS_OBJECTS := $(foreach _obj,$(LOCAL_RS_OBJECTS),$(LOCAL_OBJS_DIR)/$(_obj)) 376 377 # If the module has any kind of C++ features, enable them in LOCAL_CPPFLAGS 378 # 379 ifneq (,$(call module-has-c++-features,$(LOCAL_MODULE),rtti)) 380 LOCAL_CPPFLAGS += -frtti 381 endif 382 ifneq (,$(call module-has-c++-features,$(LOCAL_MODULE),exceptions)) 383 LOCAL_CPPFLAGS += -fexceptions 384 endif 385 386 # If we're using the 'system' STL and use rtti or exceptions, then 387 # automatically link against the GNU libsupc++ for now. 388 # 389 ifneq (,$(call module-has-c++-features,$(LOCAL_MODULE),rtti exceptions)) 390 ifeq (system,$(NDK_APP_STL)) 391 LOCAL_LDLIBS := $(LOCAL_LDLIBS) $(call host-path,$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/$(TARGET_ARCH_ABI)/libsupc++$(TARGET_LIB_EXTENSION)) 392 endif 393 endif 394 395 # Set include patch for renderscript 396 397 398 ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),) 399 LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE) 400 else 401 LOCAL_RENDERSCRIPT_INCLUDES := \ 402 $(RENDERSCRIPT_TOOLCHAIN_HEADER) \ 403 $(TARGET_C_INCLUDES)/rs/scriptc \ 404 $(LOCAL_RENDERSCRIPT_INCLUDES) 405 endif 406 407 RS_COMPAT := 408 ifneq ($(call module-is-shared-library,$(LOCAL_MODULE)),) 409 RS_COMPAT := true 410 endif 411 412 413 # Build PCH 414 415 get-pch-name = $(strip \ 416 $(subst ../,__/,\ 417 $(eval __pch := $1)\ 418 $(eval __pch := $(__pch:%.h=%.precompiled.h))\ 419 $(__pch)\ 420 )) 421 422 ifneq (,$(LOCAL_PCH)) 423 # Build PCH into obj directory 424 LOCAL_BUILT_PCH := $(call get-pch-name,$(LOCAL_PCH)) 425 426 # Build PCH 427 $(call compile-cpp-source,$(LOCAL_PCH),$(LOCAL_BUILT_PCH).gch) 428 429 # All obj files are dependent on the PCH 430 $(foreach src,$(filter $(all_cpp_patterns),$(LOCAL_SRC_FILES)),\ 431 $(eval $(LOCAL_OBJS_DIR)/$(call get-object-name,$(src)) : $(LOCAL_OBJS_DIR)/$(LOCAL_BUILT_PCH).gch)\ 432 ) 433 434 # Files from now on build with PCH 435 LOCAL_CPPFLAGS += -Winvalid-pch -include $(LOCAL_BUILT_PCH) 436 437 # Insert PCH dir at beginning of include search path 438 LOCAL_C_INCLUDES := \ 439 $(LOCAL_OBJS_DIR) \ 440 $(LOCAL_C_INCLUDES) 441 endif 442 443 # Build the sources to object files 444 # 445 446 $(foreach src,$(filter %.c,$(LOCAL_SRC_FILES)), $(call compile-c-source,$(src),$(call get-object-name,$(src)))) 447 $(foreach src,$(filter %.S %.s,$(LOCAL_SRC_FILES)), $(call compile-s-source,$(src),$(call get-object-name,$(src)))) 448 $(foreach src,$(filter $(all_cpp_patterns),$(LOCAL_SRC_FILES)),\ 449 $(call compile-cpp-source,$(src),$(call get-object-name,$(src)))\ 450 ) 451 452 $(foreach src,$(filter $(all_rs_patterns),$(LOCAL_SRC_FILES)),\ 453 $(call compile-rs-source,$(src),$(call get-rs-scriptc-name,$(src)),$(call get-rs-bc-name,$(src)),$(call get-rs-so-name,$(src)),$(call get-object-name,$(src)),$(RS_COMPAT))\ 454 ) 455 456 ifeq ($(TARGET_ARCH_ABI),x86) 457 $(foreach src,$(filter %.asm,$(LOCAL_SRC_FILES)), $(call compile-asm-source,$(src),$(call get-object-name,$(src)))) 458 endif 459 460 # 461 # The compile-xxx-source calls updated LOCAL_OBJECTS and LOCAL_DEPENDENCY_DIRS 462 # 463 ALL_DEPENDENCY_DIRS += $(sort $(LOCAL_DEPENDENCY_DIRS)) 464 CLEAN_OBJS_DIRS += $(LOCAL_OBJS_DIR) 465 466 # 467 # Handle the static and shared libraries this module depends on 468 # 469 470 # If LOCAL_LDLIBS contains anything like -l<library> then 471 # prepend a -L$(SYSROOT_LINK)/usr/lib to it to ensure that the linker 472 # looks in the right location 473 # 474 ifneq ($(filter -l%,$(LOCAL_LDLIBS)),) 475 LOCAL_LDLIBS := -L$(call host-path,$(SYSROOT_LINK)/usr/lib) $(LOCAL_LDLIBS) 476 ifneq ($(filter x86_64 mips64,$(TARGET_ARCH_ABI)),) 477 LOCAL_LDLIBS := -L$(call host-path,$(SYSROOT_LINK)/usr/lib64) $(LOCAL_LDLIBS) 478 endif 479 endif 480 481 # When LOCAL_SHORT_COMMANDS is defined to 'true' we are going to write the 482 # list of all object files and/or static/shared libraries that appear on the 483 # command line to a file, then use the @<listfile> syntax to invoke it. 484 # 485 # This allows us to link or archive a huge number of stuff even on Windows 486 # with its puny 8192 max character limit on its command-line. 487 # 488 LOCAL_SHORT_COMMANDS := $(strip $(LOCAL_SHORT_COMMANDS)) 489 ifndef LOCAL_SHORT_COMMANDS 490 LOCAL_SHORT_COMMANDS := $(strip $(NDK_APP_SHORT_COMMANDS)) 491 endif 492 493 $(call generate-file-dir,$(LOCAL_BUILT_MODULE)) 494 495 $(LOCAL_BUILT_MODULE): PRIVATE_OBJECTS := $(LOCAL_OBJECTS) 496 $(LOCAL_BUILT_MODULE): PRIVATE_LIBGCC := $(TARGET_LIBGCC) 497 498 $(LOCAL_BUILT_MODULE): PRIVATE_LD := $(TARGET_LD) 499 $(LOCAL_BUILT_MODULE): PRIVATE_LDFLAGS := $(TARGET_LDFLAGS) $(LOCAL_LDFLAGS) $(NDK_APP_LDFLAGS) 500 $(LOCAL_BUILT_MODULE): PRIVATE_LDLIBS := $(LOCAL_LDLIBS) $(TARGET_LDLIBS) 501 502 $(LOCAL_BUILT_MODULE): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) 503 $(LOCAL_BUILT_MODULE): PRIVATE_CXX := $(TARGET_CXX) 504 $(LOCAL_BUILT_MODULE): PRIVATE_CC := $(TARGET_CC) 505 $(LOCAL_BUILT_MODULE): PRIVATE_SYSROOT_LINK := $(SYSROOT_LINK) 506 507 ifeq ($(call module-get-class,$(LOCAL_MODULE)),STATIC_LIBRARY) 508 509 # 510 # This is a static library module, things are very easy. We only need 511 # to build the object files and archive them with 'ar'. Note that module 512 # dependencies can be ignored here, i.e. if the module depends on other 513 # static or shared libraries, there is no need to actually build them 514 # before, so don't add Make dependencies to them. 515 # 516 # In other words, consider the following graph: 517 # 518 # libfoo.so -> libA.a ->libB.a 519 # 520 # then libA.a and libB.a can be built in parallel, only linking libfoo.so 521 # depends on their completion. 522 # 523 524 ar_objects := $(call host-path,$(LOCAL_OBJECTS)) 525 526 ifeq ($(LOCAL_SHORT_COMMANDS),true) 527 $(call ndk_log,Building static library module '$(LOCAL_MODULE)' with linker list file) 528 ar_list_file := $(LOCAL_OBJS_DIR)/archiver.list 529 $(call generate-list-file,$(ar_objects),$(ar_list_file)) 530 ar_objects := @$(call host-path,$(ar_list_file)) 531 $(LOCAL_BUILT_MODULE): $(ar_list_file) 532 endif 533 534 # Compute 'ar' flags. Thin archives simply require 'T' here. 535 ar_flags := $(TARGET_ARFLAGS) 536 ifeq (true,$(thin_archive)) 537 $(call ndk_log,$(TARGET_ARCH_ABI):Building static library '$(LOCAL_MODULE)' as thin archive) 538 ar_flags := $(ar_flags)T 539 endif 540 541 $(LOCAL_BUILT_MODULE): PRIVATE_ABI := $(TARGET_ARCH_ABI) 542 $(LOCAL_BUILT_MODULE): PRIVATE_AR := $(TARGET_AR) $(ar_flags) 543 $(LOCAL_BUILT_MODULE): PRIVATE_AR_OBJECTS := $(ar_objects) 544 $(LOCAL_BUILT_MODULE): PRIVATE_BUILD_STATIC_LIB := $(cmd-build-static-library) 545 546 $(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 547 $(call host-echo-build-step,$(PRIVATE_ABI),StaticLibrary) "$(PRIVATE_NAME)" 548 $(hide) $(call host-rm,$@) 549 $(hide) $(PRIVATE_BUILD_STATIC_LIB) 550 551 ALL_STATIC_LIBRARIES += $(LOCAL_BUILT_MODULE) 552 553 endif 554 555 ifneq (,$(filter SHARED_LIBRARY EXECUTABLE,$(call module-get-class,$(LOCAL_MODULE)))) 556 557 # 558 # This is a shared library or an executable, so computing dependencies properly is 559 # crucial. The general rule to apply is the following: 560 # 561 # - collect the list of all static libraries that need to be part 562 # of the link, and in the right order. To do so, get the transitive 563 # closure of LOCAL_STATIC_LIBRARIES and LOCAL_WHOLE_STATIC_LIBRARIES 564 # and ensure they are ordered topologically. 565 # 566 # - collect the list of all shared libraries that need to be part of 567 # the link. This is the transitive closure of the list of 568 # LOCAL_SHARED_LIBRARIES for the module and all its dependent static 569 # libraries identified in the step above. Of course, need to be 570 # ordered topologically too. 571 # 572 # - add Make dependencies to ensure that all these libs are built 573 # before the module itself too. 574 # 575 # A few quick examples: 576 # 577 # main.exe -> libA.a -> libB.a -> libfoo.so -> libC.a 578 # 579 # static_libs(main.exe) = libA.a libB.a (i.e. no libC.a) 580 # shared_libs(main.exe) = libfoo.so 581 # static_libs(libfoo.so) = libC.a 582 # 583 # main.exe -> libA.a ---> libB.a 584 # | ^ 585 # v | 586 # libC.a ------ 587 # 588 # static_libs(main.exe) = libA.a libC.a libB.a 589 # (i.e. libB.a must appear after all libraries that depend on it). 590 # 591 all_libs := $(call module-get-link-libs,$(LOCAL_MODULE)) 592 shared_libs := $(call module-filter-shared-libraries,$(all_libs)) 593 static_libs := $(call module-filter-static-libraries,$(all_libs)) 594 whole_static_libs := $(call module-extract-whole-static-libs,$(LOCAL_MODULE),$(static_libs)) 595 static_libs := $(filter-out $(whole_static_libs),$(static_libs)) 596 597 $(call -ndk-mod-debug,module $(LOCAL_MODULE) [$(LOCAL_BUILT_MODULE)]) 598 $(call -ndk-mod-debug,. all_libs='$(all_libs)') 599 $(call -ndk-mod-debug,. shared_libs='$(shared_libs)') 600 $(call -ndk-mod-debug,. static_libs='$(static_libs)') 601 $(call -ndk-mod-debug,. whole_static_libs='$(whole_static_libs)') 602 603 shared_libs := $(call map,module-get-built,$(shared_libs))\ 604 $(TARGET_PREBUILT_SHARED_LIBRARIES) 605 static_libs := $(call map,module-get-built,$(static_libs)) 606 whole_static_libs := $(call map,module-get-built,$(whole_static_libs)) 607 608 $(call -ndk-mod-debug,. built_shared_libs='$(shared_libs)') 609 $(call -ndk-mod-debug,. built_static_libs='$(static_libs)') 610 $(call -ndk-mod-debug,. built_whole_static_libs='$(whole_static_libs)') 611 612 # The list of object/static/shared libraries passed to the linker when 613 # building shared libraries and executables. order is important. 614 # 615 # Cannot use immediate evaluation because PRIVATE_LIBGCC may not be defined at this point. 616 linker_objects_and_libraries = $(strip $(call TARGET-get-linker-objects-and-libraries,\ 617 $(LOCAL_OBJECTS), \ 618 $(static_libs), \ 619 $(whole_static_libs), \ 620 $(shared_libs))) 621 622 ifeq ($(LOCAL_SHORT_COMMANDS),true) 623 $(call ndk_log,Building ELF binary module '$(LOCAL_MODULE)' with linker list file) 624 linker_options := $(linker_objects_and_libraries) 625 linker_list_file := $(LOCAL_OBJS_DIR)/linker.list 626 linker_objects_and_libraries := @$(call host-path,$(linker_list_file)) 627 $(call generate-list-file,$(linker_options),$(linker_list_file)) 628 $(LOCAL_BUILT_MODULE): $(linker_list_file) 629 endif 630 631 $(LOCAL_BUILT_MODULE): $(shared_libs) $(static_libs) $(whole_static_libs) 632 $(LOCAL_BUILT_MODULE): PRIVATE_ABI := $(TARGET_ARCH_ABI) 633 $(LOCAL_BUILT_MODULE): PRIVATE_LINKER_OBJECTS_AND_LIBRARIES := $(linker_objects_and_libraries) 634 $(LOCAL_BUILT_MODULE): PRIVATE_STATIC_LIBRARIES := $(static_libs) 635 $(LOCAL_BUILT_MODULE): PRIVATE_WHOLE_STATIC_LIBRARIES := $(whole_static_libs)) 636 $(LOCAL_BUILT_MODULE): PRIVATE_SHARED_LIBRARIES := $(shared_libs)) 637 638 endif 639 640 # 641 # If this is a shared library module 642 # 643 ifeq ($(call module-get-class,$(LOCAL_MODULE)),SHARED_LIBRARY) 644 $(LOCAL_BUILT_MODULE): PRIVATE_BUILD_SHARED_LIB := $(cmd-build-shared-library) 645 $(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 646 $(call host-echo-build-step,$(PRIVATE_ABI),SharedLibrary) "$(PRIVATE_NAME)" 647 $(hide) $(PRIVATE_BUILD_SHARED_LIB) 648 649 ALL_SHARED_LIBRARIES += $(LOCAL_BUILT_MODULE) 650 endif 651 652 # 653 # If this is an executable module 654 # 655 ifeq ($(call module-get-class,$(LOCAL_MODULE)),EXECUTABLE) 656 $(LOCAL_BUILT_MODULE): PRIVATE_ABI := $(TARGET_ARCH_ABI) 657 $(LOCAL_BUILT_MODULE): PRIVATE_BUILD_EXECUTABLE := $(cmd-build-executable) 658 $(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 659 $(call host-echo-build-step,$(PRIVATE_ABI),Executable) "$(PRIVATE_NAME)" 660 $(hide) $(PRIVATE_BUILD_EXECUTABLE) 661 662 ALL_EXECUTABLES += $(LOCAL_BUILT_MODULE) 663 endif 664 665 # 666 # If this is a copyable prebuilt module 667 # 668 ifeq ($(call module-is-copyable,$(LOCAL_MODULE)),$(true)) 669 $(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS) 670 $(call host-echo-build-step,$(PRIVATE_ABI),Prebuilt) "$(PRIVATE_NAME) <= $(call pretty-dir,$(dir $<))" 671 $(hide) $(call host-cp,$<,$@) 672 endif 673 674 # 675 # If this is an installable module 676 # 677 ifeq ($(call module-is-installable,$(LOCAL_MODULE)),$(true)) 678 $(LOCAL_INSTALLED): PRIVATE_ABI := $(TARGET_ARCH_ABI) 679 $(LOCAL_INSTALLED): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE)) 680 $(LOCAL_INSTALLED): PRIVATE_SRC := $(LOCAL_BUILT_MODULE) 681 $(LOCAL_INSTALLED): PRIVATE_DST_DIR := $(NDK_APP_DST_DIR) 682 $(LOCAL_INSTALLED): PRIVATE_DST := $(LOCAL_INSTALLED) 683 $(LOCAL_INSTALLED): PRIVATE_STRIP := $(TARGET_STRIP) 684 $(LOCAL_INSTALLED): PRIVATE_STRIP_CMD := $(call cmd-strip, $(PRIVATE_DST)) 685 $(LOCAL_INSTALLED): PRIVATE_OBJCOPY := $(TARGET_OBJCOPY) 686 $(LOCAL_INSTALLED): PRIVATE_OBJCOPY_CMD := $(call cmd-add-gnu-debuglink, $(PRIVATE_DST), $(PRIVATE_SRC)) 687 688 $(LOCAL_INSTALLED): $(LOCAL_BUILT_MODULE) clean-installed-binaries 689 $(call host-echo-build-step,$(PRIVATE_ABI),Install) "$(PRIVATE_NAME) => $(call pretty-dir,$(PRIVATE_DST))" 690 $(hide) $(call host-install,$(PRIVATE_SRC),$(PRIVATE_DST)) 691 $(hide) $(PRIVATE_STRIP_CMD) 692 693 #$(hide) $(PRIVATE_OBJCOPY_CMD) 694 695 $(call generate-file-dir,$(LOCAL_INSTALLED)) 696 697 endif 698