linux/scripts/Makefile.headersinst
Masahiro Yamada d5470d1443 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>
2019-06-15 19:57:02 +09:00

101 lines
3.0 KiB
Makefile

# 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
src-subdirs := $(patsubst $(src)/%/,%,$(wildcard $(src)/*/))
gen-subdirs := $(patsubst $(gen)/%/,%,$(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 $(@D) $(<D) $(@F)
$(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)