In the Linux authoring process, there are two files that we must understand and know. One of these is the Kconfig file, and the other is the makefile file. If you are familiar with it, then it is certainly necessary for the kernel to compile the. config file, in the. config file, we found that some modules were compiled into the kernel, and some just generated a module. In the middle, how do we let the kernel discover the modules we write, which we need to explain in kconfig. As for how to generate the module, you need to use Makefile to tell the compiler how to build the module. Imitation is actually the best teacher, we can use the Kernel network card e1000 module as an example, explain how the kernel is set up and compiled.
First, we can take a look at how e1000 is described in Kconfig in 2.6.32.60,
The above content is extracted from the drivers/net/kconfig. Content does not look complicated, the most important thing is to explain the module name, purpose, dependent module name, description and so on. As long as we have this note, we can see the e1000 option when we enter make menuconfig under the shell, enter Y to compile the kernel, enter N to not compile, and enter M to write the module, which is known to all.
So, with this module, which files need to be compiled, we see this content in Drivers/net/makefile,
Obviously, this code just tell us, want to compile e1000, must contain e1000 this directory, so e1000 directory there is bound to have a makefile, sure enough, we found this e1000 in the makefile directory, the content is as follows,
Read this document, in fact, we should have the bottom of psychology. Originally this e1000 module final generated file is E1000.ko, dependent on the file is E1000_main.c, e1000_hw.c, E1000_ETHTOOL.C, e1000_param.c these four files. As long as the config_e1000 is set, the module will be compiled normally. All we have to do is turn on the switch and the rest of the kernel will help us get everything done. Of course, if you want to get this module out, it is possible to compile it yourself with a separate module.
The compilation of Linux drivers is actually more important than the two configuration files.
Kconfig and makefile of Linux drivers