Uboot makefile inside two all: function (pseudo target, empty command) __uboot

Source: Internet
Author: User

Uboot's makefile has two all:


First all: No dependencies, no commands. Followed by two articles include

Sinclude $ (obj) INCLUDE/AUTOCONF.MK.DEP
Sinclude $ (obj) include/autoconf.mk


Another all: $ (all-y) $ (subdir_examples)

This all is what we really need to do.


To understand the role of the all NULL command here. You have to know the next few points

1

When there are two identical targets in the makefile, the latter target is executed. Because the latter target overloads the previous one.

Like what

All

Echo all1

All

Echo all2

Execute make will output the latter one all2


2 pseudo target

A place to use is when there is no need to produce an actual target file (for example, just execute instructions).

Clean

RM *.O

This does not produce a file. Only the instructions need to be executed. If the current directory does not have a file called clean. It is normal to perform make clean. If there is a clean file under the directory. Because the clean file is up to date, the RM *.O operation is not performed. It is therefore necessary to define a pseudo target. Regardless of whether the target exists under the directory. will perform clean operations RM *.O

. Phony clean

Clean

RM *.O


3 Empty command

A dependent file can exist, but there is no command line.

Like what

All

Or

All: $ (obj)

The only effect of an empty command is to prevent make from trying to find implied commands for rebuilding this target when it is executing

This sentence is not understood for the time being. Look at the back first.


4makefile execution rules and include this is the key point

Makefile is first parsed.

Encountered include. First to resolve the include file (assuming that inc.mk), after parsing finished and then back to resolve the original makefile.

The key point is if this inc.mk doesn't exist. Make does not exit. Instead, a warning is first made to continue to deal with the contents of the original makefile.

Wait until the content of the original makefile is disposed of. Will try to reconstruct the Inc.mk file using the rule, which is to try to execute the inc.mk file as a target. If we can't reconstruct this inc.mk. Then report an error and make exits. If this inc.mk was rebuilt. Then reset the state of the original makefile and start executing the makefile again.



Look back at Uboot's makefile. Assume that we have successfully executed make xxxx_config. Next, a make command is executed

The first encounter is a

All

Sinclude $ (obj) INCLUDE/AUTOCONF.MK.DEP
Sinclude $ (obj) include/autoconf.mk

Let's see what happens if there is no first all: what would be the result.

AUTOCONF.MK.DEP and Autoconf.mk are non-existent at this time.

But according to rule fourth. Make does not exit. will continue to carry it out first. Perform a complete makefile

Look back at the include file.

If you print a "reach" at the end of makefile and print a sentence in sinclude $ (obj) include/autoconf.mk, then the result we see is

makefile:189: "Hereis include AUTOCONF.MK.DEP"
makefile:892: "Reach and End"
Generating INCLUDE/AUTOCONF.MK
Generating INCLUDE/AUTOCONF.MK.DEP
makefile:189: "Hereis include AUTOCONF.MK.DEP"
makefile:892: "Reach and End"
Make: ' Include/autoconf.mk ' are up to date.


According to fourth, the first time no autoconf.mk performed the entire makefile of the read-print that had been printed on reach-end.

Then go back and execute include/autoconf.mk and INCLUDE/AUTOCONF.MK.DEP as a target. That's why there's generating include/autoconf.mk.
The output of the generating INCLUDE/AUTOCONF.MK.DEP. Reset the makefile state after completion. Re-execute the makefile. At this time autoconf.mk and AUTOCONF.MK.DEP all have.

Why not compile Uboot? Because the command we execute is make. is not followed by a parameter, so makefile compiles the first target encountered by default. Because we have commented on the first all:

So the include is executed directly. Open AUTOCONF.MK.DEP See the first line is include/autoconf.mk:include/common.h. This is the first goal that makefile encountered.

Include/autoconf.mk. Therefore, the INCLUDE/AUTOCONF.MK as the ultimate goal of implementation. At this time the INCLUDE/AUTOCONF.MK was first produced, so is the latest. Makefile that there was no need to do it again.

So nothing was done, and finally the make: ' Include/autoconf.mk ' was up to date. It also understood that the only effect of the previous third empty command was to prevent make from trying to find implied commands for rebuilding the target when it was executed. This implied command is the execution of the first encountered goal.


If there is the first all: words. Makefile knew that the ultimate goal to be implemented was all. Instead of the include/autoconf.mk included in the AUTOCONF.MK.DEP.

Continue execution to all that follows: All behind will overwrite all in front. Perform the operation here. So the final execution is the second all


So the first all: meaning


If you perform make without any other goals. A single make. The include/autoconf.mk in AUTOCONF.MK.DEP can be avoided as the wrong target.

If you perform make, you have a goal. This all: there is no matter.











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.