By analyzing qemu makefile, we can understand the organization of qemu code and the division of qemu functional modules. On the one hand, it helps to understand the design idea of qemu source code, and on the other hand, it helps to crop qemu code as needed, generate a streamlined qemu that meets the specified requirements.
To better understand the qemu makefile design, we recommend that you read the following two articles if you are not familiar with makefile syntax rules:
1. makefile Common Function Analysis
2. Write makefile with me
Bytes ----------------------------------------------------------------------------------------
/* Relationship Between qemu makefile dependency targets */
P, Li {white-space: Pre-wrap ;}
ALL: Build-All (1)
Build-ALL: $ (tools) recurse-All (2)
Recurse-ALL: $ (subdir_rules) $ (romsubdir_rules) (3)
P, Li {white-space: Pre-wrap; subdir_rules =$ (patsubst %, subdir-%, $ (target_dirs) (4)
Romsubdir_rules = $ (patsubst %, romsubdir-%, $ (roms) (5)
Subdir-%: $ (generated_headers) (6)
$ (Call quiet-command, $ (make) $ (subdir_makeflags)-C $ * V = "$ (v)" target_dir = "$ */" All ,)
Romsubdir-%: (7)
$ (Call quiet-command, $ (make) $ (subdir_makeflags)-c pc-bios/$ * V = "$ (v)" target_dir = "$ */",)
The above is the makefile of the simplified version of qemu. The following describes the meanings of the above rules in detail.
Bytes -------------------------------------------------------------------------------------------
P, Li {white-space: Pre-wrap ;}
Src_path =/home/src/qemu-0.15.1
Tools = qemu-ga qemu-NBD qemu-IMG qemu-IO/* Definition of tools in Rule (2 */
Target_dirs = Definition of target_dirs in i386-softmmu/* Rule (4 */
ROMs = optionrom/* Rule (5) romsubdir_rules definition */
Bytes --------------------------------------------------------------------------------------------
The most important rule in the preceding rule is the call of two functions: P, Li {white-space: Pre-wrap ;}
Subdir-%: $ (generated_headers)
$ (Call quiet-command, $ (make) $ (subdir_makeflags)-C $ * V = "$ (v)" target_dir = "$ */" All ,)
The above rules are equivalent:
Make -- no-print-directory-C i386-softmmu v = "" target_dir = "i386-softmmu/" All
Recall the common format of make-C:
Make-C path Parameter
The meaning of the above rule is: Execute the dependency target all in makefile under the i386-softmmu, the passed parameters are v = "" And target_dir = "i386-softmmu /"
Romsubdir-%:
$ (Call quiet-command, $ (make) $ (subdir_makeflags)-c pc-bios/$ * V = "$ (v)" target_dir = "$ */",)
Like the subdir-i386-softmmu, the above rule means to execute all the dependency targets under PC-bios/, passing the parameter V = "$ (V) "target_dir =" $ */", note that $ * indicates the name of the target file that does not contain the extension.
Since then, makefile has entered the i386-softmmu and PC-bios directory, execute the corresponding makfile
Bytes ---------------------------------------------------------------------------------------------
From the i386-softmmu/makefile can clearly find out which code completed qemu functional modules simulation.
1. Simulation of CPU function modules
- Libobj-y
= Exec. O translate-all.o cpu-exec.o translate. o
- Libobj-y + = TCG/TCG. o
- Libobj-y + = FPU/softfloat. o
- Libobj-y + = op_helper.o helper. o
- Ifeq ($ (target_base_arch), i386)
- Libobj-y + = cpuid. o
- Endif
- Libobj-$ (config_need_mmu)
+ = MMU. o
- Libobj-$ (target_arm)
+ = Neon_helper.o iwmmxt_helper.o
- Libobj-y + = disas. o
2. Simulation of hardware devices
- # Hardware support
- Obj-i386-y
+ = VGA. o
- Obj-i386-y
+ = Mc146818rtc. O i8259.o PC. o
- Obj-i386-y
+ = Cirrus_vga.o SGA. o apic. O ioapic. O piix_pci.o
- Obj-i386-y
+ = Vmport. o
- Obj-i386-y
+ = Device-hotplug.o pci-hotplug.o smbios. o
Wdt_ib700.o
- Obj-i386-y
+ = Debugcon. O multiboot. o
- Obj-i386-y
+ = Pc_piix.o
- Obj-i386-$ (maid)
+ = Kvmclock. o
- Obj-i386-$ (config_spice)
+ = Qxl. O qxl-logger.o qxl-render.o
3. platform-independent code in qemu (platform-shared code)
- Translate. O: translate. c CPU. h
- Translate-all.o: translate-all.c CPU. h
- TCG/TCG. O: CPU. h
- # Helper_cflags is used
For all the Code Compiled with static register
- # VARIABLES
- Op_helper.o user-exec.o: qemu_cflags
+ =$ (Helper_cflags)
- # Note: This is a workaround. The real
Fix is
To avoid compiling
- # Cpu_signal_handler ()
In user-exec.c.
- Signal. O: qemu_cflags
+ =$ (Helper_cflags)
4. KVM-related code
- OBJ-$ (config_kvm)
+ = KVM. O kvm-all.o
- OBJ-$ (config_no_kvm)
+ = Kvm-stub.o
According. /configure cannot be enabled by modules. This makefile also has other functional modules. The code corresponding to these functional modules is clearly displayed here, which can effectively improve the qemu code understanding and cropping efficiency.