1. Linux Makefile Analysis
(1) The role of Makefile
a. Decide which files to compile
b. How to compile these files
c. How to connect these files, and most importantly, what is their order
There are many Makefile files in the Linux kernel. The following are the five major categories of Makefile files:
a. Decide which files to compile.
The compilation process of the Linux kernel starts with the top-level Makefile, and then recursively enters each level of subdirectory to call their Makefiles. It is divided into three steps.
1. The top-level Makefile determines which subdirectories under the kernel root directory will be compiled into the kernel.
2. arch/$(ARCH)/Makefile determines which files and directories under the arch/$(ARCH) directory will be compiled into the kernel.
3. The Makefile in each subdirectory determines which files in the directory will be compiled into the kernel, which files will be compiled into modules (ie, drivers), and which subdirectories will be entered to continue calling their Makefiles.
Let's look at step 1 first. In the top-level Makefile, we can see:
As can be seen above, the top-level Makefile divides these 13 subdirectories into 5 categories: init-y, drivers-y, net-y, libs-y and core-y. There is also an arch that is included into the kernel in arch/$(ARCH)/Makefile.
For non-x86 platforms, you also need to specify cross-compilation tools.
For arch/$(ARCH)/Makefile in step 2, taking the ARM system as an example, you can see the following content in arch/arm/Makefile:
Line 94: In addition to the previous 5 types, another type of head-y appears, but it appears directly as a question mark. MMUEXT is defined in the front of arch/arm/Makefile. For processors without MMU, the value of MMUEXT is -nommu, and the file head-nommu.S is used; for processors with MMU, the value of MMUEXT is empty, and the file head.S is used.
In arch/arm/Makefile, lines 171, 172, and 173 further expand the contents of core-y, and line 191 expands the contents of libs-y. These are architecture-related directories. CONFIG_ARCH_S3C2410 in lines 173 to 175 is defined when configuring the kernel. It has three values: y, m, or empty. y means compiled into the kernel, m means compiled as a module, and empty means not used.
When compiling the kernel, the directories listed in init-y, core-y, libs-y, drivers-y, and net-y will be entered in turn to execute their Makefiles. Each subdirectory will generate a built-in.o (a lib.a file may be generated in the directory listed in libs-y). Finally, the file represented by head-y will be compiled with these built-in.o
, lib.a together into the kernel image file vmlinux.
For step 3:
When configuring the kernel, a configuration file .config is generated. The kernel top-level Makefile uses the following statement to indirectly include the .config file, and then decides which files to compile based on the variables defined in .config. The so-called "indirect" inclusion is because it includes the include/config/auto.conf file, which only removes the comments in the .config file and adds some variables based on the variables defined in the top-level Makefile.
In the include/config/auto.conf file, there are two main types of variable values: "y" and "m". The Makefiles of each subdirectory use these variables to decide which files are compiled into the kernel, which files are compiled into modules, and which subdirectories to enter for further compilation. This is determined by the following 4 methods (obj-y, obj-m, lib-y are variables in Makefile).
obj-y is used to define which files are compiled into the kernel (built-in)
obj-m is used to define which files are compiled into loadable modules.
lib-y is used to define which files are compiled into library files
obj-y and obj-m can also be used to specify the next subdirectory to enter.
(2) How to compile these files
That is, what are the compile options and link options. These options are divided into three categories: global, applicable to the entire kernel source tree; local, applicable only to all files in a Makefile; individual, applicable only to a certain file.
(3) How to connect these files and what is their order
Previous article:TQ2440 Study Notes - 7. NOR Flash and NAND Flash
Next article:TQ2440 uses Jlink-Flasher to burn u-boot or program
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Another technical solution for power-type plug-in hybrid: A brief discussion on Volvo T8 plug-in hybrid technology
- DIY Energy Saving Socket Strip
- Can you recommend some 16-bit or 32-bit dual in-line microcontrollers with a price range of 2-6 yuan?
- 18 celebrities collectively denounce rogue software
- Analog circuits are the entry point for the future development of integrated circuits in my country! !
- USB HOST Technology in Car Driving Recorder
- Aerospace measurement and control PXI telemetry and remote control system
- SensorTile.box accelerometer IIS3DHHCTR test project
- AD When viewing in 3D, the color cannot be changed in any way, it is just one color.
- A C++ question about constructors, I don't understand it
- Jiuxing shares - causes and hazards of motor bearing heating