Android.mk (4) Dependency: The mode of target programming

Source: Internet
Author: User
Tags builtin

Https://www.jianshu.com/p/3777a585a8d0

Another paradigm

I have always felt that makefile is indeed a good match for C + + programmers, because the two paradigms used by Makefile are unfamiliar to C + + programmers, one that is functional, and one that relies on the form of a target chain.

Makefile from the most basic, can be abstracted into the following:

    target ... : prerequisites ...            command            ...            ...

As you are familiar with, the meaning of this paragraph is: When the prerequisites is updated, execute command commands. If Target is a real target, that is, a real file, then the file is generated. If it is a pseudo-target, it can be used as a portal, such as clean, can also become a real target of dependence.
Can be clearly divided into two parts: one is the paradigm of the target dependency chain, which is very different from the C language of the procedural language. With Shang words, with Prolog a bit like. Has its own set of logic systems.
Behind the command, we have said a lot, I personally want you to use the function of the idea to write.

We landed in a practical example:

$(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE)    $(call build-systemimage-target,[email protected])

This $ (built_systemimage) is a true target, corresponding to the file system.img to be generated, as follows:

$(systemimage_intermediates)/system.img

Let's take a look at the target of System.img, look first, and the result is actually two:

$(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS)

Then we find that this dependency expands on a layer:

$(filter $(TARGET_OUT)/%,     $(ALL_PREBUILT)     $(ALL_COPIED_HEADERS) $(ALL_GENERATED_SOURCES) $(ALL_DEFAULT_INSTALLED_MODULES) $(PDK_FUSION_SYSIMG_FILES) $(RECOVERY_RESOURCE_ZIP))

Expansion continues, for example, for All_prebuilt, where each module constantly adds its own stuff:

$(TARGET_OUT)/bin/monkey

Other objective principles are interlinked, and there is not much space to waste.
All in all, as long as there is any change in this large set of goals, the system.img will be regenerated. How to generate? In the next line is written: Call Build-systemimage-target AH.

Makefile Writing Guide

Both the objective and the functional paradigm are well-learned, and here's how we organize the materials to complete our project.

    1. Define the total target first
      The general purpose of the makefile is to output one or more result files, which are defined first by the gross position target.
      Then assume that the sub-goals have been built, and write a script that turns these intermediate products into the final target.
      such as compiling a simple C program, the overall goal is an executable file, the final processing of the material is already compiled. o files and input of third-party library files, etc., we don't care how they are compiled, assuming they're ready, we just have to write a linked script.
      Like the example of system.img above us, depending on the more, we classify the column bar, and finally we just need to put them into a bag.
    2. Layer-by-layer decomposition, progressive completion
      Then find out what the first layer of the big goal is, like the one we've seen above, and expand by layers.
      For C files, consider each one at this time. O is compiled from the source file.
    3. Modular, functional
      The above two steps are the target pattern, this step starts to make the function pattern. The reusable functions of each goal are abstracted, the sub-file is divided into files, the collation of code, etc.
    4. Test tuning
      When a project is large to a certain extent, the readability of the makefile is severely degraded.
      At this point we still reduce the complexity by the two main lines of target and function. The goal is hierarchical, and we can debug it one layer at a time, for example, by first adjusting the compilation process from. C to. o, and then aligning the. O to the assembly part that is linked together.
      Which sub-module has a problem, it is specially tuned that part.
      For the functional part, we have always stressed that the function of the idea is that for a certain input, can have a deterministic output, no side effects, so as to reduce the difficulty of debugging, we can a function of a function to debug.
      Makefile debug to log the main, but also through the make-p to output a complete list of variables and targets.
Make-p, see what make is doing.

Here is an excerpt from the output of my make-p under Cygwin.

Make tool information

The first is the make tool to report its own basic situation:

The files is:main.cpp# GNU Make 4.1# Built for x86_64-unknown-cygwin# Copyright (C) 1988-2014 Free Software Foundation, Inc.# License GPLv3+: GNU GPL version 3 or later # This is free software: you are free to change and redistribute it.# There is NO WARRANTY, to the extent permitted by law.# make 数据基础,打印在 Tue May 3 17:54:36 2016
Variable

The following is a list of variables, containing our own definitions, and also contains make automatically generated for us.

