ANDROID.MK (5) How to calculate?

Source: Internet
Author: User

Https://www.jianshu.com/p/57c01e97c9b8

What about calculations?

In the front we have makefile as a language of the main characteristics of a general description, it sets the target pattern and functional pattern, and a large number of macro ideas, has been able to write quite complex makefile.
However, unfortunately, although it is already very complicated, we will find in the actual android.mk that there are a lot of things in the light of the makefile string substitution can not do, how is this good?

In fact, that's why we talked about the shell function at the very beginning of the first lecture, because it was solved by shell scripting.

Let's look at a practical example: Core.mk The version number of make is greater than or equal to the 3.81 version of the script:

# Check for broken versions of make.# (allow any version under Cygwin since we don ' t actually build the platform there.)Ifeq (,$(FindString cygwin,$ (Shell Uname-sm)))IFNEQ (1,$(Strip $ (Shell Expr$ (make_version) \>= 3.81))) $ (warning ********************************************************************************)$ (  Warning * You is using version $ (make_version) of make.) $ (warning * Android can only is built by versions 3.81 and higher.) $ (warning * see https://source.android.com/source/download.html)$ (warning ********************** )$ (error stopping)endifendif 
Evaluates the value of an expression-expr statement

The expr statement can be used to calculate the value of the result of a variable.

    • Addition: +
    • Subtraction:-
    • Multiplication: \*
    • Division:/
    • Find remainder:%

Pay special attention to multiplication by adding a \ before *

Cancel the definition of a variable-unset statement

In the process of actually writing makefile, it is sometimes necessary to modify the environment variables. unset statements are available in the shell

Not much to say, directly on the example:

$(shell unset _JAVA_OPTIONS && java -version 2>&1)javac_version_str := $(shell unset _JAVA_OPTIONS && javac -version 2>&1)
What about the shell?

The shell is finally able to do some simple calculations, but to a certain extent to the size of the demand, or not, how to do?
In the ANDROID.MK system, you can see Python,ruby have been introduced, need to use, do not hesitate. The completion of the work is main, the method is not important.



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

ANDROID.MK (5) How to calculate?

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.