As we all know, the Linux kernel is configured and compiled using the make command, which is inevitable. Such a complex and large kernel source can never use one or several Makefiles to complete configuration compilation. Instead, it requires a set of Makefile systems that are equally complex, large, and customized for the Linux kernel.
Although she is a complex system, for most kernel developers only need to know how to use it without knowing the details. She is largely transparent to most kernel developers, hiding most of the implementation details, effectively reducing the developer's burden, allowing it to focus on kernel development without spending time and effort on the compilation process. .
1.1 Makefile in Linux kernel 1.1.1 Top-level MakefileThe top level Makefile of the source directory tree is the entry point for the entire kernel source management, which plays a decisive role in the source code compilation of the entire kernel. When compiling the kernel, the top-level Makefile recursively traverses the Makefiles in all subdirectories of the kernel source according to the rules, and compiles the kernel modules in each subdirectory. Familiarize yourself with the Makefile and help with kernel compilation.
1. Kernel version number
Open the top-level Makefile, the first few lines record the version number of the kernel source, usually as follows:
The code version is 2.6.35.3. After the compiled kernel runs on the target board, you can get the command by typing the uname -a command:
2. Compile control
(1) Architecture
Linux is an operating system that supports a large number of architectures. The architecture needs to be specified during the compilation process to correspond to the actual platform. In the top-level Makefile, specify by the variable ARCH:
If the ARCH parameter is not specified in the compile command line, the system will compile locally and automatically specify it by getting the local information:
If you are doing ARM embedded Linux development, you must specify ARCH as arm (note the case, you must match the arm in the arch/ directory), such as:
Of course, you can also modify the Makefile, which will be modified to ARCH? = $(SUBARCH) is changed to ARCH = arm, and you can make it directly from the command line.
(2) compiler
If you are not compiling locally, you must specify a cross compiler, specified by CROSS_COMPILE. The Makefile and cross compiler are specified as follows:
CONFIG_CROSS_COMPILE is a configuration option that can be specified during kernel configuration. If CONFIG_CROSS_COMPILE is not specified when configuring the kernel, and CROSS_COMPILE is not specified in the compilation parameter, it will be compiled with the local compiler.
For ARM embedded Linux development, you must specify a cross compiler that can be configured in the kernel via CONFIG.
_CROSS_COMPILE specifies a cross compiler, which can also be specified by CROSS_COMPILE. Assuming the cross compiler used is arm-linux-gnueabihf-gcc, specify CROSS_COMPILE as arm-linux-gnueabihf-:
Or in the Makefile, directly specify the value of CROSS_COMPILE:
Note: The cross compiler specified by CROSS_COMPILE must be installed and set the system environment variables correctly; if no environment variables are set, you need to use absolute addresses, for example:
If you specify both ARCH and CROSS_COMPILE, you can simply make a compilation at compile time.
1.1.2 Makefiles for subdirectoriesIn the subdirectory of the kernel source, almost every subdirectory has a corresponding Makefile, which manages the code in the corresponding directory. The compilation control of the files or subdirectories of the directory, there are two representations in the Makefile, one is the default selection compilation, represented by obj-y, such as:
The other representation is associated with the kernel configuration options, and the compilation and compilation methods depend on the kernel configuration, for example:
Whether to compile the wdt.c file, or how to compile it depends on the variable CONFIG_WDT value after the kernel configuration: if set to [*] in the configuration, statically compile to the kernel, if configured as [M], compile to Wdt.ko module, otherwise it will not compile.
Description: The controlled target is a directory. Obj-y does not directly determine the files of the controlled directory and the files of the subdirectories. It only interacts with the controlled directory Makefile. The actual compilation is controlled in the Makefile of the controlled subdirectory. For example, "obj-y += gpio/", which files in the final gpio directory are compiled depends entirely on the Makefile in the gpio directory. The meaning of "obj-$(CONFIG_PCI) += pci/" is the same.
2500 Puffs - 3500 Puffs Vape Pen,disposable pods,Dab Pen Atomizer,Vape Pen Nicotine
Shenzhen Xcool Vapor Technology Co.,Ltd , http://www.xcoolvapor.com