# variable# ' override ' Directivegnumakeflags: =# Auto <d =$(Patsubst%/,%,$ (Dir$<))Automatically? F =$(Notdir$?)Default. Shellflags: =-C# makefile (from ' makefile ', line) Result_findstring2: =# makefilemakeflags = P# Default Cweave = CweaveAutomatically? B$(Patsubst%/,%,$ (Dir$?))# environment !:: =:: # auto @d = $ (patsubst%/,%,$ (dir [email protected])) # environment homedrive = C:# auto @f = $ (notdir [email protected]) # Auto ^ D = $ (patsubst%/,%,$ (dir Span class= "hljs-variable" >$^)) # makefilecurdir: =/cygdrive/d/working/codeblocks/hello # Makefileshell =/bin/sh# default RM = Rm-f # default CO = co ...            
Directory information
# 目录# SCCS:无法对其进行 stat 操作。# . (设备 114478965,i-节点 1688849860268365):10 文件, 19 不可能.# RCS:无法对其进行 stat 操作。# 10 文件, 19 不可能在 3 目录中。
Implied rule information
# implied rules.%.out:%.A:%.LN:%.O:%:%.O# Recipe to execute (built-in): $ (LINK.O)$^$ (Loadlibes)$ (ldlibs)-O[Email protected]%.C:%:%.c# Recipe to execute (built-in): $ (LINK.C)$^$ (Loadlibes)$ (ldlibs)-O[Email protected]%.LN:%.c# Recipe to execute (built-in): $ (lint.c)-C$*$<%.O:%.c# Recipe to execute (built-in): $ (COMPILE.C)$ (output_option)$<%.cc:%:%.cc# Recipe to execute (built-in): $ (link.cc)$^$ (Loadlibes)$ (ldlibs)-O[Email protected]%.O:%.cc# Recipe to execute (built-in): $ (compile.cc)$ (output_option)$<%. C:%: %. C# Recipe to execute (built-in): $ (LINK. C$^$ (Loadlibes)$ (ldlibs)-O[Email protected]%.O:%. C# Recipe to execute (built-in): $ (COMPILE. C$ (output_option)$<%.cpp:%:%.cpp# Recipe to execute (built-in): $ (LINK.cpp)$^ $ (loadlibes) $ (ldlibs)-O [email protected]%.O:%.cpp# Recipe to execute (built-in): $ (COMPILE.cpp) c6>$ (output_option) $<%.p:%:%.p# Recipe to execute (built-in): $ (LINK.P) $^ $ (loadlibes) $ (ldlibs)-O [email protected]%.O:%.p# Recipe to execute (built-in): $ (COMPILE.P) $ (output_option) $&L t;                  .....
Document targets and false targets
# file# is not a goal:. WEB.P:# Builtin Rule# The search for implied rules has not been completed.# never check the modification time.# file has not been updated.# Recipe to execute (built-in):$ (Tangle)$<# is not a goal:. L.R:# Builtin Rule# The search for implied rules has not been completed.# never check the modification time.# file has not been updated.# Recipe to execute (built-in): $ (LEX.L)$< >[Email protected] mv-f LEX.YY.R[Email protected]ALL8:# false Target (. Phony of the premises).# The search for implied rules has not been completed.# file does not exist.# file has not been updated.# Recipe to execute (from ' Makefile ', line): @echo$(Filter-out default interpreter JIT Optimizing,xoc) @echo$(Filter-out default interpreter JIT Optimizing,default)ALL9:# false Target (. Phony of the premises).# The search for implied rules has not been completed.# file does not exist.# file has not been updated.# Recipe to execute (from ' Makefile ', line 75):$(Eval arch_of_boot_oat: = $ (Lastword $ (SUBST/, $ (dir $ (BOOT_ART_ SRC)))) $ (eval oat_temp: = $ ( product_out)/data/dalvik-cache/temp-oat/system/framework/$ (ARCH_OF_BOOT_OAT)) $ (eval oat_src: = $ (patsubst%.art,% . Oat,$ (BOOT_ART_SRC)) $ ( Eval oat_dist: = $ (patsubst%.art,%.oat,$ (BOOT_ART_DST))) @ echo $ (arch_of_boot_oat) @echo $ (oat_temp) @echo $ (oat_src) @echo $ (oat_dist) ...        


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

Android.mk (4) Dependency: The mode of target programming

Related Article

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.