1
2-include $(BASEDIR)/include/config/auto.conf
3
4include $(XEN_ROOT)/Config.mk
5
6
7ifneq ($(origin crash_debug),undefined)
8$(error "You must use 'make menuconfig' to enable/disable crash_debug now.")
9endif
10ifeq ($(origin debug),command line)
11$(warning "You must use 'make menuconfig' to enable/disable debug now.")
12endif
13ifneq ($(origin frame_pointer),undefined)
14$(error "You must use 'make menuconfig' to enable/disable frame_pointer now.")
15endif
16ifneq ($(origin kexec),undefined)
17$(error "You must use 'make menuconfig' to enable/disable kexec now.")
18endif
19ifneq ($(origin lock_profile),undefined)
20$(error "You must use 'make menuconfig' to enable/disable lock_profile now.")
21endif
22ifneq ($(origin perfc),undefined)
23$(error "You must use 'make menuconfig' to enable/disable perfc now.")
24endif
25ifneq ($(origin verbose),undefined)
26$(error "You must use 'make menuconfig' to enable/disable verbose now.")
27endif
28
29# Set ARCH/SUBARCH appropriately.
30override TARGET_SUBARCH  := $(XEN_TARGET_ARCH)
31override TARGET_ARCH     := $(shell echo $(XEN_TARGET_ARCH) | \
32                              sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
33
34TARGET := $(BASEDIR)/xen
35
36# Note that link order matters!
37ALL_OBJS-y               += $(BASEDIR)/common/built_in.o
38ALL_OBJS-y               += $(BASEDIR)/drivers/built_in.o
39ALL_OBJS-y               += $(BASEDIR)/xsm/built_in.o
40ALL_OBJS-y               += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o
41ALL_OBJS-$(CONFIG_CRYPTO)   += $(BASEDIR)/crypto/built_in.o
42
43ifeq ($(CONFIG_DEBUG),y)
44CFLAGS += -O1
45else
46CFLAGS += -O2 -fomit-frame-pointer
47endif
48
49CFLAGS += -nostdinc -fno-builtin -fno-common
50CFLAGS += -Werror -Wredundant-decls -Wno-pointer-arith
51CFLAGS += -pipe -g -D__XEN__ -include $(BASEDIR)/include/xen/config.h
52CFLAGS += '-D__OBJECT_FILE__="$@"'
53
54ifneq ($(clang),y)
55# Clang doesn't understand this command line argument, and doesn't appear to
56# have an suitable alternative.  The resulting compiled binary does function,
57# but has an excessively large symbol table.
58CFLAGS += -Wa,--strip-local-absolute
59endif
60
61CFLAGS-$(CONFIG_FRAME_POINTER) += -fno-omit-frame-pointer
62
63ifneq ($(max_phys_irqs),)
64CFLAGS-y                += -DMAX_PHYS_IRQS=$(max_phys_irqs)
65endif
66
67AFLAGS-y                += -D__ASSEMBLY__
68
69# Clang's built-in assembler can't handle .code16/.code32/.code64 yet
70AFLAGS-$(clang)         += -no-integrated-as
71
72ALL_OBJS := $(ALL_OBJS-y)
73
74# Get gcc to generate the dependencies for us.
75CFLAGS-y += -MMD -MF $(@D)/.$(@F).d
76
77CFLAGS += $(CFLAGS-y)
78
79# Most CFLAGS are safe for assembly files:
80#  -std=gnu{89,99} gets confused by #-prefixed end-of-line comments
81#  -flto makes no sense and annoys clang
82AFLAGS += $(AFLAGS-y) $(filter-out -std=gnu% -flto,$(CFLAGS))
83
84# LDFLAGS are only passed directly to $(LD)
85LDFLAGS += $(LDFLAGS_DIRECT)
86
87LDFLAGS += $(LDFLAGS-y)
88
89include $(BASEDIR)/arch/$(TARGET_ARCH)/Rules.mk
90
91DEPS = .*.d
92
93include Makefile
94
95define gendep
96    ifneq ($(1),$(subst /,:,$(1)))
97        DEPS += $(dir $(1)).$(notdir $(1)).d
98    endif
99endef
100$(foreach o,$(filter-out %/,$(obj-y)),$(eval $(call gendep,$(o))))
101
102# Ensure each subdirectory has exactly one trailing slash.
103subdir-n := $(patsubst %,%/,$(patsubst %/,%,$(subdir-n) $(subdir-)))
104subdir-y := $(patsubst %,%/,$(patsubst %/,%,$(subdir-y)))
105
106# Add explicitly declared subdirectories to the object lists.
107obj-y += $(patsubst %/,%/built_in.o,$(subdir-y))
108
109# Add implicitly declared subdirectories (in the object lists) to the
110# subdirectory list, and rewrite the object-list entry.
111subdir-y += $(filter %/,$(obj-y))
112obj-y    := $(patsubst %/,%/built-in.o,$(obj-y))
113
114subdir-all := $(subdir-y) $(subdir-n)
115
116$(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -DINIT_SECTIONS_ONLY
117
118ifeq ($(CONFIG_GCOV),y)
119$(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage
120endif
121
122ifeq ($(CONFIG_UBSAN),y)
123$(filter-out %.init.o $(noubsan-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fsanitize=undefined
124endif
125
126ifeq ($(CONFIG_LTO),y)
127CFLAGS += -flto
128LDFLAGS-$(clang) += -plugin LLVMgold.so
129# Would like to handle all object files as bitcode, but objects made from
130# pure asm are in a different format and have to be collected separately.
131# Mirror the directory tree, collecting them as built_in_bin.o.
132# If there are no binary objects in a given directory, make a dummy .o
133obj-bin-y += $(patsubst %/built_in.o,%/built_in_bin.o,$(filter %/built_in.o,$(obj-y)))
134else
135# For a non-LTO build, bundle obj-bin targets in with the normal objs.
136obj-y += $(obj-bin-y)
137obj-bin-y :=
138endif
139
140# Always build obj-bin files as binary even if they come from C source.
141$(obj-bin-y): CFLAGS := $(filter-out -flto,$(CFLAGS))
142
143built_in.o: $(obj-y)
144ifeq ($(obj-y),)
145	$(CC) $(CFLAGS) -c -x c /dev/null -o $@
146else
147ifeq ($(CONFIG_LTO),y)
148	$(LD_LTO) -r -o $@ $^
149else
150	$(LD) $(LDFLAGS) -r -o $@ $^
151endif
152endif
153
154built_in_bin.o: $(obj-bin-y)
155ifeq ($(obj-bin-y),)
156	$(CC) $(AFLAGS) -c -x assembler /dev/null -o $@
157else
158	$(LD) $(LDFLAGS) -r -o $@ $^
159endif
160
161# Force execution of pattern rules (for which PHONY cannot be directly used).
162.PHONY: FORCE
163FORCE:
164
165%/built_in.o: FORCE
166	$(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o
167
168%/built_in_bin.o: FORCE
169	$(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in_bin.o
170
171.PHONY: clean
172clean:: $(addprefix _clean_, $(subdir-all))
173	rm -f *.o *~ core $(DEPS_RM)
174_clean_%/: FORCE
175	$(MAKE) -f $(BASEDIR)/Rules.mk -C $* clean
176
177%.o: %.c Makefile
178	$(CC) $(CFLAGS) -c $< -o $@
179
180%.o: %.S Makefile
181	$(CC) $(AFLAGS) -c $< -o $@
182
183SPECIAL_DATA_SECTIONS := rodata $(foreach a,1 2 4 8 16, \
184					    $(foreach w,1 2 4, \
185							rodata.str$(w).$(a)) \
186					    rodata.cst$(a)) \
187			 $(foreach r,rel rel.ro,data.$(r).local)
188
189$(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): %.init.o: %.o Makefile
190	$(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' | while read idx name sz rest; do \
191		case "$$name" in \
192		.*.local) ;; \
193		.text|.text.*|.data|.data.*|.bss) \
194			test $$sz != 0 || continue; \
195			echo "Error: size of $<:$$name is 0x$$sz" >&2; \
196			exit $$(expr $$idx + 1);; \
197		esac; \
198	done
199	$(OBJCOPY) $(foreach s,$(SPECIAL_DATA_SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@
200
201%.i: %.c Makefile
202	$(CPP) $(CFLAGS) $< -o $@
203
204%.s: %.c Makefile
205	$(CC) $(CFLAGS) -S $< -o $@
206
207# -std=gnu{89,99} gets confused by # as an end-of-line comment marker
208%.s: %.S Makefile
209	$(CPP) $(AFLAGS) $< -o $@
210
211-include $(DEPS_INCLUDE)
212