1 # SPDX-License-Identifier: GPL-2.0
2 # ==========================================================================
5 # All headers under include/uapi, include/generated/uapi,
6 # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
8 # They are preprocessed to remove __KERNEL__ section of the file.
10 # ==========================================================================
15 include scripts/Kbuild.include
17 src := $(srctree)/$(obj)
18 gen := $(objtree)/$(subst include/,include/generated/,$(obj))
21 -include $(src)/Kbuild
23 src-subdirs := $(patsubst $(src)/%/,%,$(wildcard $(src)/*/))
24 gen-subdirs := $(patsubst $(gen)/%/,%,$(wildcard $(gen)/*/))
25 all-subdirs := $(sort $(src-subdirs) $(gen-subdirs))
27 src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h'))
28 src-headers := $(filter-out $(no-export-headers), $(src-headers))
29 gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h'))
30 gen-headers := $(filter-out $(no-export-headers), $(gen-headers))
32 # If the same header is exported from source and generated directories,
33 # the former takes precedence, but this should be warned.
34 duplicated := $(filter $(gen-headers), $(src-headers))
35 $(if $(duplicated), $(warning duplicated header export: $(duplicated)))
37 gen-headers := $(filter-out $(duplicated), $(gen-headers))
40 all-subdirs := $(addprefix $(dst)/, $(all-subdirs))
41 src-headers := $(addprefix $(dst)/, $(src-headers))
42 gen-headers := $(addprefix $(dst)/, $(gen-headers))
43 all-headers := $(src-headers) $(gen-headers)
45 # Work out what needs to be removed
46 old-subdirs := $(wildcard $(all-subdirs))
47 old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h'))
48 unwanted := $(filter-out $(all-headers), $(old-headers))
51 existing-dirs := $(sort $(dir $(old-headers)))
52 wanted-dirs := $(sort $(dir $(all-headers)))
53 new-dirs := $(filter-out $(existing-dirs), $(wanted-dirs))
54 $(if $(new-dirs), $(shell mkdir -p $(new-dirs)))
60 quiet_cmd_install = HDRINST $@
61 cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $(@D) $(<D) $(@F)
63 $(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE
64 $(call if_changed,install)
66 $(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE
67 $(call if_changed,install)
69 quiet_cmd_remove = REMOVE $(unwanted)
70 cmd_remove = rm -f $(unwanted)
72 __headers: $(all-headers)
78 existing-headers := $(filter $(old-headers), $(all-headers))
80 -include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd)
84 quiet_cmd_check = HDRCHK $<
85 cmd_check = $(PERL) $(srctree)/scripts/headers_check.pl $(dst) $(SRCARCH) $<; touch $@
87 check-files := $(addsuffix .chk, $(all-headers))
89 $(check-files): $(dst)/%.chk : $(dst)/% $(srctree)/scripts/headers_check.pl
92 __headers: $(check-files)