ANDROID.MK (1) function

Source: Internet
Author: User

https://www.jianshu.com/p/46224d15fc5f

From the function.

Everyone is used to looking at the beginning, starting from the building goals, resulting in every document cooked is the previous part. Many tutorials are also a way to view their rough, from the overall to give everyone a thought. For example, the 4th chapter of "Deep understanding of the Android kernel design idea", such as "Android Kernel Anatomy," chapter 18th, such as "deep analysis of Android 5.0 System" chapter 2nd.

So I'm going to do the opposite, starting with the calling function.

Last trick: Shell functions

Let's first list the last housekeeping trick, the Shell function, which can be used to execute shell commands. All of the problems that can be solved by using the Shell function call external functions.
However, calling the shell needs to start a new process that affects performance and does not use it as long as there are other ways to recommend it.

For example, if we want to list which CPP files are in the current directory, makefile can write:

$(shell ls *.cpp)all :    @echo -n "The files is:"    @echo $(files).PHONY : all
Stitching strings

In makefile, the use of a wide range of stitching is the string, the join function is to do this thing.
Format: $ (Join string 1, String 2)
can also be multiple strings spelled together: $ (Join string 1 Strings 2 Strings 3, string 4 string 5 string 6)
Multiple strings are 1 and 4 spelling, 2 and 5 ... In short, the comma before and after the spelling.

Go to Space

It's okay, it's not a bad thing to go to a space.
$ (Strip string)

File path operation function

In the actual makefile development, we often encounter the path names stored in the variables to be processed.

Let's start with an outline:

    • There is a file name that does not know where to come, want to take its path, with Dir
    • There is a file name that does not know where to come, want to only take its file name, with Notdir
    • If you want only the extension, determine what type, with suffix
    • If you want to do not extend the name, take out to spell an individual extension up, such as XXX.C, as long as XXX, in the future to spell a XXX.O or XXX or the like, with basename
    • To add an extension to a file, use Addsuffix
    • Want to take the file to another path, put a directory name up, with Addprefix
Directory path function to fetch a file dir

Cases:

$(dir $(oatfile))all2 :    @echo -n "The result is: "    @echo $(result)

Output: The result is:out/target/product/ali6753_65t_m0/obj/apps/musicfx_intermediates/oat/arm64/

Take file name function

Cases:

$(dir $(oatfile))result_notdir := $(notdir $(oatfile))all2 : @echo "The result is: " @echo $(result_dir) @echo $(result_notdir)

Output:
The result is:
out/target/product/ali6753_65t_m0/obj/apps/musicfx_intermediates/oat/arm64/
Package.odex

Fetch file name extension

Cases:

$(dir $(oatfile))result_notdir := $(notdir $(oatfile))result_suffix := $(suffix $(oatfile))all2 : @echo "The result is: " @echo $(result_dir) @echo $(result_notdir) @echo $(result_suffix)

Output:
The result is:
out/target/product/ali6753_65t_m0/obj/apps/musicfx_intermediates/oat/arm64/
Package.odex
. Odex

Fetch file Base name

If you use only the basename function, the path is the same, only the name of the extension is removed. But we have just learned notdir, use it together.

Cases:

$(suffix $(oatfile))result_basename := $(basename $(oatfile))result_basename2 := $(basename $(notdir $(oatfile)))all2 : @echo "The result is: " @echo $(result_suffix) @echo $(result_basename) @echo $(result_basename2)

Output:
The result is:
. Odex
Out/target/product/ali6753_65t_m0/obj/apps/musicfx_intermediates/oat/arm64/package
Package

Add a suffix to a name

Use the Addsuffix function, $ (addsuffix file name, extension)
Let's give an example: Now you want to compress the oat files into. tar.gz:

$(basename $(oatfile))compress_oat := tar cfvz $(addsuffix .tar.gz , $(result_basename)) $(oatfile)all2 : @echo "The result is: " @echo $(compress_oat)

The output is as follows:
The result is:
Tar cfvz out/target/product/ali6753_65t_m0/obj/apps/musicfx_intermediates/oat/arm64/package.tar.gz out/target/ Product/ali6753_65t_m0/obj/apps/musicfx_intermediates/oat/arm64/package.odex

Prefix file names

This is used to change paths, Addprefix. A prefix can be added behind.

Cases:

$(addprefix /data/dalvik-cache/, $(oatfile2))all3:    @echo $(result_oatfile2)

Output:
/data/dalvik-cache/system.odex/data/dalvik-cache/music.odex/data/dalvik-cache/contacts.odex

Do string substitution directly

If we do not want to disassemble the added trouble, there is an easy way to do string substitution directly.
The SUBST function is defined as follows: $ (subst source string, target string, strings to be replaced)

For example, let's rewrite the makefile to replace the. odex extension with a. tag.gz extension and spell a tar command:

$(subst $(suffix $(oatfile)),.tar.gz,$(oatfile))compress_oat := tar cfvz $(oatfile_targz) $(oatfile)all4 : @echo "The result is: " @echo $(compress_oat)

The output is as follows:
The result is:
Tar cfvz out/target/product/ali6753_65t_m0/obj/apps/musicfx_intermediates/oat/arm64/package.tar.gz out/target/ Product/ali6753_65t_m0/obj/apps/musicfx_intermediates/oat/arm64/package.odex

Filter function

There are two types of filter functions:

    • Filter is eligible to leave
    • Filter-out is eligible to get rid of.

Let's look at an example:

all8:    @echo $(filter-out default interpreter jit optimizing,xoc)    @echo $(filter-out default interpreter jit optimizing,default)

Output Result:

$ make all8xoc

Filter-out default interpreter JIT Optimizing,default this sentence, because default is in the list, so it is filtered out, and becomes an empty string.
Filter-out default Interpreter JIT Optimizing,xoc: This is because XOC is not in the filter list, so left.

The processing of words

File list, parameter list and so on can be regarded as the processing of words

For example, we want to check the last file in Makefile_list, which can be written like this:

$(call parent-dir,$(lastword $(MAKEFILE_LIST)))

For word processing, there are the following common functions:

    • FirstWord: Take the first word
    • Lastword: Take the Last word
    • Words: Count How many words there are
    • Word: Take nth word
    • Wordlist: Take a subset of the words

Word has a value of 1 and cannot fetch 0.

Let's look at an example:

SETTINGS_ART_DST: = Out/target/product/6753_doov_l5_64_m/system/priv-app/settings/oat/arm64/settings.odex.phony: All10all10: @echo "Install: [email protected]" $ (eval settings_art_dst_list: = $ (subst/,,$ ( SETTINGS_ART_DST)) @echo $ (words $ (settings_art_dst_list)) @echo $ (Word 1, $ (settings_art_dst_ LIST) @echo $ (Word 2,$ (settings_art_dst_list)) @echo $ (wordlist 5,10, $ (Settings_art_ dst_list))                 

The output is as follows:

$ make all10Install: all1010outtargetsystem priv-app Settings oat arm64 Settings.odex


Agent Jtag.
Links: https://www.jianshu.com/p/46224d15fc5f
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

ANDROID.MK (1) function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.