Kernel version

Linux 2.6.32.2

The process of configuring the kernel

To configure the kernel, run the make menuconfig command. The following describes the process of executing the command

Implement the goal

%config: scripts_basic outputmakefile FORCE
    $(Q)mkdir -p include/linux include/config
    $(Q)$(MAKE) $(build)=scripts/kconfig $@
Copy the code

Depend on the target

scripts_basic:
    $(Q)$(MAKE) $(build)=scripts/basic
Copy the code

The role of $(build)

### # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= # Usage: # $(Q)$(MAKE) $(build)=dir build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/ makefile. build obj # This is an abbreviation for executing a specific Makefile # so $(Q)$(MAKE) $(build)=scripts/basic can be converted to # $(Q)$(MAKE) -f $(if) $(KBUILD_SRC),$(srctree)/)scripts/ makefile. build obj=scripts/basicCopy the code

Makefile.build key statement

The purpose of this line is to include makefiles in the directory obj records to compile some programs running on the host

# src := $(obj)
# The filename Kbuild has precedence over Makefile
# kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
# kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
# include $(kbuild-file)
Copy the code

make menuconfig

Now back to the original target, make Menuconfig executes the following instructions

%config: scripts_basic outputmakefile FORCE $(Q)mkdir -p include/linux include/config $(Q)$(MAKE) $(build)=scripts/kconfig $@ # $(Q)$(MAKE) $(build)=scripts/kconfig menuconfigCopy the code

Again, it goes into the makfile. build file and includes the Makefile in the scripts/kconfig directory, and the target is menuconfig

scripts/kconfig/Makefile

The corresponding targets are as follows

Ifdef KBUILD_KCONFIG Kconfig := $(KBUILD_KCONFIG) else # Arch /arm/Kconfig Kconfig := arch/$SRCARCH /Kconfig endif menuconfig: $(obj)/ McOnf $< $(Kconfig)Copy the code

It depends on a program called scripts/kconfig/ McOnf that doesn’t exist, and its generation rules are given below the Makefile. It also checks whether the program from which it was generated exists. Execution of scripts are scripts/kconfig lxdialog/check – lxdialog. Sh, if there is no installation dependent libraries, appear error

# Check if we can link to ncurses
check() {
        $cc -xc - -o $tmp 2>/dev/null <<'EOF'
#include CURSES_LOC
main() {}
EOF
    if [ $? != 0 ]; then
        echo " *** Unable to find the ncurses libraries or the"       1>&2
        echo " *** required header files."                            1>&2
        echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
        echo " *** "                                                  1>&2
        echo " *** Install ncurses (ncurses-devel) and try again."    1>&2
        echo " *** "                                                  1>&2
        exit 1
    fi
}
Copy the code

This is why you need to install make Menuconfig before you execute it, because you need it

Once the above steps are complete, scripts/kconfig/ McOnf is generated, and it’s time to start the configuration

Scripts /kconfig/ McOnf $(kconfig) # for arm, the following path has been replaced with an absolute pathCopy the code

At this point, the real configuration begins. McOnf reads and parses Kconfig. The rules for parsing can be found in the McOnf. c file, but there is no need to see how it is implemented. The syntax can refer to www.kernel.org/doc/html/la…

If nothing else, the terminal now displays a graphical interface and you can configure the options. Upon exit, the program writes the configuration items to the.config file and generates the corresponding header file for the source code to use.