MakefileKconfig Kernel configuration kernel pruning

Source: Internet
Author: User
MakefileKconfig Kernel configuration kernel pruning-general Linux technology-Linux programming and kernel information. The following is a detailed description. Suppose we want to use the following tree directory for test driver under the drivers directory of the kernel source code:
| ---- Test
| ---- Cpu
| ---- Cpu. c
| ---- Test. c
| ---- Test_client.c
| ---- Test_ioctl.c
| ---- Test_proc.c
| ---- Test_queue.c
To add directories and subdirectories to the kernel, we need to create Kconfig and Makefile files for the newly added directories. The Kconfig and Makefile files in the parent directory of the newly added directory also need to be modified, so that the newly added Kconfig and Makefile files can be referenced.
The new test directory should contain the following Kconfig file:
#
# TEST driver configuration
#
Menu "Test Driver"
Comment "Test Driver"
Config TEST
Bool "TEST suport"
Config TEST_USER
Tristate "TEST user-space interface"
Depends on TEST
Endmenu
Because the TEST driver is a new function for the kernel, you must first create a menu TEST Driver, and then display "TEST support", waiting for the user to select. Then, determine whether the user has selected the TEST Driver, if it is (CONFIG_TEST = y), the sub-function: user interface and CPU Function Support will be further displayed. Because the user interface function can be compiled into a kernel module, the query statement here uses tristate.
To make the Kconfig File work, modify the drivers/Kconfig file and add the following content:
Source "drivers/test/Kconfig"
The source in the script means to reference the new Kconfig file. The new test directory should contain the following Makefile file:
# Drivers/test/Makefile
#
# Makefile for the TEST
#
Obj-$ (CONFIG_TEST) + = test. o test_queue.o test_client.o
Obj-$ (CONFIG_TEST_USER) + = test_ioctl.o
Obj-$ (CONFIG_PROC_FS) + = test_proc.o
Obj-$ (CONFIG_TEST_CPU) + = cpu/
This script builds the obj-* list based on the value of the configuration variable. Because the test directory contains a sub-directory cpu, when CONFIG_TEST_CPU = y, you need to add the cpu directory to the list.
The cpu directory in the test directory must also contain the following Makefile file:
# Drivers/test/cpu/Makefile
#
# Makefile for the TEST cpu
#
Obj-$ (CONFIG_TEST_CPU) + = cpu. o
To enable the entire test directory to be used by the compilation command, the Makefile file in the parent directory of the test directory also needs to add the following script:
Obj-$ (CONFIG_TEST) + = test/
The new test tree directory after the Kconfig and Makefile files are added is as follows:
| ---- Test
| ---- Cpu
| ---- Cpu. c
| ---- Makefile
| ---- Test. c
| ---- Test_client.c
| ---- Test_ioctl.c
| ---- Test_proc.c
| ---- Test_queue.c
| ---- Makefile
| ---- Kconfig

This completes the work.
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.