为了更好的理解qemu的Makefile的设计,对于不熟悉makefile语法规则的同学建议阅读下面两篇文章:
1. 《Makefile常用函数分析》
2. 《跟我一起写makefile》
----------------------------------------------------------------------------------------
/*qemu的Makefile的依赖目标之间的关系*/
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="$*/",)
上面即是qemu简化版的Makefile,下面就来详细分析下上面规则的含义。-------------------------------------------------------------------------------------------
p, li { white-space: pre-wrap; }
SRC_PATH=/home/src/qemu-0.15.1
TOOLS=qemu-ga qemu-nbd qemu-img qemu-io /*规则(2)中TOOLS的定义*/
TARGET_DIRS=i386-softmmu /*规则(4)中TARGET_DIRS的定义*/
ROMS=optionrom /*规则(5)中ROMSUBDIR_RULES的定义*/
--------------------------------------------------------------------------------------------
上述规则中最重要的规则就是两个函数的调用: p, li { white-space: pre-wrap; }
subdir-%: $(GENERATED_HEADERS)
$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" TARGET_DIR="$*/" all,)
上面规则等价于:
make --no-print-directory -C i386-softmmu V="" TARGET_DIR="i386-softmmu/" all
回想make -C的常用格式:
make -C path 参数
则上面规则的含义为:执行i386-softmmu下的Makefile中的依赖目标all, 传递的参数是V=""和TARGET_DIR="i386-softmmu/"
romsubdir-%:
$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C pc-bios/$* V="$(V)" TARGET_DIR="$*/",)
与subdir-i386-softmmu一样,上面规则的含义就是:执行pc-bios/下的所有依赖目标,传递的参数为 V="$(V)" TARGET_DIR="$*/",需要注意的是这里的$*代表的是不包含扩展名的目标文件的名称。
自此,Makefile就进入了i386-softmmu和pc-bios两个目录下,执行相对应的Makfile
---------------------------------------------------------------------------------------------
从i386-softmmu/Makefile中能够清晰的找出哪些代码完成了qemu哪些功能模块的仿真。
1. cpu功能模块的仿真
- 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
- # 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-$(CONFIG_KVM) += kvmclock.o
- obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
- 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)
- obj-$(CONFIG_KVM) += kvm.o kvm-all.o
- obj-$(CONFIG_NO_KVM) += kvm-stub.o