Linux make menuconfig Execution Process summary

Source: Internet
Author: User
Tags builtin

Linux/2.6.20.6/make menuconfig


When the "make menuconfig" command is executed in the top-level directory, the rule of the top-level makefile row 415th will be executed.

Config % config: scripts_basic outputmakefile force
$ (Q) mkdir-P include/Linux include/config
$ (Q) $ (make) $ (build) = scripts/kconfig $ @

Here, "menuconfig" matches the pattern "% config. Therefore, the execution rules are as follows:

Menuconfig: scripts_basic outputmakefile force
$ (Q) mkdir-P include/Linux include/config
$ (Q) $ (make) $ (build) = scripts/kconfig menuconfig

This rule has three dependencies: scripts_basic, outputmakefile, and force. Let's take a look at these three dependencies:

1. Force

First, analyze the dependency, and its rule definition is in row 1485:

Phony + = force
Force:

This rule does not have commands or dependencies, and its target is not an existing file name. When executing this rule, the target force will always be regarded as the latest. In this way, when it is dependent on other rules, because the dependency is always considered to have been updated, the commands defined in the rule will always be executed.

2. scripts_basic

The rule for this dependency is defined in row 347:

Scripts_basic:
$ (Q) $ (make) $ (build) = scripts/basic

The build variable is defined in the 114 rows of scripts/kbuild. include:

Build: =-F $ (if $ (kbuild_src), $ (srctree)/) scripts/makefile. Build OBJ

Therefore, the above rules can be written as follows:

Scripts_basic:
$ (Q) $ (make)-F $ (if $ (kbuild_src), $ (srctree)/) scripts/makefile. Build OBJ = scripts/basic

The command for this rule will eventually enter the scripts directory, execute the makefile. Build File, and pass the parameter OBJ = scripts/basic.

The following lines in makefile. Build:

SRC: = $ (OBJ)

This assigns the passed value to SRC, so

SRC: = scripts/basic

The makefile in the SRC (scripts/basic) directory is included in the two lines starting from row 16th (if kbuild exists, kbuild is included)

Kbuild-Dir: = $ (if $ (filter/%, $ (SRC), $ (SRC), $ (srctree)/$ (SRC ))
Include $ (if $ (wildcard $ (kbuild-DIR)/kbuild), $ (kbuild-DIR)/kbuild, $ (kbuild-DIR)/makefile)

Included scripts/makefile. Lib in row 19th,

Row 83rd of makefile. Build is the first target encountered by make in makefile. build.

_ Build: $ (if $ (kbuild_builtin), $ (builtin-target) $ (Lib-target) $ (extra-y ))/
$ (If $ (kbuild_modules), $ (obj-m ))/
$ (Subdir-ym) $ (always)
@:

Kbuild_builtin defines the 207th rows of makefile on the top layer

Kbuild_builtin: = 1

If you execute "make modules", some processing will be performed on it in row 214.

Ifeq ($ (makecmdgoals), modules)
Kbuild_builtin: = $ (if $ (config_modversions), 1)
Endif

So here we are going to kbuild_builtin: = 1

Kbuild_modules defines the 206th rows of makefile on the top layer,

Kbuild_modules: =

If you execute any command in "make all", "Make _ all", "Make modules", and "make", the variable will be processed in line 3.

Ifneq ($ (filter all _ all modules, $ (makecmdgoals )),)
Kbuild_modules: = 1
Endif

Ifeq ($ (makecmdgoals ),)
Kbuild_modules: = 1
Endif

Therefore, kbuild_modules: =

After analyzing these two variables, the above rules can be rewritten

_ Build: $ (builtin-target) $ (Lib-target) $ (extra-y) $ (subdir-ym) $ (always)
@:

This is through rules

Scripts_basic:
$ (Q) $ (make)-F $ (if $ (kbuild_src), $ (srctree)/) scripts/makefile. Build OBJ = scripts/basic

The first rule executed in the scripts/makefile. Build File,

The dependencies in the rule are represented by several variables $ (builtin-target) $ (Lib-target) $ (extra-y) $ (subdir-ym) $ (always. The rule command is a colon command ":", and the colon (:) command is a built-in bash command, which is usually considered as a true command. Bash help explanation (help :): no effect; the command does nothing. A zero exit code is returned. (no effect, this command is a null operation, and the exit status is always 0 ).
_ Build: $ (builtin-target) $ (Lib-target) $ (extra-y) $ (subdir-ym) $ (always)
@:

Build some dependency targets. Here we mainly build the targets specified by the $ (always) variable. Other variables are not defined in scripts/basic/makefile.

3. outputmakefile

Go back to the top-level makefile and check the rules.

Menuconfig: scripts_basic outputmakefile force
$ (Q) mkdir-P include/Linux include/config
$ (Q) $ (make) $ (build) = scripts/kconfig menuconfig

The outputmakefile parameter construction rule in starts to be defined in row 357.

Outputmakefile:
Ifneq ($ (kbuild_src ),)
$ (Q) $ (config_shell) $ (srctree)/scripts/mkmakefile/
$ (Srctree) $ (objtree) $ (Version) $ (patchlevel)
Endif

The command for this rule runs a shell script scripts/mkmakefile and passes four parameters. This script generates a MAKEFILE file in the directory specified by the $ (objtree) parameter. Because kbuild_src is empty, this script will not be executed.

Let's look back at the rule.

Menuconfig: scripts_basic outputmakefile force
$ (Q) mkdir-P include/Linux include/config
$ (Q) $ (make) $ (build) = scripts/kconfig menuconfig

After the dependency is processed, execute the rule command. The first command creates two directories, and the second command expands

$ (Q) $ (make)-F $ (if $ (kbuild_src), $ (srctree)/) scripts/makefile. Build OBJ = scripts/kconfig menuconfig

This command still runs the makefile scripts/makefile. Build File. And execute the menuconfig rules in it. According to the above analysis, the makefile. Build will contain the scripts/kconfig/MAKEFILE file. Then execute the rule with menuconfig as the target and define it in line 13 of scripts/kconfig/makefile.

Menuconfig: $ (OBJ)/mconf
$ <ARCH/$ (ARCH)/kconfig

From this command, we can see that the arch/ARM/kconfig script will be run and the configuration interface will appear.

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.