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# Macro    : this-makefile
66# Returns  : the name of the current Makefile in the inclusion stack
67# Usage    : $(this-makefile)
68# -----------------------------------------------------------------------------
69this-makefile = $(lastword $(MAKEFILE_LIST))
70
71# -----------------------------------------------------------------------------
72# Macro    : local-makefile
73# Returns  : the name of the last parsed Android.mk file
74# Usage    : $(local-makefile)
75# -----------------------------------------------------------------------------
76local-makefile = $(lastword $(filter %Android.mk,$(MAKEFILE_LIST)))
77
78# -----------------------------------------------------------------------------
79# Function : assert-defined
80# Arguments: 1: list of variable names
81# Returns  : None
82# Usage    : $(call assert-defined, VAR1 VAR2 VAR3...)
83# Rationale: Checks that all variables listed in $1 are defined, or abort the
84#            build
85# -----------------------------------------------------------------------------
86assert-defined = $(foreach __varname,$(strip $1),\
87  $(if $(strip $($(__varname))),,\
88    $(call __ndk_error, Assertion failure: $(__varname) is not defined)\
89  )\
90)
91
92# -----------------------------------------------------------------------------
93# Function : clear-vars
94# Arguments: 1: list of variable names
95#            2: file where the variable should be defined
96# Returns  : None
97# Usage    : $(call clear-vars, VAR1 VAR2 VAR3...)
98# Rationale: Clears/undefines all variables in argument list
99# -----------------------------------------------------------------------------
100clear-vars = $(foreach __varname,$1,$(eval $(__varname) := $(empty)))
101
102# -----------------------------------------------------------------------------
103# Function : check-required-vars
104# Arguments: 1: list of variable names
105#            2: file where the variable(s) should be defined
106# Returns  : None
107# Usage    : $(call check-required-vars, VAR1 VAR2 VAR3..., <file>)
108# Rationale: Checks that all required vars listed in $1 were defined by $2
109#            or abort the build with an error
110# -----------------------------------------------------------------------------
111check-required-vars = $(foreach __varname,$1,\
112  $(if $(strip $($(__varname))),,\
113    $(call __ndk_info, Required variable $(__varname) is not defined by $2)\
114    $(call __ndk_error,Aborting)\
115  )\
116)
117
118# =============================================================================
119#
120# Modules database
121#
122# The following declarations are used to manage the list of modules
123# defined in application's Android.mk files.
124#
125# Technical note:
126#    We use __ndk_modules to hold the list of all modules corresponding
127#    to a given application.
128#
129#    For each module 'foo', __ndk_modules.foo.<field> is used
130#    to store module-specific information.
131#
132#        android_mk   -> points to the Android.mk where the module is defined
133#        type         -> type of module (e.g. 'static', 'shared', ...)
134#        built        -> location of module built file (e.g. out/apps/<app>/<abi>/libfoo.so)
135#        installed    -> location of module installation (e.g. $PROJECT/libs/<abi>/libfoo.so)
136#        depends      -> list of other modules this module depends on
137#
138#    Note that some modules are never installed (e.g. static libraries).
139#
140# =============================================================================
141
142# the list of managed fields per module
143modules-fields = type android_mk built installed depends
144
145# -----------------------------------------------------------------------------
146# Function : modules-clear
147# Arguments: None
148# Returns  : None
149# Usage    : $(call modules-clear)
150# Rationale: clears the list of defined modules known by the build system
151# -----------------------------------------------------------------------------
152modules-clear = \
153    $(foreach __mod,$(__ndk_modules),\
154        $(foreach __field,$(modules-fields),\
155            $(eval __ndk_modules.$(__mod).$(__field) := $(empty))\
156        )\
157    )\
158    $(eval __ndk_modules := $(empty_set))
159
160# -----------------------------------------------------------------------------
161# Function : modules-get-list
162# Arguments: None
163# Returns  : The list of all recorded modules
164# Usage    : $(call modules-get-list)
165# -----------------------------------------------------------------------------
166modules-get-list = $(__ndk_modules)
167
168# -----------------------------------------------------------------------------
169# Function : modules-add
170# Arguments: 1: module name
171#            2: built module path
172#            3: path to Android.mk where the module is defined
173#            4: type of module (e.g. 'static')
174# Returns  : None
175# Usage    : $(call modules-add,<modulename>,<Android.mk path>)
176# Rationale: add a new module. If it is already defined, print an error message
177#            and abort.
178# -----------------------------------------------------------------------------
179module-add = \
180  $(if $(call set_is_member,$(__ndk_modules),$1),\
181       $(call __ndk_info,Trying to define local module '$1' in $3.)\
182       $(call __ndk_info,But this module was already defined by $(__ndk_modules.$1.android_mk).)\
183       $(call __ndk_error,Aborting.)\
184  )\
185  $(eval __ndk_modules := $(call set_insert,$(__ndk_modules),$1))\
186  $(eval __ndk_modules.$1.android_mk := $3)\
187  $(eval __ndk_modules.$1.type       := $4)\
188  $(eval __ndk_modules.$1.built      := $2)\
189
190module-add-static-library = $(call module-add,$1,$2,$3,static)
191module-add-shared-library = $(call module-add,$1,$2,$3,shared)
192module-add-executable     = $(call module-add,$1,$2,$3,executable)
193
194# Returns $(true) iff module $1 is of type $2
195module-is-type = $(call seq,$(__ndk_modules.$1.type),$2)
196
197# Retrieve built location of module $1
198module-get-built = $(__ndk_modules.$1.built)
199
200# Returns $(true) is module $1 is of a given type
201module-is-static-library = $(call module-is-type,$1,static)
202module-is-shared-library = $(call module-is-type,$1,shared)
203module-is-exectuable     = $(call module-is-type,$1,executable)
204module-is-installable    = $(call or,$(call module-is-type,$1,shared),$(call module-is-type,$1,executable))
205
206# Dump all module information. Only use this for debugging
207modules-dump-database = \
208    $(info Modules: $(__ndk_modules)) \
209    $(foreach __mod,$(__ndk_modules),\
210        $(info $(space)$(space)$(__mod):)\
211        $(foreach __field,$(modules-fields),\
212            $(info $(space)$(space)$(space)$(space)$(__field): $(__ndk_modules.$(__mod).$(__field)))\
213        )\
214    )\
215    $(info --- end of list)
216
217
218# -----------------------------------------------------------------------------
219# Function : module-add-static-depends
220# Arguments: 1: module name
221#            2: list/set of static library modules this module depends on.
222# Returns  : None
223# Usage    : $(call module-add-static-depends,<modulename>,<list of module names>)
224# Rationale: Record that a module depends on a set of static libraries.
225#            Use module-get-static-dependencies to retrieve final list.
226# -----------------------------------------------------------------------------
227module-add-static-depends = \
228    $(call modules-add-depends-any,$1,$2,depends) \
229
230# -----------------------------------------------------------------------------
231# Function : module-add-shared-depends
232# Arguments: 1: module name
233#            2: list/set of shared library modules this module depends on.
234# Returns  : None
235# Usage    : $(call module-add-shared-depends,<modulename>,<list of module names>)
236# Rationale: Record that a module depends on a set of shared libraries.
237#            Use modulge-get-shared-dependencies to retrieve final list.
238# -----------------------------------------------------------------------------
239module-add-shared-depends = \
240    $(call modules-add-depends-any,$1,$2,depends) \
241
242# Used internally by module-add-static-depends and module-add-shared-depends
243# NOTE: this function must not modify the existing dependency order when new depends are added.
244#
245modules-add-depends-any = \
246    $(eval __ndk_modules.$1.$3 += $(filter-out $(__ndk_modules.$1.$3),$(call strip-lib-prefix,$2)))
247
248# -----------------------------------------------------------------------------
249# Function : module-set-installed
250# Arguments: 1: module name
251#            2: installation path for the module
252# Returns  : None
253# Usage    : $(call module-set-installed,<module>,<installed>)
254# Rationale: Records the installed path of a given module. Can later be retrieved
255#            with module-get-installed.
256# -----------------------------------------------------------------------------
257module-set-installed = \
258    $(eval __ndk_modules.$1.installed := $2)
259
260# -----------------------------------------------------------------------------
261# Function : module-get-installed
262# Arguments: 1: module name
263# Returns  : Path of installed locaiton
264# Usage    : $(call module-get-installed,<module>)
265# -----------------------------------------------------------------------------
266module-get-installed = $(__ndk_modules.$1.installed)
267
268# -----------------------------------------------------------------------------
269# Function : modules-get-all-dependencies
270# Arguments: 1: list of module names
271# Returns  : List of all the modules $1 depends on transitively.
272# Usage    : $(call modules-all-get-dependencies,<list of module names>)
273# Rationale: This computes the closure of all module dependencies starting from $1
274# -----------------------------------------------------------------------------
275module-get-all-dependencies = \
276    $(strip $(call modules-get-closure,$1,depends))
277
278modules-get-closure = \
279    $(eval __closure_deps  := $(strip $1)) \
280    $(eval __closure_wq    := $(__closure_deps)) \
281    $(eval __closure_field := $(strip $2)) \
282    $(call modules-closure)\
283    $(__closure_deps)
284
285# Used internally by modules-get-dependencies
286# Note the tricky use of conditional recursion to work around the fact that
287# the GNU Make language does not have any conditional looping construct
288# like 'while'.
289#
290modules-closure = \
291    $(eval __closure_mod := $(call first,$(__closure_wq))) \
292    $(eval __closure_wq  := $(call rest,$(__closure_wq))) \
293    $(eval __closure_new := $(filter-out $(__closure_deps),$(__ndk_modules.$(__closure_mod).$(__closure_field))))\
294    $(eval __closure_deps += $(__closure_new)) \
295    $(eval __closure_wq   := $(strip $(__closure_wq) $(__closure_new)))\
296    $(if $(__closure_wq),$(call modules-closure)) \
297
298
299# =============================================================================
300#
301# Utility functions
302#
303# =============================================================================
304
305# -----------------------------------------------------------------------------
306# Function : check-user-define
307# Arguments: 1: name of variable that must be defined by the user
308#            2: name of Makefile where the variable should be defined
309#            3: name/description of the Makefile where the check is done, which
310#               must be included by $2
311# Returns  : None
312# -----------------------------------------------------------------------------
313check-user-define = $(if $(strip $($1)),,\
314  $(call __ndk_error,Missing $1 before including $3 in $2))
315
316# -----------------------------------------------------------------------------
317# This is used to check that LOCAL_MODULE is properly defined by an Android.mk
318# file before including one of the $(BUILD_SHARED_LIBRARY), etc... files.
319#
320# Function : check-user-LOCAL_MODULE
321# Arguments: 1: name/description of the included build Makefile where the
322#               check is done
323# Returns  : None
324# Usage    : $(call check-user-LOCAL_MODULE, BUILD_SHARED_LIBRARY)
325# -----------------------------------------------------------------------------
326check-defined-LOCAL_MODULE = \
327  $(call check-user-define,LOCAL_MODULE,$(local-makefile),$(1)) \
328  $(if $(call seq,$(words $(LOCAL_MODULE)),1),,\
329    $(call __ndk_info,LOCAL_MODULE definition in $(local-makefile) must not contain space)\
330    $(call __ndk_error,Please correct error. Aborting)\
331  )
332
333# -----------------------------------------------------------------------------
334# Strip any 'lib' prefix in front of a given string.
335#
336# Function : strip-lib-prefix
337# Arguments: 1: module name
338# Returns  : module name, without any 'lib' prefix if any
339# Usage    : $(call strip-lib-prefix,$(LOCAL_MODULE))
340# -----------------------------------------------------------------------------
341strip-lib-prefix = $(1:lib%=%)
342
343# -----------------------------------------------------------------------------
344# This is used to strip any lib prefix from LOCAL_MODULE, then check that
345# the corresponding module name is not already defined.
346#
347# Function : check-user-LOCAL_MODULE
348# Arguments: 1: path of Android.mk where this LOCAL_MODULE is defined
349# Returns  : None
350# Usage    : $(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE))
351# -----------------------------------------------------------------------------
352check-LOCAL_MODULE = \
353  $(eval LOCAL_MODULE := $$(call strip-lib-prefix,$$(LOCAL_MODULE)))
354
355# -----------------------------------------------------------------------------
356# Macro    : my-dir
357# Returns  : the directory of the current Makefile
358# Usage    : $(my-dir)
359# -----------------------------------------------------------------------------
360my-dir = $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
361
362# -----------------------------------------------------------------------------
363# Function : all-makefiles-under
364# Arguments: 1: directory path
365# Returns  : a list of all makefiles immediately below some directory
366# Usage    : $(call all-makefiles-under, <some path>)
367# -----------------------------------------------------------------------------
368all-makefiles-under = $(wildcard $1/*/Android.mk)
369
370# -----------------------------------------------------------------------------
371# Macro    : all-subdir-makefiles
372# Returns  : list of all makefiles in subdirectories of the current Makefile's
373#            location
374# Usage    : $(all-subdir-makefiles)
375# -----------------------------------------------------------------------------
376all-subdir-makefiles = $(call all-makefiles-under,$(call my-dir))
377
378# =============================================================================
379#
380# Source file tagging support.
381#
382# Each source file listed in LOCAL_SRC_FILES can have any number of
383# 'tags' associated to it. A tag name must not contain space, and its
384# usage can vary.
385#
386# For example, the 'debug' tag is used to sources that must be built
387# in debug mode, the 'arm' tag is used for sources that must be built
388# using the 32-bit instruction set on ARM platforms, and 'neon' is used
389# for sources that must be built with ARM Advanced SIMD (a.k.a. NEON)
390# support.
391#
392# More tags might be introduced in the future.
393#
394#  LOCAL_SRC_TAGS contains the list of all tags used (initially empty)
395#  LOCAL_SRC_FILES contains the list of all source files.
396#  LOCAL_SRC_TAG.<tagname> contains the set of source file names tagged
397#      with <tagname>
398#  LOCAL_SRC_FILES_TAGS.<filename> contains the set of tags for a given
399#      source file name
400#
401# Tags are processed by a toolchain-specific function (e.g. TARGET-compute-cflags)
402# which will call various functions to compute source-file specific settings.
403# These are currently stored as:
404#
405#  LOCAL_SRC_FILES_TARGET_CFLAGS.<filename> contains the list of
406#      target-specific C compiler flags used to compile a given
407#      source file. This is set by the function TARGET-set-cflags
408#      defined in the toolchain's setup.mk script.
409#
410#  LOCAL_SRC_FILES_TEXT.<filename> contains the 'text' that will be
411#      displayed along the label of the build output line. For example
412#      'thumb' or 'arm  ' with ARM-based toolchains.
413#
414# =============================================================================
415
416# -----------------------------------------------------------------------------
417# Macro    : clear-all-src-tags
418# Returns  : remove all source file tags and associated data.
419# Usage    : $(clear-all-src-tags)
420# -----------------------------------------------------------------------------
421clear-all-src-tags = \
422$(foreach __tag,$(LOCAL_SRC_TAGS), \
423    $(eval LOCAL_SRC_TAG.$(__tag) := $(empty)) \
424) \
425$(foreach __src,$(LOCAL_SRC_FILES), \
426    $(eval LOCAL_SRC_FILES_TAGS.$(__src) := $(empty)) \
427    $(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) := $(empty)) \
428    $(eval LOCAL_SRC_FILES_TEXT.$(__src) := $(empty)) \
429) \
430$(eval LOCAL_SRC_TAGS := $(empty_set))
431
432# -----------------------------------------------------------------------------
433# Macro    : tag-src-files
434# Arguments: 1: list of source files to tag
435#            2: tag name (must not contain space)
436# Usage    : $(call tag-src-files,<list-of-source-files>,<tagname>)
437# Rationale: Add a tag to a list of source files
438# -----------------------------------------------------------------------------
439tag-src-files = \
440$(eval LOCAL_SRC_TAGS := $(call set_insert,$2,$(LOCAL_SRC_TAGS))) \
441$(eval LOCAL_SRC_TAG.$2 := $(call set_union,$1,$(LOCAL_SRC_TAG.$2))) \
442$(foreach __src,$1, \
443    $(eval LOCAL_SRC_FILES_TAGS.$(__src) += $2) \
444)
445
446# -----------------------------------------------------------------------------
447# Macro    : get-src-files-with-tag
448# Arguments: 1: tag name
449# Usage    : $(call get-src-files-with-tag,<tagname>)
450# Return   : The list of source file names that have been tagged with <tagname>
451# -----------------------------------------------------------------------------
452get-src-files-with-tag = $(LOCAL_SRC_TAG.$1)
453
454# -----------------------------------------------------------------------------
455# Macro    : get-src-files-without-tag
456# Arguments: 1: tag name
457# Usage    : $(call get-src-files-without-tag,<tagname>)
458# Return   : The list of source file names that have NOT been tagged with <tagname>
459# -----------------------------------------------------------------------------
460get-src-files-without-tag = $(filter-out $(LOCAL_SRC_TAG.$1),$(LOCAL_SRC_FILES))
461
462# -----------------------------------------------------------------------------
463# Macro    : set-src-files-target-cflags
464# Arguments: 1: list of source files
465#            2: list of compiler flags
466# Usage    : $(call set-src-files-target-cflags,<sources>,<flags>)
467# Rationale: Set or replace the set of compiler flags that will be applied
468#            when building a given set of source files. This function should
469#            normally be called from the toolchain-specific function that
470#            computes all compiler flags for all source files.
471# -----------------------------------------------------------------------------
472set-src-files-target-cflags = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) := $2))
473
474# -----------------------------------------------------------------------------
475# Macro    : add-src-files-target-cflags
476# Arguments: 1: list of source files
477#            2: list of compiler flags
478# Usage    : $(call add-src-files-target-cflags,<sources>,<flags>)
479# Rationale: A variant of set-src-files-target-cflags that can be used
480#            to append, instead of replace, compiler flags for specific
481#            source files.
482# -----------------------------------------------------------------------------
483add-src-files-target-cflags = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) += $2))
484
485# -----------------------------------------------------------------------------
486# Macro    : get-src-file-target-cflags
487# Arguments: 1: single source file name
488# Usage    : $(call get-src-file-target-cflags,<source>)
489# Rationale: Return the set of target-specific compiler flags that must be
490#            applied to a given source file. These must be set prior to this
491#            call using set-src-files-target-cflags or add-src-files-target-cflags
492# -----------------------------------------------------------------------------
493get-src-file-target-cflags = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$1)
494
495# -----------------------------------------------------------------------------
496# Macro    : set-src-files-text
497# Arguments: 1: list of source files
498#            2: text
499# Usage    : $(call set-src-files-text,<sources>,<text>)
500# Rationale: Set or replace the 'text' associated to a set of source files.
501#            The text is a very short string that complements the build
502#            label. For example, it will be either 'thumb' or 'arm  ' for
503#            ARM-based toolchains. This function must be called by the
504#            toolchain-specific functions that processes all source files.
505# -----------------------------------------------------------------------------
506set-src-files-text = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TEXT.$(__src) := $2))
507
508# -----------------------------------------------------------------------------
509# Macro    : get-src-file-text
510# Arguments: 1: single source file
511# Usage    : $(call get-src-file-text,<source>)
512# Rationale: Return the 'text' associated to a given source file when
513#            set-src-files-text was called.
514# -----------------------------------------------------------------------------
515get-src-file-text = $(LOCAL_SRC_FILES_TEXT.$1)
516
517# This should only be called for debugging the source files tagging system
518dump-src-file-tags = \
519$(info LOCAL_SRC_TAGS := $(LOCAL_SRC_TAGS)) \
520$(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES)) \
521$(foreach __tag,$(LOCAL_SRC_TAGS),$(info LOCAL_SRC_TAG.$(__tag) = $(LOCAL_SRC_TAG.$(__tag)))) \
522$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TAGS.$(__src) = $(LOCAL_SRC_FILES_TAGS.$(__src)))) \
523$(info WITH arm = $(call get-src-files-with-tag,arm)) \
524$(info WITHOUT arm = $(call get-src-files-without-tag,arm)) \
525$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src)))) \
526$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TEXT.$(__src) = $(LOCAL_SRC_FILES_TEXT.$(__src)))) \
527
528
529# =============================================================================
530#
531# Application.mk support
532#
533# =============================================================================
534
535# the list of variables that *must* be defined in Application.mk files
536NDK_APP_VARS_REQUIRED :=
537
538# the list of variables that *may* be defined in Application.mk files
539NDK_APP_VARS_OPTIONAL := APP_OPTIM APP_CPPFLAGS APP_CFLAGS APP_CXXFLAGS \
540                         APP_PLATFORM APP_BUILD_SCRIPT APP_ABI APP_MODULES \
541                         APP_PROJECT_PATH
542
543# the list of all variables that may appear in an Application.mk file
544# or defined by the build scripts.
545NDK_APP_VARS := $(NDK_APP_VARS_REQUIRED) \
546                $(NDK_APP_VARS_OPTIONAL) \
547                APP_DEBUGGABLE \
548                APP_MANIFEST
549
550# =============================================================================
551#
552# Android.mk support
553#
554# =============================================================================
555
556
557# =============================================================================
558#
559# Generated files support
560#
561# =============================================================================
562
563
564# -----------------------------------------------------------------------------
565# Function  : host-static-library-path
566# Arguments : 1: library module name (e.g. 'foo')
567# Returns   : location of generated host library name (e.g. '..../libfoo.a)
568# Usage     : $(call host-static-library-path,<modulename>)
569# -----------------------------------------------------------------------------
570host-static-library-path = $(HOST_OUT)/lib$1.a
571
572# -----------------------------------------------------------------------------
573# Function  : host-executable-path
574# Arguments : 1: executable module name (e.g. 'foo')
575# Returns   : location of generated host executable name (e.g. '..../foo)
576# Usage     : $(call host-executable-path,<modulename>)
577# -----------------------------------------------------------------------------
578host-executable-path = $(HOST_OUT)/$1$(HOST_EXE)
579
580# -----------------------------------------------------------------------------
581# Function  : static-library-path
582# Arguments : 1: library module name (e.g. 'foo')
583# Returns   : location of generated static library name (e.g. '..../libfoo.a)
584# Usage     : $(call static-library-path,<modulename>)
585# -----------------------------------------------------------------------------
586static-library-path = $(TARGET_OUT)/lib$1.a
587
588# -----------------------------------------------------------------------------
589# Function  : shared-library-path
590# Arguments : 1: library module name (e.g. 'foo')
591# Returns   : location of generated shared library name (e.g. '..../libfoo.so)
592# Usage     : $(call shared-library-path,<modulename>)
593# -----------------------------------------------------------------------------
594shared-library-path = $(TARGET_OUT)/lib$1.so
595
596# -----------------------------------------------------------------------------
597# Function  : executable-path
598# Arguments : 1: executable module name (e.g. 'foo')
599# Returns   : location of generated exectuable name (e.g. '..../foo)
600# Usage     : $(call executable-path,<modulename>)
601# -----------------------------------------------------------------------------
602executable-path = $(TARGET_OUT)/$1
603
604# =============================================================================
605#
606# Build commands support
607#
608# =============================================================================
609
610# -----------------------------------------------------------------------------
611# Macro    : hide
612# Returns  : nothing
613# Usage    : $(hide)<make commands>
614# Rationale: To be used as a prefix for Make build commands to hide them
615#            by default during the build. To show them, set V=1 in your
616#            environment or command-line.
617#
618#            For example:
619#
620#                foo.o: foo.c
621#                -->|$(hide) <build-commands>
622#
623#            Where '-->|' stands for a single tab character.
624#
625# -----------------------------------------------------------------------------
626ifeq ($(V),1)
627hide = $(empty)
628else
629hide = @
630endif
631
632# -----------------------------------------------------------------------------
633# Template  : ev-compile-c-source
634# Arguments : 1: single C source file name (relative to LOCAL_PATH)
635#             2: target object file (without path)
636# Returns   : None
637# Usage     : $(eval $(call ev-compile-c-source,<srcfile>,<objfile>)
638# Rationale : Internal template evaluated by compile-c-source and
639#             compile-s-source
640# -----------------------------------------------------------------------------
641define  ev-compile-c-source
642_SRC:=$$(LOCAL_PATH)/$(1)
643_OBJ:=$$(LOCAL_OBJS_DIR)/$(2)
644
645$$(_OBJ): PRIVATE_SRC      := $$(_SRC)
646$$(_OBJ): PRIVATE_OBJ      := $$(_OBJ)
647$$(_OBJ): PRIVATE_MODULE   := $$(LOCAL_MODULE)
648$$(_OBJ): PRIVATE_ARM_MODE := $$(LOCAL_ARM_MODE)
649$$(_OBJ): PRIVATE_ARM_TEXT := $$(call get-src-file-text,$1)
650$$(_OBJ): PRIVATE_CC       := $$($$(my)CC)
651$$(_OBJ): PRIVATE_CFLAGS   := $$($$(my)CFLAGS) \
652                              $$(call get-src-file-target-cflags,$(1)) \
653                              $$(LOCAL_C_INCLUDES:%=-I%) \
654                              -I$$(LOCAL_PATH) \
655                              $$(LOCAL_CFLAGS) \
656                              $$(NDK_APP_CFLAGS)
657
658$$(_OBJ): $$(_SRC) $$(LOCAL_MAKEFILE) $$(NDK_APP_APPLICATION_MK)
659	@mkdir -p $$(dir $$(PRIVATE_OBJ))
660	@echo "Compile $$(PRIVATE_ARM_TEXT)  : $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC)"
661	$(hide) $$(PRIVATE_CC) $$(PRIVATE_CFLAGS) -c \
662	-MMD -MP -MF $$(PRIVATE_OBJ).d \
663	$$(PRIVATE_SRC) \
664	-o $$(PRIVATE_OBJ)
665
666LOCAL_OBJECTS         += $$(_OBJ)
667LOCAL_DEPENDENCY_DIRS += $$(dir $$(_OBJ))
668endef
669
670# -----------------------------------------------------------------------------
671# Function  : compile-c-source
672# Arguments : 1: single C source file name (relative to LOCAL_PATH)
673# Returns   : None
674# Usage     : $(call compile-c-source,<srcfile>)
675# Rationale : Setup everything required to build a single C source file
676# -----------------------------------------------------------------------------
677compile-c-source = $(eval $(call ev-compile-c-source,$1,$(1:%.c=%.o)))
678
679# -----------------------------------------------------------------------------
680# Function  : compile-s-source
681# Arguments : 1: single Assembly source file name (relative to LOCAL_PATH)
682# Returns   : None
683# Usage     : $(call compile-s-source,<srcfile>)
684# Rationale : Setup everything required to build a single Assembly source file
685# -----------------------------------------------------------------------------
686compile-s-source = $(eval $(call ev-compile-c-source,$1,$(1:%.S=%.o)))
687
688
689# -----------------------------------------------------------------------------
690# Template  : ev-compile-cpp-source
691# Arguments : 1: single C++ source file name (relative to LOCAL_PATH)
692#             2: target object file (without path)
693# Returns   : None
694# Usage     : $(eval $(call ev-compile-cpp-source,<srcfile>,<objfile>)
695# Rationale : Internal template evaluated by compile-cpp-source
696# -----------------------------------------------------------------------------
697
698define  ev-compile-cpp-source
699_SRC:=$$(LOCAL_PATH)/$(1)
700_OBJ:=$$(LOCAL_OBJS_DIR)/$(2)
701
702$$(_OBJ): PRIVATE_SRC      := $$(_SRC)
703$$(_OBJ): PRIVATE_OBJ      := $$(_OBJ)
704$$(_OBJ): PRIVATE_MODULE   := $$(LOCAL_MODULE)
705$$(_OBJ): PRIVATE_ARM_MODE := $$(LOCAL_ARM_MODE)
706$$(_OBJ): PRIVATE_ARM_TEXT := $$(call get-src-file-text,$1)
707$$(_OBJ): PRIVATE_CXX      := $$($$(my)CXX)
708$$(_OBJ): PRIVATE_CXXFLAGS := $$($$(my)CXXFLAGS) \
709                              $$(call get-src-file-target-cflags,$(1)) \
710                              $$(LOCAL_C_INCLUDES:%=-I%) \
711                              -I$$(LOCAL_PATH) \
712                              $$(LOCAL_CFLAGS) \
713                              $$(LOCAL_CPPFLAGS) \
714                              $$(LOCAL_CXXFLAGS) \
715                              $$(NDK_APP_CFLAGS) \
716                              $$(NDK_APP_CPPFLAGS) \
717                              $$(NDK_APP_CXXFLAGS) \
718
719$$(_OBJ): $$(_SRC) $$(LOCAL_MAKEFILE) $$(NDK_APP_APPLICATION_MK)
720	@mkdir -p $$(dir $$(PRIVATE_OBJ))
721	@echo "Compile++ $$(PRIVATE_ARM_TEXT): $$(PRIVATE_MODULE) <= $$(PRIVATE_SRC)"
722	$(hide) $$(PRIVATE_CXX) $$(PRIVATE_CXXFLAGS) -c \
723	-MMD -MP -MF $$(PRIVATE_OBJ).d \
724	$$(PRIVATE_SRC) \
725	-o $$(PRIVATE_OBJ)
726
727LOCAL_OBJECTS         += $$(_OBJ)
728LOCAL_DEPENDENCY_DIRS += $$(dir $$(_OBJ))
729endef
730
731# -----------------------------------------------------------------------------
732# Function  : compile-cpp-source
733# Arguments : 1: single C++ source file name (relative to LOCAL_PATH)
734# Returns   : None
735# Usage     : $(call compile-c-source,<srcfile>)
736# Rationale : Setup everything required to build a single C++ source file
737# -----------------------------------------------------------------------------
738compile-cpp-source = $(eval $(call ev-compile-cpp-source,$1,$(1:%$(LOCAL_CPP_EXTENSION)=%.o)))
739
740# -----------------------------------------------------------------------------
741# Command   : cmd-install-file
742# Arguments : 1: source file
743#             2: destination file
744# Returns   : None
745# Usage     : $(call cmd-install-file,<srcfile>,<dstfile>)
746# Rationale : To be used as a Make build command to copy/install a file to
747#             a given location.
748# -----------------------------------------------------------------------------
749define cmd-install-file
750@mkdir -p $(dir $2)
751$(hide) cp -fp $1 $2
752endef
753
754