Transferred from: http://nfer-zhuang.iteye.com/blog/1752387
I. Description
above we have made a general description of the ACP android.mk file, so that we have a preliminary understanding of the Android.mk file, below we will focus on the first line: local_path:= $ (call My-dir)
Second, Local_pathsomeone asked, in this android.mk is not used to Local_path, why first define such a variable? Why does the provision have to be placed before all the include $ (clear_vars)? in the android.mk we find that local_src_files: = ACP, the Ndk file describes the Local_src_files as follows:This is a list of the source files that would be built for your module. The only list of files that would be is passed to a compiler, since the build system automatically computes dependencies for you.
Note that source files names is relative to Local_path and you can use the PATH components.Therefore, the Local_path variable is used indirectly when defining local_src_files, that is, a relative path based on the current path that defines local_src_files. Let's take a look at why Local_path's definition must be placed before all of the include $ (clear_vars). Local_path Gets the current path by calling the My-dir function, the definition of the My-dir function is located in the Core/definitions.mk file:Makefile Code
<span style="Font-size:small; " out where we are. Define my-dir $ (strip \ $ (eval md_file_:= $$ (lastword $$)) \ $ ( if $ (Filter $ (clear_vars), $ (md_file_)), \ Set before including $$ (Clear_vars)) \ , \ %/,%, $ (dir $ (md_file_) )) \) Endef</span>
Note that it is clear here that the definition of local_path must be placed before any include $ (clear_vars) statement, and if you do not do so, the compiler will immediately give an error and stop working. But how does it judge that the definition of Local_path is before any include $ (clear_vars) statement, we see there is such a sentence:
Makefile Code
$ (if $ (filter $ (clear_vars), $ (md_file_))
This judgment statement is a key, let's first look at the definition of the Clear_vars variable
third,clear_vars There is a clear definition of build/core/config.mk in the following:
Makefile Code
Clear_vars:= $ (Build_system)/clear_vars.mk
andBuild_system is defined in the Build/core/main.mk file:
Build_system: = $ (Topdir) Build/core
Makefile Code
immediately following:
Makefile Code
Topdir: =
That is, Topdir is the root directory of the Android source code , build_system= Build/core, so the value of the Clear_vars variable is build/core/clear_ Vars.mk, of course, this is also relative to the Android source root path.
we get the value of the Clear_vars variable, and we go back to the My-dir function. Iv. My-dirAccording to GNU make definition, Gnu make automatically adds all read makefile paths to the makefile_list variable, and is added in the order in which they are read. then, when running this MAKEFILE file, the last MAKEFILE in the $ (makefile_list) string is definitely the last read MAKEFILE, which is $ (Lastword $ (makefile_list)) and will return build/ Tools/acp/android.mk, this string is assigned to the temporary variable $$ by $ (eval md_file_: = $$ (Lastword makefile_list)) operation. Determine if Md_file_ contains the value of the Clear_vars variable $ (if $ (filter $ (clear_vars), $ (Md_file_)), and will certainly return the failure again by $ (Patsubst%/,%,$ (dir $ (md_ File_)) function, you get the current path, which is BUILD/TOOLS/ACP If we call the My-dir function after the include $ (clear_vars), then $$ (Lastword $$ (makefile_list)) will definitely return $ (build_system)/clear_ Vars.mk, meanwhile, $ (Patsubst%/,%,$ (dir $ (md_file_)) will also return a value of $ (build_system) Build/core instead of the current path BUILD/TOOLS/ACP. As a result, the value of the Local_path is the wrong value, and the other variables that depend on Local_path are more likely to be correct! So,
Local_path must be defined before any including $ (clear_vars)) .
In Layman's Android makefile (2)--local_path (reprint)