kbuild: re-implement Makefile.headersinst without recursion
Since commit fcc8487d47
("uapi: export all headers under uapi
directories"), the headers in uapi directories are all exported by
default although exceptional cases are still allowed by the syntax
'no-export-headers'.
The traditional directory descending has been kept (in a somewhat
hacky way), but it is actually unneeded.
Get rid of it to simplify the code.
Also, handle files one by one instead of the previous per-directory
processing. This will emit much more log, but I like it.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
parent
59b2bd05f5
commit
d5470d1443
8
Makefile
8
Makefile
|
@ -1194,13 +1194,13 @@ PHONY += headers
|
||||||
headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
|
headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
|
||||||
$(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \
|
$(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \
|
||||||
$(error Headers not exportable for the $(SRCARCH) architecture))
|
$(error Headers not exportable for the $(SRCARCH) architecture))
|
||||||
$(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include
|
$(Q)$(MAKE) $(hdr-inst)=include/uapi
|
||||||
$(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include
|
$(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi
|
||||||
|
|
||||||
PHONY += headers_check
|
PHONY += headers_check
|
||||||
headers_check: headers
|
headers_check: headers
|
||||||
$(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1
|
$(Q)$(MAKE) $(hdr-inst)=include/uapi HDRCHECK=1
|
||||||
$(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include HDRCHECK=1
|
$(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi HDRCHECK=1
|
||||||
|
|
||||||
ifdef CONFIG_HEADERS_INSTALL
|
ifdef CONFIG_HEADERS_INSTALL
|
||||||
prepare: headers
|
prepare: headers
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
ifeq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/a.out.h),)
|
ifeq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/a.out.h),)
|
||||||
no-export-headers += a.out.h
|
no-export-headers += linux/a.out.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/kvm.h),)
|
ifeq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/kvm.h),)
|
||||||
no-export-headers += kvm.h
|
no-export-headers += linux/kvm.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/kvm_para.h),)
|
ifeq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/kvm_para.h),)
|
||||||
ifeq ($(wildcard $(objtree)/arch/$(SRCARCH)/include/generated/uapi/asm/kvm_para.h),)
|
ifeq ($(wildcard $(objtree)/arch/$(SRCARCH)/include/generated/uapi/asm/kvm_para.h),)
|
||||||
no-export-headers += kvm_para.h
|
no-export-headers += linux/kvm_para.h
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
|
@ -14,109 +14,87 @@ __headers:
|
||||||
|
|
||||||
include scripts/Kbuild.include
|
include scripts/Kbuild.include
|
||||||
|
|
||||||
srcdir := $(srctree)/$(obj)
|
src := $(srctree)/$(obj)
|
||||||
|
gen := $(objtree)/$(subst include/,include/generated/,$(obj))
|
||||||
|
dst := usr/include
|
||||||
|
|
||||||
# When make is run under a fakechroot environment, the function
|
-include $(src)/Kbuild
|
||||||
# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular
|
|
||||||
# files. So, we are using a combination of sort/dir/wildcard which works
|
|
||||||
# with fakechroot.
|
|
||||||
subdirs := $(patsubst $(srcdir)/%/,%,\
|
|
||||||
$(filter-out $(srcdir)/,\
|
|
||||||
$(sort $(dir $(wildcard $(srcdir)/*/)))))
|
|
||||||
|
|
||||||
# Recursion
|
src-subdirs := $(patsubst $(src)/%/,%,$(wildcard $(src)/*/))
|
||||||
__headers: $(subdirs)
|
gen-subdirs := $(patsubst $(gen)/%/,%,$(wildcard $(gen)/*/))
|
||||||
|
all-subdirs := $(sort $(src-subdirs) $(gen-subdirs))
|
||||||
|
|
||||||
PHONY += $(subdirs)
|
src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h'))
|
||||||
$(subdirs):
|
src-headers := $(filter-out $(no-export-headers), $(src-headers))
|
||||||
$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@
|
gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h'))
|
||||||
|
gen-headers := $(filter-out $(no-export-headers), $(gen-headers))
|
||||||
|
|
||||||
# Skip header install/check for include/uapi and arch/$(SRCARCH)/include/uapi.
|
# If the same header is exported from source and generated directories,
|
||||||
# We have only sub-directories there.
|
# the former takes precedence, but this should be warned.
|
||||||
skip-inst := $(if $(filter %/uapi,$(obj)),1)
|
duplicated := $(filter $(gen-headers), $(src-headers))
|
||||||
|
$(if $(duplicated), $(warning duplicated header export: $(duplicated)))
|
||||||
|
|
||||||
ifeq ($(skip-inst),)
|
gen-headers := $(filter-out $(duplicated), $(gen-headers))
|
||||||
|
|
||||||
# Kbuild file is optional
|
# Add dst path prefix
|
||||||
kbuild-file := $(srctree)/$(obj)/Kbuild
|
all-subdirs := $(addprefix $(dst)/, $(all-subdirs))
|
||||||
-include $(kbuild-file)
|
src-headers := $(addprefix $(dst)/, $(src-headers))
|
||||||
|
gen-headers := $(addprefix $(dst)/, $(gen-headers))
|
||||||
installdir := usr/$(dst)
|
all-headers := $(src-headers) $(gen-headers)
|
||||||
gendir := $(objtree)/$(subst include/,include/generated/,$(obj))
|
|
||||||
header-files := $(notdir $(wildcard $(srcdir)/*.h))
|
|
||||||
header-files := $(filter-out $(no-export-headers), $(header-files))
|
|
||||||
genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
|
|
||||||
genhdr-files := $(filter-out $(header-files), $(genhdr-files))
|
|
||||||
|
|
||||||
# files used to track state of install/check
|
|
||||||
install-file := $(installdir)/.install
|
|
||||||
check-file := $(installdir)/.check
|
|
||||||
|
|
||||||
# all headers files for this dir
|
|
||||||
all-files := $(header-files) $(genhdr-files)
|
|
||||||
output-files := $(addprefix $(installdir)/, $(all-files))
|
|
||||||
|
|
||||||
# Work out what needs to be removed
|
# Work out what needs to be removed
|
||||||
oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
|
old-subdirs := $(wildcard $(all-subdirs))
|
||||||
unwanted := $(filter-out $(all-files),$(oldheaders))
|
old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h'))
|
||||||
|
unwanted := $(filter-out $(all-headers), $(old-headers))
|
||||||
|
|
||||||
# Prefix unwanted with full paths to objtree
|
# Create directories
|
||||||
unwanted-file := $(addprefix $(installdir)/, $(unwanted))
|
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)))
|
||||||
|
|
||||||
printdir = $(patsubst %/,%,$(dir $@))
|
# Rules
|
||||||
|
|
||||||
quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
|
|
||||||
file$(if $(word 2, $(all-files)),s))
|
|
||||||
cmd_install = \
|
|
||||||
$(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
|
|
||||||
$(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
|
|
||||||
touch $@
|
|
||||||
|
|
||||||
quiet_cmd_remove = REMOVE $(unwanted)
|
|
||||||
cmd_remove = rm -f $(unwanted-file)
|
|
||||||
|
|
||||||
quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
|
|
||||||
# Headers list can be pretty long, xargs helps to avoid
|
|
||||||
# the "Argument list too long" error.
|
|
||||||
cmd_check = for f in $(all-files); do \
|
|
||||||
echo "$(installdir)/$${f}"; done \
|
|
||||||
| xargs \
|
|
||||||
$(PERL) $< usr/include $(SRCARCH); \
|
|
||||||
touch $@
|
|
||||||
|
|
||||||
ifndef HDRCHECK
|
ifndef HDRCHECK
|
||||||
# Rules for installing headers
|
|
||||||
__headers: $(install-file)
|
|
||||||
@:
|
|
||||||
|
|
||||||
targets += $(install-file)
|
quiet_cmd_install = HDRINST $@
|
||||||
$(install-file): scripts/headers_install.sh \
|
cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $(@D) $(<D) $(@F)
|
||||||
$(addprefix $(srcdir)/,$(header-files)) \
|
|
||||||
$(addprefix $(gendir)/,$(genhdr-files)) FORCE
|
$(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE
|
||||||
$(if $(unwanted),$(call cmd,remove),)
|
|
||||||
$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
|
|
||||||
$(call if_changed,install)
|
$(call if_changed,install)
|
||||||
|
|
||||||
else
|
$(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE
|
||||||
__headers: $(check-file)
|
$(call if_changed,install)
|
||||||
|
|
||||||
|
quiet_cmd_remove = REMOVE $(unwanted)
|
||||||
|
cmd_remove = rm -f $(unwanted)
|
||||||
|
|
||||||
|
__headers: $(all-headers)
|
||||||
|
ifneq ($(unwanted),)
|
||||||
|
$(call cmd,remove)
|
||||||
|
endif
|
||||||
@:
|
@:
|
||||||
|
|
||||||
targets += $(check-file)
|
existing-headers := $(filter $(old-headers), $(all-headers))
|
||||||
$(check-file): scripts/headers_check.pl $(output-files) FORCE
|
|
||||||
$(call if_changed,check)
|
-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
|
endif
|
||||||
|
|
||||||
cmd_files := $(wildcard \
|
|
||||||
$(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
|
|
||||||
|
|
||||||
ifneq ($(cmd_files),)
|
|
||||||
include $(cmd_files)
|
|
||||||
endif
|
|
||||||
|
|
||||||
endif # skip-inst
|
|
||||||
|
|
||||||
PHONY += FORCE
|
PHONY += FORCE
|
||||||
FORCE: ;
|
FORCE:
|
||||||
|
|
||||||
.PHONY: $(PHONY)
|
.PHONY: $(PHONY)
|
||||||
|
|
Loading…
Reference in New Issue