-
Notifications
You must be signed in to change notification settings - Fork 1
/
xen_kconfig_memo.txt
112 lines (78 loc) · 3.38 KB
/
xen_kconfig_memo.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
all: dist
dist: DESTDIR=$(DISTDIR)/install
dist: $(TARGS_DIST) dist-misc
SUBSYSTEMS?=xen tools stubdom docs
TARGS_DIST=$(patsubst %, dist-%, $(SUBSYSTEMS))
dist-%: DESTDIR=$(DISTDIR)/install
dist-%: install-%
@: # do nothing
install-xen:
$(MAKE) -C xen install
# Now, build process descend into subdir: xen
# Note, double colon rule is used
install:: include/config/auto.conf
build install::
ifneq ($(XEN_TARGET_ARCH),x86_32)
$(MAKE) -f Rules.mk _$@
else
echo "*** Xen x86/32 target no longer supported!"
endif
include/config/%.conf: include/config/auto.conf.cmd $(KCONFIG_CONFIG)
$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" silentoldconfig
# Empty recipe,avoid implicit rule
include/config/auto.conf.cmd: ;
# Allow people to just run `make` as before and not force them to configure
$(KCONFIG_CONFIG):
$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" defconfig
So, 对于 Xen 来说,如果用户没有显式的 make *config 来生成 .config 文件,则会通过 defconfig 来生成。
$(BASEDIR)/tools/kconfig/Makefile.kconfig 包含了 tools/kconfig 下的 Makefile 和 Makefile.host,
Makefile.host 用于编译 kconfig 的 host program,Makefile 则包含各种 config target,defconfig 就定义在其中。
编译的重头落在这条 recipe:
$(MAKE) -f Rules.mk _$@
而 xen/Rule.mk 中又 include xen/Makefile, _install 定义在这里:
_install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
Rules.mk 中 include 了
Makefile(此时是 xen/Makefile)
$(XEN_ROOT)/Config.mk
$(XEN_ROOT)/config/$(XEN_TARGET_ARCH).mk
变量 TARGET 定义在 xen/Rule.mk 中:
TARGET := $(BASEDIR)/xen
xen/Makefile 中有:
export BASEDIR := $(CURDIR)
config/x86_64.mk 有:
CONFIG_XEN_INSTALL_SUFFIX := .gz
所以将上面的 rule 扩展出来就是:
_install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
==》
_install: <完整路径>/xen/xen.gz
# In xen/Makefile
(TARGET).gz: $(TARGET)
gzip -n -f -9 < $< > [email protected]
mv [email protected] $@
$(TARGET): delete-unfresh-files
...
$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) $@
xen/arch/x86/Makefile:
$(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
$(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
prelink.o: $(ALL_OBJS)
$(LD) $(LDFLAGS) -r -o $@ $^
# In xen/Rules.mk
ALL_OBJS-y += $(BASEDIR)/common/built_in.o
ALL_OBJS-y += $(BASEDIR)/drivers/built_in.o
ALL_OBJS-y += $(BASEDIR)/xsm/built_in.o
ALL_OBJS-y += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o
ALL_OBJS-$(CONFIG_CRYPTO) += $(BASEDIR)/crypto/built_in.o
ALL_OBJS := $(ALL_OBJS-y)
# In xen/arch/x86/Makefile
ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
# In xen/Rules.mk
%/built_in.o: FORCE
$(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o
built_in.o: $(obj-y)
$(LD) $(LDFLAGS) -r -o $@ $^
因为有 -C $*,且 xen/Rules.mk 中有: include Makefile,以 $(BASEDIR)/common/built_in.o 为例,被 include 的 Makefile 是 $(BASEDIR)/common/Makefile,
这个 Makefile 中定义的是 obj-y,subdir-y 等, 跟 kernel 一样,每个目录下的所有 object file 被 link 为 built_in.o,子目录的 built_in.o 被 link 到父目录
的 built_in.o 中:
subdir-y += $(filter %/,$(obj-y))
obj-y += $(patsubst %/,%/built_in.o,$(subdir-y))