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