* [Xen-devel] [RFC XEN PATCH 01/23] xen: Fix strange byte in common/Kconfig
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-24 10:41 ` [Xen-devel] [PATCH for-4.13 " Andrew Cooper
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 02/23] xen: Makefile: Remove outdated comment Anthony PERARD
` (20 subsequent siblings)
21 siblings, 1 reply; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 907 bytes --]
Current description of the file by `file`:
common/Kconfig: Non-ISO extended-ASCII text
Change that byte to an ascii quote so the file can become properly
encoded, and all ASCII.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/common/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index 7b5dd9d49596..5c0f8d30c709 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -386,7 +386,7 @@ config TRACEBUFFER
default y
---help---
Enable tracing infrastructure and pre-defined tracepoints within Xen.
- This will allow live information about Xens execution and performance
+ This will allow live information about Xen's execution and performance
to be collected at run time for debugging or performance analysis.
Memory and execution overhead when not active is minimal.
--
Anthony PERARD
[-- Attachment #2: Type: text/plain, Size: 157 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [Xen-devel] [PATCH for-4.13 01/23] xen: Fix strange byte in common/Kconfig
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 01/23] xen: Fix strange byte in common/Kconfig Anthony PERARD
@ 2019-10-24 10:41 ` Andrew Cooper
2019-10-24 10:48 ` Jürgen Groß
0 siblings, 1 reply; 25+ messages in thread
From: Andrew Cooper @ 2019-10-24 10:41 UTC (permalink / raw)
To: Anthony PERARD, xen-devel, Juergen Gross
[-- Attachment #1.1: Type: text/plain, Size: 1296 bytes --]
On 23/10/2019 17:48, Anthony PERARD wrote:
> Current description of the file by `file`:
> common/Kconfig: Non-ISO extended-ASCII text
>
> Change that byte to an ascii quote so the file can become properly
> encoded, and all ASCII.
>
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
I see "about Xen~Rs execution" in menuconfig, and this is new content in
4.13 so wants fixing.
> ---
> xen/common/Kconfig | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/xen/common/Kconfig b/xen/common/Kconfig
> index 7b5dd9d49596..5c0f8d30c709 100644
> --- a/xen/common/Kconfig
> +++ b/xen/common/Kconfig
> @@ -386,7 +386,7 @@ config TRACEBUFFER
> default y
> ---help---
> Enable tracing infrastructure and pre-defined tracepoints within Xen.
> - This will allow live information about Xen�s execution and performance
> + This will allow live information about Xen's execution and performance
> to be collected at run time for debugging or performance analysis.
> Memory and execution overhead when not active is minimal.
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel
[-- Attachment #1.2: Type: text/html, Size: 2297 bytes --]
[-- Attachment #2: Type: text/plain, Size: 157 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [Xen-devel] [PATCH for-4.13 01/23] xen: Fix strange byte in common/Kconfig
2019-10-24 10:41 ` [Xen-devel] [PATCH for-4.13 " Andrew Cooper
@ 2019-10-24 10:48 ` Jürgen Groß
0 siblings, 0 replies; 25+ messages in thread
From: Jürgen Groß @ 2019-10-24 10:48 UTC (permalink / raw)
To: Andrew Cooper, Anthony PERARD, xen-devel
On 24.10.19 12:41, Andrew Cooper wrote:
> On 23/10/2019 17:48, Anthony PERARD wrote:
>> Current description of the file by `file`:
>> common/Kconfig: Non-ISO extended-ASCII text
>>
>> Change that byte to an ascii quote so the file can become properly
>> encoded, and all ASCII.
>>
>> Signed-off-by: Anthony PERARD<anthony.perard@citrix.com>
>
> Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
>
> I see "about Xen~Rs execution" in menuconfig, and this is new content in
> 4.13 so wants fixing.
Agreed.
Release-acked-by: Juergen Gross <jgross@suse.com>
Juergen
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 02/23] xen: Makefile: Remove outdated comment
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 01/23] xen: Fix strange byte in common/Kconfig Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 04/23] build: Import Kbuild from Linux v5.3 Anthony PERARD
` (19 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
The comment could have been removed with
18cd4997d26b9df95dda87503e41c823279a07a0.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/arch/x86/Makefile | 1 -
1 file changed, 1 deletion(-)
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 2443fd2cc5bd..af6c83dfbae6 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -176,7 +176,6 @@ CFLAGS-$(XEN_BUILD_EFI) += -DXEN_BUILD_EFI
$(TARGET).efi: VIRT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A VIRT_START$$,,p')
$(TARGET).efi: ALT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A ALT_START$$,,p')
-# Don't use $(wildcard ...) here - at least make 3.80 expands this too early!
$(TARGET).efi: guard = $(if $(filter y,$(XEN_BUILD_PE)),,:)
ifneq ($(build_id_linker),)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 04/23] build: Import Kbuild from Linux v5.3
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 01/23] xen: Fix strange byte in common/Kconfig Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 02/23] xen: Makefile: Remove outdated comment Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 05/23] xen: Kbuild: Remove extra -include from C flags Anthony PERARD
` (18 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
This patch import part of Kbuild, the build system from Linux v5.3,
4d856f72c10ecb060868ed10ff1b1453943fc6c8.
File imported:
scripts/{Makefile.*,Kbuild.include} -> xen/scripts/
scripts/basic -> xen/scripts/basic
scripts/mkmakefile -> xen/scripts/Makefile
but without:
- Extra warning (ccflags)
Makefile.extrawarn
- Support to build modules
Makefile.modbuiltin
Makefile.modinst
Makefile.modpost
Makefile.modsign
- Support to install dtb files
Makefile.dtbinst
`scripts/basic' is for fixdep, a helper to fix dependencies generated
by gcc, and add Kbuild generated dependencies.
`scripts/mkmakefile' is used for out-of-tree builds.
Also update xen/.gitignore to exclude files generated by Kbuild.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/.gitignore | 4 +
xen/scripts/Kbuild.include | 333 +++++++++++++++++++
xen/scripts/Makefile.asm-generic | 58 ++++
xen/scripts/Makefile.build | 528 +++++++++++++++++++++++++++++++
xen/scripts/Makefile.clean | 90 ++++++
xen/scripts/Makefile.gcc-plugins | 59 ++++
| 102 ++++++
xen/scripts/Makefile.host | 164 ++++++++++
xen/scripts/Makefile.kasan | 51 +++
xen/scripts/Makefile.kcov | 10 +
xen/scripts/Makefile.lib | 435 +++++++++++++++++++++++++
xen/scripts/Makefile.ubsan | 19 ++
xen/scripts/basic/.gitignore | 1 +
xen/scripts/basic/Makefile | 16 +
xen/scripts/basic/fixdep.c | 410 ++++++++++++++++++++++++
xen/scripts/mkmakefile | 17 +
16 files changed, 2297 insertions(+)
create mode 100644 xen/scripts/Kbuild.include
create mode 100644 xen/scripts/Makefile.asm-generic
create mode 100644 xen/scripts/Makefile.build
create mode 100644 xen/scripts/Makefile.clean
create mode 100644 xen/scripts/Makefile.gcc-plugins
create mode 100644 xen/scripts/Makefile.headersinst
create mode 100644 xen/scripts/Makefile.host
create mode 100644 xen/scripts/Makefile.kasan
create mode 100644 xen/scripts/Makefile.kcov
create mode 100644 xen/scripts/Makefile.lib
create mode 100644 xen/scripts/Makefile.ubsan
create mode 100644 xen/scripts/basic/.gitignore
create mode 100644 xen/scripts/basic/Makefile
create mode 100644 xen/scripts/basic/fixdep.c
create mode 100755 xen/scripts/mkmakefile
diff --git a/xen/.gitignore b/xen/.gitignore
index 9fef41a09b47..516bbd459342 100644
--- a/xen/.gitignore
+++ b/xen/.gitignore
@@ -1,2 +1,6 @@
+.*
*.lex.c
*.tab.[ch]
+
+# We don't want to ignore the following even if they are dot-files
+!.gitignore
diff --git a/xen/scripts/Kbuild.include b/xen/scripts/Kbuild.include
new file mode 100644
index 000000000000..4b0432e095ae
--- /dev/null
+++ b/xen/scripts/Kbuild.include
@@ -0,0 +1,333 @@
+# SPDX-License-Identifier: GPL-2.0
+####
+# kbuild: Generic definitions
+
+# Convenient variables
+comma := ,
+quote := "
+squote := '
+empty :=
+space := $(empty) $(empty)
+space_escape := _-_SPACE_-_
+pound := \#
+
+###
+# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
+dot-target = $(dir $@).$(notdir $@)
+
+###
+# The temporary file to save gcc -MD generated dependencies must not
+# contain a comma
+depfile = $(subst $(comma),_,$(dot-target).d)
+
+###
+# filename of target with directory and extension stripped
+basetarget = $(basename $(notdir $@))
+
+###
+# real prerequisites without phony targets
+real-prereqs = $(filter-out $(PHONY), $^)
+
+###
+# Escape single quote for use in echo statements
+escsq = $(subst $(squote),'\$(squote)',$1)
+
+###
+# Easy method for doing a status message
+ kecho := :
+ quiet_kecho := echo
+silent_kecho := :
+kecho := $($(quiet)kecho)
+
+###
+# filechk is used to check if the content of a generated file is updated.
+# Sample usage:
+#
+# filechk_sample = echo $(KERNELRELEASE)
+# version.h: FORCE
+# $(call filechk,sample)
+#
+# The rule defined shall write to stdout the content of the new file.
+# The existing file will be compared with the new one.
+# - If no file exist it is created
+# - If the content differ the new file is used
+# - If they are equal no change, and no timestamp update
+# - stdin is piped in from the first prerequisite ($<) so one has
+# to specify a valid file as first prerequisite (often the kbuild file)
+define filechk
+ $(Q)set -e; \
+ mkdir -p $(dir $@); \
+ { $(filechk_$(1)); } > $@.tmp; \
+ if [ -r $@ ] && cmp -s $@ $@.tmp; then \
+ rm -f $@.tmp; \
+ else \
+ $(kecho) ' UPD $@'; \
+ mv -f $@.tmp $@; \
+ fi
+endef
+
+######
+# gcc support functions
+# See documentation in Documentation/kbuild/makefiles.rst
+
+# cc-cross-prefix
+# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-)
+# Return first <prefix> where a <prefix>gcc is found in PATH.
+# If no gcc found in PATH with listed prefixes return nothing
+#
+# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it
+# would try to directly execute the shell builtin 'command'. This workaround
+# should be kept for a long time since this issue was fixed only after the
+# GNU Make 4.2.1 release.
+cc-cross-prefix = $(firstword $(foreach c, $(1), \
+ $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c))))
+
+# output directory for tests below
+TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/)
+
+# try-run
+# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
+# Exit code chooses option. "$$TMP" serves as a temporary file and is
+# automatically cleaned up.
+try-run = $(shell set -e; \
+ TMP="$(TMPOUT).$$$$.tmp"; \
+ TMPO="$(TMPOUT).$$$$.o"; \
+ if ($(1)) >/dev/null 2>&1; \
+ then echo "$(2)"; \
+ else echo "$(3)"; \
+ fi; \
+ rm -f "$$TMP" "$$TMPO")
+
+# as-option
+# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
+
+as-option = $(call try-run,\
+ $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
+
+# as-instr
+# Usage: cflags-y += $(call as-instr,instr,option1,option2)
+
+as-instr = $(call try-run,\
+ printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
+
+# __cc-option
+# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
+__cc-option = $(call try-run,\
+ $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
+
+# Do not attempt to build with gcc plugins during cc-option tests.
+# (And this uses delayed resolution so the flags will be up to date.)
+CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
+
+# cc-option
+# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
+
+cc-option = $(call __cc-option, $(CC),\
+ $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
+
+# cc-option-yn
+# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
+cc-option-yn = $(call try-run,\
+ $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
+
+# cc-disable-warning
+# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
+cc-disable-warning = $(call try-run,\
+ $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
+
+# cc-ifversion
+# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
+cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
+
+# ld-option
+# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
+ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
+
+# ar-option
+# Usage: KBUILD_ARFLAGS := $(call ar-option,D)
+# Important: no spaces around options
+ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2))
+
+# ld-version
+# Note this is mainly for HJ Lu's 3 number binutil versions
+ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh)
+
+# ld-ifversion
+# Usage: $(call ld-ifversion, -ge, 22252, y)
+ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))
+
+######
+
+###
+# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
+# Usage:
+# $(Q)$(MAKE) $(build)=dir
+build := -f $(srctree)/scripts/Makefile.build obj
+
+###
+# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj=
+# Usage:
+# $(Q)$(MAKE) $(modbuiltin)=dir
+modbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj
+
+###
+# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
+# Usage:
+# $(Q)$(MAKE) $(dtbinst)=dir
+dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
+
+###
+# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=
+# Usage:
+# $(Q)$(MAKE) $(clean)=dir
+clean := -f $(srctree)/scripts/Makefile.clean obj
+
+# echo command.
+# Short version is used, if $(quiet) equals `quiet_', otherwise full one.
+echo-cmd = $(if $($(quiet)cmd_$(1)),\
+ echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
+
+# printing commands
+cmd = @set -e; $(echo-cmd) $(cmd_$(1))
+
+###
+# if_changed - execute command if any prerequisite is newer than
+# target, or command line has changed
+# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies
+# including used config symbols
+# if_changed_rule - as if_changed but execute rule instead
+# See Documentation/kbuild/makefiles.rst for more info
+
+ifneq ($(KBUILD_NOCMDDEP),1)
+# Check if both commands are the same including their order. Result is empty
+# string if equal. User may override this check using make KBUILD_NOCMDDEP=1
+cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \
+ $(subst $(space),$(space_escape),$(strip $(cmd_$1))))
+else
+cmd-check = $(if $(strip $(cmd_$@)),,1)
+endif
+
+# Replace >$< with >$$< to preserve $ when reloading the .cmd file
+# (needed for make)
+# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file
+# (needed for make)
+# Replace >'< with >'\''< to be able to enclose the whole string in '...'
+# (needed for the shell)
+make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
+
+# Find any prerequisites that is newer than target or that does not exist.
+# PHONY targets skipped in both cases.
+any-prereq = $(filter-out $(PHONY),$?)$(filter-out $(PHONY) $(wildcard $^),$^)
+
+# Execute command if command has changed or prerequisite(s) are updated.
+if_changed = $(if $(any-prereq)$(cmd-check), \
+ $(cmd); \
+ printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
+
+# Execute the command and also postprocess generated .d dependencies file.
+if_changed_dep = $(if $(any-prereq)$(cmd-check),$(cmd_and_fixdep),@:)
+
+cmd_and_fixdep = \
+ $(cmd); \
+ scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
+ rm -f $(depfile)
+
+# Usage: $(call if_changed_rule,foo)
+# Will check if $(cmd_foo) or any of the prerequisites changed,
+# and if so will execute $(rule_foo).
+if_changed_rule = $(if $(any-prereq)$(cmd-check),$(rule_$(1)),@:)
+
+###
+# why - tell why a target got built
+# enabled by make V=2
+# Output (listed in the order they are checked):
+# (1) - due to target is PHONY
+# (2) - due to target missing
+# (3) - due to: file1.h file2.h
+# (4) - due to command line change
+# (5) - due to missing .cmd file
+# (6) - due to target not in $(targets)
+# (1) PHONY targets are always build
+# (2) No target, so we better build it
+# (3) Prerequisite is newer than target
+# (4) The command line stored in the file named dir/.target.cmd
+# differed from actual command line. This happens when compiler
+# options changes
+# (5) No dir/.target.cmd file (used to store command line)
+# (6) No dir/.target.cmd file and target not listed in $(targets)
+# This is a good hint that there is a bug in the kbuild file
+ifeq ($(KBUILD_VERBOSE),2)
+why = \
+ $(if $(filter $@, $(PHONY)),- due to target is PHONY, \
+ $(if $(wildcard $@), \
+ $(if $(any-prereq),- due to: $(any-prereq), \
+ $(if $(cmd-check), \
+ $(if $(cmd_$@),- due to command line change, \
+ $(if $(filter $@, $(targets)), \
+ - due to missing .cmd file, \
+ - due to $(notdir $@) not in $$(targets) \
+ ) \
+ ) \
+ ) \
+ ), \
+ - due to target missing \
+ ) \
+ )
+
+echo-why = $(call escsq, $(strip $(why)))
+endif
+
+###############################################################################
+#
+# When a Kconfig string contains a filename, it is suitable for
+# passing to shell commands. It is surrounded by double-quotes, and
+# any double-quotes or backslashes within it are escaped by
+# backslashes.
+#
+# This is no use for dependencies or $(wildcard). We need to strip the
+# surrounding quotes and the escaping from quotes and backslashes, and
+# we *do* need to escape any spaces in the string. So, for example:
+#
+# Usage: $(eval $(call config_filename,FOO))
+#
+# Defines FOO_FILENAME based on the contents of the CONFIG_FOO option,
+# transformed as described above to be suitable for use within the
+# makefile.
+#
+# Also, if the filename is a relative filename and exists in the source
+# tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to
+# be prefixed to *both* command invocation and dependencies.
+#
+# Note: We also print the filenames in the quiet_cmd_foo text, and
+# perhaps ought to have a version specially escaped for that purpose.
+# But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good
+# enough. It'll strip the quotes in the common case where there's no
+# space and it's a simple filename, and it'll retain the quotes when
+# there's a space. There are some esoteric cases in which it'll print
+# the wrong thing, but we don't really care. The actual dependencies
+# and commands *do* get it right, with various combinations of single
+# and double quotes, backslashes and spaces in the filenames.
+#
+###############################################################################
+#
+define config_filename
+ifneq ($$(CONFIG_$(1)),"")
+$(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1)))))))
+ifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME)))
+else
+ifeq ($$(wildcard $$($(1)_FILENAME)),)
+ifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),)
+$(1)_SRCPREFIX := $(srctree)/
+endif
+endif
+endif
+endif
+endef
+#
+###############################################################################
+
+# delete partially updated (i.e. corrupted) files on error
+.DELETE_ON_ERROR:
+
+# do not delete intermediate files automatically
+.SECONDARY:
diff --git a/xen/scripts/Makefile.asm-generic b/xen/scripts/Makefile.asm-generic
new file mode 100644
index 000000000000..82ad63dcd62b
--- /dev/null
+++ b/xen/scripts/Makefile.asm-generic
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: GPL-2.0
+# include/asm-generic contains a lot of files that are used
+# verbatim by several architectures.
+#
+# This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
+# and for each file listed in this file with generic-y creates
+# a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
+
+PHONY := all
+all:
+
+src := $(subst /generated,,$(obj))
+-include $(src)/Kbuild
+
+# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
+ifneq ($(SRCARCH),um)
+include $(generic)/Kbuild
+endif
+
+include scripts/Kbuild.include
+
+redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
+redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f)))
+redundant := $(sort $(redundant))
+$(if $(redundant),\
+ $(warning redundant generic-y found in $(src)/Kbuild: $(redundant)))
+
+# If arch does not implement mandatory headers, fallback to asm-generic ones.
+mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
+generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
+
+generic-y := $(addprefix $(obj)/, $(generic-y))
+generated-y := $(addprefix $(obj)/, $(generated-y))
+
+# Remove stale wrappers when the corresponding files are removed from generic-y
+old-headers := $(wildcard $(obj)/*.h)
+unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
+
+quiet_cmd_wrap = WRAP $@
+ cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
+
+quiet_cmd_remove = REMOVE $(unwanted)
+ cmd_remove = rm -f $(unwanted)
+
+all: $(generic-y)
+ $(if $(unwanted),$(call cmd,remove))
+ @:
+
+$(obj)/%.h:
+ $(call cmd,wrap)
+
+# Create output directory. Skip it if at least one old header exists
+# since we know the output directory already exists.
+ifeq ($(old-headers),)
+$(shell mkdir -p $(obj))
+endif
+
+.PHONY: $(PHONY)
diff --git a/xen/scripts/Makefile.build b/xen/scripts/Makefile.build
new file mode 100644
index 000000000000..2f66ed388d1c
--- /dev/null
+++ b/xen/scripts/Makefile.build
@@ -0,0 +1,528 @@
+# SPDX-License-Identifier: GPL-2.0
+# ==========================================================================
+# Building
+# ==========================================================================
+
+src := $(obj)
+
+PHONY := __build
+__build:
+
+# Init all relevant variables used in kbuild files so
+# 1) they have correct type
+# 2) they do not inherit any value from the environment
+obj-y :=
+obj-m :=
+lib-y :=
+lib-m :=
+always :=
+targets :=
+subdir-y :=
+subdir-m :=
+EXTRA_AFLAGS :=
+EXTRA_CFLAGS :=
+EXTRA_CPPFLAGS :=
+EXTRA_LDFLAGS :=
+asflags-y :=
+ccflags-y :=
+cppflags-y :=
+ldflags-y :=
+
+subdir-asflags-y :=
+subdir-ccflags-y :=
+
+# Read auto.conf if it exists, otherwise ignore
+-include include/config/auto.conf
+
+include scripts/Kbuild.include
+
+# The filename Kbuild has precedence over Makefile
+kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
+kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
+include $(kbuild-file)
+
+include scripts/Makefile.lib
+
+# Do not include host rules unless needed
+ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
+include scripts/Makefile.host
+endif
+
+ifndef obj
+$(warning kbuild: Makefile.build is included improperly)
+endif
+
+ifeq ($(MAKECMDGOALS)$(need-modorder),)
+ifneq ($(obj-m),)
+$(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.)
+$(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.)
+endif
+endif
+
+# ===========================================================================
+
+ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
+lib-target := $(obj)/lib.a
+real-obj-y += $(obj)/lib-ksyms.o
+endif
+
+ifneq ($(strip $(real-obj-y) $(need-builtin)),)
+builtin-target := $(obj)/built-in.a
+endif
+
+ifeq ($(CONFIG_MODULES)$(need-modorder),y1)
+modorder-target := $(obj)/modules.order
+endif
+
+mod-targets := $(patsubst %.o, %.mod, $(obj-m))
+
+__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
+ $(if $(KBUILD_MODULES),$(obj-m) $(mod-targets) $(modorder-target)) \
+ $(subdir-ym) $(always)
+ @:
+
+# Linus' kernel sanity checking tool
+ifeq ($(KBUILD_CHECKSRC),1)
+ quiet_cmd_checksrc = CHECK $<
+ cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
+else ifeq ($(KBUILD_CHECKSRC),2)
+ quiet_cmd_force_checksrc = CHECK $<
+ cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
+endif
+
+ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
+ cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
+endif
+
+# Compile C sources (.c)
+# ---------------------------------------------------------------------------
+
+# Default is built-in, unless we know otherwise
+$(foreach x, i ll lst o s symtypes, $(patsubst %.o,%.$(x),$(real-obj-m))): \
+ part-of-module := y
+
+modkern_cflags = \
+ $(if $(part-of-module), \
+ $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
+ $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL))
+quiet_modtag = $(if $(part-of-module),[M], )
+
+quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
+ cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS), $(c_flags)) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
+
+$(obj)/%.s: $(src)/%.c FORCE
+ $(call if_changed_dep,cc_s_c)
+
+quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
+cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
+
+$(obj)/%.i: $(src)/%.c FORCE
+ $(call if_changed_dep,cpp_i_c)
+
+# These mirror gensymtypes_S and co below, keep them in synch.
+cmd_gensymtypes_c = \
+ $(CPP) -D__GENKSYMS__ $(c_flags) $< | \
+ scripts/genksyms/genksyms $(if $(1), -T $(2)) \
+ $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
+ $(if $(KBUILD_PRESERVE),-p) \
+ -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
+
+quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
+cmd_cc_symtypes_c = \
+ $(call cmd_gensymtypes_c,true,$@) >/dev/null; \
+ test -s $@ || rm -f $@
+
+$(obj)/%.symtypes : $(src)/%.c FORCE
+ $(call cmd,cc_symtypes_c)
+
+# LLVM assembly
+# Generate .ll files from .c
+quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
+ cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
+
+$(obj)/%.ll: $(src)/%.c FORCE
+ $(call if_changed_dep,cc_ll_c)
+
+# C (.c) files
+# The C file is compiled and updated dependency information is generated.
+# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
+
+quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
+ cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
+
+ifdef CONFIG_MODVERSIONS
+# When module versioning is enabled the following steps are executed:
+# o compile a <file>.o from <file>.c
+# o if <file>.o doesn't contain a __ksymtab version, i.e. does
+# not export symbols, it's done.
+# o otherwise, we calculate symbol versions using the good old
+# genksyms on the preprocessed source and postprocess them in a way
+# that they are usable as a linker script
+# o generate .tmp_<file>.o from <file>.o using the linker to
+# replace the unresolved symbols __crc_exported_symbol with
+# the actual value of the checksum generated by genksyms
+# o remove .tmp_<file>.o to <file>.o
+
+cmd_modversions_c = \
+ if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
+ $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
+ > $(@D)/.tmp_$(@F:.o=.ver); \
+ \
+ $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
+ -T $(@D)/.tmp_$(@F:.o=.ver); \
+ mv -f $(@D)/.tmp_$(@F) $@; \
+ rm -f $(@D)/.tmp_$(@F:.o=.ver); \
+ fi
+endif
+
+ifdef CONFIG_FTRACE_MCOUNT_RECORD
+ifndef CC_USING_RECORD_MCOUNT
+# compiler will not generate __mcount_loc use recordmcount or recordmcount.pl
+ifdef BUILD_C_RECORDMCOUNT
+ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
+ RECORDMCOUNT_FLAGS = -w
+endif
+# Due to recursion, we must skip empty.o.
+# The empty.o file is created in the make process in order to determine
+# the target endianness and word size. It is made before all other C
+# files, including recordmcount.
+sub_cmd_record_mcount = \
+ if [ $(@) != "scripts/mod/empty.o" ]; then \
+ $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \
+ fi;
+recordmcount_source := $(srctree)/scripts/recordmcount.c \
+ $(srctree)/scripts/recordmcount.h
+else
+sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
+ "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
+ "$(if $(CONFIG_64BIT),64,32)" \
+ "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
+ "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
+ "$(if $(part-of-module),1,0)" "$(@)";
+recordmcount_source := $(srctree)/scripts/recordmcount.pl
+endif # BUILD_C_RECORDMCOUNT
+cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), \
+ $(sub_cmd_record_mcount))
+endif # CC_USING_RECORD_MCOUNT
+endif # CONFIG_FTRACE_MCOUNT_RECORD
+
+ifdef CONFIG_STACK_VALIDATION
+ifneq ($(SKIP_STACK_VALIDATION),1)
+
+__objtool_obj := $(objtree)/tools/objtool/objtool
+
+objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check)
+
+objtool_args += $(if $(part-of-module), --module,)
+
+ifndef CONFIG_FRAME_POINTER
+objtool_args += --no-fp
+endif
+ifdef CONFIG_GCOV_KERNEL
+objtool_args += --no-unreachable
+endif
+ifdef CONFIG_RETPOLINE
+ objtool_args += --retpoline
+endif
+ifdef CONFIG_X86_SMAP
+ objtool_args += --uaccess
+endif
+
+# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
+# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
+# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
+cmd_objtool = $(if $(patsubst y%,, \
+ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
+ $(__objtool_obj) $(objtool_args) $@)
+objtool_obj = $(if $(patsubst y%,, \
+ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
+ $(__objtool_obj))
+
+endif # SKIP_STACK_VALIDATION
+endif # CONFIG_STACK_VALIDATION
+
+# Rebuild all objects when objtool changes, or is enabled/disabled.
+objtool_dep = $(objtool_obj) \
+ $(wildcard include/config/orc/unwinder.h \
+ include/config/stack/validation.h)
+
+ifdef CONFIG_TRIM_UNUSED_KSYMS
+cmd_gen_ksymdeps = \
+ $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
+endif
+
+define rule_cc_o_c
+ $(call cmd,checksrc)
+ $(call cmd_and_fixdep,cc_o_c)
+ $(call cmd,gen_ksymdeps)
+ $(call cmd,checkdoc)
+ $(call cmd,objtool)
+ $(call cmd,modversions_c)
+ $(call cmd,record_mcount)
+endef
+
+define rule_as_o_S
+ $(call cmd_and_fixdep,as_o_S)
+ $(call cmd,gen_ksymdeps)
+ $(call cmd,objtool)
+ $(call cmd,modversions_S)
+endef
+
+# List module undefined symbols (or empty line if not enabled)
+ifdef CONFIG_TRIM_UNUSED_KSYMS
+cmd_undef_syms = $(NM) $< | sed -n 's/^ *U //p' | xargs echo
+else
+cmd_undef_syms = echo
+endif
+
+# Built-in and composite module parts
+$(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
+ $(call cmd,force_checksrc)
+ $(call if_changed_rule,cc_o_c)
+
+cmd_mod = { \
+ echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
+ $(cmd_undef_syms); \
+ } > $@
+
+$(obj)/%.mod: $(obj)/%.o FORCE
+ $(call if_changed,mod)
+
+targets += $(mod-targets)
+
+quiet_cmd_cc_lst_c = MKLST $@
+ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
+ $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
+ System.map $(OBJDUMP) > $@
+
+$(obj)/%.lst: $(src)/%.c FORCE
+ $(call if_changed_dep,cc_lst_c)
+
+# header test (header-test-y, header-test-m target)
+# ---------------------------------------------------------------------------
+
+quiet_cmd_cc_s_h = CC $@
+ cmd_cc_s_h = $(CC) $(c_flags) -S -o $@ -x c /dev/null -include $<
+
+$(obj)/%.h.s: $(src)/%.h FORCE
+ $(call if_changed_dep,cc_s_h)
+
+# Compile assembler sources (.S)
+# ---------------------------------------------------------------------------
+
+modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)
+
+$(real-obj-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
+$(real-obj-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
+
+# .S file exports must have their C prototypes defined in asm/asm-prototypes.h
+# or a file that it includes, in order to get versioned symbols. We build a
+# dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
+# the .S file (with trailing ';'), and run genksyms on that, to extract vers.
+#
+# This is convoluted. The .S file must first be preprocessed to run guards and
+# expand names, then the resulting exports must be constructed into plain
+# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
+# to make the genksyms input.
+#
+# These mirror gensymtypes_c and co above, keep them in synch.
+cmd_gensymtypes_S = \
+ { echo "\#include <linux/kernel.h>" ; \
+ echo "\#include <asm/asm-prototypes.h>" ; \
+ $(CPP) $(a_flags) $< | \
+ grep "\<___EXPORT_SYMBOL\>" | \
+ sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \
+ $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | \
+ scripts/genksyms/genksyms $(if $(1), -T $(2)) \
+ $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
+ $(if $(KBUILD_PRESERVE),-p) \
+ -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
+
+quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
+cmd_cc_symtypes_S = \
+ $(call cmd_gensymtypes_S,true,$@) >/dev/null; \
+ test -s $@ || rm -f $@
+
+$(obj)/%.symtypes : $(src)/%.S FORCE
+ $(call cmd,cc_symtypes_S)
+
+
+quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
+cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
+
+$(obj)/%.s: $(src)/%.S FORCE
+ $(call if_changed_dep,cpp_s_S)
+
+quiet_cmd_as_o_S = AS $(quiet_modtag) $@
+ cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
+
+ifdef CONFIG_MODVERSIONS
+
+ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
+
+ifneq ($(ASM_PROTOTYPES),)
+
+# versioning matches the C process described above, with difference that
+# we parse asm-prototypes.h C header to get function definitions.
+
+cmd_modversions_S = \
+ if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
+ $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
+ > $(@D)/.tmp_$(@F:.o=.ver); \
+ \
+ $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
+ -T $(@D)/.tmp_$(@F:.o=.ver); \
+ mv -f $(@D)/.tmp_$(@F) $@; \
+ rm -f $(@D)/.tmp_$(@F:.o=.ver); \
+ fi
+endif
+endif
+
+$(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
+ $(call if_changed_rule,as_o_S)
+
+targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
+targets += $(extra-y) $(MAKECMDGOALS) $(always)
+
+# Linker scripts preprocessor (.lds.S -> .lds)
+# ---------------------------------------------------------------------------
+quiet_cmd_cpp_lds_S = LDS $@
+ cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
+ -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
+
+$(obj)/%.lds: $(src)/%.lds.S FORCE
+ $(call if_changed_dep,cpp_lds_S)
+
+# ASN.1 grammar
+# ---------------------------------------------------------------------------
+quiet_cmd_asn1_compiler = ASN.1 $@
+ cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
+ $(subst .h,.c,$@) $(subst .c,.h,$@)
+
+$(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
+ $(call cmd,asn1_compiler)
+
+# Build the compiled-in targets
+# ---------------------------------------------------------------------------
+
+# To build objects in subdirs, we need to descend into the directories
+$(sort $(subdir-obj-y)): $(subdir-ym) ;
+
+#
+# Rule to compile a set of .o files into one .a file (without symbol table)
+#
+ifdef builtin-target
+
+quiet_cmd_ar_builtin = AR $@
+ cmd_ar_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(real-prereqs)
+
+$(builtin-target): $(real-obj-y) FORCE
+ $(call if_changed,ar_builtin)
+
+targets += $(builtin-target)
+endif # builtin-target
+
+#
+# Rule to create modules.order file
+#
+# Create commands to either record .ko file or cat modules.order from
+# a subdirectory
+$(modorder-target): $(subdir-ym) FORCE
+ $(Q){ $(foreach m, $(modorder), \
+ $(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \
+ | $(AWK) '!x[$$0]++' - > $@
+
+#
+# Rule to compile a set of .o files into one .a file (with symbol table)
+#
+ifdef lib-target
+
+$(lib-target): $(lib-y) FORCE
+ $(call if_changed,ar)
+
+targets += $(lib-target)
+
+dummy-object = $(obj)/.lib_exports.o
+ksyms-lds = $(dot-target).lds
+
+quiet_cmd_export_list = EXPORTS $@
+cmd_export_list = $(OBJDUMP) -h $< | \
+ sed -ne '/___ksymtab/s/.*+\([^ ]*\).*/EXTERN(\1)/p' >$(ksyms-lds);\
+ rm -f $(dummy-object);\
+ echo | $(CC) $(a_flags) -c -o $(dummy-object) -x assembler -;\
+ $(LD) $(ld_flags) -r -o $@ -T $(ksyms-lds) $(dummy-object);\
+ rm $(dummy-object) $(ksyms-lds)
+
+$(obj)/lib-ksyms.o: $(lib-target) FORCE
+ $(call if_changed,export_list)
+
+targets += $(obj)/lib-ksyms.o
+
+endif
+
+# NOTE:
+# Do not replace $(filter %.o,^) with $(real-prereqs). When a single object
+# module is turned into a multi object module, $^ will contain header file
+# dependencies recorded in the .*.cmd file.
+quiet_cmd_link_multi-m = LD [M] $@
+ cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^)
+
+$(multi-used-m): FORCE
+ $(call if_changed,link_multi-m)
+$(call multi_depend, $(multi-used-m), .o, -objs -y -m)
+
+targets += $(multi-used-m)
+targets := $(filter-out $(PHONY), $(targets))
+
+# Add intermediate targets:
+# When building objects with specific suffix patterns, add intermediate
+# targets that the final targets are derived from.
+intermediate_targets = $(foreach sfx, $(2), \
+ $(patsubst %$(strip $(1)),%$(sfx), \
+ $(filter %$(strip $(1)), $(targets))))
+# %.asn1.o <- %.asn1.[ch] <- %.asn1
+# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
+# %.lex.o <- %.lex.c <- %.l
+# %.tab.o <- %.tab.[ch] <- %.y
+targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
+ $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
+ $(call intermediate_targets, .lex.o, .lex.c) \
+ $(call intermediate_targets, .tab.o, .tab.c .tab.h)
+
+# Descending
+# ---------------------------------------------------------------------------
+
+PHONY += $(subdir-ym)
+$(subdir-ym):
+ $(Q)$(MAKE) $(build)=$@ \
+ need-builtin=$(if $(filter $@/built-in.a, $(subdir-obj-y)),1) \
+ need-modorder=$(if $(need-modorder),$(if $(filter $@/modules.order, $(modorder)),1))
+
+# Add FORCE to the prequisites of a target to force it to be always rebuilt.
+# ---------------------------------------------------------------------------
+
+PHONY += FORCE
+
+FORCE:
+
+# Read all saved command lines and dependencies for the $(targets) we
+# may be building above, using $(if_changed{,_dep}). As an
+# optimization, we don't need to read them if the target does not
+# exist, we will rebuild anyway in that case.
+
+existing-targets := $(wildcard $(sort $(targets)))
+
+-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
+
+ifdef building_out_of_srctree
+# Create directories for object files if they do not exist
+obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
+# If targets exist, their directories apparently exist. Skip mkdir.
+existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
+obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
+ifneq ($(obj-dirs),)
+$(shell mkdir -p $(obj-dirs))
+endif
+endif
+
+.PHONY: $(PHONY)
diff --git a/xen/scripts/Makefile.clean b/xen/scripts/Makefile.clean
new file mode 100644
index 000000000000..0b80e3207b20
--- /dev/null
+++ b/xen/scripts/Makefile.clean
@@ -0,0 +1,90 @@
+# SPDX-License-Identifier: GPL-2.0
+# ==========================================================================
+# Cleaning up
+# ==========================================================================
+
+src := $(obj)
+
+PHONY := __clean
+__clean:
+
+include scripts/Kbuild.include
+
+# The filename Kbuild has precedence over Makefile
+kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
+include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
+
+# Figure out what we need to build from the various variables
+# ==========================================================================
+
+__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
+subdir-y += $(__subdir-y)
+__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
+subdir-m += $(__subdir-m)
+__subdir- := $(patsubst %/,%,$(filter %/, $(obj-)))
+subdir- += $(__subdir-)
+
+# Subdirectories we need to descend into
+
+subdir-ym := $(sort $(subdir-y) $(subdir-m))
+subdir-ymn := $(sort $(subdir-ym) $(subdir-))
+
+# Add subdir path
+
+subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
+
+# build a list of files to remove, usually relative to the current
+# directory
+
+__clean-files := $(extra-y) $(extra-m) $(extra-) \
+ $(always) $(targets) $(clean-files) \
+ $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
+ $(hostlibs-y) $(hostlibs-m) $(hostlibs-) \
+ $(hostcxxlibs-y) $(hostcxxlibs-m)
+
+__clean-files := $(filter-out $(no-clean-files), $(__clean-files))
+
+# clean-files is given relative to the current directory, unless it
+# starts with $(objtree)/ (which means "./", so do not add "./" unless
+# you want to delete a file from the toplevel object directory).
+
+__clean-files := $(wildcard \
+ $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \
+ $(filter $(objtree)/%, $(__clean-files)))
+
+# same as clean-files
+
+__clean-dirs := $(wildcard \
+ $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(clean-dirs))) \
+ $(filter $(objtree)/%, $(clean-dirs)))
+
+# ==========================================================================
+
+quiet_cmd_clean = CLEAN $(obj)
+ cmd_clean = rm -f $(__clean-files)
+quiet_cmd_cleandir = CLEAN $(__clean-dirs)
+ cmd_cleandir = rm -rf $(__clean-dirs)
+
+
+__clean: $(subdir-ymn)
+ifneq ($(strip $(__clean-files)),)
+ +$(call cmd,clean)
+endif
+ifneq ($(strip $(__clean-dirs)),)
+ +$(call cmd,cleandir)
+endif
+ @:
+
+
+# ===========================================================================
+# Generic stuff
+# ===========================================================================
+
+# Descending
+# ---------------------------------------------------------------------------
+
+PHONY += $(subdir-ymn)
+$(subdir-ymn):
+ $(Q)$(MAKE) $(clean)=$@
+
+.PHONY: $(PHONY)
diff --git a/xen/scripts/Makefile.gcc-plugins b/xen/scripts/Makefile.gcc-plugins
new file mode 100644
index 000000000000..5f7df50cfe7a
--- /dev/null
+++ b/xen/scripts/Makefile.gcc-plugins
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0
+
+gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so
+
+gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so
+gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) \
+ += -DLATENT_ENTROPY_PLUGIN
+ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
+ DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable
+endif
+export DISABLE_LATENT_ENTROPY_PLUGIN
+
+gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so
+
+gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so
+gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) \
+ += -fplugin-arg-structleak_plugin-verbose
+gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF) \
+ += -fplugin-arg-structleak_plugin-byref
+gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) \
+ += -fplugin-arg-structleak_plugin-byref-all
+gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) \
+ += -DSTRUCTLEAK_PLUGIN
+
+gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += randomize_layout_plugin.so
+gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) \
+ += -DRANDSTRUCT_PLUGIN
+gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) \
+ += -fplugin-arg-randomize_layout_plugin-performance-mode
+
+gcc-plugin-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak_plugin.so
+gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
+ += -DSTACKLEAK_PLUGIN
+gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
+ += -fplugin-arg-stackleak_plugin-track-min-size=$(CONFIG_STACKLEAK_TRACK_MIN_SIZE)
+ifdef CONFIG_GCC_PLUGIN_STACKLEAK
+ DISABLE_STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-disable
+endif
+export DISABLE_STACKLEAK_PLUGIN
+
+gcc-plugin-$(CONFIG_GCC_PLUGIN_ARM_SSP_PER_TASK) += arm_ssp_per_task_plugin.so
+ifdef CONFIG_GCC_PLUGIN_ARM_SSP_PER_TASK
+ DISABLE_ARM_SSP_PER_TASK_PLUGIN += -fplugin-arg-arm_ssp_per_task_plugin-disable
+endif
+export DISABLE_ARM_SSP_PER_TASK_PLUGIN
+
+# All the plugin CFLAGS are collected here in case a build target needs to
+# filter them out of the KBUILD_CFLAGS.
+GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))
+# The sancov_plugin.so is included via CFLAGS_KCOV, so it is removed here.
+GCC_PLUGINS_CFLAGS := $(filter-out %/sancov_plugin.so, $(GCC_PLUGINS_CFLAGS))
+export GCC_PLUGINS_CFLAGS
+
+# Add the flags to the build!
+KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
+
+# All enabled GCC plugins are collected here for building below.
+GCC_PLUGIN := $(gcc-plugin-y)
+export GCC_PLUGIN
--git a/xen/scripts/Makefile.headersinst b/xen/scripts/Makefile.headersinst
new file mode 100644
index 000000000000..1b405a7ed14f
--- /dev/null
+++ b/xen/scripts/Makefile.headersinst
@@ -0,0 +1,102 @@
+# SPDX-License-Identifier: GPL-2.0
+# ==========================================================================
+# Installing headers
+#
+# All headers under include/uapi, include/generated/uapi,
+# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
+# exported.
+# They are preprocessed to remove __KERNEL__ section of the file.
+#
+# ==========================================================================
+
+PHONY := __headers
+__headers:
+
+include scripts/Kbuild.include
+
+src := $(srctree)/$(obj)
+gen := $(objtree)/$(subst include/,include/generated/,$(obj))
+dst := usr/include
+
+-include $(src)/Kbuild
+
+# $(filter %/, ...) is a workaround for GNU Make <= 4.2.1, where
+# $(wildcard $(src)/*/) contains not only directories but also regular files.
+src-subdirs := $(patsubst $(src)/%/,%,$(filter %/, $(wildcard $(src)/*/)))
+gen-subdirs := $(patsubst $(gen)/%/,%,$(filter %/, $(wildcard $(gen)/*/)))
+all-subdirs := $(sort $(src-subdirs) $(gen-subdirs))
+
+src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h'))
+src-headers := $(filter-out $(no-export-headers), $(src-headers))
+gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h'))
+gen-headers := $(filter-out $(no-export-headers), $(gen-headers))
+
+# If the same header is exported from source and generated directories,
+# the former takes precedence, but this should be warned.
+duplicated := $(filter $(gen-headers), $(src-headers))
+$(if $(duplicated), $(warning duplicated header export: $(duplicated)))
+
+gen-headers := $(filter-out $(duplicated), $(gen-headers))
+
+# Add dst path prefix
+all-subdirs := $(addprefix $(dst)/, $(all-subdirs))
+src-headers := $(addprefix $(dst)/, $(src-headers))
+gen-headers := $(addprefix $(dst)/, $(gen-headers))
+all-headers := $(src-headers) $(gen-headers)
+
+# Work out what needs to be removed
+old-subdirs := $(wildcard $(all-subdirs))
+old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h'))
+unwanted := $(filter-out $(all-headers), $(old-headers))
+
+# Create directories
+existing-dirs := $(sort $(dir $(old-headers)))
+wanted-dirs := $(sort $(dir $(all-headers)))
+new-dirs := $(filter-out $(existing-dirs), $(wanted-dirs))
+$(if $(new-dirs), $(shell mkdir -p $(new-dirs)))
+
+# Rules
+
+ifndef HDRCHECK
+
+quiet_cmd_install = HDRINST $@
+ cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $< $@
+
+$(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE
+ $(call if_changed,install)
+
+$(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE
+ $(call if_changed,install)
+
+quiet_cmd_remove = REMOVE $(unwanted)
+ cmd_remove = rm -f $(unwanted)
+
+__headers: $(all-headers)
+ifneq ($(unwanted),)
+ $(call cmd,remove)
+endif
+ @:
+
+existing-headers := $(filter $(old-headers), $(all-headers))
+
+-include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd)
+
+else
+
+quiet_cmd_check = HDRCHK $<
+ cmd_check = $(PERL) $(srctree)/scripts/headers_check.pl $(dst) $(SRCARCH) $<; touch $@
+
+check-files := $(addsuffix .chk, $(all-headers))
+
+$(check-files): $(dst)/%.chk : $(dst)/% $(srctree)/scripts/headers_check.pl
+ $(call cmd,check)
+
+__headers: $(check-files)
+ @:
+
+endif
+
+PHONY += FORCE
+FORCE:
+
+.PHONY: $(PHONY)
diff --git a/xen/scripts/Makefile.host b/xen/scripts/Makefile.host
new file mode 100644
index 000000000000..2208ebbd8c4c
--- /dev/null
+++ b/xen/scripts/Makefile.host
@@ -0,0 +1,164 @@
+# SPDX-License-Identifier: GPL-2.0
+# ==========================================================================
+# Building binaries on the host system
+# Binaries are used during the compilation of the kernel, for example
+# to preprocess a data file.
+#
+# Both C and C++ are supported, but preferred language is C for such utilities.
+#
+# Sample syntax (see Documentation/kbuild/makefiles.rst for reference)
+# hostprogs-y := bin2hex
+# Will compile bin2hex.c and create an executable named bin2hex
+#
+# hostprogs-y := lxdialog
+# lxdialog-objs := checklist.o lxdialog.o
+# Will compile lxdialog.c and checklist.c, and then link the executable
+# lxdialog, based on checklist.o and lxdialog.o
+#
+# hostprogs-y := qconf
+# qconf-cxxobjs := qconf.o
+# qconf-objs := menu.o
+# Will compile qconf as a C++ program, and menu as a C program.
+# They are linked as C++ code to the executable qconf
+
+__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
+host-cshlib := $(sort $(hostlibs-y) $(hostlibs-m))
+host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
+
+# C code
+# Executables compiled from a single .c file
+host-csingle := $(foreach m,$(__hostprogs), \
+ $(if $($(m)-objs)$($(m)-cxxobjs),,$(m)))
+
+# C executables linked based on several .o files
+host-cmulti := $(foreach m,$(__hostprogs),\
+ $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
+
+# Object (.o) files compiled from .c files
+host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
+
+# C++ code
+# C++ executables compiled from at least one .cc file
+# and zero or more .c files
+host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
+
+# C++ Object (.o) files compiled from .cc files
+host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
+
+# Object (.o) files used by the shared libaries
+host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
+host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
+
+host-csingle := $(addprefix $(obj)/,$(host-csingle))
+host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
+host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
+host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
+host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
+host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
+host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
+host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
+host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
+
+#####
+# Handle options to gcc. Support building with separate output directory
+
+_hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
+ $(HOSTCFLAGS_$(basetarget).o)
+_hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
+ $(HOSTCXXFLAGS_$(basetarget).o)
+
+# $(objtree)/$(obj) for including generated headers from checkin source files
+ifeq ($(KBUILD_EXTMOD),)
+ifdef building_out_of_srctree
+_hostc_flags += -I $(objtree)/$(obj)
+_hostcxx_flags += -I $(objtree)/$(obj)
+endif
+endif
+
+hostc_flags = -Wp,-MD,$(depfile) $(_hostc_flags)
+hostcxx_flags = -Wp,-MD,$(depfile) $(_hostcxx_flags)
+
+#####
+# Compile programs on the host
+
+# Create executable from a single .c file
+# host-csingle -> Executable
+quiet_cmd_host-csingle = HOSTCC $@
+ cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
+ $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
+$(host-csingle): $(obj)/%: $(src)/%.c FORCE
+ $(call if_changed_dep,host-csingle)
+
+# Link an executable based on list of .o files, all plain c
+# host-cmulti -> executable
+quiet_cmd_host-cmulti = HOSTLD $@
+ cmd_host-cmulti = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \
+ $(addprefix $(obj)/,$($(@F)-objs)) \
+ $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
+$(host-cmulti): FORCE
+ $(call if_changed,host-cmulti)
+$(call multi_depend, $(host-cmulti), , -objs)
+
+# Create .o file from a single .c file
+# host-cobjs -> .o
+quiet_cmd_host-cobjs = HOSTCC $@
+ cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
+$(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
+ $(call if_changed_dep,host-cobjs)
+
+# Link an executable based on list of .o files, a mixture of .c and .cc
+# host-cxxmulti -> executable
+quiet_cmd_host-cxxmulti = HOSTLD $@
+ cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \
+ $(foreach o,objs cxxobjs,\
+ $(addprefix $(obj)/,$($(@F)-$(o)))) \
+ $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
+$(host-cxxmulti): FORCE
+ $(call if_changed,host-cxxmulti)
+$(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
+
+# Create .o file from a single .cc (C++) file
+quiet_cmd_host-cxxobjs = HOSTCXX $@
+ cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
+$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
+ $(call if_changed_dep,host-cxxobjs)
+
+# Compile .c file, create position independent .o file
+# host-cshobjs -> .o
+quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
+ cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
+$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
+ $(call if_changed_dep,host-cshobjs)
+
+# Compile .c file, create position independent .o file
+# Note that plugin capable gcc versions can be either C or C++ based
+# therefore plugin source files have to be compilable in both C and C++ mode.
+# This is why a C++ compiler is invoked on a .c file.
+# host-cxxshobjs -> .o
+quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
+ cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
+$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
+ $(call if_changed_dep,host-cxxshobjs)
+
+# Link a shared library, based on position independent .o files
+# *.o -> .so shared library (host-cshlib)
+quiet_cmd_host-cshlib = HOSTLLD -shared $@
+ cmd_host-cshlib = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
+ $(addprefix $(obj)/,$($(@F:.so=-objs))) \
+ $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
+$(host-cshlib): FORCE
+ $(call if_changed,host-cshlib)
+$(call multi_depend, $(host-cshlib), .so, -objs)
+
+# Link a shared library, based on position independent .o files
+# *.o -> .so shared library (host-cxxshlib)
+quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
+ cmd_host-cxxshlib = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
+ $(addprefix $(obj)/,$($(@F:.so=-objs))) \
+ $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
+$(host-cxxshlib): FORCE
+ $(call if_changed,host-cxxshlib)
+$(call multi_depend, $(host-cxxshlib), .so, -objs)
+
+targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
+ $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
diff --git a/xen/scripts/Makefile.kasan b/xen/scripts/Makefile.kasan
new file mode 100644
index 000000000000..6410bd22fe38
--- /dev/null
+++ b/xen/scripts/Makefile.kasan
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: GPL-2.0
+ifdef CONFIG_KASAN_GENERIC
+
+ifdef CONFIG_KASAN_INLINE
+ call_threshold := 10000
+else
+ call_threshold := 0
+endif
+
+KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
+
+CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
+
+cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1)))
+
+# -fasan-shadow-offset fails without -fsanitize
+CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \
+ -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \
+ $(call cc-option, -fsanitize=kernel-address \
+ -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET)))
+
+ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),)
+ CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
+else
+ # Now add all the compiler specific options that are valid standalone
+ CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \
+ $(call cc-param,asan-globals=1) \
+ $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
+ $(call cc-param,asan-stack=$(CONFIG_KASAN_STACK)) \
+ $(call cc-param,asan-instrument-allocas=1)
+endif
+
+endif # CONFIG_KASAN_GENERIC
+
+ifdef CONFIG_KASAN_SW_TAGS
+
+ifdef CONFIG_KASAN_INLINE
+ instrumentation_flags := -mllvm -hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET)
+else
+ instrumentation_flags := -mllvm -hwasan-instrument-with-calls=1
+endif
+
+CFLAGS_KASAN := -fsanitize=kernel-hwaddress \
+ -mllvm -hwasan-instrument-stack=0 \
+ $(instrumentation_flags)
+
+endif # CONFIG_KASAN_SW_TAGS
+
+ifdef CONFIG_KASAN
+CFLAGS_KASAN_NOSANITIZE := -fno-builtin
+endif
diff --git a/xen/scripts/Makefile.kcov b/xen/scripts/Makefile.kcov
new file mode 100644
index 000000000000..52b113302443
--- /dev/null
+++ b/xen/scripts/Makefile.kcov
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-only
+ifdef CONFIG_KCOV
+
+kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) += -fsanitize-coverage=trace-pc
+kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp
+kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) += -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
+
+export CFLAGS_KCOV := $(kcov-flags-y)
+
+endif
diff --git a/xen/scripts/Makefile.lib b/xen/scripts/Makefile.lib
new file mode 100644
index 000000000000..41c50f9461e5
--- /dev/null
+++ b/xen/scripts/Makefile.lib
@@ -0,0 +1,435 @@
+# SPDX-License-Identifier: GPL-2.0
+# Backward compatibility
+asflags-y += $(EXTRA_AFLAGS)
+ccflags-y += $(EXTRA_CFLAGS)
+cppflags-y += $(EXTRA_CPPFLAGS)
+ldflags-y += $(EXTRA_LDFLAGS)
+
+# flags that take effect in current and sub directories
+KBUILD_AFLAGS += $(subdir-asflags-y)
+KBUILD_CFLAGS += $(subdir-ccflags-y)
+
+# Figure out what we need to build from the various variables
+# ===========================================================================
+
+# When an object is listed to be built compiled-in and modular,
+# only build the compiled-in version
+obj-m := $(filter-out $(obj-y),$(obj-m))
+
+# Libraries are always collected in one lib file.
+# Filter out objects already built-in
+lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
+
+# Determine modorder.
+# Unfortunately, we don't have information about ordering between -y
+# and -m subdirs. Just put -y's first.
+modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
+
+# Handle objects in subdirs
+# ---------------------------------------------------------------------------
+# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a
+# and add the directory to the list of dirs to descend into: $(subdir-y)
+# o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
+# and add the directory to the list of dirs to descend into: $(subdir-m)
+__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
+subdir-y += $(__subdir-y)
+__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
+subdir-m += $(__subdir-m)
+obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
+obj-m := $(filter-out %/, $(obj-m))
+
+# Subdirectories we need to descend into
+subdir-ym := $(sort $(subdir-y) $(subdir-m))
+
+# if $(foo-objs), $(foo-y), or $(foo-m) exists, foo.o is a composite object
+multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
+multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m))))
+multi-used := $(multi-used-y) $(multi-used-m)
+
+# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
+# tell kbuild to descend
+subdir-obj-y := $(filter %/built-in.a, $(obj-y))
+
+# Replace multi-part objects by their individual parts,
+# including built-in.a from subdirectories
+real-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
+real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
+
+# DTB
+# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
+extra-y += $(dtb-y)
+extra-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
+
+ifneq ($(CHECK_DTBS),)
+extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
+extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
+endif
+
+# Test self-contained headers
+
+# Wildcard searches in $(srctree)/$(src)/, but not in $(objtree)/$(obj)/.
+# Stale generated headers are often left over, so pattern matching should
+# be avoided. Please notice $(srctree)/$(src)/ and $(objtree)/$(obj) point
+# to the same location for in-tree building. So, header-test-pattern-y should
+# be used with care.
+header-test-y += $(filter-out $(header-test-), \
+ $(patsubst $(srctree)/$(src)/%, %, \
+ $(wildcard $(addprefix $(srctree)/$(src)/, \
+ $(header-test-pattern-y)))))
+
+extra-$(CONFIG_HEADER_TEST) += $(addsuffix .s, $(header-test-y) $(header-test-m))
+
+# Add subdir path
+
+extra-y := $(addprefix $(obj)/,$(extra-y))
+always := $(addprefix $(obj)/,$(always))
+targets := $(addprefix $(obj)/,$(targets))
+modorder := $(addprefix $(obj)/,$(modorder))
+obj-m := $(addprefix $(obj)/,$(obj-m))
+lib-y := $(addprefix $(obj)/,$(lib-y))
+subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y))
+real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
+real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
+multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
+subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
+
+# Finds the multi-part object the current object will be linked into.
+# If the object belongs to two or more multi-part objects, all of them are
+# concatenated with a colon separator.
+modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\
+ $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))))
+
+modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
+
+# These flags are needed for modversions and compiling, so we define them here
+# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
+# end up in (or would, if it gets compiled in)
+name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
+basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
+modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname))
+
+orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
+ $(ccflags-y) $(CFLAGS_$(basetarget).o)
+_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
+orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
+ $(asflags-y) $(AFLAGS_$(basetarget).o)
+_a_flags = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags))
+_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
+
+#
+# Enable gcov profiling flags for a file, directory or for all files depending
+# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
+# (in this order)
+#
+ifeq ($(CONFIG_GCOV_KERNEL),y)
+_c_flags += $(if $(patsubst n%,, \
+ $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
+ $(CFLAGS_GCOV))
+endif
+
+#
+# Enable address sanitizer flags for kernel except some files or directories
+# we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
+#
+ifeq ($(CONFIG_KASAN),y)
+_c_flags += $(if $(patsubst n%,, \
+ $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
+ $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
+endif
+
+ifeq ($(CONFIG_UBSAN),y)
+_c_flags += $(if $(patsubst n%,, \
+ $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
+ $(CFLAGS_UBSAN))
+endif
+
+ifeq ($(CONFIG_KCOV),y)
+_c_flags += $(if $(patsubst n%,, \
+ $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
+ $(CFLAGS_KCOV))
+endif
+
+# $(srctree)/$(src) for including checkin headers from generated source files
+# $(objtree)/$(obj) for including generated headers from checkin source files
+ifeq ($(KBUILD_EXTMOD),)
+ifdef building_out_of_srctree
+_c_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
+_a_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
+_cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
+endif
+endif
+
+c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
+ -include $(srctree)/include/linux/compiler_types.h \
+ $(_c_flags) $(modkern_cflags) \
+ $(basename_flags) $(modname_flags)
+
+a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
+ $(_a_flags) $(modkern_aflags)
+
+cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
+ $(_cpp_flags)
+
+ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
+
+DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
+
+dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
+ $(addprefix -I,$(DTC_INCLUDE)) \
+ -undef -D__DTS__
+
+# Useful for describing the dependency of composite objects
+# Usage:
+# $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
+define multi_depend
+$(foreach m, $(notdir $1), \
+ $(eval $(obj)/$m: \
+ $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
+endef
+
+# LEX
+# ---------------------------------------------------------------------------
+quiet_cmd_flex = LEX $@
+ cmd_flex = $(LEX) -o$@ -L $<
+
+$(obj)/%.lex.c: $(src)/%.l FORCE
+ $(call if_changed,flex)
+
+# YACC
+# ---------------------------------------------------------------------------
+quiet_cmd_bison = YACC $@
+ cmd_bison = $(YACC) -o$@ -t -l $<
+
+$(obj)/%.tab.c: $(src)/%.y FORCE
+ $(call if_changed,bison)
+
+quiet_cmd_bison_h = YACC $@
+ cmd_bison_h = $(YACC) -o/dev/null --defines=$@ -t -l $<
+
+$(obj)/%.tab.h: $(src)/%.y FORCE
+ $(call if_changed,bison_h)
+
+# Shipped files
+# ===========================================================================
+
+quiet_cmd_shipped = SHIPPED $@
+cmd_shipped = cat $< > $@
+
+$(obj)/%: $(src)/%_shipped
+ $(call cmd,shipped)
+
+# Commands useful for building a boot image
+# ===========================================================================
+#
+# Use as following:
+#
+# target: source(s) FORCE
+# $(if_changed,ld/objcopy/gzip)
+#
+# and add target to extra-y so that we know we have to
+# read in the saved command line
+
+# Linking
+# ---------------------------------------------------------------------------
+
+quiet_cmd_ld = LD $@
+ cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
+
+# Archive
+# ---------------------------------------------------------------------------
+
+quiet_cmd_ar = AR $@
+ cmd_ar = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(real-prereqs)
+
+# Objcopy
+# ---------------------------------------------------------------------------
+
+quiet_cmd_objcopy = OBJCOPY $@
+cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
+
+# Gzip
+# ---------------------------------------------------------------------------
+
+quiet_cmd_gzip = GZIP $@
+ cmd_gzip = cat $(real-prereqs) | gzip -n -f -9 > $@
+
+# DTC
+# ---------------------------------------------------------------------------
+DTC ?= $(objtree)/scripts/dtc/dtc
+
+# Disable noisy checks by default
+ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
+DTC_FLAGS += -Wno-unit_address_vs_reg \
+ -Wno-unit_address_format \
+ -Wno-avoid_unnecessary_addr_size \
+ -Wno-alias_paths \
+ -Wno-graph_child_address \
+ -Wno-simple_bus_reg \
+ -Wno-unique_unit_address \
+ -Wno-pci_device_reg
+endif
+
+ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
+DTC_FLAGS += -Wnode_name_chars_strict \
+ -Wproperty_name_chars_strict
+endif
+
+DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
+
+# Generate an assembly file to wrap the output of the device tree compiler
+quiet_cmd_dt_S_dtb= DTB $@
+cmd_dt_S_dtb= \
+{ \
+ echo '\#include <asm-generic/vmlinux.lds.h>'; \
+ echo '.section .dtb.init.rodata,"a"'; \
+ echo '.balign STRUCT_ALIGNMENT'; \
+ echo '.global __dtb_$(subst -,_,$(*F))_begin'; \
+ echo '__dtb_$(subst -,_,$(*F))_begin:'; \
+ echo '.incbin "$<" '; \
+ echo '__dtb_$(subst -,_,$(*F))_end:'; \
+ echo '.global __dtb_$(subst -,_,$(*F))_end'; \
+ echo '.balign STRUCT_ALIGNMENT'; \
+} > $@
+
+$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
+ $(call if_changed,dt_S_dtb)
+
+quiet_cmd_dtc = DTC $@
+cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
+ $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
+ $(DTC) -O $(2) -o $@ -b 0 \
+ $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
+ -d $(depfile).dtc.tmp $(dtc-tmp) ; \
+ cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
+
+$(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
+ $(call if_changed_dep,dtc,dtb)
+
+DT_CHECKER ?= dt-validate
+DT_BINDING_DIR := Documentation/devicetree/bindings
+DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.yaml
+
+quiet_cmd_dtb_check = CHECK $@
+ cmd_dtb_check = $(DT_CHECKER) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ ;
+
+define rule_dtc_dt_yaml
+ $(call cmd_and_fixdep,dtc,yaml)
+ $(call cmd,dtb_check)
+endef
+
+$(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
+ $(call if_changed_rule,dtc_dt_yaml)
+
+dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
+
+# Bzip2
+# ---------------------------------------------------------------------------
+
+# Bzip2 and LZMA do not include size in file... so we have to fake that;
+# append the size as a 32-bit littleendian number as gzip does.
+size_append = printf $(shell \
+dec_size=0; \
+for F in $(real-prereqs); do \
+ fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \
+ dec_size=$$(expr $$dec_size + $$fsize); \
+done; \
+printf "%08x\n" $$dec_size | \
+ sed 's/\(..\)/\1 /g' | { \
+ read ch0 ch1 ch2 ch3; \
+ for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \
+ printf '%s%03o' '\\' $$((0x$$ch)); \
+ done; \
+ } \
+)
+
+quiet_cmd_bzip2 = BZIP2 $@
+ cmd_bzip2 = { cat $(real-prereqs) | bzip2 -9; $(size_append); } > $@
+
+# Lzma
+# ---------------------------------------------------------------------------
+
+quiet_cmd_lzma = LZMA $@
+ cmd_lzma = { cat $(real-prereqs) | lzma -9; $(size_append); } > $@
+
+quiet_cmd_lzo = LZO $@
+ cmd_lzo = { cat $(real-prereqs) | lzop -9; $(size_append); } > $@
+
+quiet_cmd_lz4 = LZ4 $@
+ cmd_lz4 = { cat $(real-prereqs) | lz4c -l -c1 stdin stdout; \
+ $(size_append); } > $@
+
+# U-Boot mkimage
+# ---------------------------------------------------------------------------
+
+MKIMAGE := $(srctree)/scripts/mkuboot.sh
+
+# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
+# the number of overrides in arch makefiles
+UIMAGE_ARCH ?= $(SRCARCH)
+UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
+UIMAGE_OPTS-y ?=
+UIMAGE_TYPE ?= kernel
+UIMAGE_LOADADDR ?= arch_must_set_this
+UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
+UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
+
+quiet_cmd_uimage = UIMAGE $@
+ cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
+ -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
+ -T $(UIMAGE_TYPE) \
+ -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
+ -n $(UIMAGE_NAME) -d $< $@
+
+# XZ
+# ---------------------------------------------------------------------------
+# Use xzkern to compress the kernel image and xzmisc to compress other things.
+#
+# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
+# of the kernel decompressor. A BCJ filter is used if it is available for
+# the target architecture. xzkern also appends uncompressed size of the data
+# using size_append. The .xz format has the size information available at
+# the end of the file too, but it's in more complex format and it's good to
+# avoid changing the part of the boot code that reads the uncompressed size.
+# Note that the bytes added by size_append will make the xz tool think that
+# the file is corrupt. This is expected.
+#
+# xzmisc doesn't use size_append, so it can be used to create normal .xz
+# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
+# big dictionary would increase the memory usage too much in the multi-call
+# decompression mode. A BCJ filter isn't used either.
+quiet_cmd_xzkern = XZKERN $@
+ cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
+ $(size_append); } > $@
+
+quiet_cmd_xzmisc = XZMISC $@
+ cmd_xzmisc = cat $(real-prereqs) | xz --check=crc32 --lzma2=dict=1MiB > $@
+
+# ASM offsets
+# ---------------------------------------------------------------------------
+
+# Default sed regexp - multiline due to syntax constraints
+#
+# Use [:space:] because LLVM's integrated assembler inserts <tab> around
+# the .ascii directive whereas GCC keeps the <space> as-is.
+define sed-offsets
+ 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
+ /^->/{s:->#\(.*\):/* \1 */:; \
+ s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
+ s:->::; p;}'
+endef
+
+# Use filechk to avoid rebuilds when a header changes, but the resulting file
+# does not
+define filechk_offsets
+ echo "#ifndef $2"; \
+ echo "#define $2"; \
+ echo "/*"; \
+ echo " * DO NOT MODIFY."; \
+ echo " *"; \
+ echo " * This file was generated by Kbuild"; \
+ echo " */"; \
+ echo ""; \
+ sed -ne $(sed-offsets) < $<; \
+ echo ""; \
+ echo "#endif"
+endef
diff --git a/xen/scripts/Makefile.ubsan b/xen/scripts/Makefile.ubsan
new file mode 100644
index 000000000000..019771b845c5
--- /dev/null
+++ b/xen/scripts/Makefile.ubsan
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0
+ifdef CONFIG_UBSAN
+ CFLAGS_UBSAN += $(call cc-option, -fsanitize=shift)
+ CFLAGS_UBSAN += $(call cc-option, -fsanitize=integer-divide-by-zero)
+ CFLAGS_UBSAN += $(call cc-option, -fsanitize=unreachable)
+ CFLAGS_UBSAN += $(call cc-option, -fsanitize=signed-integer-overflow)
+ CFLAGS_UBSAN += $(call cc-option, -fsanitize=bounds)
+ CFLAGS_UBSAN += $(call cc-option, -fsanitize=object-size)
+ CFLAGS_UBSAN += $(call cc-option, -fsanitize=bool)
+ CFLAGS_UBSAN += $(call cc-option, -fsanitize=enum)
+
+ifdef CONFIG_UBSAN_ALIGNMENT
+ CFLAGS_UBSAN += $(call cc-option, -fsanitize=alignment)
+endif
+
+ # -fsanitize=* options makes GCC less smart than usual and
+ # increase number of 'maybe-uninitialized false-positives
+ CFLAGS_UBSAN += $(call cc-option, -Wno-maybe-uninitialized)
+endif
diff --git a/xen/scripts/basic/.gitignore b/xen/scripts/basic/.gitignore
new file mode 100644
index 000000000000..a776371a3502
--- /dev/null
+++ b/xen/scripts/basic/.gitignore
@@ -0,0 +1 @@
+fixdep
diff --git a/xen/scripts/basic/Makefile b/xen/scripts/basic/Makefile
new file mode 100644
index 000000000000..548aeb592806
--- /dev/null
+++ b/xen/scripts/basic/Makefile
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+###
+# This Makefile lists the most basic programs used during the build process.
+# The programs listed herein are what are needed to do the basic stuff,
+# such as fix file dependencies.
+# This initial step is needed to avoid files to be recompiled
+# when kernel configuration changes (which is what happens when
+# .config is included by main Makefile.
+# ---------------------------------------------------------------------------
+# fixdep: Used to generate dependency information during build process
+
+hostprogs-y := fixdep
+always := $(hostprogs-y)
+
+# fixdep is needed to compile other host programs
+$(addprefix $(obj)/,$(filter-out fixdep,$(always))): $(obj)/fixdep
diff --git a/xen/scripts/basic/fixdep.c b/xen/scripts/basic/fixdep.c
new file mode 100644
index 000000000000..9ba47b0a47b9
--- /dev/null
+++ b/xen/scripts/basic/fixdep.c
@@ -0,0 +1,410 @@
+/*
+ * "Optimize" a list of dependencies as spit out by gcc -MD
+ * for the kernel build
+ * ===========================================================================
+ *
+ * Author Kai Germaschewski
+ * Copyright 2002 by Kai Germaschewski <kai.germaschewski@gmx.de>
+ *
+ * This software may be used and distributed according to the terms
+ * of the GNU General Public License, incorporated herein by reference.
+ *
+ *
+ * Introduction:
+ *
+ * gcc produces a very nice and correct list of dependencies which
+ * tells make when to remake a file.
+ *
+ * To use this list as-is however has the drawback that virtually
+ * every file in the kernel includes autoconf.h.
+ *
+ * If the user re-runs make *config, autoconf.h will be
+ * regenerated. make notices that and will rebuild every file which
+ * includes autoconf.h, i.e. basically all files. This is extremely
+ * annoying if the user just changed CONFIG_HIS_DRIVER from n to m.
+ *
+ * So we play the same trick that "mkdep" played before. We replace
+ * the dependency on autoconf.h by a dependency on every config
+ * option which is mentioned in any of the listed prerequisites.
+ *
+ * kconfig populates a tree in include/config/ with an empty file
+ * for each config symbol and when the configuration is updated
+ * the files representing changed config options are touched
+ * which then let make pick up the changes and the files that use
+ * the config symbols are rebuilt.
+ *
+ * So if the user changes his CONFIG_HIS_DRIVER option, only the objects
+ * which depend on "include/config/his/driver.h" will be rebuilt,
+ * so most likely only his driver ;-)
+ *
+ * The idea above dates, by the way, back to Michael E Chastain, AFAIK.
+ *
+ * So to get dependencies right, there are two issues:
+ * o if any of the files the compiler read changed, we need to rebuild
+ * o if the command line given to the compile the file changed, we
+ * better rebuild as well.
+ *
+ * The former is handled by using the -MD output, the later by saving
+ * the command line used to compile the old object and comparing it
+ * to the one we would now use.
+ *
+ * Again, also this idea is pretty old and has been discussed on
+ * kbuild-devel a long time ago. I don't have a sensibly working
+ * internet connection right now, so I rather don't mention names
+ * without double checking.
+ *
+ * This code here has been based partially based on mkdep.c, which
+ * says the following about its history:
+ *
+ * Copyright abandoned, Michael Chastain, <mailto:mec@shout.net>.
+ * This is a C version of syncdep.pl by Werner Almesberger.
+ *
+ *
+ * It is invoked as
+ *
+ * fixdep <depfile> <target> <cmdline>
+ *
+ * and will read the dependency file <depfile>
+ *
+ * The transformed dependency snipped is written to stdout.
+ *
+ * It first generates a line
+ *
+ * cmd_<target> = <cmdline>
+ *
+ * and then basically copies the .<target>.d file to stdout, in the
+ * process filtering out the dependency on autoconf.h and adding
+ * dependencies on include/config/my/option.h for every
+ * CONFIG_MY_OPTION encountered in any of the prerequisites.
+ *
+ * It will also filter out all the dependencies on *.ver. We need
+ * to make sure that the generated version checksum are globally up
+ * to date before even starting the recursive build, so it's too late
+ * at this point anyway.
+ *
+ * We don't even try to really parse the header files, but
+ * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will
+ * be picked up as well. It's not a problem with respect to
+ * correctness, since that can only give too many dependencies, thus
+ * we cannot miss a rebuild. Since people tend to not mention totally
+ * unrelated CONFIG_ options all over the place, it's not an
+ * efficiency problem either.
+ *
+ * (Note: it'd be easy to port over the complete mkdep state machine,
+ * but I don't think the added complexity is worth it)
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+
+static void usage(void)
+{
+ fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n");
+ exit(1);
+}
+
+/*
+ * In the intended usage of this program, the stdout is redirected to .*.cmd
+ * files. The return value of printf() and putchar() must be checked to catch
+ * any error, e.g. "No space left on device".
+ */
+static void xprintf(const char *format, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, format);
+ ret = vprintf(format, ap);
+ if (ret < 0) {
+ perror("fixdep");
+ exit(1);
+ }
+ va_end(ap);
+}
+
+static void xputchar(int c)
+{
+ int ret;
+
+ ret = putchar(c);
+ if (ret == EOF) {
+ perror("fixdep");
+ exit(1);
+ }
+}
+
+/*
+ * Print out a dependency path from a symbol name
+ */
+static void print_dep(const char *m, int slen, const char *dir)
+{
+ int c, prev_c = '/', i;
+
+ xprintf(" $(wildcard %s/", dir);
+ for (i = 0; i < slen; i++) {
+ c = m[i];
+ if (c == '_')
+ c = '/';
+ else
+ c = tolower(c);
+ if (c != '/' || prev_c != '/')
+ xputchar(c);
+ prev_c = c;
+ }
+ xprintf(".h) \\\n");
+}
+
+struct item {
+ struct item *next;
+ unsigned int len;
+ unsigned int hash;
+ char name[0];
+};
+
+#define HASHSZ 256
+static struct item *hashtab[HASHSZ];
+
+static unsigned int strhash(const char *str, unsigned int sz)
+{
+ /* fnv32 hash */
+ unsigned int i, hash = 2166136261U;
+
+ for (i = 0; i < sz; i++)
+ hash = (hash ^ str[i]) * 0x01000193;
+ return hash;
+}
+
+/*
+ * Lookup a value in the configuration string.
+ */
+static int is_defined_config(const char *name, int len, unsigned int hash)
+{
+ struct item *aux;
+
+ for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) {
+ if (aux->hash == hash && aux->len == len &&
+ memcmp(aux->name, name, len) == 0)
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Add a new value to the configuration string.
+ */
+static void define_config(const char *name, int len, unsigned int hash)
+{
+ struct item *aux = malloc(sizeof(*aux) + len);
+
+ if (!aux) {
+ perror("fixdep:malloc");
+ exit(1);
+ }
+ memcpy(aux->name, name, len);
+ aux->len = len;
+ aux->hash = hash;
+ aux->next = hashtab[hash % HASHSZ];
+ hashtab[hash % HASHSZ] = aux;
+}
+
+/*
+ * Record the use of a CONFIG_* word.
+ */
+static void use_config(const char *m, int slen)
+{
+ unsigned int hash = strhash(m, slen);
+
+ if (is_defined_config(m, slen, hash))
+ return;
+
+ define_config(m, slen, hash);
+ print_dep(m, slen, "include/config");
+}
+
+/* test if s ends in sub */
+static int str_ends_with(const char *s, int slen, const char *sub)
+{
+ int sublen = strlen(sub);
+
+ if (sublen > slen)
+ return 0;
+
+ return !memcmp(s + slen - sublen, sub, sublen);
+}
+
+static void parse_config_file(const char *p)
+{
+ const char *q, *r;
+ const char *start = p;
+
+ while ((p = strstr(p, "CONFIG_"))) {
+ if (p > start && (isalnum(p[-1]) || p[-1] == '_')) {
+ p += 7;
+ continue;
+ }
+ p += 7;
+ q = p;
+ while (*q && (isalnum(*q) || *q == '_'))
+ q++;
+ if (str_ends_with(p, q - p, "_MODULE"))
+ r = q - 7;
+ else
+ r = q;
+ if (r > p)
+ use_config(p, r - p);
+ p = q;
+ }
+}
+
+static void *read_file(const char *filename)
+{
+ struct stat st;
+ int fd;
+ char *buf;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "fixdep: error opening file: ");
+ perror(filename);
+ exit(2);
+ }
+ if (fstat(fd, &st) < 0) {
+ fprintf(stderr, "fixdep: error fstat'ing file: ");
+ perror(filename);
+ exit(2);
+ }
+ buf = malloc(st.st_size + 1);
+ if (!buf) {
+ perror("fixdep: malloc");
+ exit(2);
+ }
+ if (read(fd, buf, st.st_size) != st.st_size) {
+ perror("fixdep: read");
+ exit(2);
+ }
+ buf[st.st_size] = '\0';
+ close(fd);
+
+ return buf;
+}
+
+/* Ignore certain dependencies */
+static int is_ignored_file(const char *s, int len)
+{
+ return str_ends_with(s, len, "include/generated/autoconf.h") ||
+ str_ends_with(s, len, "include/generated/autoksyms.h") ||
+ str_ends_with(s, len, ".ver");
+}
+
+/*
+ * Important: The below generated source_foo.o and deps_foo.o variable
+ * assignments are parsed not only by make, but also by the rather simple
+ * parser in scripts/mod/sumversion.c.
+ */
+static void parse_dep_file(char *m, const char *target)
+{
+ char *p;
+ int is_last, is_target;
+ int saw_any_target = 0;
+ int is_first_dep = 0;
+ void *buf;
+
+ while (1) {
+ /* Skip any "white space" */
+ while (*m == ' ' || *m == '\\' || *m == '\n')
+ m++;
+
+ if (!*m)
+ break;
+
+ /* Find next "white space" */
+ p = m;
+ while (*p && *p != ' ' && *p != '\\' && *p != '\n')
+ p++;
+ is_last = (*p == '\0');
+ /* Is the token we found a target name? */
+ is_target = (*(p-1) == ':');
+ /* Don't write any target names into the dependency file */
+ if (is_target) {
+ /* The /next/ file is the first dependency */
+ is_first_dep = 1;
+ } else if (!is_ignored_file(m, p - m)) {
+ *p = '\0';
+
+ /*
+ * Do not list the source file as dependency, so that
+ * kbuild is not confused if a .c file is rewritten
+ * into .S or vice versa. Storing it in source_* is
+ * needed for modpost to compute srcversions.
+ */
+ if (is_first_dep) {
+ /*
+ * If processing the concatenation of multiple
+ * dependency files, only process the first
+ * target name, which will be the original
+ * source name, and ignore any other target
+ * names, which will be intermediate temporary
+ * files.
+ */
+ if (!saw_any_target) {
+ saw_any_target = 1;
+ xprintf("source_%s := %s\n\n",
+ target, m);
+ xprintf("deps_%s := \\\n", target);
+ }
+ is_first_dep = 0;
+ } else {
+ xprintf(" %s \\\n", m);
+ }
+
+ buf = read_file(m);
+ parse_config_file(buf);
+ free(buf);
+ }
+
+ if (is_last)
+ break;
+
+ /*
+ * Start searching for next token immediately after the first
+ * "whitespace" character that follows this token.
+ */
+ m = p + 1;
+ }
+
+ if (!saw_any_target) {
+ fprintf(stderr, "fixdep: parse error; no targets found\n");
+ exit(1);
+ }
+
+ xprintf("\n%s: $(deps_%s)\n\n", target, target);
+ xprintf("$(deps_%s):\n", target);
+}
+
+int main(int argc, char *argv[])
+{
+ const char *depfile, *target, *cmdline;
+ void *buf;
+
+ if (argc != 4)
+ usage();
+
+ depfile = argv[1];
+ target = argv[2];
+ cmdline = argv[3];
+
+ xprintf("cmd_%s := %s\n\n", target, cmdline);
+
+ buf = read_file(depfile);
+ parse_dep_file(buf, target);
+ free(buf);
+
+ return 0;
+}
diff --git a/xen/scripts/mkmakefile b/xen/scripts/mkmakefile
new file mode 100755
index 000000000000..4d0faebb1719
--- /dev/null
+++ b/xen/scripts/mkmakefile
@@ -0,0 +1,17 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# Generates a small Makefile used in the root of the output
+# directory, to allow make to be started from there.
+# The Makefile also allow for more convinient build of external modules
+
+# Usage
+# $1 - Kernel src directory
+
+if [ "${quiet}" != "silent_" ]; then
+ echo " GEN Makefile"
+fi
+
+cat << EOF > Makefile
+# Automatically generated by $(realpath $0): don't edit
+include $(realpath $1/Makefile)
+EOF
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 05/23] xen: Kbuild: Remove extra -include from C flags
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (2 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 04/23] build: Import Kbuild from Linux v5.3 Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 06/23] xen, Kbuild: filter-out -Wa, % from CFLAGS for %.i:%.c rules Anthony PERARD
` (17 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
Kbuild includes linux/compiler_types.h into the CFLAGS list, but Xen
don't need that.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/scripts/Makefile.lib | 1 -
1 file changed, 1 deletion(-)
diff --git a/xen/scripts/Makefile.lib b/xen/scripts/Makefile.lib
index 41c50f9461e5..b746199b7f6b 100644
--- a/xen/scripts/Makefile.lib
+++ b/xen/scripts/Makefile.lib
@@ -160,7 +160,6 @@ endif
endif
c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
- -include $(srctree)/include/linux/compiler_types.h \
$(_c_flags) $(modkern_cflags) \
$(basename_flags) $(modname_flags)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 06/23] xen, Kbuild: filter-out -Wa, % from CFLAGS for %.i:%.c rules
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (3 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 05/23] xen: Kbuild: Remove extra -include from C flags Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 07/23] xen, Kbuild: Handle obj-bin-y and %.init.o objects Anthony PERARD
` (16 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
As it is done currently in Rules.mk.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/scripts/Makefile.build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/xen/scripts/Makefile.build b/xen/scripts/Makefile.build
index 2f66ed388d1c..dd972d5b5edb 100644
--- a/xen/scripts/Makefile.build
+++ b/xen/scripts/Makefile.build
@@ -114,7 +114,7 @@ $(obj)/%.s: $(src)/%.c FORCE
$(call if_changed_dep,cc_s_c)
quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
-cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
+cmd_cpp_i_c = $(CPP) $(filter-out -Wa$(comma)%,$(c_flags)) -o $@ $<
$(obj)/%.i: $(src)/%.c FORCE
$(call if_changed_dep,cpp_i_c)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 07/23] xen, Kbuild: Handle obj-bin-y and %.init.o objects
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (4 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 06/23] xen, Kbuild: filter-out -Wa, % from CFLAGS for %.i:%.c rules Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 08/23] xen, Kbuild: Change filechk_offsets Anthony PERARD
` (15 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
SPECIAL_DATA_SECTIONS is put in Kbuild.include so it can be use in
kbuild makefiles.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/scripts/Kbuild.include | 10 ++++++++++
xen/scripts/Makefile.build | 24 ++++++++++++++++++++++++
xen/scripts/Makefile.lib | 7 +++++++
3 files changed, 41 insertions(+)
diff --git a/xen/scripts/Kbuild.include b/xen/scripts/Kbuild.include
index 4b0432e095ae..6f95a2519f3c 100644
--- a/xen/scripts/Kbuild.include
+++ b/xen/scripts/Kbuild.include
@@ -326,6 +326,16 @@ endef
#
###############################################################################
+# For building %.init.o files, can be used in kbuild makefiles
+SPECIAL_DATA_SECTIONS := rodata $(foreach a,1 2 4 8 16, \
+ $(foreach w,1 2 4, \
+ rodata.str$(w).$(a)) \
+ rodata.cst$(a)) \
+ $(foreach r,rel rel.ro,data.$(r).local)
+
+###############################################################################
+
+
# delete partially updated (i.e. corrupted) files on error
.DELETE_ON_ERROR:
diff --git a/xen/scripts/Makefile.build b/xen/scripts/Makefile.build
index dd972d5b5edb..68b504c9bdc5 100644
--- a/xen/scripts/Makefile.build
+++ b/xen/scripts/Makefile.build
@@ -384,6 +384,30 @@ $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
targets += $(extra-y) $(MAKECMDGOALS) $(always)
+# %.init.o objects
+# ----------------
+
+quiet_cmd_obj_init_o = INIT_OBJ $@
+define cmd_obj_init_o
+ set -e; \
+ $(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' | while read idx name sz rest; do \
+ case "$$name" in \
+ .*.local) ;; \
+ .text|.text.*|.data|.data.*|.bss) \
+ test $$sz != 0 || continue; \
+ echo "Error: size of $<:$$name is 0x$$sz" >&2; \
+ exit $$(expr $$idx + 1);; \
+ esac; \
+ done; \
+ $(OBJCOPY) $(foreach s,$(SPECIAL_DATA_SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@
+endef
+
+$(obj)/%.init.o: $(obj)/%.o FORCE
+ $(call if_changed,obj_init_o)
+
+# Add intermediates files into tagets
+targets += $(patsubst %.init.o,%.o,$(filter %.init.o,$(targets)))
+
# Linker scripts preprocessor (.lds.S -> .lds)
# ---------------------------------------------------------------------------
quiet_cmd_cpp_lds_S = LDS $@
diff --git a/xen/scripts/Makefile.lib b/xen/scripts/Makefile.lib
index b746199b7f6b..e022f053494e 100644
--- a/xen/scripts/Makefile.lib
+++ b/xen/scripts/Makefile.lib
@@ -16,6 +16,10 @@ KBUILD_CFLAGS += $(subdir-ccflags-y)
# only build the compiled-in version
obj-m := $(filter-out $(obj-y),$(obj-m))
+# For a non-LTO build, bundle obj-bin targets in with the normal objs.
+obj-y += $(obj-bin-y)
+obj-bin-y :=
+
# Libraries are always collected in one lib file.
# Filter out objects already built-in
lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
@@ -108,6 +112,9 @@ name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname))
+# See comment about INIT_SECTIONS_ONLY in include/xen/compiler.h
+$(filter %.init.o,$(real-obj-y) $(extra-y)): ccflags-y += -DINIT_SECTIONS_ONLY
+
orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
$(ccflags-y) $(CFLAGS_$(basetarget).o)
_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 08/23] xen, Kbuild: Change filechk_offsets
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (5 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 07/23] xen, Kbuild: Handle obj-bin-y and %.init.o objects Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 09/23] xen, Kbuild: Filter-out -Wa, in %.s:%.c rules Anthony PERARD
` (14 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
This functions will be use later to generate asm-offsets.h.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/scripts/Makefile.lib | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/xen/scripts/Makefile.lib b/xen/scripts/Makefile.lib
index e022f053494e..19641e836dc3 100644
--- a/xen/scripts/Makefile.lib
+++ b/xen/scripts/Makefile.lib
@@ -413,29 +413,26 @@ quiet_cmd_xzmisc = XZMISC $@
# ASM offsets
# ---------------------------------------------------------------------------
-# Default sed regexp - multiline due to syntax constraints
+# Default sed regexp
#
-# Use [:space:] because LLVM's integrated assembler inserts <tab> around
-# the .ascii directive whereas GCC keeps the <space> as-is.
define sed-offsets
- 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
- /^->/{s:->#\(.*\):/* \1 */:; \
- s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
- s:->::; p;}'
+ '/^[^#].*==>/{s:.*==>(.*)<==.*:\1:; s: [\$$#]: :; p;}'
endef
# Use filechk to avoid rebuilds when a header changes, but the resulting file
# does not
define filechk_offsets
- echo "#ifndef $2"; \
- echo "#define $2"; \
echo "/*"; \
echo " * DO NOT MODIFY."; \
echo " *"; \
- echo " * This file was generated by Kbuild"; \
+ echo " * This file was auto-generated from $<"; \
+ echo " *"; \
echo " */"; \
echo ""; \
- sed -ne $(sed-offsets) < $<; \
+ echo "#ifndef $2"; \
+ echo "#define $2"; \
+ echo ""; \
+ sed -rne $(sed-offsets) < $<; \
echo ""; \
echo "#endif"
endef
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 09/23] xen, Kbuild: Filter-out -Wa, in %.s:%.c rules
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (6 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 08/23] xen, Kbuild: Change filechk_offsets Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 10/23] xen,Kbuild: Handle __OBJECT_*__ Anthony PERARD
` (13 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
As it is done in the same rule in Rules.mk.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/scripts/Makefile.build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/xen/scripts/Makefile.build b/xen/scripts/Makefile.build
index 68b504c9bdc5..c8ef52220a61 100644
--- a/xen/scripts/Makefile.build
+++ b/xen/scripts/Makefile.build
@@ -108,7 +108,7 @@ modkern_cflags = \
quiet_modtag = $(if $(part-of-module),[M], )
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
- cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS), $(c_flags)) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
+ cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS) -Wa$(comma)%, $(c_flags)) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
$(obj)/%.s: $(src)/%.c FORCE
$(call if_changed_dep,cc_s_c)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 10/23] xen,Kbuild: Handle __OBJECT_*__
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (7 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 09/23] xen, Kbuild: Filter-out -Wa, in %.s:%.c rules Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 11/23] First conversion to kbuild makefiles Anthony PERARD
` (12 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
Define __OBJECT_FILE__ and __OBJECT_LABEL__ as it is done in
arch/x86/Rules.mk.
Those defines would also be created when doing an ARM build, when
Kbuild will be used to build xen.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/scripts/Makefile.lib | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/xen/scripts/Makefile.lib b/xen/scripts/Makefile.lib
index 19641e836dc3..7ba3cf034c98 100644
--- a/xen/scripts/Makefile.lib
+++ b/xen/scripts/Makefile.lib
@@ -97,20 +97,12 @@ real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
-# Finds the multi-part object the current object will be linked into.
-# If the object belongs to two or more multi-part objects, all of them are
-# concatenated with a colon separator.
-modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\
- $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))))
-
-modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
-
-# These flags are needed for modversions and compiling, so we define them here
-# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
-# end up in (or would, if it gets compiled in)
-name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
-basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
-modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname))
+object_file_flags = '-D__OBJECT_FILE__="$(subst $(obj)/,,$@)"'
+ifeq ($(findstring -DHAVE_AS_QUOTED_SYM,$(KBUILD_CFLAGS)),)
+object_file_flags += '-D__OBJECT_LABEL__=$(subst /,$$,$(subst -,_,$(@)))'
+else
+object_file_flags += '-D__OBJECT_LABEL__=$(subst -,_,$(@))'
+endif
# See comment about INIT_SECTIONS_ONLY in include/xen/compiler.h
$(filter %.init.o,$(real-obj-y) $(extra-y)): ccflags-y += -DINIT_SECTIONS_ONLY
@@ -168,13 +160,13 @@ endif
c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
$(_c_flags) $(modkern_cflags) \
- $(basename_flags) $(modname_flags)
+ $(object_file_flags)
a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
- $(_a_flags) $(modkern_aflags)
+ $(object_file_flags) $(_a_flags)
cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
- $(_cpp_flags)
+ $(object_file_flags) $(_cpp_flags)
ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 11/23] First conversion to kbuild makefiles
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (8 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 10/23] xen,Kbuild: Handle __OBJECT_*__ Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 12/23] Build guest_walk* in arch/x86/mm Anthony PERARD
` (11 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
Kbuild uses obj-y=subdir/ instead of subdir-y=subdir
Adding CFLAGS in a specific subdirectory is done via ccflags-y instead
of CFLAGS.
Done with sed:
sed -i -r 's#^subdir-(.*)#obj-\1/#; s#^CFLAGS #ccflags-y #' **/*/Makefile
---
xen/arch/arm/Makefile | 14 +++++++-------
xen/arch/arm/arm32/Makefile | 2 +-
xen/arch/arm/arm64/Makefile | 2 +-
xen/arch/arm/efi/Makefile | 2 +-
xen/arch/x86/Makefile | 18 +++++++++---------
xen/arch/x86/acpi/Makefile | 2 +-
xen/arch/x86/cpu/Makefile | 4 ++--
xen/arch/x86/efi/Makefile | 2 +-
xen/arch/x86/hvm/Makefile | 6 +++---
xen/arch/x86/mm/Makefile | 4 ++--
xen/arch/x86/x86_64/Makefile | 2 +-
xen/common/Makefile | 8 ++++----
xen/common/libelf/Makefile | 2 +-
xen/common/libfdt/Makefile | 2 +-
xen/drivers/Makefile | 14 +++++++-------
xen/drivers/acpi/Makefile | 6 +++---
xen/drivers/passthrough/Makefile | 8 ++++----
xen/drivers/passthrough/vtd/Makefile | 2 +-
xen/lib/Makefile | 2 +-
xen/xsm/Makefile | 2 +-
xen/xsm/flask/Makefile | 4 ++--
xen/xsm/flask/ss/Makefile | 2 +-
22 files changed, 55 insertions(+), 55 deletions(-)
diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 70f532e42a06..1044c2298a05 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -1,11 +1,11 @@
-subdir-$(CONFIG_ARM_32) += arm32
-subdir-$(CONFIG_ARM_64) += arm64
-subdir-$(CONFIG_ARM_64) += efi
-subdir-$(CONFIG_ACPI) += acpi
+obj-$(CONFIG_ARM_32) += arm32/
+obj-$(CONFIG_ARM_64) += arm64/
+obj-$(CONFIG_ARM_64) += efi/
+obj-$(CONFIG_ACPI) += acpi/
ifneq ($(CONFIG_NO_PLAT),y)
-subdir-y += platforms
+obj-y += platforms/
endif
-subdir-$(CONFIG_TEE) += tee
+obj-$(CONFIG_TEE) += tee/
obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.o
@@ -48,7 +48,7 @@ obj-y += sysctl.o
obj-y += time.o
obj-y += traps.o
obj-y += vcpreg.o
-subdir-$(CONFIG_NEW_VGIC) += vgic
+obj-$(CONFIG_NEW_VGIC) += vgic/
ifneq ($(CONFIG_NEW_VGIC),y)
obj-y += gic-vgic.o
obj-y += vgic.o
diff --git a/xen/arch/arm/arm32/Makefile b/xen/arch/arm/arm32/Makefile
index 0ac254f34714..539bbef298a7 100644
--- a/xen/arch/arm/arm32/Makefile
+++ b/xen/arch/arm/arm32/Makefile
@@ -1,4 +1,4 @@
-subdir-y += lib
+obj-y += lib/
obj-$(EARLY_PRINTK) += debug.o
obj-y += domctl.o
diff --git a/xen/arch/arm/arm64/Makefile b/xen/arch/arm/arm64/Makefile
index c4f3a28a0d0b..db8565b71a33 100644
--- a/xen/arch/arm/arm64/Makefile
+++ b/xen/arch/arm/arm64/Makefile
@@ -1,4 +1,4 @@
-subdir-y += lib
+obj-y += lib/
obj-y += cache.o
obj-$(CONFIG_HARDEN_BRANCH_PREDICTOR) += bpi.o
diff --git a/xen/arch/arm/efi/Makefile b/xen/arch/arm/efi/Makefile
index d34c9168914a..e4aaba3e074b 100644
--- a/xen/arch/arm/efi/Makefile
+++ b/xen/arch/arm/efi/Makefile
@@ -1,4 +1,4 @@
-CFLAGS += -fshort-wchar
+ccflags-y += -fshort-wchar
obj-y += boot.init.o runtime.o
obj-$(CONFIG_ACPI) += efi-dom0.init.o
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index af6c83dfbae6..864a0669bc9f 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -1,12 +1,12 @@
-subdir-y += acpi
-subdir-y += cpu
-subdir-y += genapic
-subdir-$(CONFIG_XEN_GUEST) += guest
-subdir-$(CONFIG_HVM) += hvm
-subdir-y += mm
-subdir-$(CONFIG_XENOPROF) += oprofile
-subdir-$(CONFIG_PV) += pv
-subdir-y += x86_64
+obj-y += acpi/
+obj-y += cpu/
+obj-y += genapic/
+obj-$(CONFIG_XEN_GUEST) += guest/
+obj-$(CONFIG_HVM) += hvm/
+obj-y += mm/
+obj-$(CONFIG_XENOPROF) += oprofile/
+obj-$(CONFIG_PV) += pv/
+obj-y += x86_64/
alternative-y := alternative.init.o
alternative-$(CONFIG_LIVEPATCH) :=
diff --git a/xen/arch/x86/acpi/Makefile b/xen/arch/x86/acpi/Makefile
index 27b4aa30b0ca..1b9e62571301 100644
--- a/xen/arch/x86/acpi/Makefile
+++ b/xen/arch/x86/acpi/Makefile
@@ -1,4 +1,4 @@
-subdir-y += cpufreq
+obj-y += cpufreq/
obj-y += lib.o power.o suspend.o cpu_idle.o cpuidle_menu.o
obj-bin-y += boot.init.o wakeup_prot.o
diff --git a/xen/arch/x86/cpu/Makefile b/xen/arch/x86/cpu/Makefile
index 466acc8b10e5..de983006a1b1 100644
--- a/xen/arch/x86/cpu/Makefile
+++ b/xen/arch/x86/cpu/Makefile
@@ -1,5 +1,5 @@
-subdir-y += mcheck
-subdir-y += mtrr
+obj-y += mcheck/
+obj-y += mtrr/
obj-y += amd.o
obj-y += centaur.o
diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile
index 4bc0a196e9ca..2cbb3de3a8ab 100644
--- a/xen/arch/x86/efi/Makefile
+++ b/xen/arch/x86/efi/Makefile
@@ -1,4 +1,4 @@
-CFLAGS += -fshort-wchar
+ccflags-y += -fshort-wchar
%.o: %.ihex
$(OBJCOPY) -I ihex -O binary $< $@
diff --git a/xen/arch/x86/hvm/Makefile b/xen/arch/x86/hvm/Makefile
index 43e5f3a21f8b..346419154460 100644
--- a/xen/arch/x86/hvm/Makefile
+++ b/xen/arch/x86/hvm/Makefile
@@ -1,6 +1,6 @@
-subdir-y += svm
-subdir-y += vmx
-subdir-y += viridian
+obj-y += svm/
+obj-y += vmx/
+obj-y += viridian/
obj-y += asid.o
obj-y += dm.o
diff --git a/xen/arch/x86/mm/Makefile b/xen/arch/x86/mm/Makefile
index 5010a29d6cb0..d87dc0aa6eeb 100644
--- a/xen/arch/x86/mm/Makefile
+++ b/xen/arch/x86/mm/Makefile
@@ -1,5 +1,5 @@
-subdir-y += shadow
-subdir-$(CONFIG_HVM) += hap
+obj-y += shadow/
+obj-$(CONFIG_HVM) += hap/
obj-$(CONFIG_HVM) += altp2m.o
obj-$(CONFIG_HVM) += guest_walk_2.o guest_walk_3.o guest_walk_4.o
diff --git a/xen/arch/x86/x86_64/Makefile b/xen/arch/x86/x86_64/Makefile
index 4bfa1480eb7e..2bb1eb0a8131 100644
--- a/xen/arch/x86/x86_64/Makefile
+++ b/xen/arch/x86/x86_64/Makefile
@@ -1,4 +1,4 @@
-subdir-$(CONFIG_PV) += compat
+obj-$(CONFIG_PV) += compat/
obj-bin-y += entry.o
obj-y += traps.o
diff --git a/xen/common/Makefile b/xen/common/Makefile
index 62b34e69e95c..d4db0a6d466a 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -73,8 +73,8 @@ obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o kernel.o memory.o multicall
extra-y := symbols-dummy.o
-subdir-$(CONFIG_COVERAGE) += coverage
-subdir-$(CONFIG_UBSAN) += ubsan
+obj-$(CONFIG_COVERAGE) += coverage/
+obj-$(CONFIG_UBSAN) += ubsan/
-subdir-$(CONFIG_NEEDS_LIBELF) += libelf
-subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt
+obj-$(CONFIG_NEEDS_LIBELF) += libelf/
+obj-$(CONFIG_HAS_DEVICE_TREE) += libfdt/
diff --git a/xen/common/libelf/Makefile b/xen/common/libelf/Makefile
index 3d9e38f27e65..9a433f01fbd4 100644
--- a/xen/common/libelf/Makefile
+++ b/xen/common/libelf/Makefile
@@ -3,7 +3,7 @@ nocov-y += libelf.o
SECTIONS := text data $(SPECIAL_DATA_SECTIONS)
-CFLAGS += -Wno-pointer-sign
+ccflags-y += -Wno-pointer-sign
libelf.o: libelf-temp.o Makefile
$(OBJCOPY) $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@
diff --git a/xen/common/libfdt/Makefile b/xen/common/libfdt/Makefile
index c075bbf5462a..9ea5c696d52a 100644
--- a/xen/common/libfdt/Makefile
+++ b/xen/common/libfdt/Makefile
@@ -5,7 +5,7 @@ SECTIONS := text data $(SPECIAL_DATA_SECTIONS)
obj-y += libfdt.o
nocov-y += libfdt.o
-CFLAGS += -I$(BASEDIR)/include/xen/libfdt/
+ccflags-y += -I$(BASEDIR)/include/xen/libfdt/
libfdt.o: libfdt-temp.o Makefile
$(OBJCOPY) $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@
diff --git a/xen/drivers/Makefile b/xen/drivers/Makefile
index 30bab3cfdb36..2a1ae8ad130a 100644
--- a/xen/drivers/Makefile
+++ b/xen/drivers/Makefile
@@ -1,7 +1,7 @@
-subdir-y += char
-subdir-$(CONFIG_HAS_CPUFREQ) += cpufreq
-subdir-$(CONFIG_HAS_PCI) += pci
-subdir-$(CONFIG_HAS_VPCI) += vpci
-subdir-$(CONFIG_HAS_PASSTHROUGH) += passthrough
-subdir-$(CONFIG_ACPI) += acpi
-subdir-$(CONFIG_VIDEO) += video
+obj-y += char/
+obj-$(CONFIG_HAS_CPUFREQ) += cpufreq/
+obj-$(CONFIG_HAS_PCI) += pci/
+obj-$(CONFIG_HAS_VPCI) += vpci/
+obj-$(CONFIG_HAS_PASSTHROUGH) += passthrough/
+obj-$(CONFIG_ACPI) += acpi/
+obj-$(CONFIG_VIDEO) += video/
diff --git a/xen/drivers/acpi/Makefile b/xen/drivers/acpi/Makefile
index 444b11d5839d..4f8e97228ee2 100644
--- a/xen/drivers/acpi/Makefile
+++ b/xen/drivers/acpi/Makefile
@@ -1,6 +1,6 @@
-subdir-y += tables
-subdir-y += utilities
-subdir-$(CONFIG_X86) += apei
+obj-y += tables/
+obj-y += utilities/
+obj-$(CONFIG_X86) += apei/
obj-bin-y += tables.init.o
obj-$(CONFIG_NUMA) += numa.o
diff --git a/xen/drivers/passthrough/Makefile b/xen/drivers/passthrough/Makefile
index d50ab188c83c..e973e16c7484 100644
--- a/xen/drivers/passthrough/Makefile
+++ b/xen/drivers/passthrough/Makefile
@@ -1,7 +1,7 @@
-subdir-$(CONFIG_X86) += vtd
-subdir-$(CONFIG_X86) += amd
-subdir-$(CONFIG_X86) += x86
-subdir-$(CONFIG_ARM) += arm
+obj-$(CONFIG_X86) += vtd/
+obj-$(CONFIG_X86) += amd/
+obj-$(CONFIG_X86) += x86/
+obj-$(CONFIG_ARM) += arm/
obj-y += iommu.o
obj-$(CONFIG_HAS_PCI) += pci.o
diff --git a/xen/drivers/passthrough/vtd/Makefile b/xen/drivers/passthrough/vtd/Makefile
index f302653858a0..fde7555fac07 100644
--- a/xen/drivers/passthrough/vtd/Makefile
+++ b/xen/drivers/passthrough/vtd/Makefile
@@ -1,4 +1,4 @@
-subdir-$(CONFIG_X86) += x86
+obj-$(CONFIG_X86) += x86/
obj-y += iommu.o
obj-y += dmar.o
diff --git a/xen/lib/Makefile b/xen/lib/Makefile
index dcdb75931378..7019ca00e8fd 100644
--- a/xen/lib/Makefile
+++ b/xen/lib/Makefile
@@ -1 +1 @@
-subdir-$(CONFIG_X86) += x86
+obj-$(CONFIG_X86) += x86/
diff --git a/xen/xsm/Makefile b/xen/xsm/Makefile
index e4d581e065f8..cf0a728f1c96 100644
--- a/xen/xsm/Makefile
+++ b/xen/xsm/Makefile
@@ -3,4 +3,4 @@ obj-$(CONFIG_XSM) += xsm_policy.o
obj-$(CONFIG_XSM) += dummy.o
obj-$(CONFIG_XSM_SILO) += silo.o
-subdir-$(CONFIG_XSM_FLASK) += flask
+obj-$(CONFIG_XSM_FLASK) += flask/
diff --git a/xen/xsm/flask/Makefile b/xen/xsm/flask/Makefile
index f5ffab12268c..b1fd96a6ccec 100644
--- a/xen/xsm/flask/Makefile
+++ b/xen/xsm/flask/Makefile
@@ -2,9 +2,9 @@ obj-y += avc.o
obj-y += hooks.o
obj-y += flask_op.o
-subdir-y += ss
+obj-y += ss/
-CFLAGS += -I./include
+ccflags-y += -I./include
AWK = awk
diff --git a/xen/xsm/flask/ss/Makefile b/xen/xsm/flask/ss/Makefile
index 046ce8f53326..30f910a9c9c1 100644
--- a/xen/xsm/flask/ss/Makefile
+++ b/xen/xsm/flask/ss/Makefile
@@ -8,4 +8,4 @@ obj-y += services.o
obj-y += conditional.o
obj-y += mls.o
-CFLAGS += -I../include
+ccflags-y += -I../include
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 12/23] Build guest_walk* in arch/x86/mm
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (9 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 11/23] First conversion to kbuild makefiles Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 13/23] convert common/libelf/Makefile to kbuild makefile Anthony PERARD
` (10 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
Rewrite the rules to build the different level of guest page walk so
the work and use Kbuild functions.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/arch/x86/mm/Makefile | 14 +++++++-------
xen/arch/x86/mm/hap/Makefile | 14 +++++++-------
xen/arch/x86/mm/shadow/Makefile | 14 +++++++-------
3 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/xen/arch/x86/mm/Makefile b/xen/arch/x86/mm/Makefile
index d87dc0aa6eeb..9c6d14c2fabb 100644
--- a/xen/arch/x86/mm/Makefile
+++ b/xen/arch/x86/mm/Makefile
@@ -11,11 +11,11 @@ obj-y += p2m.o p2m-pt.o
obj-$(CONFIG_HVM) += p2m-ept.o p2m-pod.o
obj-y += paging.o
-guest_walk_%.o: guest_walk.c Makefile
- $(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
+$(foreach sfx,o i s,$(obj)/guest_walk_%.$(sfx)): ccflags-y = -DGUEST_PAGING_LEVELS=$*
-guest_walk_%.i: guest_walk.c Makefile
- $(CPP) $(filter-out -Wa$(comma)%,$(CFLAGS)) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
-
-guest_walk_%.s: guest_walk.c Makefile
- $(CC) $(filter-out -Wa$(comma)%,$(CFLAGS)) -DGUEST_PAGING_LEVELS=$* -S $< -o $@
+$(obj)/guest_walk_%.o: $(src)/guest_walk.c FORCE
+ $(call if_changed_dep,cc_o_c)
+$(obj)/guest_walk_%.i: $(src)/guest_walk.c FORCE
+ $(call if_changed_dep,cpp_i_c)
+$(obj)/guest_walk_%.s: $(src)/guest_walk.c FORCE
+ $(call if_changed_dep,cc_s_c)
diff --git a/xen/arch/x86/mm/hap/Makefile b/xen/arch/x86/mm/hap/Makefile
index b14a9aff93d2..a0da2bfe77e6 100644
--- a/xen/arch/x86/mm/hap/Makefile
+++ b/xen/arch/x86/mm/hap/Makefile
@@ -5,11 +5,11 @@ obj-y += guest_walk_4level.o
obj-y += nested_hap.o
obj-y += nested_ept.o
-guest_walk_%level.o: guest_walk.c Makefile
- $(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
+$(foreach sfx,o i s,$(obj)/guest_walk_%level.$(sfx)): ccflags-y = -DGUEST_PAGING_LEVELS=$*
-guest_walk_%level.i: guest_walk.c Makefile
- $(CPP) $(filter-out -Wa$(comma)%,$(CFLAGS)) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
-
-guest_walk_%level.s: guest_walk.c Makefile
- $(CC) $(filter-out -Wa$(comma)%,$(CFLAGS)) -DGUEST_PAGING_LEVELS=$* -S $< -o $@
+$(obj)/guest_walk_%level.o: $(src)/guest_walk.c FORCE
+ $(call if_changed_dep,cc_o_c)
+$(obj)/guest_walk_%level.i: $(src)/guest_walk.c FORCE
+ $(call if_changed_dep,cpp_i_c)
+$(obj)/guest_walk_%level.s: $(src)/guest_walk.c FORCE
+ $(call if_changed_dep,cc_s_c)
diff --git a/xen/arch/x86/mm/shadow/Makefile b/xen/arch/x86/mm/shadow/Makefile
index ff03a9937f9b..8c264fab7fda 100644
--- a/xen/arch/x86/mm/shadow/Makefile
+++ b/xen/arch/x86/mm/shadow/Makefile
@@ -6,11 +6,11 @@ else
obj-y += none.o
endif
-guest_%.o: multi.c Makefile
- $(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
+$(foreach sfx,o i s,$(obj)/guest_%.$(sfx)): ccflags-y = -DGUEST_PAGING_LEVELS=$*
-guest_%.i: multi.c Makefile
- $(CPP) $(filter-out -Wa$(comma)%,$(CFLAGS)) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
-
-guest_%.s: multi.c Makefile
- $(CC) $(filter-out -Wa$(comma)%,$(CFLAGS)) -DGUEST_PAGING_LEVELS=$* -S $< -o $@
+$(obj)/guest_%.o: $(src)/multi.c FORCE
+ $(call if_changed_dep,cc_o_c)
+$(obj)/guest_%.i: $(src)/multi.c FORCE
+ $(call if_changed_dep,cpp_i_c)
+$(obj)/guest_%.s: $(src)/multi.c FORCE
+ $(call if_changed_dep,cc_s_c)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 13/23] convert common/libelf/Makefile to kbuild makefile
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (10 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 12/23] Build guest_walk* in arch/x86/mm Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 14/23] convert common/libfdt " Anthony PERARD
` (9 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
Use existing command line of objcopy and ld instead of writing new one
and simply edit the flags.
`targets' is to let know kbuild that other files beside the one
declared in obj-bin-y will be built.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
xen/common/libelf/Makefile | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/xen/common/libelf/Makefile b/xen/common/libelf/Makefile
index 9a433f01fbd4..2be9ea82b241 100644
--- a/xen/common/libelf/Makefile
+++ b/xen/common/libelf/Makefile
@@ -4,9 +4,14 @@ nocov-y += libelf.o
SECTIONS := text data $(SPECIAL_DATA_SECTIONS)
ccflags-y += -Wno-pointer-sign
+ldflags-y += -r
+OBJCOPYFLAGS += $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s))
-libelf.o: libelf-temp.o Makefile
- $(OBJCOPY) $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@
+libelf-temp-objs := libelf-tools.o libelf-loader.o libelf-dominfo.o #libelf-relocate.o
+targets += $(libelf-temp-objs) libelf-temp.o
-libelf-temp.o: libelf-tools.o libelf-loader.o libelf-dominfo.o #libelf-relocate.o
- $(LD) $(LDFLAGS) -r -o $@ $^
+$(obj)/libelf.o: $(obj)/libelf-temp.o FORCE
+ $(call if_changed,objcopy)
+
+$(obj)/libelf-temp.o: $(addprefix $(obj)/,$(libelf-temp-objs)) FORCE
+ $(call if_changed,ld)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 14/23] convert common/libfdt to kbuild makefile
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (11 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 13/23] convert common/libelf/Makefile to kbuild makefile Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 15/23] convert tools/Makefile to kbuild Anthony PERARD
` (8 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
UNTESTED
---
xen/common/libfdt/Makefile | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/xen/common/libfdt/Makefile b/xen/common/libfdt/Makefile
index 9ea5c696d52a..a233d82b15ee 100644
--- a/xen/common/libfdt/Makefile
+++ b/xen/common/libfdt/Makefile
@@ -1,14 +1,16 @@
-include Makefile.libfdt
+include $(srctree)/$(src)/Makefile.libfdt
SECTIONS := text data $(SPECIAL_DATA_SECTIONS)
obj-y += libfdt.o
nocov-y += libfdt.o
-ccflags-y += -I$(BASEDIR)/include/xen/libfdt/
+ccflags-y += -I$(srctree)/include/xen/libfdt/
+ldflags-y += -r
+OBJCOPYFLAGS += $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s))
-libfdt.o: libfdt-temp.o Makefile
- $(OBJCOPY) $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@
+$(obj)/libfdt.o: $(obj)/libfdt-temp.o FORCE
+ $(call if_changed,objcopy)
-libfdt-temp.o: $(LIBFDT_OBJS)
- $(LD) $(LDFLAGS) -r -o $@ $^
+$(obj)/libfdt-temp.o: $(addprefix $(obj)/,$(LIBFDT_OBJS)) FORCE
+ $(call if_changed,ld)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 15/23] convert tools/Makefile to kbuild
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (12 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 14/23] convert common/libfdt " Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 16/23] convert include/Makefile to Kbuild Anthony PERARD
` (7 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
---
xen/tools/Makefile | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/xen/tools/Makefile b/xen/tools/Makefile
index e940939d61f4..b43f62592019 100644
--- a/xen/tools/Makefile
+++ b/xen/tools/Makefile
@@ -1,13 +1,2 @@
-
-include $(XEN_ROOT)/Config.mk
-
-.PHONY: default
-default:
- $(MAKE) symbols
-
-.PHONY: clean
-clean:
- rm -f *.o symbols
-
-symbols: symbols.c
- $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
+hostprogs-y += symbols
+always += $(hostprogs-y)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 16/23] convert include/Makefile to Kbuild
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (13 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 15/23] convert tools/Makefile to kbuild Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 17/23] convert arch/x86/boot/Makefile to kbuild Anthony PERARD
` (6 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
---
xen/include/Makefile | 125 ++++++++++++++++++++++++++++---------------
1 file changed, 82 insertions(+), 43 deletions(-)
diff --git a/xen/include/Makefile b/xen/include/Makefile
index c3e0283d347f..56eb9b7f4540 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -1,5 +1,3 @@
-include $(XEN_ROOT)/Config.mk
-
ifneq ($(CONFIG_COMPAT),)
compat-arch-$(CONFIG_X86) := x86_32
@@ -46,67 +44,96 @@ endif
endif
-public-$(CONFIG_X86) := $(wildcard public/arch-x86/*.h public/arch-x86/*/*.h)
-public-$(CONFIG_ARM) := $(wildcard public/arch-arm/*.h public/arch-arm/*/*.h)
+public-$(CONFIG_X86) := $(wildcard $(srctree)/$(src)/public/arch-x86/*.h $(srctree)/$(src)/public/arch-x86/*/*.h)
+public-$(CONFIG_ARM) := $(wildcard $(srctree)/$(src)/public/arch-arm/*.h $(srctree)/$(src)/public/arch-arm/*/*.h)
+
+all: $(addprefix $(obj)/,$(headers-y))
-.PHONY: all
-all: $(headers-y)
+$(obj)/compat/%.h: $(obj)/compat/%.i $(srctree)/tools/compat-build-header.py FORCE
+ $(call if_changed,compat_header)
-compat/%.h: compat/%.i Makefile $(BASEDIR)/tools/compat-build-header.py
- set -e; id=_$$(echo $@ | tr '[:lower:]-/.' '[:upper:]___'); \
+quiet_cmd_compat_header = COMPAT-H $@
+define cmd_compat_header
+ set -e; id=_$$(echo $(patsubst $(obj)/%,%,$(@)) | tr '[:lower:]-/.' '[:upper:]___'); \
echo "#ifndef $$id" >$@.new; \
echo "#define $$id" >>$@.new; \
echo "#include <xen/compat.h>" >>$@.new; \
- $(if $(filter-out compat/arch-%.h,$@),echo "#include <$(patsubst compat/%,public/%,$@)>" >>$@.new;) \
+ $(if $(filter-out $(obj)/compat/arch-%.h,$@),echo "#include <$(patsubst $(obj)/compat/%,public/%,$@)>" >>$@.new;) \
$(if $(prefix-y),echo "$(prefix-y)" >>$@.new;) \
grep -v '^# [0-9]' $< | \
- $(PYTHON) $(BASEDIR)/tools/compat-build-header.py | uniq >>$@.new; \
+ (cd $(srctree)/$(src); $(PYTHON) $(abs_srctree)/tools/compat-build-header.py) | uniq >>$@.new; \
$(if $(suffix-y),echo "$(suffix-y)" >>$@.new;) \
- echo "#endif /* $$id */" >>$@.new
+ echo "#endif /* $$id */" >>$@.new; \
mv -f $@.new $@
+endef
+
+$(obj)/compat/%.i: $(obj)/compat/%.c FORCE
+ $(call if_changed,compat_i_c)
+
+quiet_cmd_compat_i_c = CPP $@
+ cmd_compat_i_c = $(CPP) $(filter-out -Wa$(comma)% -include %/include/xen/config.h,$(KBUILD_CFLAGS)) $(cppflags-y) -o $@ $<
-compat/%.i: compat/%.c Makefile
- $(CPP) $(filter-out -Wa$(comma)% -M% %.d -include %/include/xen/config.h,$(CFLAGS)) $(cppflags-y) -o $@ $<
+$(obj)/compat/%.c: $(src)/public/%.h $(src)/xlat.lst $(srctree)/tools/compat-build-source.py FORCE
+ $(call if_changed,compat_source)
-compat/%.c: public/%.h xlat.lst Makefile $(BASEDIR)/tools/compat-build-source.py
- mkdir -p $(@D)
+quiet_cmd_compat_source = COMPAT-C $@
+define cmd_compat_source
+ set -e; \
+ mkdir -p $(@D); \
grep -v 'DEFINE_XEN_GUEST_HANDLE(long)' $< | \
- $(PYTHON) $(BASEDIR)/tools/compat-build-source.py >$@.new
+ (cd $(srctree)/$(src); $(PYTHON) $(abs_srctree)/tools/compat-build-source.py) >$@.new; \
mv -f $@.new $@
+endef
-compat/.xlat/%.h: compat/%.h compat/.xlat/%.lst $(BASEDIR)/tools/get-fields.sh Makefile
- export PYTHON=$(PYTHON); \
+$(obj)/compat/.xlat/%.h: $(obj)/compat/%.h $(obj)/compat/.xlat/%.lst $(srctree)/tools/get-fields.sh FORCE
+ $(call if_changed,sub_xlat_h)
+
+quiet_cmd_sub_xlat_h = SUBXLAT $@
+define cmd_sub_xlat_h
+ set -e; \
while read what name; do \
- $(SHELL) $(BASEDIR)/tools/get-fields.sh "$$what" compat_$$name $< || exit $$?; \
- done <$(patsubst compat/%,compat/.xlat/%,$(basename $<)).lst >$@.new
+ $(SHELL) $(srctree)/tools/get-fields.sh "$$what" compat_$$name $< || exit $$?; \
+ done <$(patsubst $(obj)/compat/%,$(obj)/compat/.xlat/%,$(basename $<)).lst >$@.new; \
mv -f $@.new $@
+endef
+
+$(obj)/compat/.xlat/%.lst: $(src)/xlat.lst $(src)/Makefile
+ $(call filechk,xlat_lst)
-.PRECIOUS: compat/.xlat/%.lst
-compat/.xlat/%.lst: xlat.lst Makefile
- mkdir -p $(@D)
- grep -v '^[[:blank:]]*#' $< | sed -ne 's,@arch@,$(compat-arch-y),g' -re 's,[[:blank:]]+$*\.h[[:blank:]]*$$,,p' >$@.new
- $(call move-if-changed,$@.new,$@)
+define filechk_xlat_lst
+ grep -v '^[[:blank:]]*#' $< | sed -ne 's,@arch@,$(compat-arch-y),g' -re 's,[[:blank:]]+$*\.h[[:blank:]]*$$,,p'
+endef
-xlat-y := $(shell sed -ne 's,@arch@,$(compat-arch-y),g' -re 's,^[?!][[:blank:]]+[^[:blank:]]+[[:blank:]]+,,p' xlat.lst | uniq)
+xlat-y := $(shell sed -ne 's,@arch@,$(compat-arch-y),g' -re 's,^[?!][[:blank:]]+[^[:blank:]]+[[:blank:]]+,,p' $(srctree)/$(src)/xlat.lst | uniq)
xlat-y := $(filter $(patsubst compat/%,%,$(headers-y)),$(xlat-y))
-compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile
- cat $(filter %.h,$^) >$@.new
+$(obj)/compat/xlat.h: $(addprefix $(obj)/compat/.xlat/,$(xlat-y))
+ $(call if_changed,xlat_h)
+
+quiet_cmd_xlat_h = UPD $@
+define cmd_xlat_h
+ set -e; \
+ cat $(filter %.h,$^) >$@.new; \
mv -f $@.new $@
+endef
ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH))
-all: headers.chk headers99.chk headers++.chk
+all: $(obj)/headers.chk $(obj)/headers99.chk $(obj)/headers++.chk
-PUBLIC_HEADERS := $(filter-out public/arch-% public/dom0_ops.h, $(wildcard public/*.h public/*/*.h) $(public-y))
+PUBLIC_HEADERS := $(filter-out $(srctree)/$(src)/public/arch-% $(srctree)/$(src)/public/dom0_ops.h, $(wildcard $(srctree)/$(src)/public/*.h $(srctree)/$(src)/public/*/*.h) $(public-y))
-PUBLIC_C99_HEADERS := public/io/9pfs.h public/io/pvcalls.h
-PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/% public/%hvm/save.h $(PUBLIC_C99_HEADERS), $(PUBLIC_HEADERS))
+PUBLIC_C99_HEADERS := $(srctree)/$(src)/public/io/9pfs.h $(srctree)/$(src)/public/io/pvcalls.h
+PUBLIC_ANSI_HEADERS := $(filter-out $(srctree)/$(src)/public/%ctl.h $(srctree)/$(src)/public/xsm/% $(srctree)/$(src)/public/%hvm/save.h $(PUBLIC_C99_HEADERS), $(PUBLIC_HEADERS))
-public/io/9pfs.h-prereq := string
-public/io/pvcalls.h-prereq := string
+# XXX for in tree build
+$(src)/public/io/9pfs.h-prereq := string
+$(src)/public/io/pvcalls.h-prereq := string
+# XXX for out of tree build
+$(srctree)/$(src)/public/io/9pfs.h-prereq := string
+$(srctree)/$(src)/public/io/pvcalls.h-prereq := string
-headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile
+$(obj)/headers.chk: $(PUBLIC_ANSI_HEADERS) $(src)/Makefile
for i in $(filter %.h,$^); do \
$(CC) -x c -ansi -Wall -Werror -include stdint.h \
-S -o /dev/null $$i || exit 1; \
@@ -114,7 +141,7 @@ headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile
done >$@.new
mv $@.new $@
-headers99.chk: $(PUBLIC_C99_HEADERS) Makefile
+$(obj)/headers99.chk: $(PUBLIC_C99_HEADERS) $(src)/Makefile
rm -f $@.new
$(foreach i, $(filter %.h,$^), \
echo "#include "\"$(i)\" \
@@ -124,7 +151,7 @@ headers99.chk: $(PUBLIC_C99_HEADERS) Makefile
|| exit $$?; echo $(i) >> $@.new;)
mv $@.new $@
-headers++.chk: $(PUBLIC_HEADERS) Makefile
+$(obj)/headers++.chk: $(PUBLIC_HEADERS) $(src)/Makefile
rm -f $@.new
if ! $(CXX) -v >/dev/null 2>&1; then \
touch $@.new; \
@@ -133,21 +160,33 @@ headers++.chk: $(PUBLIC_HEADERS) Makefile
$(foreach i, $(filter %.h,$^), \
echo "#include "\"$(i)\" \
| $(CXX) -x c++ -std=gnu++98 -Wall -Werror -D__XEN_TOOLS__ \
- -include stdint.h -include public/xen.h \
+ -include stdint.h -include $(srctree)/$(src)/public/xen.h \
$(foreach j, $($(i)-prereq), -include c$(j)) -S -o /dev/null - \
|| exit $$?; echo $(i) >> $@.new;)
mv $@.new $@
endif
-ifeq ($(XEN_TARGET_ARCH),x86_64)
+ifeq ($(ARCH),x86_64)
.PHONY: lib-x86-all
lib-x86-all:
- $(MAKE) -C xen/lib/x86 all
+ $(Q)$(MAKE) XEN_ROOT=$(abs_srctree)/.. -C $(srctree)/$(src)/xen/lib/x86 all
all: lib-x86-all
endif
-clean::
- rm -rf compat config generated headers*.chk
- rm -f $(BASEDIR)/include/xen/lib/x86/cpuid-autogen.h
+# Update targets to help Kbuild finding which dependency file to load.
+targets += $(headers-y)
+# Adding intermediate targets
+targets += $(foreach h, $(headers-y), \
+ $(h:.h=.i) $(h:.h=.c))
+# Adding intermediate targets of xlat.h
+targets += $(addprefix compat/.xlat/,$(xlat-y))
+
+clean-dirs += compat config generated
+clean-files += headers*.chk
+clean-files += xen/lib/x86/cpuid-autogen.h
+
+PHONY += all
+all:
+ @:
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 17/23] convert arch/x86/boot/Makefile to kbuild
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (14 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 16/23] convert include/Makefile to Kbuild Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 18/23] arch/x86: Start moving build targets out of Makefile into Kbuild Anthony PERARD
` (5 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
Sources of *FLAGS for 32bit build:
- Config.mk
- config/x86_32.mk
- deleted build32.mk
---
xen/arch/x86/boot/Makefile | 72 +++++++++++++++++++++++++++++-------
xen/arch/x86/boot/build32.mk | 40 --------------------
2 files changed, 58 insertions(+), 54 deletions(-)
delete mode 100644 xen/arch/x86/boot/build32.mk
diff --git a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile
index 9b31bfcbfb8a..fe6344aa0022 100644
--- a/xen/arch/x86/boot/Makefile
+++ b/xen/arch/x86/boot/Makefile
@@ -1,20 +1,64 @@
-obj-bin-y += head.o
+# Add -Iinclude so cc-option calls can work properly. (The current CFLAGS want
+# to include a header which includes <generated/autoconf.h>)
+KBUILD_CFLAGS += $(LINUXINCLUDE)
+# Prepare CFLAGS to have 32bit build for the deps of head.S
+CFLAGS_S_c := -m32 -march=i686
+CFLAGS_S_c += -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
+CFLAGS_S_c += $(call cc-option,-Wdeclaration-after-statement)
+CFLAGS_S_c += $(call cc-disable-warning,unused-but-set-variable)
+CFLAGS_S_c += $(call cc-disable-warning,unused-local-typedefs)
-DEFS_H_DEPS = defs.h $(BASEDIR)/include/xen/stdbool.h
+EMBEDDED_EXTRA_CFLAGS := -nopie -fno-stack-protector -fno-stack-protector-all
+EMBEDDED_EXTRA_CFLAGS += -fno-exceptions
+CFLAGS_S_c += $(foreach o,$(EMBEDDED_EXTRA_CFLAGS),$(call cc-option,$(o)))
+CFLAGS_S_c += -Werror -fno-asynchronous-unwind-tables -fno-builtin -g0 -msoft-float
+CFLAGS_S_c := $(filter-out -flto,$(CFLAGS_S_c))
+CFLAGS_S_c += -fpic
+LDFLAGS_emulation_OpenBSD := _obsd
+LDFLAGS_emulation_FreeBSD := _fbsd
+LDFLAGS_S_c := -melf_i386$(LDFLAGS_emulation_$(XEN_OS)) -N -T $(srctree)/$(src)/build32.lds
-CMDLINE_DEPS = $(DEFS_H_DEPS) video.h
+head-deps := cmdline.S reloc.S
+targets += $(foreach o,$(head-deps), \
+ $(foreach sfx,o lnk bin S, \
+ $(patsubst %.S,%.$(sfx),$(o))))
-RELOC_DEPS = $(DEFS_H_DEPS) \
- $(BASEDIR)/include/generated/autoconf.h \
- $(BASEDIR)/include/xen/kconfig.h \
- $(BASEDIR)/include/xen/multiboot.h \
- $(BASEDIR)/include/xen/multiboot2.h \
- $(BASEDIR)/include/public/arch-x86/hvm/start_info.h
+$(addprefix $(obj)/,$(head-deps:.S=.o)): KBUILD_CFLAGS := $(CFLAGS_S_c)
+$(addprefix $(obj)/,$(head-deps:.S=.lnk)): KBUILD_LDFLAGS := $(LDFLAGS_S_c)
-head.o: cmdline.S reloc.S
+$(obj)/head.o: $(addprefix $(obj)/,$(head-deps))
+obj-y := head.o
-cmdline.S: cmdline.c $(CMDLINE_DEPS)
- $(MAKE) -f build32.mk $@ CMDLINE_DEPS="$(CMDLINE_DEPS)"
+# NB. awk invocation is a portable alternative to 'head -n -1'
+quiet_cmd_sed_S_bin = UPD $@
+define cmd_sed_S_bin
+ (od -v -t x $< | tr -s ' ' | awk 'NR > 1 {print s} {s=$$0}' | \
+ sed 's/ /,0x/g' | sed 's/,0x$$//' | sed 's/^[0-9]*,/ .long /') >$@
+endef
+$(addprefix $(obj)/,cmdline.S reloc.S): $(obj)/%.S: $(obj)/%.bin FORCE
+ $(call if_changed,sed_S_bin)
-reloc.S: reloc.c $(RELOC_DEPS)
- $(MAKE) -f build32.mk $@ RELOC_DEPS="$(RELOC_DEPS)"
+# Drop .got.plt during conversion to plain binary format.
+# Please check build32.lds for more details.
+quiet_cmd_check_obj_got_plt = CHECK $@
+define cmd_check_obj_got_plt
+ set -e; \
+ $(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' | \
+ while read idx name sz rest; do \
+ case "$$name" in \
+ .got.plt) \
+ test $$sz != 0c || continue; \
+ echo "Error: non-empty $$name: 0x$$sz" >&2; \
+ exit $$(expr $$idx + 1);; \
+ esac; \
+ done
+endef
+quiet_cmd_check_obj_drop_got_plt = OBJCOPY $@
+cmd_check_obj_drop_got_plt = $(cmd_check_obj_got_plt); $(cmd_objcopy)
+
+OBJCOPYFLAGS := -O binary -R .got.plt
+$(obj)/%.bin: $(obj)/%.lnk FORCE
+ $(call if_changed,check_obj_drop_got_plt)
+
+$(obj)/%.lnk: $(obj)/%.o FORCE
+ $(call if_changed,ld)
diff --git a/xen/arch/x86/boot/build32.mk b/xen/arch/x86/boot/build32.mk
deleted file mode 100644
index 48c7407c002f..000000000000
--- a/xen/arch/x86/boot/build32.mk
+++ /dev/null
@@ -1,40 +0,0 @@
-override XEN_TARGET_ARCH=x86_32
-CFLAGS =
-include $(XEN_ROOT)/Config.mk
-
-$(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS))
-
-CFLAGS += -Werror -fno-asynchronous-unwind-tables -fno-builtin -g0 -msoft-float
-CFLAGS += -I$(XEN_ROOT)/xen/include
-CFLAGS := $(filter-out -flto,$(CFLAGS))
-
-# NB. awk invocation is a portable alternative to 'head -n -1'
-%.S: %.bin
- (od -v -t x $< | tr -s ' ' | awk 'NR > 1 {print s} {s=$$0}' | \
- sed 's/ /,0x/g' | sed 's/,0x$$//' | sed 's/^[0-9]*,/ .long /') >$@
-
-# Drop .got.plt during conversion to plain binary format.
-# Please check build32.lds for more details.
-%.bin: %.lnk
- $(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' | \
- while read idx name sz rest; do \
- case "$$name" in \
- .got.plt) \
- test $$sz != 0c || continue; \
- echo "Error: non-empty $$name: 0x$$sz" >&2; \
- exit $$(expr $$idx + 1);; \
- esac; \
- done
- $(OBJCOPY) -O binary -R .got.plt $< $@
-
-%.lnk: %.o
- $(LD) $(LDFLAGS_DIRECT) -N -T build32.lds -o $@ $<
-
-%.o: %.c
- $(CC) $(CFLAGS) -c -fpic $< -o $@
-
-cmdline.o: cmdline.c $(CMDLINE_DEPS)
-
-reloc.o: reloc.c $(RELOC_DEPS)
-
-.PRECIOUS: %.bin %.lnk
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 18/23] arch/x86: Start moving build targets out of Makefile into Kbuild.
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (15 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 17/23] convert arch/x86/boot/Makefile to kbuild Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 19/23] update *FLAGS for arch/x86/Makefile Anthony PERARD
` (4 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
arch/*/Makefile will be included by the root makefile, its job will
mosty be to generate the *FLAGS for this arch.
arch/*/Kbuild will be used by recursive make, to build *.o and
others.
---
xen/arch/x86/Kbuild | 153 ++++++++++++++++++++++++++++++++++++++++++
xen/arch/x86/Makefile | 148 ----------------------------------------
2 files changed, 153 insertions(+), 148 deletions(-)
create mode 100644 xen/arch/x86/Kbuild
diff --git a/xen/arch/x86/Kbuild b/xen/arch/x86/Kbuild
new file mode 100644
index 000000000000..5cad96bed111
--- /dev/null
+++ b/xen/arch/x86/Kbuild
@@ -0,0 +1,153 @@
+obj-y += acpi/
+obj-y += cpu/
+obj-y += genapic/
+obj-$(CONFIG_XEN_GUEST) += guest/
+obj-$(CONFIG_HVM) += hvm/
+obj-y += mm/
+obj-$(CONFIG_XENOPROF) += oprofile/
+obj-$(CONFIG_PV) += pv/
+obj-y += x86_64/
+
+alternative-y := alternative.init.o
+alternative-$(CONFIG_LIVEPATCH) :=
+obj-bin-y += $(alternative-y)
+obj-y += apic.o
+obj-y += bitops.o
+obj-bin-y += bzimage.init.o
+obj-bin-y += clear_page.o
+obj-bin-y += copy_page.o
+obj-y += cpuid.o
+obj-$(CONFIG_PV) += compat.o x86_64/compat.o
+obj-$(CONFIG_KEXEC) += crash.o
+obj-y += debug.o
+obj-y += delay.o
+obj-y += desc.o
+obj-bin-y += dmi_scan.init.o
+obj-y += domctl.o
+obj-y += domain.o
+obj-bin-y += dom0_build.init.o
+obj-y += domain_page.o
+obj-y += e820.o
+obj-y += emul-i8254.o
+obj-y += extable.o
+obj-y += flushtlb.o
+obj-$(CONFIG_CRASH_DEBUG) += gdbstub.o
+obj-y += hypercall.o
+obj-y += i387.o
+obj-y += i8259.o
+obj-y += io_apic.o
+obj-$(CONFIG_LIVEPATCH) += alternative.o livepatch.o
+obj-y += msi.o
+obj-y += msr.o
+obj-$(CONFIG_INDIRECT_THUNK) += indirect-thunk.o
+obj-y += ioport_emulate.o
+obj-y += irq.o
+obj-$(CONFIG_KEXEC) += machine_kexec.o
+obj-y += microcode_amd.o
+obj-y += microcode_intel.o
+obj-y += microcode.o
+obj-y += mm.o x86_64/mm.o
+obj-$(CONFIG_HVM) += monitor.o
+obj-y += mpparse.o
+obj-y += nmi.o
+obj-y += numa.o
+obj-y += pci.o
+obj-y += percpu.o
+obj-y += physdev.o x86_64/physdev.o
+obj-y += platform_hypercall.o x86_64/platform_hypercall.o
+obj-y += psr.o
+obj-y += setup.o
+obj-y += shutdown.o
+obj-y += smp.o
+obj-y += smpboot.o
+obj-y += spec_ctrl.o
+obj-y += srat.o
+obj-y += string.o
+obj-y += sysctl.o
+obj-y += time.o
+obj-y += trace.o
+obj-y += traps.o
+obj-y += usercopy.o
+obj-y += x86_emulate.o
+obj-$(CONFIG_TBOOT) += tboot.o
+obj-y += hpet.o
+obj-y += vm_event.o
+obj-y += xstate.o
+
+extra-y += xen.lds efi.lds
+
+hostprogs-y += boot/mkelf32
+
+ifneq ($(build_id_linker),)
+notes_phdrs = --notes
+else
+ifeq ($(CONFIG_PVH_GUEST),y)
+notes_phdrs = --notes
+endif
+endif
+
+ifdef CONFIG_LIVEPATCH
+all_symbols = --all-symbols
+ifdef CONFIG_FAST_SYMBOL_LOOKUP
+all_symbols = --all-symbols --sort-by-name
+endif
+else
+all_symbols =
+endif
+
+syms-warn-dup-y := --warn-dup
+syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
+
+$(TARGET): TMP = $(@D)/.$(@F).elf32
+$(TARGET): $(TARGET)-syms $(efi-y) $(obj)/boot/mkelf32
+ $(obj)/boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TMP) $(XEN_IMG_OFFSET) \
+ `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
+ od -t x4 -N 8192 $(TMP) | grep 1badb002 > /dev/null || \
+ { echo "No Multiboot1 header found" >&2; false; }
+ od -t x4 -N 32768 $(TMP) | grep e85250d6 > /dev/null || \
+ { echo "No Multiboot2 header found" >&2; false; }
+ mv $(TMP) $(TARGET)
+
+targets += prelink.o
+LDFLAGS_prelink.o := -r --whole-archive
+$(obj)/prelink.o: $(ALL_OBJS) FORCE
+ $(call if_changed,ld)
+
+LDFLAGS_$(TARGET)-syms += -T $(obj)/xen.lds -N
+$(TARGET)-syms: $(obj)/prelink.o $(obj)/xen.lds
+ $(LD) $(ld_flags) $< $(build_id_linker) \
+ $(objtree)/common/symbols-dummy.o -o $(@D)/.$(@F).0
+ $(NM) -pa --format=sysv $(@D)/.$(@F).0 \
+ | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+ >$(@D)/.$(@F).0.S
+ $(MAKE) $(build)=$(@D) $(@D)/.$(@F).0.o
+ $(LD) $(ld_flags) $< $(build_id_linker) \
+ $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
+ $(NM) -pa --format=sysv $(@D)/.$(@F).1 \
+ | $(objtree)/tools/symbols $(all_symbols) --sysv --sort $(syms-warn-dup-y) \
+ >$(@D)/.$(@F).1.S
+ $(MAKE) $(build)=$(@D) $(@D)/.$(@F).1.o
+ $(LD) $(ld_flags) $< $(build_id_linker) \
+ $(@D)/.$(@F).1.o -o $@
+ $(NM) -pa --format=sysv $(@D)/$(@F) \
+ | $(objtree)/tools/symbols --xensyms --sysv --sort \
+ >$(@D)/$(@F).map
+ rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
+
+targets += asm-offsets.s
+CFLAGS_REMOVE_asm-offsets.o := -flto
+$(obj)/asm-offsets.s: $(src)/$(ARCH)/asm-offsets.c $(objtree)/include/asm-x86/asm-macros.h FORCE
+ $(call if_changed_dep,cc_s_c)
+
+# FLAGS for asm-macros.i
+CFLAGS_asm-macros.o := -D__ASSEMBLY__ -P
+
+# Extra aflags for efi.lds
+AFLAGS_efi.o := -DEFI
+
+quiet_cmd_xen_cpp_lds_S = LDS $@
+ cmd_xen_cpp_lds_S = $(CPP) $(filter-out -Wa$(comma)%,$(a_flags)) -P -Ui386 \
+ -o $@ $<
+
+$(obj)/%.lds: $(src)/xen.lds.S FORCE
+ $(call if_changed_dep,xen_cpp_lds_S)
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 864a0669bc9f..49b7eb9fd116 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -1,115 +1,8 @@
-obj-y += acpi/
-obj-y += cpu/
-obj-y += genapic/
-obj-$(CONFIG_XEN_GUEST) += guest/
-obj-$(CONFIG_HVM) += hvm/
-obj-y += mm/
-obj-$(CONFIG_XENOPROF) += oprofile/
-obj-$(CONFIG_PV) += pv/
-obj-y += x86_64/
-
-alternative-y := alternative.init.o
-alternative-$(CONFIG_LIVEPATCH) :=
-obj-bin-y += $(alternative-y)
-obj-y += apic.o
-obj-y += bitops.o
-obj-bin-y += bzimage.init.o
-obj-bin-y += clear_page.o
-obj-bin-y += copy_page.o
-obj-y += cpuid.o
-obj-$(CONFIG_PV) += compat.o x86_64/compat.o
-obj-$(CONFIG_KEXEC) += crash.o
-obj-y += debug.o
-obj-y += delay.o
-obj-y += desc.o
-obj-bin-y += dmi_scan.init.o
-obj-y += domctl.o
-obj-y += domain.o
-obj-bin-y += dom0_build.init.o
-obj-y += domain_page.o
-obj-y += e820.o
-obj-y += emul-i8254.o
-obj-y += extable.o
-obj-y += flushtlb.o
-obj-$(CONFIG_CRASH_DEBUG) += gdbstub.o
-obj-y += hypercall.o
-obj-y += i387.o
-obj-y += i8259.o
-obj-y += io_apic.o
-obj-$(CONFIG_LIVEPATCH) += alternative.o livepatch.o
-obj-y += msi.o
-obj-y += msr.o
-obj-$(CONFIG_INDIRECT_THUNK) += indirect-thunk.o
-obj-y += ioport_emulate.o
-obj-y += irq.o
-obj-$(CONFIG_KEXEC) += machine_kexec.o
-obj-y += microcode_amd.o
-obj-y += microcode_intel.o
-obj-y += microcode.o
-obj-y += mm.o x86_64/mm.o
-obj-$(CONFIG_HVM) += monitor.o
-obj-y += mpparse.o
-obj-y += nmi.o
-obj-y += numa.o
-obj-y += pci.o
-obj-y += percpu.o
-obj-y += physdev.o x86_64/physdev.o
-obj-y += platform_hypercall.o x86_64/platform_hypercall.o
-obj-y += psr.o
-obj-y += setup.o
-obj-y += shutdown.o
-obj-y += smp.o
-obj-y += smpboot.o
-obj-y += spec_ctrl.o
-obj-y += srat.o
-obj-y += string.o
-obj-y += sysctl.o
-obj-y += time.o
-obj-y += trace.o
-obj-y += traps.o
-obj-y += usercopy.o
-obj-y += x86_emulate.o
-obj-$(CONFIG_TBOOT) += tboot.o
-obj-y += hpet.o
-obj-y += vm_event.o
-obj-y += xstate.o
-
-x86_emulate.o: x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
-O $(BASEDIR)/include/xen/compile.h ]; then \
echo '$(TARGET).efi'; fi)
-ifneq ($(build_id_linker),)
-notes_phdrs = --notes
-else
-ifeq ($(CONFIG_PVH_GUEST),y)
-notes_phdrs = --notes
-endif
-endif
-
-ifdef CONFIG_LIVEPATCH
-all_symbols = --all-symbols
-ifdef CONFIG_FAST_SYMBOL_LOOKUP
-all_symbols = --all-symbols --sort-by-name
-endif
-else
-all_symbols =
-endif
-
-syms-warn-dup-y := --warn-dup
-syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
-
-$(TARGET): TMP = $(@D)/.$(@F).elf32
-$(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
- ./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TMP) $(XEN_IMG_OFFSET) \
- `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
- od -t x4 -N 8192 $(TMP) | grep 1badb002 > /dev/null || \
- { echo "No Multiboot1 header found" >&2; false; }
- od -t x4 -N 32768 $(TMP) | grep e85250d6 > /dev/null || \
- { echo "No Multiboot2 header found" >&2; false; }
- mv $(TMP) $(TARGET)
-
ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
ifeq ($(CONFIG_LTO),y)
@@ -127,33 +20,10 @@ prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o
$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
else
-prelink.o: $(ALL_OBJS)
- $(LD) $(LDFLAGS) -r -o $@ $^
-
prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o
$(guard) $(LD) $(LDFLAGS) -r -o $@ $(filter-out %/efi/built_in.o,$^)
endif
-$(TARGET)-syms: prelink.o xen.lds
- $(LD) $(LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
- $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
- $(NM) -pa --format=sysv $(@D)/.$(@F).0 \
- | $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort \
- >$(@D)/.$(@F).0.S
- $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
- $(LD) $(LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
- $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
- $(NM) -pa --format=sysv $(@D)/.$(@F).1 \
- | $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort $(syms-warn-dup-y) \
- >$(@D)/.$(@F).1.S
- $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o
- $(LD) $(LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
- $(@D)/.$(@F).1.o -o $@
- $(NM) -pa --format=sysv $(@D)/$(@F) \
- | $(BASEDIR)/tools/symbols --xensyms --sysv --sort \
- >$(@D)/$(@F).map
- rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
-
note.o: $(TARGET)-syms
$(OBJCOPY) -O binary --only-section=.note.gnu.build-id $(BASEDIR)/xen-syms $@.bin
$(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \
@@ -219,11 +89,6 @@ $(TARGET).efi: prelink-efi.o $(note_file) efi.lds efi/relocs-dummy.o efi/mkreloc
efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o: $(BASEDIR)/arch/x86/efi/built_in.o
efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o: ;
-asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c $(BASEDIR)/include/asm-x86/asm-macros.h
- $(CC) $(filter-out -Wa$(comma)% -flto,$(CFLAGS)) -S -o $@ $<
-
-asm-macros.i: CFLAGS += -D__ASSEMBLY__ -P
-
$(BASEDIR)/include/asm-x86/asm-macros.h: asm-macros.i Makefile
echo '#if 0' >$@.new
echo '.if 0' >>$@.new
@@ -235,19 +100,6 @@ $(BASEDIR)/include/asm-x86/asm-macros.h: asm-macros.i Makefile
echo '#endif' >>$@.new
$(call move-if-changed,$@.new,$@)
-xen.lds: xen.lds.S
- $(CC) -P -E -Ui386 $(filter-out -Wa$(comma)%,$(AFLAGS)) -o $@ $<
- sed -e 's/.*\.lds\.o:/$(@F):/g' <.$(@F).d >.$(@F).d.new
- mv -f .$(@F).d.new .$(@F).d
-
-efi.lds: xen.lds.S
- $(CC) -P -E -Ui386 -DEFI $(filter-out -Wa$(comma)%,$(AFLAGS)) -o $@ $<
- sed -e 's/.*\.lds\.o:/$(@F):/g' <.$(@F).d >.$(@F).d.new
- mv -f .$(@F).d.new .$(@F).d
-
-boot/mkelf32: boot/mkelf32.c
- $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
-
efi/mkreloc: efi/mkreloc.c
$(HOSTCC) $(HOSTCFLAGS) -g -o $@ $<
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 19/23] update *FLAGS for arch/x86/Makefile
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (16 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 18/23] arch/x86: Start moving build targets out of Makefile into Kbuild Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 20/23] update arch/Makefile Anthony PERARD
` (3 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
---
xen/arch/x86/Makefile | 65 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 49b7eb9fd116..41486c512f10 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -1,3 +1,68 @@
+# select defconfig based on actual architecture
+KBUILD_DEFCONFIG := $(ARCH)_defconfig
+
+export XEN_IMG_OFFSET := 0x200000
+
+KBUILD_CFLAGS += -I$(srctree)/include
+KBUILD_CFLAGS += -I$(srctree)/include/asm-x86/mach-generic
+KBUILD_CFLAGS += -I$(srctree)/include/asm-x86/mach-default
+KBUILD_CFLAGS += -DXEN_IMG_OFFSET=$(XEN_IMG_OFFSET)
+
+# Prevent floating-point variables from creeping into Xen.
+KBUILD_CFLAGS += -msoft-float
+
+KBUILD_CFLAGS += $(foreach o,$(EMBEDDED_EXTRA_CFLAGS),$(call cc-option,$(o)))
+KBUILD_CFLAGS += $(call cc-option,-Wnested-externs)
+KBUILD_CFLAGS += $(call as-instr,vmcall,-DHAVE_AS_VMX)
+KBUILD_CFLAGS += $(call as-instr,crc32 %eax$(comma)%eax,-DHAVE_AS_SSE4_2)
+KBUILD_CFLAGS += $(call as-instr,invept (%rax)$(comma)%rax,-DHAVE_AS_EPT)
+KBUILD_CFLAGS += $(call as-instr,rdrand %eax,-DHAVE_AS_RDRAND)
+KBUILD_CFLAGS += $(call as-instr,rdfsbase %rax,-DHAVE_AS_FSGSBASE)
+KBUILD_CFLAGS += $(call as-instr,xsaveopt (%rax),-DHAVE_AS_XSAVEOPT)
+KBUILD_CFLAGS += $(call as-instr,rdseed %eax,-DHAVE_AS_RDSEED)
+KBUILD_CFLAGS += $(call as-instr,clwb (%rax),-DHAVE_AS_CLWB)
+KBUILD_CFLAGS += $(call as-instr,.equ \"x\"$(comma)1,-DHAVE_AS_QUOTED_SYM)
+KBUILD_CFLAGS += $(call as-instr,invpcid (%rax)$(comma)%rax,-DHAVE_AS_INVPCID)
+
+# GAS's idea of true is -1. Clang's idea is 1
+KBUILD_CFLAGS += $(call as-instr,\
+ .if ((1 > 0) < 0); .error "";.endif,,-DHAVE_AS_NEGATIVE_TRUE)
+
+# Check to see whether the assmbler supports the .nop directive.
+KBUILD_CFLAGS += $(call as-instr,\
+ .L1: .L2: .nops (.L2 - .L1)$(comma)9,-DHAVE_AS_NOPS_DIRECTIVE)
+
+KBUILD_CFLAGS += -mno-red-zone -fpic -fno-asynchronous-unwind-tables
+
+# Xen doesn't use SSE interally. If the compiler supports it, also skip the
+# SSE setup for variadic function calls.
+KBUILD_CFLAGS += -mno-sse $(call cc-option,-mskip-rax-setup)
+
+# -fvisibility=hidden reduces -fpic cost, if it's available
+ifeq ($(call cc-option-yn,-fvisibility=hidden),y)
+KBUILD_CFLAGS += -DGCC_HAS_VISIBILITY_ATTRIBUTE
+endif
+
+# Compile with thunk-extern, indirect-branch-register if avaiable.
+ifeq ($(call cc-option-yn,-mindirect-branch-register),y)
+KBUILD_CFLAGS += -mindirect-branch=thunk-extern -mindirect-branch-register
+KBUILD_CFLAGS += -DCONFIG_INDIRECT_THUNK
+KBUILD_CFLAGS += -fno-jump-tables
+export CONFIG_INDIRECT_THUNK=y
+endif
+
+# If supported by the compiler, reduce stack alignment to 8 bytes. But allow
+# this to be overridden elsewhere.
+# XXX adding to cflags instead of CFLAGS-stack-boundary
+KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)
+
+# Set up the assembler include path properly for older toolchains.
+KBUILD_CFLAGS += -Wa,-I$(srctree)/include
+
+# XXX from xen.git/config/x86_64.mk
+LDFLAGS_emulation_OpenBSD := _obsd
+LDFLAGS_emulation_FreeBSD := _fbsd
+KBUILD_LDFLAGS += -melf_x86_64$(LDFLAGS_emulation_$(XEN_OS))
efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
-O $(BASEDIR)/include/xen/compile.h ]; then \
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 20/23] update arch/Makefile
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (17 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 19/23] update *FLAGS for arch/x86/Makefile Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 21/23] Import root Makefile from Linux v5.3 Anthony PERARD
` (2 subsequent siblings)
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
archprepare target
make asm-offsets.h
make asm-macros.[ih]
---
xen/Kbuild | 10 ++++++++
xen/arch/x86/Makefile | 54 +++++++++++++++++++++----------------------
2 files changed, 37 insertions(+), 27 deletions(-)
create mode 100644 xen/Kbuild
diff --git a/xen/Kbuild b/xen/Kbuild
new file mode 100644
index 000000000000..3b36d67226d6
--- /dev/null
+++ b/xen/Kbuild
@@ -0,0 +1,10 @@
+#####
+# Generate asm-offsets.h
+
+offsets-file := include/asm-$(SRCARCH)/asm-offsets.h
+
+always += $(offsets-file)
+
+$(offsets-file): arch/$(SRCARCH)/asm-offsets.s FORCE
+ $(call filechk,offsets,__ASM_OFFSETS_H__)
+
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 41486c512f10..9a6a0a595975 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -64,11 +64,17 @@ LDFLAGS_emulation_OpenBSD := _obsd
LDFLAGS_emulation_FreeBSD := _fbsd
KBUILD_LDFLAGS += -melf_x86_64$(LDFLAGS_emulation_$(XEN_OS))
+archheaders: $(objtree)/include/asm-x86/asm-macros.h
+
+archprepare:
+ $(Q)$(MAKE) $(build)=arch/$(SRCARCH) arch/$(SRCARCH)/asm-offsets.s
+
efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
-O $(BASEDIR)/include/xen/compile.h ]; then \
echo '$(TARGET).efi'; fi)
-ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
+head-y := arch/x86/boot/
+head-y += arch/x86/efi/
ifeq ($(CONFIG_LTO),y)
# Gather all LTO objects together
@@ -104,7 +110,10 @@ EFI_LDFLAGS += --major-os-version=2 --minor-os-version=0
EFI_LDFLAGS += --major-subsystem-version=2 --minor-subsystem-version=0
# Check if the compiler supports the MS ABI.
-export XEN_BUILD_EFI := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
+#export XEN_BUILD_EFI := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
+# XXX FIXME: The subdir efi/ depends on symbolic links of files in common/efi/
+# XXX Disable EFI build for now.
+override XEN_BUILD_EFI :=
# Check if the linker supports PE.
XEN_BUILD_PE := $(if $(XEN_BUILD_EFI),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
CFLAGS-$(XEN_BUILD_EFI) += -DXEN_BUILD_EFI
@@ -154,31 +163,22 @@ $(TARGET).efi: prelink-efi.o $(note_file) efi.lds efi/relocs-dummy.o efi/mkreloc
efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o: $(BASEDIR)/arch/x86/efi/built_in.o
efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o: ;
-$(BASEDIR)/include/asm-x86/asm-macros.h: asm-macros.i Makefile
- echo '#if 0' >$@.new
- echo '.if 0' >>$@.new
- echo '#endif' >>$@.new
- echo 'asm ( ".include \"$@\"" );' >>$@.new
- echo '#if 0' >>$@.new
- echo '.endif' >>$@.new
- cat $< >>$@.new
- echo '#endif' >>$@.new
- $(call move-if-changed,$@.new,$@)
+define filechk_asm-macros.h
+ echo '#if 0'; \
+ echo '.if 0'; \
+ echo '#endif'; \
+ echo 'asm ( ".include \"$@\"" );'; \
+ echo '#if 0'; \
+ echo '.endif'; \
+ cat $<; \
+ echo '#endif'
+endef
+
+$(objtree)/arch/x86/asm-macros.i: FORCE
+ $(Q)$(MAKE) $(build)=$(@D) $@
+
+$(objtree)/include/asm-x86/asm-macros.h: $(objtree)/arch/x86/asm-macros.i Makefile FORCE
+ $(call filechk,asm-macros.h)
efi/mkreloc: efi/mkreloc.c
$(HOSTCC) $(HOSTCFLAGS) -g -o $@ $<
-
-.PHONY: clean
-clean::
- rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32
- rm -f asm-macros.i $(BASEDIR)/include/asm-x86/asm-macros.*
- rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d $(BASEDIR)/.xen.elf32
- rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.efi efi/mkreloc
- rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
- rm -f note.o
-
-# Suppress loading of DEPS files for internal, temporary target files. This
-# then also suppresses re-generation of the respective .*.d2 files.
-ifeq ($(filter-out .xen%.o,$(notdir $(MAKECMDGOALS))),)
-DEPS:=
-endif
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 21/23] Import root Makefile from Linux v5.3
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (18 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 20/23] update arch/Makefile Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 22/23] Changes to root Makefile Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 23/23] xen/tools/kconfig: Delete duplicate makefiles Anthony PERARD
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
Edit a lot of it out, mostly CFLAGS, build of modules.
Edit in xenversion.
---
xen/Makefile | 1249 ++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 1001 insertions(+), 248 deletions(-)
diff --git a/xen/Makefile b/xen/Makefile
index b1b60e679082..90645668957c 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
# This is the correct place to edit the build version.
# All other places this is stored (eg. compile.h) should be autogenerated.
export XEN_VERSION = 4
@@ -11,284 +12,1036 @@ export XEN_DOMAIN ?= $(shell ([ -x /bin/dnsdomainname ] && /bin/dnsdomainname) |
export XEN_BUILD_DATE ?= $(shell LC_ALL=C date)
export XEN_BUILD_TIME ?= $(shell LC_ALL=C date +%T)
export XEN_BUILD_HOST ?= $(shell hostname)
-export XEN_CONFIG_EXPERT ?= n
-export BASEDIR := $(CURDIR)
-export XEN_ROOT := $(BASEDIR)/..
+export XEN_ROOT := $(CURDIR)/..
+
+# *DOCUMENTATION*
+# To see a list of typical targets execute "make help"
+# More info can be located in ./README
+# Comments in this file are targeted only to the developer, do not
+# expect to learn how to build the kernel reading this file.
+
+# That's our default target when none is given on the command line
+PHONY := _all
+_all:
+
+# We are using a recursive build, so we need to do a little thinking
+# to get the ordering right.
+#
+# Most importantly: sub-Makefiles should only ever modify files in
+# their own directory. If in some directory we have a dependency on
+# a file in another dir (which doesn't happen often, but it's often
+# unavoidable when linking the built-in.a targets which finally
+# turn into xen), we will call a sub make in that other dir, and
+# after that we are sure that everything which is in that other dir
+# is now up to date.
+#
+# The only cases where we need to modify files which have global
+# effects are thus separated out and done before the recursive
+# descending is started. They are now explicitly listed as the
+# prepare rule.
+
+ifneq ($(sub_make_done),1)
# Do not use make's built-in rules and variables
+# (this increases performance and avoids hard-to-debug behaviour)
MAKEFLAGS += -rR
-EFI_MOUNTPOINT ?= $(BOOT_DIR)/efi
+# Avoid funny character set dependencies
+unexport LC_ALL
+LC_COLLATE=C
+LC_NUMERIC=C
+export LC_COLLATE LC_NUMERIC
-ARCH=$(XEN_TARGET_ARCH)
-SRCARCH=$(shell echo $(ARCH) | sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+# Avoid interference with shell env settings
+unexport GREP_OPTIONS
-# Don't break if the build process wasn't called from the top level
-# we need XEN_TARGET_ARCH to generate the proper config
-include $(XEN_ROOT)/Config.mk
+# Beautify output
+# ---------------------------------------------------------------------------
+#
+# Normally, we echo the whole command before executing it. By making
+# that echo $($(quiet)$(cmd)), we now have the possibility to set
+# $(quiet) to choose other forms of output instead, e.g.
+#
+# quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
+# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
+#
+# If $(quiet) is empty, the whole command will be printed.
+# If it is set to "quiet_", only the short version will be printed.
+# If it is set to "silent_", nothing will be printed at all, since
+# the variable $(silent_cmd_cc_o_c) doesn't exist.
+#
+# A simple variant is to prefix commands with $(Q) - that's useful
+# for commands that shall be hidden in non-verbose mode.
+#
+# $(Q)ln $@ :<
+#
+# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
+# If KBUILD_VERBOSE equals 1 then the above command is displayed.
+#
+# To put more focus on warnings, be less verbose as default
+# Use 'make V=1' to see the full commands
-# Allow someone to change their config file
-export KCONFIG_CONFIG ?= .config
+ifeq ("$(origin V)", "command line")
+ KBUILD_VERBOSE = $(V)
+endif
+ifndef KBUILD_VERBOSE
+ KBUILD_VERBOSE = 0
+endif
-.PHONY: default
-default: build
+ifeq ($(KBUILD_VERBOSE),1)
+ quiet =
+ Q =
+else
+ quiet=quiet_
+ Q = @
+endif
+
+# If the user is running make -s (silent mode), suppress echoing of
+# commands
+
+ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
+ quiet=silent_
+endif
+
+export quiet Q KBUILD_VERBOSE
-.PHONY: dist
-dist: install
+# Kbuild will save output files in the current working directory.
+# This does not need to match to the root of the kernel source tree.
+#
+# For example, you can do this:
+#
+# cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
+#
+# If you want to save output files in a different location, there are
+# two syntaxes to specify it.
+#
+# 1) O=
+# Use "make O=dir/to/store/output/files/"
+#
+# 2) Set KBUILD_OUTPUT
+# Set the environment variable KBUILD_OUTPUT to point to the output directory.
+# export KBUILD_OUTPUT=dir/to/store/output/files/; make
+#
+# The O= assignment takes precedence over the KBUILD_OUTPUT environment
+# variable.
-build install:: include/config/auto.conf
+# Do we want to change the working directory?
+ifeq ("$(origin O)", "command line")
+ KBUILD_OUTPUT := $(O)
+endif
-.PHONY: build install uninstall clean distclean cscope TAGS tags MAP gtags tests
-build install uninstall debug clean distclean cscope TAGS tags MAP gtags tests::
-ifneq ($(XEN_TARGET_ARCH),x86_32)
- $(MAKE) -f Rules.mk _$@
+ifneq ($(KBUILD_OUTPUT),)
+# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
+# expand a shell special character '~'. We use a somewhat tedious way here.
+abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
+$(if $(abs_objtree),, \
+ $(error failed to create output directory "$(KBUILD_OUTPUT)"))
+
+# $(realpath ...) resolves symlinks
+abs_objtree := $(realpath $(abs_objtree))
+else
+abs_objtree := $(CURDIR)
+endif # ifneq ($(KBUILD_OUTPUT),)
+
+ifeq ($(abs_objtree),$(CURDIR))
+# Suppress "Entering directory ..." unless we are changing the work directory.
+MAKEFLAGS += --no-print-directory
else
- echo "*** Xen x86/32 target no longer supported!"
+need-sub-make := 1
+endif
+
+abs_srctree := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
+
+ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
+$(error source directory cannot contain spaces or colons)
+endif
+
+ifneq ($(abs_srctree),$(abs_objtree))
+# Look for make include files relative to root of kernel src
+#
+# This does not become effective immediately because MAKEFLAGS is re-parsed
+# once after the Makefile is read. We need to invoke sub-make.
+MAKEFLAGS += --include-dir=$(abs_srctree)
+need-sub-make := 1
+endif
+
+ifneq ($(filter 3.%,$(MAKE_VERSION)),)
+# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
+# We need to invoke sub-make to avoid implicit rules in the top Makefile.
+need-sub-make := 1
+# Cancel implicit rules for this Makefile.
+$(lastword $(MAKEFILE_LIST)): ;
+endif
+
+export abs_srctree abs_objtree
+export sub_make_done := 1
+
+ifeq ($(need-sub-make),1)
+
+PHONY += $(MAKECMDGOALS) sub-make
+
+$(filter-out _all sub-make $(lastword $(MAKEFILE_LIST)), $(MAKECMDGOALS)) _all: sub-make
+ @:
+
+# Invoke a second make in the output directory, passing relevant variables
+sub-make:
+ $(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
+
+endif # need-sub-make
+endif # sub_make_done
+
+# We process the rest of the Makefile if this is the final invocation of make
+ifeq ($(need-sub-make),)
+
+# Do not print "Entering directory ...",
+# but we want to display it when entering to the output directory
+# so that IDEs/editors are able to understand relative filenames.
+MAKEFLAGS += --no-print-directory
+
+# Call a source code checker (by default, "sparse") as part of the
+# C compilation.
+#
+# Use 'make C=1' to enable checking of only re-compiled files.
+# Use 'make C=2' to enable checking of *all* source files, regardless
+# of whether they are re-compiled or not.
+#
+# See the file "Documentation/dev-tools/sparse.rst" for more details,
+# including where to get the "sparse" utility.
+
+ifeq ("$(origin C)", "command line")
+ KBUILD_CHECKSRC = $(C)
+endif
+ifndef KBUILD_CHECKSRC
+ KBUILD_CHECKSRC = 0
+endif
+
+export KBUILD_CHECKSRC
+
+ifeq ($(abs_srctree),$(abs_objtree))
+ # building in the source tree
+ srctree := .
+ building_out_of_srctree :=
+else
+ ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))
+ # building in a subdirectory of the source tree
+ srctree := ..
+ else
+ srctree := $(abs_srctree)
+ endif
+ building_out_of_srctree := 1
+endif
+
+ifneq ($(KBUILD_ABS_SRCTREE),)
+srctree := $(abs_srctree)
+endif
+
+objtree := .
+VPATH := $(srctree)
+
+export building_out_of_srctree srctree objtree VPATH
+
+# To make sure we do not include .config for any of the *config targets
+# catch them early, and hand them over to scripts/kconfig/Makefile
+# It is allowed to specify more targets when calling make, including
+# mixing *config targets and build targets.
+# For example 'make oldconfig all'.
+# Detect when mixed targets is specified, and make a second invocation
+# of make so .config is not included in this case either (for *config).
+
+version_h := include/xen/compile.h
+
+clean-targets := %clean mrproper cleandocs
+no-dot-config-targets := $(clean-targets) \
+ cscope gtags TAGS tags help% %docs check% \
+ $(version_h) headers headers_% archheaders \
+ xenversion
+no-sync-config-targets := $(no-dot-config-targets) install %install
+
+config-targets := 0
+mixed-targets := 0
+dot-config := 1
+may-sync-config := 1
+
+ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
+ ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
+ dot-config := 0
+ endif
endif
-.PHONY: _build
-_build: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
-
-.PHONY: _install
-_install: D=$(DESTDIR)
-_install: T=$(notdir $(TARGET))
-_install: Z=$(CONFIG_XEN_INSTALL_SUFFIX)
-_install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
- [ -d $(D)$(BOOT_DIR) ] || $(INSTALL_DIR) $(D)$(BOOT_DIR)
- $(INSTALL_DATA) $(TARGET)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION)$(Z)
- ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION)$(Z)
- ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION)$(Z)
- ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)$(Z)
- [ -d "$(D)$(DEBUG_DIR)" ] || $(INSTALL_DIR) $(D)$(DEBUG_DIR)
- $(INSTALL_DATA) $(TARGET)-syms $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION)
- $(INSTALL_DATA) $(TARGET)-syms.map $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION).map
- $(INSTALL_DATA) $(KCONFIG_CONFIG) $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION).config
- if [ -r $(TARGET).efi -a -n '$(EFI_DIR)' ]; then \
- [ -d $(D)$(EFI_DIR) ] || $(INSTALL_DIR) $(D)$(EFI_DIR); \
- $(INSTALL_DATA) $(TARGET).efi $(D)$(EFI_DIR)/$(T)-$(XEN_FULLVERSION).efi; \
- if [ -e $(TARGET).efi.map ]; then \
- $(INSTALL_DATA) $(TARGET).efi.map $(D)$(DEBUG_DIR)/$(T)-$(XEN_FULLVERSION).efi.map; \
- fi; \
- ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION).efi; \
- ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi; \
- ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T).efi; \
- if [ -n '$(EFI_MOUNTPOINT)' -a -n '$(EFI_VENDOR)' ]; then \
- $(INSTALL_DATA) $(TARGET).efi $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi; \
- elif [ "$(D)" = "$(patsubst $(shell cd $(XEN_ROOT) && pwd)/%,%,$(D))" ]; then \
- echo 'EFI installation only partially done (EFI_VENDOR not set)' >&2; \
- fi; \
- fi
-
-.PHONY: _tests
-_tests:
- $(MAKE) -f $(BASEDIR)/Rules.mk -C test tests
-
-.PHONY: _uninstall
-_uninstall: D=$(DESTDIR)
-_uninstall: T=$(notdir $(TARGET))
-_uninstall: Z=$(CONFIG_XEN_INSTALL_SUFFIX)
-_uninstall:
- rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION).config
- rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION)$(Z)
- rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION)$(Z)
- rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION)$(Z)
- rm -f $(D)$(BOOT_DIR)/$(T)$(Z)
- rm -f $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION)
- rm -f $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION).map
- rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_FULLVERSION).efi
- rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION).efi
- rm -f $(D)$(DEBUG_DIR)/$(T)-$(XEN_FULLVERSION).efi.map
- rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi
- rm -f $(D)$(EFI_DIR)/$(T).efi
- rm -f $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi
-
-.PHONY: _debug
-_debug:
- $(OBJDUMP) -D -S $(TARGET)-syms > $(TARGET).s
-
-.PHONY: _clean
-_clean: delete-unfresh-files
- $(MAKE) -C tools clean
- $(MAKE) -f $(BASEDIR)/Rules.mk -C include clean
- $(MAKE) -f $(BASEDIR)/Rules.mk -C common clean
- $(MAKE) -f $(BASEDIR)/Rules.mk -C drivers clean
- $(MAKE) -f $(BASEDIR)/Rules.mk -C xsm clean
- $(MAKE) -f $(BASEDIR)/Rules.mk -C crypto clean
- $(MAKE) -f $(BASEDIR)/Rules.mk -C arch/arm clean
- $(MAKE) -f $(BASEDIR)/Rules.mk -C arch/x86 clean
- $(MAKE) -f $(BASEDIR)/Rules.mk -C test clean
- $(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) clean
- find . \( -name "*.o" -o -name ".*.d" -o -name ".*.d2" -o -name "*.gcno" \) -exec rm -f {} \;
- rm -f include/asm $(TARGET) $(TARGET).gz $(TARGET).efi $(TARGET).efi.map $(TARGET)-syms $(TARGET)-syms.map *~ core
- rm -f include/asm-*/asm-offsets.h
- rm -f .banner
-
-.PHONY: _distclean
-_distclean: clean
- rm -f tags TAGS cscope.files cscope.in.out cscope.out cscope.po.out GTAGS GPATH GRTAGS GSYMS .config
-
-$(TARGET).gz: $(TARGET)
- gzip -n -f -9 < $< > $@.new
- mv $@.new $@
-
-$(TARGET): delete-unfresh-files
- $(MAKE) -C tools
- $(MAKE) -f $(BASEDIR)/Rules.mk include/xen/compile.h
- [ -e include/asm ] || ln -sf asm-$(TARGET_ARCH) include/asm
- [ -e arch/$(TARGET_ARCH)/efi ] && for f in boot.c runtime.c compat.c efi.h;\
- do test -r arch/$(TARGET_ARCH)/efi/$$f || \
- ln -nsf ../../../common/efi/$$f arch/$(TARGET_ARCH)/efi/; \
- done; \
- true
- $(MAKE) -f $(BASEDIR)/Rules.mk -C include
- $(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) asm-offsets.s
- $(MAKE) -f $(BASEDIR)/Rules.mk include/asm-$(TARGET_ARCH)/asm-offsets.h
- $(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) $@
-
-# drivers/char/console.o contains static banner/compile info. Blow it away.
-# Don't refresh these files during e.g., 'sudo make install'
-.PHONY: delete-unfresh-files
-delete-unfresh-files:
- @if [ ! -r include/xen/compile.h -o -O include/xen/compile.h ]; then \
- rm -f include/xen/compile.h; \
- fi
-
-.banner: Makefile
- @if which figlet >/dev/null 2>&1 ; then \
- echo " Xen $(XEN_FULLVERSION)" | figlet -f tools/xen.flf > $@.tmp; \
- else \
- echo " Xen $(XEN_FULLVERSION)" > $@.tmp; \
- fi
- @mv -f $@.tmp $@
-
-# compile.h contains dynamic build info. Rebuilt on every 'make' invocation.
-include/xen/compile.h: include/xen/compile.h.in .banner
- @sed -e 's/@@date@@/$(XEN_BUILD_DATE)/g' \
- -e 's/@@time@@/$(XEN_BUILD_TIME)/g' \
- -e 's/@@whoami@@/$(XEN_WHOAMI)/g' \
- -e 's/@@domain@@/$(XEN_DOMAIN)/g' \
- -e 's/@@hostname@@/$(XEN_BUILD_HOST)/g' \
- -e 's!@@compiler@@!$(shell $(CC) $(CFLAGS) --version 2>&1 | head -1)!g' \
- -e 's/@@version@@/$(XEN_VERSION)/g' \
- -e 's/@@subversion@@/$(XEN_SUBVERSION)/g' \
- -e 's/@@extraversion@@/$(XEN_EXTRAVERSION)/g' \
- -e 's!@@changeset@@!$(shell tools/scmversion $(XEN_ROOT) || echo "unavailable")!g' \
- < include/xen/compile.h.in > $@.new
- @cat .banner
- @$(PYTHON) tools/fig-to-oct.py < .banner >> $@.new
- @mv -f $@.new $@
-
-include/asm-$(TARGET_ARCH)/asm-offsets.h: arch/$(TARGET_ARCH)/asm-offsets.s
- @(set -e; \
- echo "/*"; \
- echo " * DO NOT MODIFY."; \
- echo " *"; \
- echo " * This file was auto-generated from $<"; \
- echo " *"; \
- echo " */"; \
- echo ""; \
- echo "#ifndef __ASM_OFFSETS_H__"; \
- echo "#define __ASM_OFFSETS_H__"; \
- echo ""; \
- sed -rne "/^[^#].*==>/{s:.*==>(.*)<==.*:\1:; s: [\$$#]: :; p;}"; \
- echo ""; \
- echo "#endif") <$< >$@
-
-SUBDIRS = xsm arch/$(TARGET_ARCH) common drivers test
-define all_sources
- ( find include/asm-$(TARGET_ARCH) -name '*.h' -print; \
- find include -name 'asm-*' -prune -o -name '*.h' -print; \
- find $(SUBDIRS) -name '*.[chS]' -print )
+ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
+ ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
+ may-sync-config := 0
+ endif
+endif
+
+ifneq ($(filter config %config,$(MAKECMDGOALS)),)
+ config-targets := 1
+ ifneq ($(words $(MAKECMDGOALS)),1)
+ mixed-targets := 1
+ endif
+endif
+
+# For "make -j clean all", "make -j mrproper defconfig all", etc.
+ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
+ ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
+ mixed-targets := 1
+ endif
+endif
+
+# install and modules_install need also be processed one by one
+ifneq ($(filter install,$(MAKECMDGOALS)),)
+ ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
+ mixed-targets := 1
+ endif
+endif
+
+ifeq ($(mixed-targets),1)
+# ===========================================================================
+# We're called with mixed targets (*config and build targets).
+# Handle them one by one.
+
+PHONY += $(MAKECMDGOALS) __build_one_by_one
+
+$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
+ @:
+
+__build_one_by_one:
+ $(Q)set -e; \
+ for i in $(MAKECMDGOALS); do \
+ $(MAKE) -f $(srctree)/Makefile $$i; \
+ done
+
+else
+
+include scripts/Kbuild.include
+
+# Cross compiling and selecting different set of gcc/bin-utils
+# ---------------------------------------------------------------------------
+#
+# When performing cross compilation for other architectures ARCH shall be set
+# to the target architecture. (See arch/* for the possibilities).
+# ARCH can be set during invocation of make:
+# make ARCH=ia64
+# Another way is to have ARCH set in the environment.
+# The default ARCH is the host where make is executed.
+
+# CROSS_COMPILE specify the prefix used for all executables used
+# during compilation. Only gcc and related bin-utils executables
+# are prefixed with $(CROSS_COMPILE).
+# CROSS_COMPILE can be set on the command line
+# make CROSS_COMPILE=ia64-linux-
+# Alternatively CROSS_COMPILE can be set in the environment.
+# Default value for CROSS_COMPILE is not to prefix executables
+# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
+ARCH ?= $(SUBARCH)
+SRCARCH := $(shell echo $(XEN_TARGET_ARCH) | \
+ sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+
+KCONFIG_CONFIG ?= .config
+export KCONFIG_CONFIG
+
+# SHELL used by kbuild
+CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
+ else if [ -x /bin/bash ]; then echo /bin/bash; \
+ else echo sh; fi ; fi)
+
+HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
+HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
+HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
+
+HOSTCC = gcc
+HOSTCXX = g++
+KBUILD_HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
+ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
+ $(HOSTCFLAGS)
+KBUILD_HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
+KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
+KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
+
+# Make variables (CC, etc...)
+AS = $(CROSS_COMPILE)as
+LD = $(CROSS_COMPILE)ld
+CC = $(CROSS_COMPILE)gcc
+CPP = $(CC) -E
+AR = $(CROSS_COMPILE)ar
+NM = $(CROSS_COMPILE)nm
+STRIP = $(CROSS_COMPILE)strip
+OBJCOPY = $(CROSS_COMPILE)objcopy
+OBJDUMP = $(CROSS_COMPILE)objdump
+OBJSIZE = $(CROSS_COMPILE)size
+PAHOLE = pahole
+LEX = flex
+YACC = bison
+AWK = awk
+PERL = perl
+PYTHON = python
+PYTHON2 = python2
+PYTHON3 = python3
+CHECK = sparse
+
+CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
+ -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
+NOSTDINC_FLAGS :=
+CFLAGS_KERNEL =
+AFLAGS_KERNEL =
+LDFLAGS_vmlinux =
+
+# Use LINUXINCLUDE when you must reference the include/ directory.
+# Needed to be compatible with the O= option
+LINUXINCLUDE := \
+ $(if $(building_out_of_srctree),-I$(srctree)/include) \
+ -I$(objtree)/include
+
+KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
+KBUILD_CFLAGS :=
+KBUILD_CPPFLAGS :=
+KBUILD_LDFLAGS :=
+GCC_PLUGINS_CFLAGS :=
+CLANG_FLAGS :=
+
+export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
+export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE PAHOLE LEX YACC AWK
+export PERL PYTHON PYTHON2 PYTHON3 CHECK CHECKFLAGS MAKE HOSTCXX
+export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
+
+export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
+export KBUILD_CFLAGS CFLAGS_KERNEL
+export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN
+export KBUILD_AFLAGS AFLAGS_KERNEL
+export KBUILD_ARFLAGS
+
+# Files to ignore in find ... statements
+
+export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
+ -name CVS -o -name .pc -o -name .hg -o -name .git \) \
+ -prune -o
+export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
+ --exclude CVS --exclude .pc --exclude .hg --exclude .git
+
+# ===========================================================================
+# Rules shared between *config targets and build targets
+
+# Basic helpers built in scripts/basic/
+PHONY += scripts_basic
+scripts_basic:
+ $(Q)$(MAKE) $(build)=scripts/basic
+
+PHONY += outputmakefile
+# outputmakefile generates a Makefile in the output directory, if using a
+# separate output directory. This allows convenient use of make in the
+# output directory.
+# At the same time when output Makefile generated, generate .gitignore to
+# ignore whole output directory
+outputmakefile:
+ifdef building_out_of_srctree
+ $(Q)ln -fsn $(srctree) source
+ $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
+ $(Q)test -e .gitignore || \
+ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
+endif
+
+ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
+ifneq ($(CROSS_COMPILE),)
+CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
+GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
+CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)
+GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
+endif
+ifneq ($(GCC_TOOLCHAIN),)
+CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
+endif
+ifeq ($(shell $(AS) --version 2>&1 | head -n 1 | grep clang),)
+CLANG_FLAGS += -no-integrated-as
+endif
+CLANG_FLAGS += -Werror=unknown-warning-option
+KBUILD_CFLAGS += $(CLANG_FLAGS)
+KBUILD_AFLAGS += $(CLANG_FLAGS)
+export CLANG_FLAGS
+endif
+
+# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
+# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
+# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
+# and from include/config/auto.conf.cmd to detect the compiler upgrade.
+CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1)
+
+ifeq ($(config-targets),1)
+# ===========================================================================
+# *config targets only - make sure prerequisites are updated, and descend
+# in scripts/kconfig to make the *config target
+
+# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
+# KBUILD_DEFCONFIG may point out an alternative default configuration
+# used for 'make defconfig'
+include arch/$(SRCARCH)/Makefile
+export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
+
+config: scripts_basic outputmakefile FORCE
+ $(Q)$(MAKE) $(build)=scripts/kconfig $@
+
+%config: scripts_basic outputmakefile FORCE
+ $(Q)$(MAKE) $(build)=scripts/kconfig $@
+
+else
+# ===========================================================================
+# Build targets only - this includes vmlinux, arch specific targets, clean
+# targets and others. In general all targets except *config targets.
+
+PHONY += all
+_all: all
+
+# Just do built-in.
+
+KBUILD_BUILTIN := 1
+
+export KBUILD_BUILTIN
+
+ifeq ($(dot-config),1)
+include include/config/auto.conf
+endif
+
+ifeq ($(KBUILD_EXTMOD),)
+# Objects we will link into vmlinux / subdirs we need to visit
+init-y := init/
+drivers-y := drivers/ sound/
+drivers-$(CONFIG_SAMPLES) += samples/
+drivers-$(CONFIG_KERNEL_HEADER_TEST) += include/
+net-y := net/
+libs-y := lib/
+core-y := usr/
+virt-y := virt/
+endif # KBUILD_EXTMOD
+
+# The all: target is the default when no target is given on the
+# command line.
+# This allow a user to issue only 'make' to build a kernel including modules
+# Defaults to vmlinux, but the arch makefile usually adds further targets
+all: vmlinux
+
+CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
+ $(call cc-option,-fno-tree-loop-im) \
+ $(call cc-disable-warning,maybe-uninitialized,)
+export CFLAGS_GCOV
+
+# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
+ifdef CONFIG_FUNCTION_TRACER
+ CC_FLAGS_FTRACE := -pg
+endif
+
+RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
+RETPOLINE_VDSO_CFLAGS_GCC := -mindirect-branch=thunk-inline -mindirect-branch-register
+RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
+RETPOLINE_VDSO_CFLAGS_CLANG := -mretpoline
+RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
+RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_VDSO_CFLAGS_CLANG)))
+export RETPOLINE_CFLAGS
+export RETPOLINE_VDSO_CFLAGS
+
+# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
+# values of the respective KBUILD_* variables
+ARCH_CPPFLAGS :=
+ARCH_AFLAGS :=
+ARCH_CFLAGS :=
+include arch/$(SRCARCH)/Makefile
+
+ifeq ($(dot-config),1)
+ifeq ($(may-sync-config),1)
+# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
+# changes are detected. This should be included after arch/$(SRCARCH)/Makefile
+# because some architectures define CROSS_COMPILE there.
+include include/config/auto.conf.cmd
+
+$(KCONFIG_CONFIG):
+ @echo >&2 '***'
+ @echo >&2 '*** Configuration file "$@" not found!'
+ @echo >&2 '***'
+ @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
+ @echo >&2 '*** "make menuconfig" or "make xconfig").'
+ @echo >&2 '***'
+ @/bin/false
+
+# The actual configuration files used during the build are stored in
+# include/generated/ and include/config/. Update them if .config is newer than
+# include/config/auto.conf (which mirrors .config).
+#
+# This exploits the 'multi-target pattern rule' trick.
+# The syncconfig should be executed only once to make all the targets.
+%/auto.conf %/auto.conf.cmd %/tristate.conf: $(KCONFIG_CONFIG)
+ $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
+else
+# External modules and some install targets need include/generated/autoconf.h
+# and include/config/auto.conf but do not care if they are up-to-date.
+# Use auto.conf to trigger the test
+PHONY += include/config/auto.conf
+
+include/config/auto.conf:
+ $(Q)test -e include/generated/autoconf.h -a -e $@ || ( \
+ echo >&2; \
+ echo >&2 " ERROR: Kernel configuration is invalid."; \
+ echo >&2 " include/generated/autoconf.h or $@ are missing.";\
+ echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
+ echo >&2 ; \
+ /bin/false)
+
+endif # may-sync-config
+endif # $(dot-config)
+
+
+# arch Makefile may override CC so keep this after arch Makefile is included
+NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
+
+
+
+# use the deterministic mode of AR if available
+KBUILD_ARFLAGS := $(call ar-option,D)
+
+include scripts/Makefile.kasan
+include scripts/Makefile.ubsan
+
+# Add any arch overrides and user supplied CPPFLAGS, AFLAGS and CFLAGS as the
+# last assignments
+KBUILD_CPPFLAGS += $(ARCH_CPPFLAGS) $(KCPPFLAGS)
+KBUILD_AFLAGS += $(ARCH_AFLAGS) $(KAFLAGS)
+KBUILD_CFLAGS += $(ARCH_CFLAGS) $(KCFLAGS)
+
+# insure the checker run with the right endianness
+CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
+
+# the checker needs the correct machine size
+CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
+
+# Default kernel image to build when no specific target is given.
+# KBUILD_IMAGE may be overruled on the command line or
+# set in the environment
+# Also any assignments in arch/$(ARCH)/Makefile take precedence over
+# this default value
+export KBUILD_IMAGE ?= vmlinux
+
+#
+# INSTALL_PATH specifies where to place the updated kernel and system map
+# images. Default is /boot, but you can set it to other values
+export INSTALL_PATH ?= /boot
+
+HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
+
+PHONY += prepare0
+
+core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
+
+vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
+ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
+ $(net-y) $(net-m) $(libs-y) $(libs-m) $(virt-y)))
+
+vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \
+ $(patsubst %/,%,$(filter %/, $(init-) $(core-) \
+ $(drivers-) $(net-) $(libs-) $(virt-))))
+
+init-y := $(patsubst %/, %/built-in.a, $(init-y))
+core-y := $(patsubst %/, %/built-in.a, $(core-y))
+drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y))
+net-y := $(patsubst %/, %/built-in.a, $(net-y))
+libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
+libs-y2 := $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y)))
+virt-y := $(patsubst %/, %/built-in.a, $(virt-y))
+
+# Externally visible symbols (used by link-vmlinux.sh)
+export KBUILD_VMLINUX_OBJS := $(head-y) $(init-y) $(core-y) $(libs-y2) \
+ $(drivers-y) $(net-y) $(virt-y)
+export KBUILD_VMLINUX_LIBS := $(libs-y1)
+export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
+export LDFLAGS_vmlinux
+# used by scripts/package/Makefile
+export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) LICENSES arch include scripts tools)
+
+vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)
+
+ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
+
+# Final link of vmlinux with optional arch pass after final link
+cmd_link-vmlinux = \
+ $(CONFIG_SHELL) $< $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) ; \
+ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+
+vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
+ +$(call if_changed,link-vmlinux)
+
+targets := vmlinux
+
+# The actual objects are generated when descending,
+# make sure no implicit rule kicks in
+$(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
+
+# Handle descending into subdirectories listed in $(vmlinux-dirs)
+# Preset locale variables to speed up the build process. Limit locale
+# tweaks to this spot to avoid wrong language settings when running
+# make menuconfig etc.
+# Error messages still appears in the original language
+
+PHONY += $(vmlinux-dirs)
+$(vmlinux-dirs): prepare
+ $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1
+
+filechk_kernel.release = \
+ echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
+
+# Store (new) KERNELRELEASE string in include/config/kernel.release
+include/config/kernel.release: FORCE
+ $(call filechk,kernel.release)
+
+# Additional helpers built in scripts/
+# Carefully list dependencies so we do not try to build scripts twice
+# in parallel
+PHONY += scripts
+scripts: scripts_basic scripts_dtc
+ $(Q)$(MAKE) $(build)=$(@)
+
+# Things we need to do before we recursively start building the kernel
+# or the modules are listed in "prepare".
+# A multi level approach is used. prepareN is processed before prepareN-1.
+# archprepare is used in arch Makefiles and when processed asm symlink,
+# version.h and scripts_basic is processed / created.
+
+PHONY += prepare archprepare prepare3
+
+# prepare3 is used to check if we are building in a separate output directory,
+# and if so do:
+# 1) Check that make has not been executed in the kernel src $(srctree)
+prepare3: include/config/kernel.release
+ifdef building_out_of_srctree
+ @$(kecho) ' Using $(srctree) as source for kernel'
+ $(Q)if [ -f $(srctree)/.config -o \
+ -d $(srctree)/include/config -o \
+ -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
+ echo >&2 " $(srctree) is not clean, please run 'make ARCH=$(ARCH) mrproper'"; \
+ echo >&2 " in the '$(srctree)' directory.";\
+ /bin/false; \
+ fi;
+endif
+
+archprepare: archheaders archscripts scripts prepare3 outputmakefile \
+ asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h
+
+prepare0: archprepare
+ $(Q)$(MAKE) $(build)=scripts/mod
+ $(Q)$(MAKE) $(build)=.
+
+# All the preparing..
+prepare: prepare0
+
+# Generate some files
+# ---------------------------------------------------------------------------
+
+# KERNELRELEASE can change from a few different places, meaning version.h
+# needs to be updated, so this check is forced on all builds
+
+uts_len := 64
+define filechk_utsrelease.h
+ if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
+ echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
+ exit 1; \
+ fi; \
+ echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
endef
-define set_exuberant_flags
- exuberant_flags=`$1 --version 2>/dev/null | (grep -iq exuberant && \
- echo "-I __initdata,__exitdata,__acquires,__releases \
- -I EXPORT_SYMBOL \
- --extra=+f --c-kinds=+px") || true`
+define filechk_version.h
+ echo \#define LINUX_VERSION_CODE $(shell \
+ expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \
+ echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'
endef
-.PHONY: xenversion
+$(version_h): FORCE
+ $(call filechk,version.h)
+ $(Q)rm -f $(old_version_h)
+
+###
+# Cleaning is done on three levels.
+# make clean Delete most generated files
+# Leave enough to build external modules
+# make mrproper Delete the current configuration, and all generated files
+# make distclean Remove editor backup files, patch leftover files and the like
+
+# Directories & files removed with 'make clean'
+CLEAN_DIRS += include/ksym
+CLEAN_FILES += modules.builtin.modinfo
+
+# Directories & files removed with 'make mrproper'
+MRPROPER_DIRS += include/config include/generated \
+ arch/$(SRCARCH)/include/generated .tmp_objdiff
+MRPROPER_FILES += .config .config.old .version \
+ Module.symvers \
+ signing_key.pem signing_key.priv signing_key.x509 \
+ x509.genkey extra_certificates signing_key.x509.keyid \
+ signing_key.x509.signer vmlinux-gdb.py
+
+# Directories & files removed with 'make distclean'
+DISTCLEAN_DIRS +=
+DISTCLEAN_FILES += tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
+
+# clean - Delete most, but leave enough to build external modules
+#
+clean: rm-dirs := $(CLEAN_DIRS)
+clean: rm-files := $(CLEAN_FILES)
+clean-dirs := $(addprefix _clean_, . $(vmlinux-alldirs))
+
+PHONY += $(clean-dirs) clean archclean vmlinuxclean
+$(clean-dirs):
+ $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
+
+vmlinuxclean:
+ $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
+ $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
+
+clean: archclean vmlinuxclean
+
+# mrproper - Delete all generated files, including .config
+#
+mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
+mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
+mrproper-dirs := $(addprefix _mrproper_,scripts)
+
+PHONY += $(mrproper-dirs) mrproper
+$(mrproper-dirs):
+ $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
+
+mrproper: clean $(mrproper-dirs)
+ $(call cmd,rmdirs)
+ $(call cmd,rmfiles)
+
+# distclean
+#
+distclean: rm-dirs := $(wildcard $(DISTCLEAN_DIRS))
+distclean: rm-files := $(wildcard $(DISTCLEAN_FILES))
+
+PHONY += distclean
+
+distclean: mrproper
+ $(call cmd,rmdirs)
+ $(call cmd,rmfiles)
+ @find $(srctree) $(RCS_FIND_IGNORE) \
+ \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
+ -o -name '*.bak' -o -name '#*#' -o -name '*%' \
+ -o -name 'core' \) \
+ -type f -print | xargs rm -f
+
+
+# Brief documentation of the typical targets used
+# ---------------------------------------------------------------------------
+
+boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
+boards := $(sort $(notdir $(boards)))
+board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
+board-dirs := $(sort $(notdir $(board-dirs:/=)))
+
+PHONY += help
+help:
+ @echo 'Cleaning targets:'
+ @echo ' clean - Remove most generated files but keep the config and'
+ @echo ' enough build support to build external modules'
+ @echo ' mrproper - Remove all generated files + config + various backup files'
+ @echo ' distclean - mrproper + remove editor backup and patch files'
+ @echo ''
+ @echo 'Configuration targets:'
+ @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
+ @echo ''
+ @echo 'Other generic targets:'
+ @echo ' all - Build all targets marked with [*]'
+ @echo '* vmlinux - Build the bare kernel'
+ @echo '* modules - Build all modules'
+ @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
+ @echo ' dir/ - Build all files in dir and below'
+ @echo ' dir/file.[ois] - Build specified target only'
+ @echo ' dir/file.ll - Build the LLVM assembly file'
+ @echo ' (requires compiler support for LLVM assembly generation)'
+ @echo ' dir/file.lst - Build specified mixed source/assembly target only'
+ @echo ' (requires a recent binutils and recent build (System.map))'
+ @echo ' dir/file.ko - Build module including final link'
+ @echo ' modules_prepare - Set up for building external modules'
+ @echo ' tags/TAGS - Generate tags file for editors'
+ @echo ' cscope - Generate cscope index'
+ @echo ' gtags - Generate GNU GLOBAL index'
+ @echo ' kernelrelease - Output the release version string (use with make -s)'
+ @echo ' kernelversion - Output the version stored in Makefile (use with make -s)'
+ @echo ' image_name - Output the image name (use with make -s)'
+ @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
+ echo ' (default: $(INSTALL_HDR_PATH))'; \
+ echo ''
+ @echo 'Static analysers:'
+ @echo ' checkstack - Generate a list of stack hogs'
+ @echo ' namespacecheck - Name space analysis on compiled kernel'
+ @echo ' versioncheck - Sanity check on version.h usage'
+ @echo ' includecheck - Check for duplicate included header files'
+ @echo ' export_report - List the usages of all exported symbols'
+ @echo ' headers_check - Sanity check on exported headers'
+ @echo ' headerdep - Detect inclusion cycles in headers'
+ @echo ' coccicheck - Check with Coccinelle'
+ @echo ''
+ @echo 'Kernel selftest:'
+ @echo ' kselftest - Build and run kernel selftest (run as root)'
+ @echo ' Build, install, and boot kernel before'
+ @echo ' running kselftest on it'
+ @echo ' kselftest-clean - Remove all generated kselftest files'
+ @echo ' kselftest-merge - Merge all the config dependencies of kselftest to existing'
+ @echo ' .config.'
+ @echo ''
+ @$(if $(dtstree), \
+ echo 'Devicetree:'; \
+ echo '* dtbs - Build device tree blobs for enabled boards'; \
+ echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
+ echo '')
+
+ @echo 'Userspace tools targets:'
+ @echo ' use "make tools/help"'
+ @echo ' or "cd tools; make help"'
+ @echo ''
+ @echo 'Kernel packaging:'
+ @$(MAKE) $(build)=$(package-dir) help
+ @echo ''
+ @echo 'Documentation targets:'
+ @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
+ @echo ''
+ @echo 'Architecture specific targets ($(SRCARCH)):'
+ @$(if $(archhelp),$(archhelp),\
+ echo ' No architecture specific help defined for $(SRCARCH)')
+ @echo ''
+ @$(if $(boards), \
+ $(foreach b, $(boards), \
+ printf " %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
+ echo '')
+ @$(if $(board-dirs), \
+ $(foreach b, $(board-dirs), \
+ printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
+ printf " %-16s - Show all of the above\\n" help-boards; \
+ echo '')
+
+ @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
+ @echo ' make V=2 [targets] 2 => give reason for rebuild of target'
+ @echo ' make O=dir [targets] Locate all output files in "dir", including .config'
+ @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK (sparse by default)'
+ @echo ' make C=2 [targets] Force check of all c source with $$CHECK'
+ @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
+ @echo ' make W=n [targets] Enable extra gcc checks, n=1,2,3 where'
+ @echo ' 1: warnings which may be relevant and do not occur too often'
+ @echo ' 2: warnings which occur quite often but may still be relevant'
+ @echo ' 3: more obscure warnings, can most likely be ignored'
+ @echo ' Multiple levels can be combined with W=12 or W=123'
+ @echo ''
+ @echo 'Execute "make" or "make all" to build all targets marked with [*] '
+ @echo 'For further info see the ./README file'
+
+
+help-board-dirs := $(addprefix help-,$(board-dirs))
+
+help-boards: $(help-board-dirs)
+
+boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
+
+$(help-board-dirs): help-%:
+ @echo 'Architecture specific targets ($(SRCARCH) $*):'
+ @$(if $(boards-per-dir), \
+ $(foreach b, $(boards-per-dir), \
+ printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
+ echo '')
+
+
+# Misc
+# ---------------------------------------------------------------------------
+
+clean: $(clean-dirs)
+ $(call cmd,rmdirs)
+ $(call cmd,rmfiles)
+ @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
+ \( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \
+ -o -name '*.ko.*' \
+ -o -name '*.dtb' -o -name '*.dtb.S' -o -name '*.dt.yaml' \
+ -o -name '*.dwo' -o -name '*.lst' \
+ -o -name '*.su' -o -name '*.mod' \
+ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
+ -o -name '*.lex.c' -o -name '*.tab.[ch]' \
+ -o -name '*.asn1.[ch]' \
+ -o -name '*.symtypes' -o -name 'modules.order' \
+ -o -name modules.builtin -o -name '.tmp_*.o.*' \
+ -o -name '*.c.[012]*.*' \
+ -o -name '*.ll' \
+ -o -name '*.gcno' \) -type f -print | xargs rm -f
+
+# Generate tags for editors
+# ---------------------------------------------------------------------------
+quiet_cmd_tags = GEN $@
+ cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
+
+tags TAGS cscope gtags: FORCE
+ $(call cmd,tags)
+
+# Scripts to check various things for consistency
+# ---------------------------------------------------------------------------
+
+PHONY += includecheck versioncheck
+
+includecheck:
+ find $(srctree)/* $(RCS_FIND_IGNORE) \
+ -name '*.[hcS]' -type f -print | sort \
+ | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
+
+versioncheck:
+ find $(srctree)/* $(RCS_FIND_IGNORE) \
+ -name '*.[hcS]' -type f -print | sort \
+ | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
+
+PHONY += xenversion image_name
+
xenversion:
@echo $(XEN_FULLVERSION)
-.PHONY: _TAGS
-_TAGS:
- set -e; rm -f TAGS; \
- $(call set_exuberant_flags,etags); \
- $(all_sources) | xargs etags $$exuberant_flags -a
-
-.PHONY: _tags
-_tags:
- set -e; rm -f tags; \
- $(call set_exuberant_flags,ctags); \
- $(all_sources) | xargs ctags $$exuberant_flags -a
-
-.PHONY: _gtags
-_gtags:
- set -e; rm -f GTAGS GSYMS GPATH GRTAGS
- $(all_sources) | gtags -f -
-
-.PHONY: _cscope
-_cscope:
- $(all_sources) > cscope.files
- cscope -k -b -q
-
-.PHONY: _MAP
-_MAP:
- $(NM) -n $(TARGET)-syms | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' > System.map
-
-.PHONY: FORCE
-FORCE:
-
-%.o %.i %.s: %.c FORCE
- $(MAKE) -f $(BASEDIR)/Rules.mk -C $(*D) $(@F)
+image_name:
+ @echo $(KBUILD_IMAGE)
-%.o %.s: %.S FORCE
- $(MAKE) -f $(BASEDIR)/Rules.mk -C $(*D) $(@F)
+# Single targets
+# ---------------------------------------------------------------------------
+# Single targets are compatible with:
+# - build with mixed source and output
+# - build with separate output dir 'make O=...'
+#
+# target-dir => where to store outputfile
+# build-dir => directory in kernel source tree to use
-%/: FORCE
- $(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o built_in_bin.o
+build-target = $@
+build-dir = $(patsubst %/,%,$(dir $(build-target)))
-build-intermediate = $(eval $(call build-intermediate-closure,$(1)))
-define build-intermediate-closure
-$(1): FORCE
- $(MAKE) -f $(BASEDIR)/Rules.mk -C $$(@D) $$(@F)
-endef
+%.i: prepare FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
+%.ll: prepare FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
+%.lst: prepare FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
+%.o: prepare FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
+%.s: prepare FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
+%.symtypes: prepare FORCE
+ $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
-$(foreach base,arch/x86/mm/guest_walk_% \
- arch/x86/mm/hap/guest_walk_%level \
- arch/x86/mm/shadow/guest_%, \
- $(foreach ext,o i s,$(call build-intermediate,$(base).$(ext))))
+# FIXME Should go into a make.lib or something
+# ===========================================================================
-kconfig := oldconfig config menuconfig defconfig \
- nconfig xconfig gconfig savedefconfig listnewconfig olddefconfig \
- randconfig $(notdir $(wildcard arch/$(SRCARCH)/configs/*_defconfig))
-.PHONY: $(kconfig)
-$(kconfig):
- $(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" $@
+quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
+ cmd_rmdirs = rm -rf $(rm-dirs)
-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)" syncconfig
+quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
+ cmd_rmfiles = rm -f $(rm-files)
-# 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
+# read saved command lines for existing targets
+existing-targets := $(wildcard $(sort $(targets)))
-# Break the dependency chain for the first run
-include/config/auto.conf.cmd: ;
+-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
--include $(BASEDIR)/include/config/auto.conf.cmd
+endif # ifeq ($(config-targets),1)
+endif # ifeq ($(mixed-targets),1)
+endif # need-sub-make
-.PHONY: cloc
-cloc:
- $(eval tmpfile := $(shell mktemp))
- $(foreach f, $(shell find $(BASEDIR) -name *.o.d), \
- $(eval path := $(dir $(f))) \
- $(eval names := $(shell grep -o "[a-zA-Z0-9_/-]*\.[cS]" $(f))) \
- $(foreach sf, $(names), \
- $(shell if test -f $(path)/$(sf) ; then echo $(path)/$(sf) >> $(tmpfile); fi;)))
- cloc --list-file=$(tmpfile)
- rm $(tmpfile)
+PHONY += FORCE
+FORCE:
+# Declare the contents of the PHONY variable as phony. We keep that
+# information in a variable so we can use it in if_changed and friends.
+.PHONY: $(PHONY)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 22/23] Changes to root Makefile
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (19 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 21/23] Import root Makefile from Linux v5.3 Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 23/23] xen/tools/kconfig: Delete duplicate makefiles Anthony PERARD
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
- *FLAGS
- fix path to Kconfig
- List objects to build
- generate include/xen/compile.h
- make prepare phase
- changes to clean
- remove build of kernel.version
---
xen/Makefile | 263 ++++++++++++++++++++++++++++-----------------------
1 file changed, 143 insertions(+), 120 deletions(-)
diff --git a/xen/Makefile b/xen/Makefile
index 90645668957c..66448b067eb0 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -13,8 +13,6 @@ export XEN_BUILD_DATE ?= $(shell LC_ALL=C date)
export XEN_BUILD_TIME ?= $(shell LC_ALL=C date +%T)
export XEN_BUILD_HOST ?= $(shell hostname)
-export XEN_ROOT := $(CURDIR)/..
-
# *DOCUMENTATION*
# To see a list of typical targets execute "make help"
# More info can be located in ./README
@@ -238,8 +236,10 @@ endif
objtree := .
VPATH := $(srctree)
+XEN_ROOT := $(abs_srctree)/..
export building_out_of_srctree srctree objtree VPATH
+export XEN_ROOT
# To make sure we do not include .config for any of the *config targets
# catch them early, and hand them over to scripts/kconfig/Makefile
@@ -316,6 +316,15 @@ else
include scripts/Kbuild.include
+# XXX From Config.mk
+XEN_COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/ \
+ -e s/i86pc/x86_32/ -e s/amd64/x86_64/ \
+ -e s/armv7.*/arm32/ -e s/armv8.*/arm64/ \
+ -e s/aarch64/arm64/)
+XEN_TARGET_ARCH ?= $(XEN_COMPILE_ARCH)
+XEN_OS ?= $(shell uname -s)
+export XEN_OS
+
# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
@@ -334,7 +343,7 @@ include scripts/Kbuild.include
# Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
-ARCH ?= $(SUBARCH)
+ARCH ?= $(XEN_COMPILE_ARCH)
SRCARCH := $(shell echo $(XEN_TARGET_ARCH) | \
sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
@@ -363,6 +372,7 @@ KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
+CXX = $(CROSS_COMPILE)g++
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
@@ -385,7 +395,7 @@ CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
NOSTDINC_FLAGS :=
CFLAGS_KERNEL =
AFLAGS_KERNEL =
-LDFLAGS_vmlinux =
+LDFLAGS_xen =
# Use LINUXINCLUDE when you must reference the include/ directory.
# Needed to be compatible with the O= option
@@ -395,13 +405,35 @@ LINUXINCLUDE := \
KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
KBUILD_CFLAGS :=
+
+# XXX CFLAGS found in xen.git/config/$(XEN_TARGET_ARCH).mk
+KBUILD_CFLAGS += -m64
+# XXX CFLAGS found in Config.mk
+export XEN_HAS_BUILD_ID ?= n
+ifeq ($(call ld-option,--build-id),)
+build_id_linker :=
+else
+KBUILD_CFLAGS += -DBUILD_ID
+export XEN_HAS_BUILD_ID=y
+build_id_linker := --build-id=sha1
+# possible improvement: LDFLAGS_xen-syms := --build-id=sha1
+endif
+export build_id_linker
+KBUILD_CFLAGS += -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
+KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement)
+KBUILD_CFLAGS += $(call cc-disable-warning,unused-but-set-variable)
+KBUILD_CFLAGS += $(call cc-disable-warning,unused-local-typedefs)
+
+EMBEDDED_EXTRA_CFLAGS := -nopie -fno-stack-protector -fno-stack-protector-all
+EMBEDDED_EXTRA_CFLAGS += -fno-exceptions
+
KBUILD_CPPFLAGS :=
KBUILD_LDFLAGS :=
GCC_PLUGINS_CFLAGS :=
CLANG_FLAGS :=
export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
-export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE PAHOLE LEX YACC AWK
+export CXX CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE PAHOLE LEX YACC AWK
export PERL PYTHON PYTHON2 PYTHON3 CHECK CHECKFLAGS MAKE HOSTCXX
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
@@ -469,7 +501,7 @@ CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1)
ifeq ($(config-targets),1)
# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
-# in scripts/kconfig to make the *config target
+# in tools/kconfig to make the *config target
# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
# KBUILD_DEFCONFIG may point out an alternative default configuration
@@ -478,10 +510,10 @@ include arch/$(SRCARCH)/Makefile
export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
config: scripts_basic outputmakefile FORCE
- $(Q)$(MAKE) $(build)=scripts/kconfig $@
+ $(Q)$(MAKE) $(build)=tools/kconfig $@
%config: scripts_basic outputmakefile FORCE
- $(Q)$(MAKE) $(build)=scripts/kconfig $@
+ $(Q)$(MAKE) $(build)=tools/kconfig $@
else
# ===========================================================================
@@ -501,23 +533,18 @@ ifeq ($(dot-config),1)
include include/config/auto.conf
endif
-ifeq ($(KBUILD_EXTMOD),)
-# Objects we will link into vmlinux / subdirs we need to visit
-init-y := init/
-drivers-y := drivers/ sound/
-drivers-$(CONFIG_SAMPLES) += samples/
-drivers-$(CONFIG_KERNEL_HEADER_TEST) += include/
-net-y := net/
-libs-y := lib/
-core-y := usr/
-virt-y := virt/
-endif # KBUILD_EXTMOD
+# Objects we will link into xen / subdirs we need to visit
+common-y := common/
+drivers-y := drivers/
+libs-$(CONFIG_X86) := lib/
+xsm-y := xsm/
+arch-y := arch/$(SRCARCH)/
+crypto-$(CONFIG_CRYPTO) := crypto/
# The all: target is the default when no target is given on the
# command line.
-# This allow a user to issue only 'make' to build a kernel including modules
-# Defaults to vmlinux, but the arch makefile usually adds further targets
-all: vmlinux
+# Defaults to xen, but the arch makefile usually adds further targets
+all: xen
CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
$(call cc-option,-fno-tree-loop-im) \
@@ -552,14 +579,9 @@ ifeq ($(may-sync-config),1)
# because some architectures define CROSS_COMPILE there.
include include/config/auto.conf.cmd
+# Allow people to just run `make` as before and not force them to configure
$(KCONFIG_CONFIG):
- @echo >&2 '***'
- @echo >&2 '*** Configuration file "$@" not found!'
- @echo >&2 '***'
- @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
- @echo >&2 '*** "make menuconfig" or "make xconfig").'
- @echo >&2 '***'
- @/bin/false
+ $(Q)$(MAKE) -f $(srctree)/Makefile defconfig
# The actual configuration files used during the build are stored in
# include/generated/ and include/config/. Update them if .config is newer than
@@ -587,15 +609,40 @@ include/config/auto.conf:
endif # may-sync-config
endif # $(dot-config)
+# XXX CFLAGS found in Rules.mk
+ifeq ($(CONFIG_DEBUG),y)
+KBUILD_CFLAGS += -O1
+else
+KBUILD_CFLAGS += -O2
+endif
-# arch Makefile may override CC so keep this after arch Makefile is included
-NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
+ifeq ($(CONFIG_FRAME_POINTER),y)
+KBUILD_CFLAGS += -fno-omit-frame-pointer
+else
+KBUILD_CFLAGS += -fomit-frame-pointer
+endif
+KBUILD_CFLAGS += -fno-builtin -fno-common
+KBUILD_CFLAGS += -Werror -Wredundant-decls -Wno-pointer-arith
+KBUILD_CFLAGS += $(call cc-option,-Wvla)
+KBUILD_CFLAGS += -pipe -D__XEN__ -include $(srctree)/include/xen/config.h
+ifeq ($(CONFIG_DEBUG_INFO),y)
+KBUILD_CFLAGS += -g
+endif
+KBUILD_CFLAGS += -Wa,--strip-local-absolute
+
+# arch Makefile may override CC so keep this after arch Makefile is included
+NOSTDINC_FLAGS += -nostdinc
# use the deterministic mode of AR if available
KBUILD_ARFLAGS := $(call ar-option,D)
+# Most CFLAGS are safe for assembly files:
+# -std=gnu{89,99} gets confused by #-prefixed end-of-line comments
+# -flto makes no sense and annoys clang
+KBUILD_AFLAGS += $(filter-out -std=gnu% -flto,$(KBUILD_CFLAGS))
+
include scripts/Makefile.kasan
include scripts/Makefile.ubsan
@@ -616,7 +663,7 @@ CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
# set in the environment
# Also any assignments in arch/$(ARCH)/Makefile take precedence over
# this default value
-export KBUILD_IMAGE ?= vmlinux
+export KBUILD_IMAGE ?= xen
#
# INSTALL_PATH specifies where to place the updated kernel and system map
@@ -627,74 +674,59 @@ HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
PHONY += prepare0
-core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
+xen-dirs := $(patsubst %/,%,$(filter %/, $(head-y) $(common-y) \
+ $(drivers-y) $(libs-y) $(xsm-y) $(arch-y) \
+ $(crypto-y)))
-vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
- $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
- $(net-y) $(net-m) $(libs-y) $(libs-m) $(virt-y)))
+xen-alldirs := $(sort $(xen-dirs) \
+ $(patsubst %/,%,$(filter %/, $(head-y) $(common-) \
+ $(drivers-) $(libs-) $(xsm-) $(arch-) $(crypto-))))
+xen-alldirs += include
-vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \
- $(patsubst %/,%,$(filter %/, $(init-) $(core-) \
- $(drivers-) $(net-) $(libs-) $(virt-))))
-
-init-y := $(patsubst %/, %/built-in.a, $(init-y))
-core-y := $(patsubst %/, %/built-in.a, $(core-y))
+head-y := $(patsubst %/, %/built-in.a, $(head-y))
+common-y := $(patsubst %/, %/built-in.a, $(common-y))
drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y))
-net-y := $(patsubst %/, %/built-in.a, $(net-y))
libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
libs-y2 := $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y)))
-virt-y := $(patsubst %/, %/built-in.a, $(virt-y))
+xsm-y := $(patsubst %/, %/built-in.a, $(xsm-y))
+arch-y := $(patsubst %/, %/built-in.a, $(arch-y))
+crypto-y := $(patsubst %/, %/built-in.a, $(crypto-y))
-# Externally visible symbols (used by link-vmlinux.sh)
-export KBUILD_VMLINUX_OBJS := $(head-y) $(init-y) $(core-y) $(libs-y2) \
- $(drivers-y) $(net-y) $(virt-y)
+# Externally visible symbols
+export ALL_OBJS := $(head-y) $(common-y) $(drivers-y) $(libs-y2) \
+ $(xsm-y) $(arch-y) $(crypto-y)
export KBUILD_VMLINUX_LIBS := $(libs-y1)
-export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
-export LDFLAGS_vmlinux
-# used by scripts/package/Makefile
-export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) LICENSES arch include scripts tools)
-
-vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)
-
-ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
+export KBUILD_LDS := arch/$(SRCARCH)/xen.lds
+export LDFLAGS_xen
+export TARGET := xen
-# Final link of vmlinux with optional arch pass after final link
-cmd_link-vmlinux = \
- $(CONFIG_SHELL) $< $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) ; \
- $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+xen-deps := $(KBUILD_LDS) $(ALL_OBJS) $(KBUILD_VMLINUX_LIBS)
-vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
- +$(call if_changed,link-vmlinux)
+xen: $(xen-deps) FORCE
+ $(Q)$(MAKE) $(build)=arch/$(SRCARCH) xen
-targets := vmlinux
+targets := xen
# The actual objects are generated when descending,
# make sure no implicit rule kicks in
-$(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
+$(sort $(xen-deps)): $(xen-dirs) ;
-# Handle descending into subdirectories listed in $(vmlinux-dirs)
+# Handle descending into subdirectories listed in $(xen-dirs)
# Preset locale variables to speed up the build process. Limit locale
# tweaks to this spot to avoid wrong language settings when running
# make menuconfig etc.
# Error messages still appears in the original language
-PHONY += $(vmlinux-dirs)
-$(vmlinux-dirs): prepare
+PHONY += $(xen-dirs)
+$(xen-dirs): prepare
$(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1
-filechk_kernel.release = \
- echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
-
-# Store (new) KERNELRELEASE string in include/config/kernel.release
-include/config/kernel.release: FORCE
- $(call filechk,kernel.release)
-
# Additional helpers built in scripts/
# Carefully list dependencies so we do not try to build scripts twice
# in parallel
PHONY += scripts
-scripts: scripts_basic scripts_dtc
- $(Q)$(MAKE) $(build)=$(@)
+scripts: scripts_basic
+ $(Q)$(MAKE) $(build)=tools
# Things we need to do before we recursively start building the kernel
# or the modules are listed in "prepare".
@@ -707,7 +739,7 @@ PHONY += prepare archprepare prepare3
# prepare3 is used to check if we are building in a separate output directory,
# and if so do:
# 1) Check that make has not been executed in the kernel src $(srctree)
-prepare3: include/config/kernel.release
+prepare3:
ifdef building_out_of_srctree
@$(kecho) ' Using $(srctree) as source for kernel'
$(Q)if [ -f $(srctree)/.config -o \
@@ -719,11 +751,15 @@ ifdef building_out_of_srctree
fi;
endif
-archprepare: archheaders archscripts scripts prepare3 outputmakefile \
- asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h
+PHONY += preprepare
+preprepare:
+ $(Q)[ -e $(objtree)/include/asm ] || ln -sf asm-$(SRCARCH) $(objtree)/include/asm
+ $(Q)$(MAKE) $(build)=include all
+
+archprepare: preprepare archheaders scripts prepare3 outputmakefile \
+ $(version_h)
prepare0: archprepare
- $(Q)$(MAKE) $(build)=scripts/mod
$(Q)$(MAKE) $(build)=.
# All the preparing..
@@ -732,73 +768,63 @@ prepare: prepare0
# Generate some files
# ---------------------------------------------------------------------------
-# KERNELRELEASE can change from a few different places, meaning version.h
+# KERNELRELEASE can change from a few different places, meaning compile.h
# needs to be updated, so this check is forced on all builds
-uts_len := 64
-define filechk_utsrelease.h
- if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
- echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
- exit 1; \
- fi; \
- echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
-endef
-
+# compile.h contains dynamic build info. Rebuilt on every 'make' invocation.
define filechk_version.h
- echo \#define LINUX_VERSION_CODE $(shell \
- expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \
- echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'
+ echo '#define XEN_COMPILE_DATE "$(XEN_BUILD_DATE)"'; \
+ echo '#define XEN_COMPILE_TIME "$(XEN_BUILD_TIME)"'; \
+ echo '#define XEN_COMPILE_BY "$(XEN_WHOAMI)"'; \
+ echo '#define XEN_COMPILE_DOMAIN "$(XEN_DOMAIN)"'; \
+ echo '#define XEN_COMPILE_HOST "$(XEN_BUILD_HOST)"'; \
+ echo '#define XEN_COMPILER "$(shell $(CC) $(KBUILD_CFLAGS) --version 2>&1 | head -1)"'; \
+ echo; \
+ echo '#define XEN_VERSION $(XEN_VERSION)'; \
+ echo '#define XEN_SUBVERSION $(XEN_SUBVERSION)'; \
+ echo '#define XEN_EXTRAVERSION "$(XEN_EXTRAVERSION)"'; \
+ echo; \
+ echo '#define XEN_CHANGESET "$(shell tools/scmversion $(XEN_ROOT) || echo "unavailable")"'; \
+ echo '#define XEN_BANNER "Xen $(XEN_FULLVERSION)"'
endef
$(version_h): FORCE
$(call filechk,version.h)
- $(Q)rm -f $(old_version_h)
###
# Cleaning is done on three levels.
# make clean Delete most generated files
-# Leave enough to build external modules
# make mrproper Delete the current configuration, and all generated files
# make distclean Remove editor backup files, patch leftover files and the like
# Directories & files removed with 'make clean'
-CLEAN_DIRS += include/ksym
-CLEAN_FILES += modules.builtin.modinfo
# Directories & files removed with 'make mrproper'
MRPROPER_DIRS += include/config include/generated \
- arch/$(SRCARCH)/include/generated .tmp_objdiff
-MRPROPER_FILES += .config .config.old .version \
- Module.symvers \
- signing_key.pem signing_key.priv signing_key.x509 \
- x509.genkey extra_certificates signing_key.x509.keyid \
- signing_key.x509.signer vmlinux-gdb.py
+ arch/$(SRCARCH)/include/generated
+MRPROPER_FILES += .config .config.old include/asm
# Directories & files removed with 'make distclean'
DISTCLEAN_DIRS +=
DISTCLEAN_FILES += tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
-# clean - Delete most, but leave enough to build external modules
+# clean - Delete most
#
clean: rm-dirs := $(CLEAN_DIRS)
clean: rm-files := $(CLEAN_FILES)
-clean-dirs := $(addprefix _clean_, . $(vmlinux-alldirs))
+clean-dirs := $(addprefix _clean_, . $(xen-alldirs))
-PHONY += $(clean-dirs) clean archclean vmlinuxclean
+PHONY += $(clean-dirs) clean archclean
$(clean-dirs):
$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
-vmlinuxclean:
- $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
- $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
-
-clean: archclean vmlinuxclean
+clean: archclean
# mrproper - Delete all generated files, including .config
#
mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
-mrproper-dirs := $(addprefix _mrproper_,scripts)
+mrproper-dirs := $(addprefix _mrproper_,tools)
PHONY += $(mrproper-dirs) mrproper
$(mrproper-dirs):
@@ -842,7 +868,7 @@ help:
@echo ' distclean - mrproper + remove editor backup and patch files'
@echo ''
@echo 'Configuration targets:'
- @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
+ @$(MAKE) -f $(srctree)/tools/kconfig/Makefile help
@echo ''
@echo 'Other generic targets:'
@echo ' all - Build all targets marked with [*]'
@@ -950,17 +976,14 @@ $(help-board-dirs): help-%:
clean: $(clean-dirs)
$(call cmd,rmdirs)
$(call cmd,rmfiles)
- @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
- \( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \
- -o -name '*.ko.*' \
- -o -name '*.dtb' -o -name '*.dtb.S' -o -name '*.dt.yaml' \
- -o -name '*.dwo' -o -name '*.lst' \
+ @find . $(RCS_FIND_IGNORE) \
+ \( -name '*.[aios]' -o -name '.*.cmd' \
+ -o -name '*.dwo' \
-o -name '*.su' -o -name '*.mod' \
- -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
+ -o -name '.*.d' -o -name '.*.tmp' \
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
-o -name '*.asn1.[ch]' \
- -o -name '*.symtypes' -o -name 'modules.order' \
- -o -name modules.builtin -o -name '.tmp_*.o.*' \
+ -o -name '.tmp_*.o.*' \
-o -name '*.c.[012]*.*' \
-o -name '*.ll' \
-o -name '*.gcno' \) -type f -print | xargs rm -f
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [Xen-devel] [RFC XEN PATCH 23/23] xen/tools/kconfig: Delete duplicate makefiles
2019-10-23 16:48 [Xen-devel] [RFC XEN PATCH 00/23] Kconfig update + WIP of using Kbuild Anthony PERARD
` (20 preceding siblings ...)
2019-10-23 16:48 ` [Xen-devel] [RFC XEN PATCH 22/23] Changes to root Makefile Anthony PERARD
@ 2019-10-23 16:48 ` Anthony PERARD
21 siblings, 0 replies; 25+ messages in thread
From: Anthony PERARD @ 2019-10-23 16:48 UTC (permalink / raw)
To: xen-devel; +Cc: Anthony PERARD
Makefile.host is now in xen/scripts
Makefile.kconfig isn't needed anymore.
---
xen/tools/kconfig/Makefile.host | 164 -----------------------------
xen/tools/kconfig/Makefile.kconfig | 126 ----------------------
2 files changed, 290 deletions(-)
delete mode 100644 xen/tools/kconfig/Makefile.host
delete mode 100644 xen/tools/kconfig/Makefile.kconfig
diff --git a/xen/tools/kconfig/Makefile.host b/xen/tools/kconfig/Makefile.host
deleted file mode 100644
index 2208ebbd8c4c..000000000000
--- a/xen/tools/kconfig/Makefile.host
+++ /dev/null
@@ -1,164 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-# ==========================================================================
-# Building binaries on the host system
-# Binaries are used during the compilation of the kernel, for example
-# to preprocess a data file.
-#
-# Both C and C++ are supported, but preferred language is C for such utilities.
-#
-# Sample syntax (see Documentation/kbuild/makefiles.rst for reference)
-# hostprogs-y := bin2hex
-# Will compile bin2hex.c and create an executable named bin2hex
-#
-# hostprogs-y := lxdialog
-# lxdialog-objs := checklist.o lxdialog.o
-# Will compile lxdialog.c and checklist.c, and then link the executable
-# lxdialog, based on checklist.o and lxdialog.o
-#
-# hostprogs-y := qconf
-# qconf-cxxobjs := qconf.o
-# qconf-objs := menu.o
-# Will compile qconf as a C++ program, and menu as a C program.
-# They are linked as C++ code to the executable qconf
-
-__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
-host-cshlib := $(sort $(hostlibs-y) $(hostlibs-m))
-host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
-
-# C code
-# Executables compiled from a single .c file
-host-csingle := $(foreach m,$(__hostprogs), \
- $(if $($(m)-objs)$($(m)-cxxobjs),,$(m)))
-
-# C executables linked based on several .o files
-host-cmulti := $(foreach m,$(__hostprogs),\
- $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
-
-# Object (.o) files compiled from .c files
-host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
-
-# C++ code
-# C++ executables compiled from at least one .cc file
-# and zero or more .c files
-host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
-
-# C++ Object (.o) files compiled from .cc files
-host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
-
-# Object (.o) files used by the shared libaries
-host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
-host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
-
-host-csingle := $(addprefix $(obj)/,$(host-csingle))
-host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
-host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
-host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
-host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
-host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
-host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
-host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
-host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
-
-#####
-# Handle options to gcc. Support building with separate output directory
-
-_hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
- $(HOSTCFLAGS_$(basetarget).o)
-_hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
- $(HOSTCXXFLAGS_$(basetarget).o)
-
-# $(objtree)/$(obj) for including generated headers from checkin source files
-ifeq ($(KBUILD_EXTMOD),)
-ifdef building_out_of_srctree
-_hostc_flags += -I $(objtree)/$(obj)
-_hostcxx_flags += -I $(objtree)/$(obj)
-endif
-endif
-
-hostc_flags = -Wp,-MD,$(depfile) $(_hostc_flags)
-hostcxx_flags = -Wp,-MD,$(depfile) $(_hostcxx_flags)
-
-#####
-# Compile programs on the host
-
-# Create executable from a single .c file
-# host-csingle -> Executable
-quiet_cmd_host-csingle = HOSTCC $@
- cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
-$(host-csingle): $(obj)/%: $(src)/%.c FORCE
- $(call if_changed_dep,host-csingle)
-
-# Link an executable based on list of .o files, all plain c
-# host-cmulti -> executable
-quiet_cmd_host-cmulti = HOSTLD $@
- cmd_host-cmulti = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \
- $(addprefix $(obj)/,$($(@F)-objs)) \
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
-$(host-cmulti): FORCE
- $(call if_changed,host-cmulti)
-$(call multi_depend, $(host-cmulti), , -objs)
-
-# Create .o file from a single .c file
-# host-cobjs -> .o
-quiet_cmd_host-cobjs = HOSTCC $@
- cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
-$(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
- $(call if_changed_dep,host-cobjs)
-
-# Link an executable based on list of .o files, a mixture of .c and .cc
-# host-cxxmulti -> executable
-quiet_cmd_host-cxxmulti = HOSTLD $@
- cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \
- $(foreach o,objs cxxobjs,\
- $(addprefix $(obj)/,$($(@F)-$(o)))) \
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
-$(host-cxxmulti): FORCE
- $(call if_changed,host-cxxmulti)
-$(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
-
-# Create .o file from a single .cc (C++) file
-quiet_cmd_host-cxxobjs = HOSTCXX $@
- cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
-$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
- $(call if_changed_dep,host-cxxobjs)
-
-# Compile .c file, create position independent .o file
-# host-cshobjs -> .o
-quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
- cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
-$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
- $(call if_changed_dep,host-cshobjs)
-
-# Compile .c file, create position independent .o file
-# Note that plugin capable gcc versions can be either C or C++ based
-# therefore plugin source files have to be compilable in both C and C++ mode.
-# This is why a C++ compiler is invoked on a .c file.
-# host-cxxshobjs -> .o
-quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
- cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
-$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
- $(call if_changed_dep,host-cxxshobjs)
-
-# Link a shared library, based on position independent .o files
-# *.o -> .so shared library (host-cshlib)
-quiet_cmd_host-cshlib = HOSTLLD -shared $@
- cmd_host-cshlib = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
- $(addprefix $(obj)/,$($(@F:.so=-objs))) \
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
-$(host-cshlib): FORCE
- $(call if_changed,host-cshlib)
-$(call multi_depend, $(host-cshlib), .so, -objs)
-
-# Link a shared library, based on position independent .o files
-# *.o -> .so shared library (host-cxxshlib)
-quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
- cmd_host-cxxshlib = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
- $(addprefix $(obj)/,$($(@F:.so=-objs))) \
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
-$(host-cxxshlib): FORCE
- $(call if_changed,host-cxxshlib)
-$(call multi_depend, $(host-cxxshlib), .so, -objs)
-
-targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
- $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
diff --git a/xen/tools/kconfig/Makefile.kconfig b/xen/tools/kconfig/Makefile.kconfig
deleted file mode 100644
index 6d2df760ff28..000000000000
--- a/xen/tools/kconfig/Makefile.kconfig
+++ /dev/null
@@ -1,126 +0,0 @@
-# xen/tools/kconfig
-
-# default rule to do nothing
-all:
-
-# Xen doesn't have a silent build flag
-quiet :=
-Q :=
-kecho := :
-
-# eventually you'll want to do out of tree builds
-srctree := $(XEN_ROOT)/xen
-objtree := $(srctree)
-src := tools/kconfig
-obj := $(src)
-
-# handle functions (most of these lifted from different Linux makefiles
-dot-target = $(dir $@).$(notdir $@)
-depfile = $(subst $(comma),,$(dot-target).d)
-basetarget = $(basename $(notdir $@))
-cmd = $(cmd_$(1))
-if_changed = $(cmd_$(1))
-if_changed_dep = $(cmd_$(1))
-
-###
-# filechk is used to check if the content of a generated file is updated.
-# Sample usage:
-#
-# filechk_sample = echo $(KERNELRELEASE)
-# version.h: FORCE
-# $(call filechk,sample)
-#
-# The rule defined shall write to stdout the content of the new file.
-# The existing file will be compared with the new one.
-# - If no file exist it is created
-# - If the content differ the new file is used
-# - If they are equal no change, and no timestamp update
-# - stdin is piped in from the first prerequisite ($<) so one has
-# to specify a valid file as first prerequisite (often the kbuild file)
-define filechk
- $(Q)set -e; \
- mkdir -p $(dir $@); \
- { $(filechk_$(1)); } > $@.tmp; \
- if [ -r $@ ] && cmp -s $@ $@.tmp; then \
- rm -f $@.tmp; \
- else \
- $(kecho) ' UPD $@'; \
- mv -f $@.tmp $@; \
- fi
-endef
-
-define multi_depend
-$(foreach m, $(notdir $1), \
- $(eval $(obj)/$m: \
- $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
-endef
-
-# LEX
-# ---------------------------------------------------------------------------
-quiet_cmd_flex = LEX $@
- cmd_flex = $(LEX) -o$@ -L $<
-
-$(obj)/%.lex.c: $(src)/%.l FORCE
- $(call if_changed,flex)
-
-# YACC
-# ---------------------------------------------------------------------------
-quiet_cmd_bison = YACC $@
- cmd_bison = $(YACC) -o$@ -t -l $<
-
-$(obj)/%.tab.c: $(src)/%.y FORCE
- $(call if_changed,bison)
-
-quiet_cmd_bison_h = YACC $@
- cmd_bison_h = $(YACC) -o/dev/null --defines=$@ -t -l $<
-
-$(obj)/%.tab.h: $(src)/%.y FORCE
- $(call if_changed,bison_h)
-
-# Set our default defconfig file
-KBUILD_DEFCONFIG := $(ARCH)_defconfig
-
-# provide our shell
-CONFIG_SHELL := $(SHELL)
-
-# provide the host compiler
-HOSTCC ?= gcc
-HOSTCXX ?= g++
-YACC = $(if $(BISON),$(BISON),bison)
-LEX = $(if $(FLEX),$(FLEX),flex)
-
-# force target
-PHONY += FORCE
-
-FORCE:
-
-# include the original Makefile and Makefile.host from Linux
-include $(src)/Makefile
-include $(src)/Makefile.host
-
-# Add intermediate targets:
-# When building objects with specific suffix patterns, add intermediate
-# targets that the final targets are derived from.
-intermediate_targets = $(foreach sfx, $(2), \
- $(patsubst %$(strip $(1)),%$(sfx), \
- $(filter %$(strip $(1)), $(targets))))
-
-# %.lex.o <- %.lex.c <- %.l
-# %.tab.o <- %.tab.[ch] <- %.y
-targets += $(call intermediate_targets, .lex.o, .lex.c) \
- $(call intermediate_targets, .tab.o, .tab.c .tab.h)
-
-# clean up rule
-clean-deps = $(foreach f,$(host-cobjs) $(host-cxxobjs),$(dir $f).$(notdir $f).d)
-clean-shipped = $(patsubst %_shipped,%,$(wildcard $(obj)/*_shipped))
-
-clean:
- rm -rf $(clean-files)
- rm -rf $(clean-deps)
- rm -rf $(host-csingle) $(host-cmulti) $(host-cxxmulti) $(host-cobjs) $(host-cxxobjs)
- rm -rf $(clean-shipped)
-
-$(obj)/zconf%: $(src)/zconf%_shipped
- cp -f $< $@
-
-.PHONY: $(PHONY)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 25+ messages in thread