Message ID | cf5f446915bd5c8980beda22718efff32678e16b.1694078544.git.oleksii.kurochko@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | introduce stub directory to storing empty/stub headers | expand |
On Thu, Sep 07, 2023 at 12:32:56PM +0300, Oleksii Kurochko wrote: > diff --git a/xen/scripts/Makefile.asm-generic b/xen/scripts/Makefile.asm-generic > new file mode 100644 > index 0000000000..92a3a741c5 > --- /dev/null > +++ b/xen/scripts/Makefile.asm-generic > @@ -0,0 +1,53 @@ > +# SPDX-License-Identifier: GPL-2.0-only > +# include/asm-generic contains a lot of files that are used > +# verbatim by several architectures. > +# > +# This Makefile reads the file arch/$(SRCARCH)/include/asm/Makefile > +# and for each file listed in this file with generic-y creates > +# a small wrapper file in arch/$(SRCARCH)/include/generated/asm. > + > +PHONY := all > +all: > + > +src := $(subst /generated,,$(obj)) > + > +include $(srctree)/scripts/Kbuild.include > +-include $(src)/Makefile > + > +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))) This warning would need to say "$(src)/Makefile" now instead of Kbuild. Beside this, patch looks fine to me: Reviewed-by: Anthony PERARD <anthony.perard@citrix.com> Thanks,
On 07.09.2023 11:32, Oleksii Kurochko wrote: > --- /dev/null > +++ b/xen/scripts/Makefile.asm-generic > @@ -0,0 +1,53 @@ > +# SPDX-License-Identifier: GPL-2.0-only > +# include/asm-generic contains a lot of files that are used > +# verbatim by several architectures. > +# > +# This Makefile reads the file arch/$(SRCARCH)/include/asm/Makefile > +# and for each file listed in this file with generic-y creates > +# a small wrapper file in arch/$(SRCARCH)/include/generated/asm. > + > +PHONY := all > +all: > + > +src := $(subst /generated,,$(obj)) > + > +include $(srctree)/scripts/Kbuild.include > +-include $(src)/Makefile With the definition of src above, is this correct for out-of-tree builds? You want to reference the Makefile in the source tree, ... > +redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y)) > +redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f))) ... much like $(srctree) is used here (and similarly again further down). Jan
On Thu, 2023-09-07 at 11:08 +0100, Anthony PERARD wrote: > On Thu, Sep 07, 2023 at 12:32:56PM +0300, Oleksii Kurochko wrote: > > diff --git a/xen/scripts/Makefile.asm-generic > > b/xen/scripts/Makefile.asm-generic > > new file mode 100644 > > index 0000000000..92a3a741c5 > > --- /dev/null > > +++ b/xen/scripts/Makefile.asm-generic > > @@ -0,0 +1,53 @@ > > +# SPDX-License-Identifier: GPL-2.0-only > > +# include/asm-generic contains a lot of files that are used > > +# verbatim by several architectures. > > +# > > +# This Makefile reads the file > > arch/$(SRCARCH)/include/asm/Makefile > > +# and for each file listed in this file with generic-y creates > > +# a small wrapper file in arch/$(SRCARCH)/include/generated/asm. > > + > > +PHONY := all > > +all: > > + > > +src := $(subst /generated,,$(obj)) > > + > > +include $(srctree)/scripts/Kbuild.include > > +-include $(src)/Makefile > > + > > +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))) > > This warning would need to say "$(src)/Makefile" now instead of > Kbuild. Thanks. Missed that. > > Beside this, patch looks fine to me: > Reviewed-by: Anthony PERARD <anthony.perard@citrix.com> > > Thanks, > ~ Oleksii
On Thu, 2023-09-07 at 12:48 +0200, Jan Beulich wrote: > On 07.09.2023 11:32, Oleksii Kurochko wrote: > > --- /dev/null > > +++ b/xen/scripts/Makefile.asm-generic > > @@ -0,0 +1,53 @@ > > +# SPDX-License-Identifier: GPL-2.0-only > > +# include/asm-generic contains a lot of files that are used > > +# verbatim by several architectures. > > +# > > +# This Makefile reads the file > > arch/$(SRCARCH)/include/asm/Makefile > > +# and for each file listed in this file with generic-y creates > > +# a small wrapper file in arch/$(SRCARCH)/include/generated/asm. > > + > > +PHONY := all > > +all: > > + > > +src := $(subst /generated,,$(obj)) > > + > > +include $(srctree)/scripts/Kbuild.include > > +-include $(src)/Makefile > > With the definition of src above, is this correct for out-of-tree > builds? Logically you are right and I think it would be better to use $(srctree)/$src but it works for out-of-tree builds too. $ CONTAINER_NO_PULL=1 CONTAINER=riscv64 ./automation/scripts/containerize make O=xen-build V=2 XEN_TARGET_ARCH=riscv64 -C xen build $ ls -la xen/xen-build/arch/riscv/include/generated/asm/vm_event.h -rw-r--r--. 1 ok ok 34 вер 7 16:27 xen/xen- build/arch/riscv/include/generated/asm/vm_event.h > You want to reference the Makefile in the source tree, ... > > > +redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y)) > > +redundant += $(foreach f, $(generic-y), $(if $(wildcard > > $(srctree)/$(src)/$(f)),$(f))) > > ... much like $(srctree) is used here (and similarly again further > down). > ~ Oleksii
On 07.09.2023 15:45, Oleksii wrote: > On Thu, 2023-09-07 at 12:48 +0200, Jan Beulich wrote: >> On 07.09.2023 11:32, Oleksii Kurochko wrote: >>> --- /dev/null >>> +++ b/xen/scripts/Makefile.asm-generic >>> @@ -0,0 +1,53 @@ >>> +# SPDX-License-Identifier: GPL-2.0-only >>> +# include/asm-generic contains a lot of files that are used >>> +# verbatim by several architectures. >>> +# >>> +# This Makefile reads the file >>> arch/$(SRCARCH)/include/asm/Makefile >>> +# and for each file listed in this file with generic-y creates >>> +# a small wrapper file in arch/$(SRCARCH)/include/generated/asm. >>> + >>> +PHONY := all >>> +all: >>> + >>> +src := $(subst /generated,,$(obj)) >>> + >>> +include $(srctree)/scripts/Kbuild.include >>> +-include $(src)/Makefile >> >> With the definition of src above, is this correct for out-of-tree >> builds? > Logically you are right and I think it would be better to use > $(srctree)/$src but it works for out-of-tree builds too. > > $ CONTAINER_NO_PULL=1 CONTAINER=riscv64 > ./automation/scripts/containerize make O=xen-build V=2 > XEN_TARGET_ARCH=riscv64 -C xen build > > $ ls -la xen/xen-build/arch/riscv/include/generated/asm/vm_event.h > -rw-r--r--. 1 ok ok 34 вер 7 16:27 xen/xen- > build/arch/riscv/include/generated/asm/vm_event.h Oh, right, aiui because of VPATH being set to $(srctree), and therefore in the absence of a Makefile in $(objtree)/$(src)/ it'll go look for one in $(srctree)/$(src)/. Never mind then: Acked-by: Jan Beulich <jbeulich@suse.com> Jan
On Thu, 2023-09-07 at 15:56 +0200, Jan Beulich wrote: > On 07.09.2023 15:45, Oleksii wrote: > > On Thu, 2023-09-07 at 12:48 +0200, Jan Beulich wrote: > > > On 07.09.2023 11:32, Oleksii Kurochko wrote: > > > > --- /dev/null > > > > +++ b/xen/scripts/Makefile.asm-generic > > > > @@ -0,0 +1,53 @@ > > > > +# SPDX-License-Identifier: GPL-2.0-only > > > > +# include/asm-generic contains a lot of files that are used > > > > +# verbatim by several architectures. > > > > +# > > > > +# This Makefile reads the file > > > > arch/$(SRCARCH)/include/asm/Makefile > > > > +# and for each file listed in this file with generic-y creates > > > > +# a small wrapper file in > > > > arch/$(SRCARCH)/include/generated/asm. > > > > + > > > > +PHONY := all > > > > +all: > > > > + > > > > +src := $(subst /generated,,$(obj)) > > > > + > > > > +include $(srctree)/scripts/Kbuild.include > > > > +-include $(src)/Makefile > > > > > > With the definition of src above, is this correct for out-of-tree > > > builds? > > Logically you are right and I think it would be better to use > > $(srctree)/$src but it works for out-of-tree builds too. > > > > $ CONTAINER_NO_PULL=1 CONTAINER=riscv64 > > ./automation/scripts/containerize make O=xen-build V=2 > > XEN_TARGET_ARCH=riscv64 -C xen build > > > > $ ls -la xen/xen-build/arch/riscv/include/generated/asm/vm_event.h > > -rw-r--r--. 1 ok ok 34 вер 7 16:27 xen/xen- > > build/arch/riscv/include/generated/asm/vm_event.h > > Oh, right, aiui because of VPATH being set to $(srctree), and > therefore > in the absence of a Makefile in $(objtree)/$(src)/ it'll go look for > one in $(srctree)/$(src)/. Never mind then: > Acked-by: Jan Beulich <jbeulich@suse.com> > Thanks for explanation. ~ Oleksii
diff --git a/.gitignore b/.gitignore index 50273adb8d..287166f8fc 100644 --- a/.gitignore +++ b/.gitignore @@ -267,6 +267,7 @@ xen/arch/*/efi/efi.h xen/arch/*/efi/pe.c xen/arch/*/efi/runtime.c xen/arch/*/include/asm/asm-offsets.h +xen/arch/*/include/generated xen/build-dir-cppcheck/ xen/common/config_data.S xen/common/config.gz diff --git a/xen/Makefile b/xen/Makefile index f57e5a596c..2dc5e3526d 100644 --- a/xen/Makefile +++ b/xen/Makefile @@ -438,6 +438,7 @@ ifdef building_out_of_srctree endif CFLAGS += -I$(srctree)/include CFLAGS += -I$(srctree)/arch/$(SRCARCH)/include +CFLAGS += -I$(objtree)/arch/$(SRCARCH)/include/generated # Note that link order matters! ALL_OBJS-y := common/built_in.o @@ -580,16 +581,22 @@ _clean: rm -f $(TARGET).efi $(TARGET).efi.map $(TARGET).efi.elf $(TARGET).efi.stripped rm -f asm-offsets.s arch/*/include/asm/asm-offsets.h rm -f .banner .allconfig.tmp include/xen/compile.h + rm -rf $(objtree)/arch/*/include/generated .PHONY: _distclean _distclean: clean rm -f tags TAGS cscope.files cscope.in.out cscope.out cscope.po.out GTAGS GPATH GRTAGS GSYMS .config source +# Support for using generic headers in asm-generic +PHONY += asm-generic +asm-generic: + $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm + $(TARGET).gz: $(TARGET) gzip -n -f -9 < $< > $@.new mv $@.new $@ -$(TARGET): outputmakefile FORCE +$(TARGET): outputmakefile asm-generic FORCE $(Q)$(MAKE) $(build)=tools $(Q)$(MAKE) $(build)=. include/xen/compile.h $(Q)$(MAKE) $(build)=include all diff --git a/xen/scripts/Kbuild.include b/xen/scripts/Kbuild.include index 785a32c32e..c2bd8498e1 100644 --- a/xen/scripts/Kbuild.include +++ b/xen/scripts/Kbuild.include @@ -91,6 +91,12 @@ cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || e clang-ifversion = $(shell [ $(CONFIG_CLANG_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4)) +### +# Shorthand for $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic obj +# Usage: +# $(Q)$(MAKE) $(asm-generic)=dir +asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj + ### # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= # Usage: diff --git a/xen/scripts/Makefile.asm-generic b/xen/scripts/Makefile.asm-generic new file mode 100644 index 0000000000..92a3a741c5 --- /dev/null +++ b/xen/scripts/Makefile.asm-generic @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: GPL-2.0-only +# include/asm-generic contains a lot of files that are used +# verbatim by several architectures. +# +# This Makefile reads the file arch/$(SRCARCH)/include/asm/Makefile +# and for each file listed in this file with generic-y creates +# a small wrapper file in arch/$(SRCARCH)/include/generated/asm. + +PHONY := all +all: + +src := $(subst /generated,,$(obj)) + +include $(srctree)/scripts/Kbuild.include +-include $(src)/Makefile + +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)
Some headers are shared between individual architectures or are empty. To avoid duplication of these headers, asm-generic is introduced. With the following patch, an architecture uses generic headers mentioned in the file arch/$(ARCH)/include/asm/Makefile To use a generic header is needed to add to arch/$(ARCH)/include/asm/Makefile : generic-y += <name-of-header-file.h> For each mentioned header in arch/$(ARCH)/include/asm/Makefile, the necessary wrapper in arch/$(ARCH)/include/generated/asm will be generated. As the base Makefile.asm-generic from Linux kernel was taken. ( 06c2afb862f9da8 "Linux 6.5-rc1" ). Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com> --- Changes in V6: - introduce $(asm-generic) macro in Kbuild.include. - move "asm-generic" after the rule "__distclean". --- Changes in V5: - Update the commit message - Update SPDX license in Makefile. - Remove code related to UML - Include $(src)/Makefile instead of $(kbuild-file) - Update comment message in Makefile.asm-generic - Update .gitignore - Update path to generated headers in CFLAGS. - Use the latest version of Linux's Makefile.asm-generic --- Changes in V4: - introduce asm-generic support - update commit message --- Changes in V3: - Rename stubs dir to asm-generic --- Changes in V2: - Nothing changed. --- .gitignore | 1 + xen/Makefile | 9 +++++- xen/scripts/Kbuild.include | 6 ++++ xen/scripts/Makefile.asm-generic | 53 ++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 xen/scripts/Makefile.asm-generic