1# $(lastword,) for GNU Make older than 3.81
2lastword = $(word $(words $(1)),$(1))
3this-makefile := $(call lastword,$(MAKEFILE_LIST))
4
5# This is the correct place to edit the build version.
6# All other places this is stored (eg. compile.h) should be autogenerated.
7export XEN_VERSION       = 4
8export XEN_SUBVERSION    = 21
9export XEN_EXTRAVERSION ?= -unstable$(XEN_VENDORVERSION)
10export XEN_FULLVERSION   = $(XEN_VERSION).$(XEN_SUBVERSION)$(XEN_EXTRAVERSION)
11-include xen-version
12
13export XEN_WHOAMI	?= $(USER)
14ifeq ($(origin XEN_DOMAIN), undefined)
15export XEN_DOMAIN	:= $(shell ([ -x /bin/dnsdomainname ] && /bin/dnsdomainname) || ([ -x /bin/domainname ] && /bin/domainname || echo [unknown]))
16endif
17ifeq ($(origin XEN_BUILD_HOST), undefined)
18export XEN_BUILD_HOST	:= $(shell hostname)
19endif
20# XEN_BUILD_DATE and XEN_BUILD_TIME are set further down, as they depend on
21# Config.mk for SOURCE_DATE_EPOCH handling.
22
23# Best effort attempt to find a python interpreter, defaulting to Python 3 if
24# available.  Fall back to just `python`.
25PYTHON_INTERPRETER	:= $(word 1,$(shell command -v python3 || command -v python || command -v python2) python)
26export PYTHON		?= $(PYTHON_INTERPRETER)
27
28export CHECKPOLICY	?= checkpolicy
29
30$(if $(filter __%, $(MAKECMDGOALS)), \
31    $(error targets prefixed with '__' are only for internal use))
32
33# That's our default target when none is given on the command line
34PHONY := __all
35__all:
36
37# Do not use make's built-in rules and variables
38MAKEFLAGS += -rR
39
40EFI_MOUNTPOINT ?= $(BOOT_DIR)/efi
41
42# Allow someone to change their config file
43export KCONFIG_CONFIG ?= .config
44
45export TARGET := xen
46
47.PHONY: dist
48dist: install
49
50ifneq ($(root-make-done),y)
51# section to run before calling Rules.mk, but only once.
52
53ifneq ($(origin crash_debug),undefined)
54$(error "You must use e.g. 'make menuconfig' to enable/disable crash_debug now.")
55endif
56ifeq ($(origin debug),command line)
57$(warning "You must use e.g. 'make menuconfig' to enable/disable debug now.")
58endif
59ifneq ($(origin frame_pointer),undefined)
60$(error "You must use e.g. 'make menuconfig' to enable/disable frame_pointer now.")
61endif
62ifneq ($(origin kexec),undefined)
63$(error "You must use e.g. 'make menuconfig' to enable/disable kexec now.")
64endif
65ifneq ($(origin lock_profile),undefined)
66$(error "You must use e.g. 'make menuconfig' to enable/disable lock_profile now.")
67endif
68ifneq ($(origin perfc),undefined)
69$(error "You must use e.g. 'make menuconfig' to enable/disable perfc now.")
70endif
71ifneq ($(origin verbose),undefined)
72$(error "You must use e.g. 'make menuconfig' to enable/disable verbose now.")
73endif
74
75# Beautify output
76# ---------------------------------------------------------------------------
77#
78# Normally, we echo the whole command before executing it. By making
79# that echo $($(quiet)$(cmd)), we now have the possibility to set
80# $(quiet) to choose other forms of output instead, e.g.
81#
82#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
83#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
84#
85# If $(quiet) is empty, the whole command will be printed.
86# If it is set to "quiet_", only the short version will be printed.
87# If it is set to "silent_", nothing will be printed at all, since
88# the variable $(silent_cmd_cc_o_c) doesn't exist.
89#
90# A simple variant is to prefix commands with $(Q) - that's useful
91# for commands that shall be hidden in non-verbose mode.
92#
93#	$(Q)ln $@ :<
94#
95# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
96# If KBUILD_VERBOSE equals 1 then the above command is displayed.
97#
98# To put more focus on warnings, be less verbose as default
99# Use 'make V=1' to see the full commands
100
101ifeq ("$(origin V)", "command line")
102    KBUILD_VERBOSE := $(V)
103endif
104ifndef KBUILD_VERBOSE
105    KBUILD_VERBOSE := 0
106endif
107
108ifeq ($(KBUILD_VERBOSE),1)
109    quiet :=
110    Q :=
111else
112    quiet := quiet_
113    Q := @
114endif
115
116# If the user is running make -s (silent mode), suppress echoing of
117# commands
118
119ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
120    quiet := silent_
121endif
122
123export quiet Q KBUILD_VERBOSE
124
125# $(realpath,) for GNU Make older than 3.81
126realpath = $(wildcard $(foreach file,$(1),$(shell cd -P $(dir $(file)) && echo "$$PWD/$(notdir $(file))")))
127
128ifeq ("$(origin O)", "command line")
129    KBUILD_OUTPUT := $(O)
130endif
131
132ifneq ($(KBUILD_OUTPUT),)
133# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
134# expand a shell special character '~'. We use a somewhat tedious way here.
135abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
136$(if $(abs_objtree),, \
137     $(error failed to create output directory "$(KBUILD_OUTPUT)"))
138
139# $(realpath ...) resolves symlinks
140abs_objtree := $(call realpath,$(abs_objtree))
141else
142abs_objtree := $(CURDIR)
143endif
144
145ifeq ($(abs_objtree),$(CURDIR))
146# Suppress "Entering directory ..." unless we are changing the work directory.
147MAKEFLAGS += --no-print-directory
148else
149need-sub-make := 1
150endif
151
152abs_srctree := $(call realpath,$(dir $(this-makefile)))
153
154ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
155$(error source directory cannot contain spaces or colons)
156endif
157
158ifneq ($(abs_srctree),$(abs_objtree))
159# Look for make include files relative to root of kernel src
160#
161# This does not become effective immediately because MAKEFLAGS is re-parsed
162# once after the Makefile is read. We need to invoke sub-make.
163MAKEFLAGS += --include-dir=$(abs_srctree)
164need-sub-make := 1
165endif
166
167export abs_srctree abs_objtree
168export root-make-done := y
169
170ifeq ($(need-sub-make),1)
171
172PHONY += $(MAKECMDGOALS) __sub-make
173
174$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
175	@:
176
177# Invoke a second make in the output directory, passing relevant variables
178__sub-make:
179	$(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
180
181endif # need-sub-make
182endif # root-make-done
183
184# We process the rest of the Makefile if this is the final invocation of make
185ifeq ($(need-sub-make),)
186
187# Do not print "Entering directory ...",
188# but we want to display it when entering to the output directory
189# so that IDEs/editors are able to understand relative filenames.
190MAKEFLAGS += --no-print-directory
191
192ifeq ($(abs_srctree),$(abs_objtree))
193    # building in the source tree
194    srctree := .
195    building_out_of_srctree :=
196else
197    ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))
198        # building in a subdirectory of the source tree
199        srctree := ..
200    else
201        srctree := $(abs_srctree)
202    endif
203    building_out_of_srctree := 1
204endif
205
206objtree := .
207VPATH := $(srctree)
208
209export srctree objtree VPATH
210
211export XEN_ROOT := $(abs_srctree)/..
212
213# To make sure we do not include .config for any of the *config targets
214# catch them early, and hand them over to tools/kconfig/Makefile
215
216clean-targets := %clean
217no-dot-config-targets := $(clean-targets) \
218                         uninstall debug cloc \
219                         cscope TAGS tags gtags \
220                         xenversion
221
222config-build    := n
223need-config     := y
224
225ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
226    ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
227        need-config := n
228    endif
229endif
230
231ifneq ($(filter %config,$(MAKECMDGOALS)),)
232    config-build := y
233endif
234
235include scripts/Kbuild.include
236
237# Don't break if the build process wasn't called from the top level
238# we need XEN_TARGET_ARCH to generate the proper config
239include $(XEN_ROOT)/Config.mk
240
241# Set ARCH/SRCARCH appropriately.
242
243ARCH := $(XEN_TARGET_ARCH)
244SRCARCH := $(shell echo $(ARCH) | \
245    sed -e 's/x86.*/x86/' -e 's/arm\(32\|64\)/arm/g' \
246        -e 's/riscv.*/riscv/g' -e 's/ppc.*/ppc/g')
247export ARCH SRCARCH
248
249ifeq ($(origin XEN_BUILD_DATE), undefined)
250export XEN_BUILD_DATE	:= $(call date)
251endif
252ifeq ($(origin XEN_BUILD_TIME), undefined)
253export XEN_BUILD_TIME	:= $(call date,"+%T")
254endif
255
256export CONFIG_SHELL := $(SHELL)
257export CC CXX LD NM OBJCOPY OBJDUMP ADDR2LINE
258export YACC = $(if $(BISON),$(BISON),bison)
259export LEX = $(if $(FLEX),$(FLEX),flex)
260
261# Default file for 'make defconfig'.
262# May be overruled on the command line or set in the environment.
263export KBUILD_DEFCONFIG ?= $(ARCH)_defconfig
264
265# Copy CFLAGS generated by "Config.mk" so they can be reused later without
266# reparsing Config.mk by e.g. arch/x86/boot/.
267export XEN_TREEWIDE_CFLAGS := $(CFLAGS)
268
269# CLANG_FLAGS needs to be calculated before calling Kconfig
270ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
271CLANG_FLAGS :=
272
273ifeq ($(SRCARCH),x86)
274# The tests to select whether the integrated assembler is usable need to happen
275# before testing any assembler features, or else the result of the tests would
276# be stale if the integrated assembler is not used.
277
278# Older clang's built-in assembler doesn't understand .skip with labels:
279# https://bugs.llvm.org/show_bug.cgi?id=27369
280t1 = $(call as-insn,$(CC),".L0: .L1: .skip (.L1 - .L0)",,-no-integrated-as)
281
282# Check whether clang asm()-s support .include.
283t2 = $(call as-insn,$(CC) -I$(srctree)/arch/x86/include,".include \"asm/asm-defns.h\"",,-no-integrated-as)
284
285# Check whether clang keeps .macro-s between asm()-s:
286# https://bugs.llvm.org/show_bug.cgi?id=36110
287t3 = $(call as-insn,$(CC),".macro FOO;.endm"$(close); asm volatile $(open)".macro FOO;.endm",-no-integrated-as)
288
289CLANG_FLAGS += $(call or,$(t1),$(t2),$(t3))
290endif
291
292CLANG_FLAGS += -Werror=unknown-warning-option
293CFLAGS += $(CLANG_FLAGS)
294export CLANG_FLAGS
295endif
296
297export XEN_HAS_CHECKPOLICY := $(call success,$(CHECKPOLICY) -h 2>&1 | grep -q xen)
298
299# ===========================================================================
300# Rules shared between *config targets and build targets
301
302PHONY += tools_fixdep
303tools_fixdep:
304	$(Q)$(MAKE) $(build)=tools tools/fixdep
305
306PHONY += outputmakefile
307# Before starting out-of-tree build, make sure the source tree is clean.
308# outputmakefile generates a Makefile in the output directory, if using a
309# separate output directory. This allows convenient use of make in the
310# output directory.
311# At the same time when output Makefile generated, generate .gitignore to
312# ignore whole output directory
313
314quiet_cmd_makefile = GEN     Makefile
315cmd_makefile = { \
316    echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \
317    echo "include $(srctree)/Makefile"; \
318    } > Makefile
319
320outputmakefile:
321ifdef building_out_of_srctree
322	$(Q)if [ -f $(srctree)/.config -o \
323		 -d $(srctree)/include/config -o \
324		 -d $(srctree)/include/generated ]; then \
325		echo >&2 "***"; \
326		echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin XEN_TARGET_ARCH)), XEN_TARGET_ARCH=$(XEN_TARGET_ARCH)) distclean'"; \
327		echo >&2 "*** in $(abs_srctree)";\
328		echo >&2 "***"; \
329		false; \
330	fi
331	$(Q)ln -fsn $(srctree) source
332	$(call cmd,makefile)
333	$(Q)test -e .gitignore || \
334	{ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
335endif
336
337ifeq ($(config-build),y)
338# ===========================================================================
339# *config targets only - make sure prerequisites are updated, and descend
340# in tools/kconfig to make the *config target
341
342# Create a file for KCONFIG_ALLCONFIG which depends on the environment.
343# This will be use by kconfig targets allyesconfig/allmodconfig/allnoconfig/randconfig
344filechk_kconfig_allconfig = \
345    $(if $(findstring n,$(XEN_HAS_CHECKPOLICY)), echo 'CONFIG_XSM_FLASK_POLICY=n';) \
346    $(if $(KCONFIG_ALLCONFIG), cat $(KCONFIG_ALLCONFIG);) \
347    :
348
349.allconfig.tmp: FORCE
350	set -e; { $(call filechk_kconfig_allconfig); } > $@
351
352config: tools_fixdep outputmakefile FORCE
353	$(Q)$(MAKE) $(build)=tools/kconfig $@
354
355# Config.mk tries to include .config file, don't try to remake it
356%/.config: ;
357
358%config: .allconfig.tmp tools_fixdep outputmakefile FORCE
359	$(Q)$(MAKE) $(build)=tools/kconfig KCONFIG_ALLCONFIG=$< $@
360
361else # !config-build
362
363ifeq ($(need-config),y)
364-include include/config/auto.conf
365# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
366# changes are detected.
367-include include/config/auto.conf.cmd
368
369# Allow people to just run `make` as before and not force them to configure
370# Only run defconfig if $(KCONFIG_CONFIG) is missing
371$(KCONFIG_CONFIG): tools_fixdep
372	$(if $(wildcard $@), , $(Q)$(MAKE) $(build)=tools/kconfig defconfig)
373
374# The actual configuration files used during the build are stored in
375# include/generated/ and include/config/. Update them if .config is newer than
376# include/config/auto.conf (which mirrors .config).
377#
378# This exploits the 'multi-target pattern rule' trick.
379# The syncconfig should be executed only once to make all the targets.
380include/config/%.conf include/config/%.conf.cmd: $(KCONFIG_CONFIG)
381	$(Q)rm -f include/config/auto.conf
382	$(Q)$(MAKE) $(build)=tools/kconfig syncconfig
383
384ifeq ($(CONFIG_DEBUG),y)
385CFLAGS += -O1
386else
387CFLAGS += -O2
388endif
389
390ifeq ($(CONFIG_FRAME_POINTER),y)
391CFLAGS += -fno-omit-frame-pointer
392else
393CFLAGS += -fomit-frame-pointer
394endif
395
396CFLAGS-$(CONFIG_CC_SPLIT_SECTIONS) += -ffunction-sections -fdata-sections
397
398CFLAGS += -nostdinc -fno-builtin -fno-common
399$(call cc-option-add,CFLAGS,CC,-fzero-init-padding-bits=all)
400CFLAGS += -Werror -Wredundant-decls -Wwrite-strings -Wno-pointer-arith
401CFLAGS += -Wdeclaration-after-statement -Wuninitialized
402$(call cc-option-add,CFLAGS,CC,-Wvla)
403$(call cc-option-add,CFLAGS,CC,-Wflex-array-member-not-at-end)
404$(call cc-option-add,CFLAGS,CC,-Winit-self)
405CFLAGS += -pipe -D__XEN__ -include $(srctree)/include/xen/config.h
406CFLAGS-$(CONFIG_DEBUG_INFO) += -g
407
408ifneq ($(CONFIG_CC_IS_CLANG),y)
409# Clang doesn't understand this command line argument, and doesn't appear to
410# have a suitable alternative.  The resulting compiled binary does function,
411# but has an excessively large symbol table.
412CFLAGS += -Wa,--strip-local-absolute
413endif
414
415AFLAGS += -D__ASSEMBLY__
416
417$(call cc-option-add,AFLAGS,CC,-Wa$$(comma)--noexecstack)
418
419LDFLAGS-$(call ld-option,--warn-rwx-segments) += --no-warn-rwx-segments
420
421CFLAGS += $(CFLAGS-y)
422# allow extra CFLAGS externally via EXTRA_CFLAGS_XEN_CORE
423CFLAGS += $(EXTRA_CFLAGS_XEN_CORE)
424
425# Most CFLAGS are safe for assembly files:
426#  -std=gnu{89,99} gets confused by #-prefixed end-of-line comments
427#  -flto makes no sense and annoys clang
428AFLAGS += $(filter-out -std=gnu% -flto,$(CFLAGS)) $(AFLAGS-y)
429
430# LDFLAGS are only passed directly to $(LD)
431LDFLAGS += $(LDFLAGS_DIRECT) $(LDFLAGS-y)
432
433ifeq ($(CONFIG_UBSAN),y)
434CFLAGS_UBSAN := -fsanitize=undefined
435else
436CFLAGS_UBSAN :=
437endif
438
439ifeq ($(CONFIG_STACK_PROTECTOR),y)
440CFLAGS += -fstack-protector
441else
442CFLAGS += -fno-stack-protector
443endif
444
445ifeq ($(CONFIG_LTO),y)
446CFLAGS += -flto
447LDFLAGS-$(CONFIG_CC_IS_CLANG) += -plugin LLVMgold.so
448endif
449
450ifdef building_out_of_srctree
451    CFLAGS += -I$(objtree)/include
452    CFLAGS += -I$(objtree)/arch/$(SRCARCH)/include
453endif
454CFLAGS += -I$(srctree)/include
455CFLAGS += -I$(srctree)/arch/$(SRCARCH)/include
456CFLAGS += -I$(objtree)/arch/$(SRCARCH)/include/generated
457
458# Note that link order matters!
459ALL_OBJS-y                := common/built_in.o
460ALL_OBJS-y                += drivers/built_in.o
461ALL_OBJS-y                += lib/built_in.o
462ALL_OBJS-y                += xsm/built_in.o
463ALL_OBJS-y                += arch/$(SRCARCH)/built_in.o
464ALL_OBJS-$(CONFIG_CRYPTO) += crypto/built_in.o
465
466ALL_LIBS-y                := lib/lib.a
467
468include $(srctree)/arch/$(SRCARCH)/arch.mk
469
470# define new variables to avoid the ones defined in Config.mk
471export XEN_CFLAGS := $(CFLAGS)
472export XEN_AFLAGS := $(AFLAGS)
473export XEN_LDFLAGS := $(LDFLAGS)
474export CFLAGS_UBSAN
475
476endif # need-config
477
478__all: build
479
480main-targets := build install uninstall clean distclean MAP
481.PHONY: $(main-targets)
482ifneq ($(XEN_TARGET_ARCH),x86_32)
483$(main-targets): %: _% ;
484else
485$(main-targets):
486	echo "*** Xen x86/32 target no longer supported!"
487endif
488
489.PHONY: _build
490_build: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
491
492# Strip
493#
494# INSTALL_EFI_STRIP, if defined, will cause xen.efi to be stripped before it
495# is installed. If INSTALL_EFI_STRIP is '1', then the default option(s) below
496# will be used. Otherwise, INSTALL_EFI_STRIP value will be used as the
497# option(s) to the strip command.
498ifdef INSTALL_EFI_STRIP
499
500ifeq ($(INSTALL_EFI_STRIP),1)
501efi-strip-opt := --strip-debug --keep-file-symbols
502else
503efi-strip-opt := $(INSTALL_EFI_STRIP)
504endif
505
506endif
507
508.PHONY: _install
509_install: D=$(DESTDIR)
510_install: T=$(notdir $(TARGET))
511_install: Z=$(CONFIG_XEN_INSTALL_SUFFIX)
512_install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
513	[ -d $(D)$(BOOT_DIR) ] || $(INSTALL_DIR) $(D)$(BOOT_DIR)
514	$(INSTALL_DATA) $(TARGET)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION)$(Z)
515	ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION)$(Z)
516	ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION)$(Z)
517	ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)$(Z)
518	[ -d "$(D)$(DEBUG_DIR)" ] || $(INSTALL_DIR) $(D)$(DEBUG_DIR)
519	$(INSTALL_DATA) $(TARGET)-syms $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION)
520	$(INSTALL_DATA) $(TARGET)-syms.map $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION).map
521	$(INSTALL_DATA) $(KCONFIG_CONFIG) $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION).config
522	if [ -r $(TARGET).efi -a -n '$(EFI_DIR)' ]; then \
523		[ -d $(D)$(EFI_DIR) ] || $(INSTALL_DIR) $(D)$(EFI_DIR); \
524		$(INSTALL_DATA) $(TARGET).efi $(D)$(EFI_DIR)/$(T)-$(XEN_FULLVERSION).efi; \
525		for x in map elf; do \
526			if [ -e $(TARGET).efi.$$x ]; then \
527				$(INSTALL_DATA) $(TARGET).efi.$$x $(D)$(DEBUG_DIR)/$(T)-$(XEN_FULLVERSION).efi.$$x; \
528			fi; \
529		done; \
530		ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION).efi; \
531		ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi; \
532		ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T).efi; \
533		if [ -n '$(EFI_MOUNTPOINT)' -a -n '$(EFI_VENDOR)' ]; then \
534			$(if $(efi-strip-opt), \
535			     $(STRIP) $(efi-strip-opt) -p -o $(TARGET).efi.stripped $(TARGET).efi && \
536			     $(INSTALL_DATA) $(TARGET).efi.stripped $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi ||) \
537			$(INSTALL_DATA) $(TARGET).efi $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi; \
538		elif [ "$(D)" = "$(patsubst $(shell cd $(XEN_ROOT) && pwd)/%,%,$(D))" ]; then \
539			echo 'EFI installation only partially done (EFI_VENDOR not set)' >&2; \
540		fi; \
541	fi
542
543.PHONY: tests
544tests:
545	$(Q)$(MAKE) $(build)=test
546.PHONY: install-tests
547install-tests:
548	$(Q)$(MAKE) $(build)=test install
549
550.PHONY: _uninstall
551_uninstall: D=$(DESTDIR)
552_uninstall: T=$(notdir $(TARGET))
553_uninstall: Z=$(CONFIG_XEN_INSTALL_SUFFIX)
554_uninstall:
555	rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION).config
556	rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION)$(Z)
557	rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION)$(Z)
558	rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION)$(Z)
559	rm -f $(D)$(BOOT_DIR)/$(T)$(Z)
560	rm -f $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION)
561	rm -f $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION).map
562	rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_FULLVERSION).efi
563	rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION).efi
564	rm -f $(D)$(DEBUG_DIR)/$(T)-$(XEN_FULLVERSION).efi.elf
565	rm -f $(D)$(DEBUG_DIR)/$(T)-$(XEN_FULLVERSION).efi.map
566	rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi
567	rm -f $(D)$(EFI_DIR)/$(T).efi
568	if [ -n '$(EFI_MOUNTPOINT)' -a -n '$(EFI_VENDOR)' ]; then \
569		rm -f $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi; \
570	fi
571
572.PHONY: _debug
573_debug:
574	$(OBJDUMP) -D -S $(TARGET)-syms > $(TARGET).s
575
576.PHONY: _clean
577_clean:
578	$(Q)$(MAKE) $(clean)=tools
579	$(Q)$(MAKE) $(clean)=include
580	$(Q)$(MAKE) $(clean)=common
581	$(Q)$(MAKE) $(clean)=drivers
582	$(Q)$(MAKE) $(clean)=lib
583	$(Q)$(MAKE) $(clean)=xsm
584	$(Q)$(MAKE) $(clean)=crypto
585	$(Q)$(MAKE) $(clean)=arch/arm
586	$(Q)$(MAKE) $(clean)=arch/ppc
587	$(Q)$(MAKE) $(clean)=arch/riscv
588	$(Q)$(MAKE) $(clean)=arch/x86
589	$(Q)$(MAKE) $(clean)=test
590	$(Q)$(MAKE) $(clean)=tools/kconfig
591	find . \( -name "*.o" -o -name ".*.d" -o -name ".*.d2" \
592		-o -name ".*.o.tmp" -o -name "*~" -o -name "core" \
593		-o -name '*.lex.c' -o -name '*.tab.[ch]' -o -name "*.gcno" \
594		-o -name ".*.cmd" -o -name "lib.a" \) -exec rm -f {} \;
595	rm -f include/asm $(TARGET) $(TARGET).gz $(TARGET)-syms $(TARGET)-syms.map
596	rm -f $(TARGET).efi $(TARGET).efi.map $(TARGET).efi.elf $(TARGET).efi.stripped
597	rm -f asm-offsets.s arch/*/include/asm/asm-offsets.h
598	rm -f .banner .allconfig.tmp include/xen/compile.h
599	rm -rf $(objtree)/arch/*/include/generated
600
601.PHONY: _distclean
602_distclean: clean
603	rm -f tags TAGS cscope.files cscope.in.out cscope.out cscope.po.out GTAGS GPATH GRTAGS GSYMS .config source
604
605# Support for using generic headers in asm-generic
606PHONY += asm-generic
607asm-generic:
608	$(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm
609
610$(TARGET).gz: $(TARGET)
611	gzip -n -f -9 < $< > $@.new
612	mv $@.new $@
613
614$(TARGET): outputmakefile asm-generic FORCE
615	$(Q)$(MAKE) $(build)=tools
616	$(Q)$(MAKE) $(build)=. include/xen/compile.h
617	$(Q)$(MAKE) $(build)=include all
618	$(Q)$(MAKE) $(build)=arch/$(SRCARCH) include
619	$(Q)$(MAKE) $(build)=. arch/$(SRCARCH)/include/asm/asm-offsets.h
620	$(Q)$(MAKE) $(build)=. MKRELOC=$(MKRELOC) 'ALL_OBJS=$(ALL_OBJS-y)' 'ALL_LIBS=$(ALL_LIBS-y)' $@
621
622SUBDIRS = xsm arch common crypto drivers lib test
623define all_sources
624    ( find include -type f -name '*.h' -print; \
625      find $(SUBDIRS) -type f -name '*.[chS]' -print )
626endef
627
628define set_exuberant_flags
629    exuberant_flags=`$1 --version 2>/dev/null | (grep -iq exuberant && \
630	echo "-I __initdata,__exitdata,__acquires,__releases \
631	    -I EXPORT_SYMBOL \
632	    --extra=+f --c-kinds=+px") || true`
633endef
634
635.PHONY: xenversion
636xenversion:
637	@echo $(XEN_FULLVERSION)
638
639.PHONY: TAGS
640TAGS:
641	set -e; rm -f TAGS; \
642	$(call set_exuberant_flags,etags); \
643	$(all_sources) | xargs etags $$exuberant_flags -a
644
645.PHONY: tags
646tags:
647	set -e; rm -f tags; \
648	$(call set_exuberant_flags,ctags); \
649	$(all_sources) | xargs ctags $$exuberant_flags -a
650
651.PHONY: gtags
652gtags:
653	set -e; rm -f GTAGS GSYMS GPATH GRTAGS
654	$(all_sources) | gtags -f -
655
656.PHONY: cscope
657cscope:
658	$(all_sources) > cscope.files
659	cscope -k -b -q
660
661.PHONY: _MAP
662_MAP: $(TARGET)
663	$(NM) -n $(TARGET)-syms | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' > System.map
664
665%.o %.i %.s: %.c tools_fixdep FORCE
666	$(Q)$(MAKE) $(build)=$(*D) $(*D)/$(@F)
667
668%.o %.s: %.S tools_fixdep FORCE
669	$(Q)$(MAKE) $(build)=$(*D) $(*D)/$(@F)
670
671%/: tools_fixdep FORCE
672	$(Q)$(MAKE) $(build)=$* need-builtin=1
673
674.PHONY: cloc
675cloc:
676	find . -name tools -prune -o -name '*.o.cmd' -print | while read f; do \
677	    for sf in $$(grep -o "[a-zA-Z0-9_/-]*\.[cS]" $$f); do \
678		test -f "$$sf" && echo "$$sf"; \
679	    done; \
680	done | cloc --list-file=-
681
682# Target used by xen-analysis.sh script to retrieve Xen build system variables
683export-variable-%:
684	$(info $*=$($*))
685
686endif #config-build
687endif # need-sub-make
688
689PHONY += FORCE
690FORCE:
691
692# Declare the contents of the PHONY variable as phony.  We keep that
693# information in a variable so we can use it in if_changed and friends.
694.PHONY: $(PHONY)
695