forked from xen-project/mini-os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
248 lines (207 loc) · 6.86 KB
/
Makefile
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# Common Makefile for mini-os.
#
# Every architecture directory below mini-os/arch has to have a
# Makefile and a arch.mk.
#
OBJ_DIR=$(CURDIR)
TOPLEVEL_DIR=$(CURDIR)
include Config.mk
# Symlinks and headers that must be created before building the C files
GENERATED_HEADERS := include/list.h $(ARCH_LINKS) include/mini-os include/$(TARGET_ARCH_FAM)/mini-os
EXTRA_DEPS += $(GENERATED_HEADERS)
# Include common mini-os makerules.
include minios.mk
# Set tester flags
# CFLAGS += -DBLKTEST_WRITE
# Define some default flags for linking.
LDLIBS :=
APP_LDLIBS :=
LDARCHLIB := -L$(OBJ_DIR)/$(TARGET_ARCH_DIR) -l$(ARCH_LIB_NAME)
LDFLAGS_FINAL := -T $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds $(ARCH_LDFLAGS_FINAL)
# Prefix for global API names. All other symbols are localised before
# linking with EXTRA_OBJS.
GLOBAL_PREFIX := xenos_
EXTRA_OBJS =
TARGET := mini-os
# Subdirectories common to mini-os
SUBDIRS := lib
src-$(CONFIG_BLKFRONT) += blkfront.c
src-$(CONFIG_CONSFRONT) += consfront.c
src-$(CONFIG_TPMFRONT) += tpmfront.c
src-$(CONFIG_9PFRONT) += 9pfront.c
src-$(CONFIG_TPM_TIS) += tpm_tis.c
src-$(CONFIG_TPMBACK) += tpmback.c
src-y += console.c
src-y += daytime.c
src-y += e820.c
src-y += events.c
src-$(CONFIG_FBFRONT) += fbfront.c
src-y += gntmap.c
src-y += gnttab.c
src-y += hypervisor.c
src-y += kernel.c
src-y += lock.c
src-y += main.c
src-y += mm.c
src-$(CONFIG_NETFRONT) += netfront.c
src-$(CONFIG_PCIFRONT) += pcifront.c
src-y += sched.c
src-y += shutdown.c
src-$(CONFIG_TEST) += test.c
src-$(CONFIG_BALLOON) += balloon.c
src-$(CONFIG_XENBUS) += xenbus.c
src-y += lib/ctype.c
src-y += lib/math.c
src-y += lib/printf.c
src-y += lib/stack_chk_fail.c
src-y += lib/string.c
src-y += lib/sys.c
src-y += lib/xmalloc.c
src-$(CONFIG_LIBXS) += lib/xs.c
# The common mini-os objects to build.
APP_OBJS :=
OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(src-y))
.PHONY: default
default: $(OBJ_DIR)/$(TARGET)
# Create special architecture specific links. The function arch_links
# has to be defined in arch.mk (see include above).
ifneq ($(ARCH_LINKS),)
$(ARCH_LINKS):
$(arch_links)
endif
include/list.h: include/minios-external/bsd-sys-queue-h-seddery include/minios-external/bsd-sys-queue.h
perl $^ --prefix=minios >$@.new
$(call move-if-changed,$@.new,$@)
# Used by stubdom's Makefile
.PHONY: links
links: $(GENERATED_HEADERS)
include/mini-os:
ln -sf . $@
include/$(TARGET_ARCH_FAM)/mini-os:
ln -sf . $@
.PHONY: arch_lib
arch_lib:
$(MAKE) --directory=$(TARGET_ARCH_DIR) OBJ_DIR=$(OBJ_DIR)/$(TARGET_ARCH_DIR) || exit 1;
ifeq ($(CONFIG_LWIP),y)
# lwIP library
LWC := $(sort $(shell find $(LWIPDIR)/src -type f -name '*.c'))
LWC := $(filter-out %6.c %ip6_addr.c %ethernetif.c, $(LWC))
LWO := $(patsubst %.c,%.o,$(LWC))
LWO += $(OBJ_DIR)/lwip-arch.o
ifeq ($(CONFIG_NETFRONT),y)
LWO += $(OBJ_DIR)/lwip-net.o
endif
$(OBJ_DIR)/lwip.a: $(LWO)
$(RM) $@
$(AR) cqs $@ $^
OBJS += $(OBJ_DIR)/lwip.a
endif
OBJS := $(filter-out $(OBJ_DIR)/lwip%.o $(LWO), $(OBJS))
ifeq ($(libc),y)
ifeq ($(CONFIG_LIBXENTOOLCORE),y)
APP_LDLIBS += -L$(TOOLCORE_PATH) -whole-archive -lxentoolcore -no-whole-archive
LIBS += $(TOOLCORE_PATH)/libxentoolcore.a
endif
ifeq ($(CONFIG_LIBXENTOOLLOG),y)
APP_LDLIBS += -L$(TOOLLOG_PATH) -whole-archive -lxentoollog -no-whole-archive
LIBS += $(TOOLLOG_PATH)/libxentoollog.a
endif
ifeq ($(CONFIG_LIBXENEVTCHN),y)
APP_LDLIBS += -L$(EVTCHN_PATH) -whole-archive -lxenevtchn -no-whole-archive
LIBS += $(EVTCHN_PATH)/libxenevtchn.a
endif
ifeq ($(CONFIG_LIBXENGNTTAB),y)
APP_LDLIBS += -L$(GNTTAB_PATH) -whole-archive -lxengnttab -no-whole-archive
LIBS += $(GNTTAB_PATH)/libxengnttab.a
endif
ifeq ($(CONFIG_LIBXENCALL),y)
APP_LDLIBS += -L$(CALL_PATH) -whole-archive -lxencall -no-whole-archive
LIBS += $(CALL_PATH)/libxencall.a
endif
ifeq ($(CONFIG_LIBXENFOREIGNMEMORY),y)
APP_LDLIBS += -L$(FOREIGNMEMORY_PATH) -whole-archive -lxenforeignmemory -no-whole-archive
LIBS += $(FOREIGNMEMORY_PATH)/libxenforeignmemory.a
endif
ifeq ($(CONFIG_LIBXENDEVICEMODEL),y)
APP_LDLIBS += -L$(DEVICEMODEL_PATH) -whole-archive -lxendevicemodel -no-whole-archive
LIBS += $(DEVICEMODEL_PATH)/libxendevicemodel.a
endif
ifeq ($(CONFIG_LIBXENGUEST),y)
APP_LDLIBS += -L$(GUEST_PATH) -whole-archive -lxenguest -no-whole-archive
LIBS += $(GUEST_PATH)/libxenguest.a
endif
ifeq ($(CONFIG_LIBXENCTRL),y)
APP_LDLIBS += -L$(CTRL_PATH) -whole-archive -lxenctrl -no-whole-archive
LIBS += $(CTRL_PATH)/libxenctrl.a
endif
APP_LDLIBS += -lpci
APP_LDLIBS += -lz
APP_LDLIBS += -lm
LDLIBS += -lc
endif
ifneq ($(APP_OBJS)-$(lwip),-y)
OBJS := $(filter-out $(OBJ_DIR)/daytime.o, $(OBJS))
endif
$(OBJ_DIR)/$(TARGET)_app.o: $(APP_OBJS) app.lds $(LIBS)
$(LD) -r -d $(LDFLAGS) -\( $(APP_OBJS) -T app.lds -\) $(APP_LDLIBS) --undefined main -o $@
ifneq ($(APP_OBJS),)
APP_O=$(OBJ_DIR)/$(TARGET)_app.o
endif
# Special rule for x86 for now
$(OBJ_DIR)/arch/x86/minios-x86%.lds: arch/x86/minios-x86.lds.S
$(CPP) $(ASFLAGS) -P $< -o $@
$(OBJ_DIR)/$(TARGET)-kern.o: $(OBJS) arch_lib $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds
$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJS) $(LDARCHLIB) -o $@
# The following would be neat, but isn't supported in binutils < 2.25
# $(OBJCOPY) --dump-section .export_symbol=$(OBJ_DIR)/syms $@
$(OBJCOPY) --set-section-flags .export_symbol=alloc -O binary --only-section=.export_symbol $@ $(OBJ_DIR)/syms
$(OBJCOPY) -w -G $(GLOBAL_PREFIX)* --keep-global-symbols=$(OBJ_DIR)/syms --remove-section=.export_symbol $@ $@
$(OBJ_DIR)/$(TARGET): $(OBJ_DIR)/$(TARGET)-kern.o $(APP_O)
$(LD) -r $(LDFLAGS) $(OBJ_DIR)/$(TARGET)-kern.o $(APP_O) $(LDLIBS) -o $@.o
$(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start --remove-section=.export_symbol $@.o $@.o
$(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@-debug
strip -s $@-debug -o $@
gzip -n -f -9 -c $@-debug >$@-debug.gz
gzip -n -f -9 -c $@ >$@.gz
.PHONY: config
CONFIG_FILE ?= $(CURDIR)/minios-config.mk
config:
echo "$(DEFINES-y)" >$(CONFIG_FILE)
.PHONY: clean arch_clean
arch_clean:
$(MAKE) --directory=$(TARGET_ARCH_DIR) OBJ_DIR=$(OBJ_DIR)/$(TARGET_ARCH_DIR) clean || exit 1;
clean: arch_clean
for dir in $(addprefix $(OBJ_DIR)/,$(SUBDIRS)); do \
rm -f $$dir/*.o; \
done
rm -f include/list.h
rm -f $(OBJ_DIR)/*.o *~ $(OBJ_DIR)/core $(OBJ_DIR)/$(TARGET).elf $(OBJ_DIR)/$(TARGET).raw $(OBJ_DIR)/$(TARGET) $(OBJ_DIR)/$(TARGET).gz
find . $(OBJ_DIR) -type l | xargs rm -f
$(RM) $(OBJ_DIR)/lwip.a $(LWO)
rm -f tags TAGS
.PHONY: testbuild
TEST_CONFIGS := $(wildcard $(CURDIR)/$(TARGET_ARCH_DIR)/testbuild/*)
testbuild:
for arch in $(MINIOS_TARGET_ARCHS); do \
for conf in $(TEST_CONFIGS); do \
$(MAKE) clean; \
MINIOS_TARGET_ARCH=$$arch MINIOS_CONFIG=$$conf $(MAKE) || exit 1; \
done; \
done
$(MAKE) clean
define all_sources
( find . -name '*.[chS]' -print )
endef
.PHONY: cscope
cscope:
$(all_sources) > cscope.files
cscope -k -b -q
.PHONY: tags
tags:
$(all_sources) | xargs ctags
.PHONY: TAGS
TAGS:
$(all_sources) | xargs etags
.PHONY: gtags
gtags:
$(all_sources) | gtags -f -