1 # SPDX-License-Identifier: GPL-2.0 << 2 # ============================================ 1 # ========================================================================== 3 # Installing headers 2 # Installing headers 4 # 3 # 5 # All headers under include/uapi, include/gene !! 4 # header-y - list files to be installed. They are preprocessed 6 # arch/<arch>/include/uapi and arch/<arch>/inc !! 5 # to remove __KERNEL__ section of the file 7 # exported. !! 6 # genhdr-y - Same as header-y but in a generated/ directory 8 # They are preprocessed to remove __KERNEL__ s << 9 # 7 # 10 # ============================================ 8 # ========================================================================== 11 9 12 PHONY := __headers !! 10 # generated header directory 13 __headers: !! 11 gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) 14 12 15 include $(srctree)/scripts/Kbuild.include !! 13 kbuild-file := $(srctree)/$(obj)/Kbuild >> 14 include $(kbuild-file) 16 15 17 src := $(srctree)/$(obj) !! 16 # called may set destination dir (when installing to asm/) 18 gen := $(objtree)/$(subst include/,include/gen !! 17 _dst := $(if $(destination-y),$(destination-y),$(if $(dst),$(dst),$(obj))) 19 dst := usr/include !! 18 20 !! 19 old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild 21 -include $(src)/Kbuild !! 20 ifneq ($(wildcard $(old-kbuild-file)),) 22 !! 21 include $(old-kbuild-file) 23 # $(filter %/, ...) is a workaround for GNU Ma !! 22 endif 24 # $(wildcard $(src)/*/) contains not only dire !! 23 25 src-subdirs := $(patsubst $(src)/%/,%,$(filter !! 24 include scripts/Kbuild.include 26 gen-subdirs := $(patsubst $(gen)/%/,%,$(filter !! 25 27 all-subdirs := $(sort $(src-subdirs) $(gen-sub !! 26 installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst)) 28 !! 27 29 src-headers := $(if $(src-subdirs), $(shell cd !! 28 header-y := $(sort $(header-y)) 30 src-headers := $(filter-out $(no-export-header !! 29 subdirs := $(patsubst %/,%,$(filter %/, $(header-y))) 31 gen-headers := $(if $(gen-subdirs), $(shell cd !! 30 header-y := $(filter-out %/, $(header-y)) 32 gen-headers := $(filter-out $(no-export-header !! 31 33 !! 32 # files used to track state of install/check 34 # If the same header is exported from source a !! 33 install-file := $(installdir)/.install 35 # the former takes precedence, but this should !! 34 check-file := $(installdir)/.check 36 duplicated := $(filter $(gen-headers), $(src-h !! 35 37 $(if $(duplicated), $(warning duplicated heade !! 36 # generic-y list all files an architecture uses from asm-generic 38 !! 37 # Use this to build a list of headers which require a wrapper 39 gen-headers := $(filter-out $(duplicated), $(g !! 38 wrapper-files := $(filter $(header-y), $(generic-y)) 40 !! 39 41 # Add dst path prefix !! 40 srcdir := $(srctree)/$(obj) 42 all-subdirs := $(addprefix $(dst)/, $(all-subd !! 41 gendir := $(objtree)/$(gen) 43 src-headers := $(addprefix $(dst)/, $(src-head !! 42 44 gen-headers := $(addprefix $(dst)/, $(gen-head !! 43 oldsrcdir := $(srctree)/$(subst /uapi,,$(obj)) 45 all-headers := $(src-headers) $(gen-headers) !! 44 >> 45 # all headers files for this dir >> 46 header-y := $(filter-out $(generic-y), $(header-y)) >> 47 all-files := $(header-y) $(genhdr-y) $(wrapper-files) >> 48 output-files := $(addprefix $(installdir)/, $(all-files)) >> 49 >> 50 input-files1 := $(foreach hdr, $(header-y), \ >> 51 $(if $(wildcard $(srcdir)/$(hdr)), \ >> 52 $(wildcard $(srcdir)/$(hdr))) \ >> 53 ) >> 54 input-files1-name := $(notdir $(input-files1)) >> 55 input-files2 := $(foreach hdr, $(header-y), \ >> 56 $(if $(wildcard $(srcdir)/$(hdr)),, \ >> 57 $(if $(wildcard $(oldsrcdir)/$(hdr)), \ >> 58 $(wildcard $(oldsrcdir)/$(hdr)), \ >> 59 $(error Missing UAPI file $(srcdir)/$(hdr))) \ >> 60 )) >> 61 input-files2-name := $(notdir $(input-files2)) >> 62 input-files3 := $(foreach hdr, $(genhdr-y), \ >> 63 $(if $(wildcard $(gendir)/$(hdr)), \ >> 64 $(wildcard $(gendir)/$(hdr)), \ >> 65 $(error Missing generated UAPI file $(gendir)/$(hdr)) \ >> 66 )) >> 67 input-files3-name := $(notdir $(input-files3)) 46 68 47 # Work out what needs to be removed 69 # Work out what needs to be removed 48 old-subdirs := $(wildcard $(all-subdirs)) !! 70 oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 49 old-headers := $(if $(old-subdirs),$(shell fin !! 71 unwanted := $(filter-out $(all-files),$(oldheaders)) 50 unwanted := $(filter-out $(all-headers), $( << 51 << 52 # Create directories << 53 existing-dirs := $(sort $(dir $(old-headers))) << 54 wanted-dirs := $(sort $(dir $(all-headers))) << 55 new-dirs := $(filter-out $(existing-dirs) << 56 $(if $(new-dirs), $(shell mkdir -p $(new-dirs) << 57 << 58 # Rules << 59 quiet_cmd_install = HDRINST $@ << 60 cmd_install = $(CONFIG_SHELL) $(srctree) << 61 72 62 $(src-headers): $(dst)/%.h: $(src)/%.h $(srctr !! 73 # Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 63 $(call if_changed,install) !! 74 unwanted-file := $(addprefix $(installdir)/, $(unwanted)) 64 75 65 $(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctr !! 76 printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 66 $(call if_changed,install) !! 77 >> 78 quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ >> 79 file$(if $(word 2, $(all-files)),s)) >> 80 cmd_install = \ >> 81 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(input-files1-name); \ >> 82 $(CONFIG_SHELL) $< $(installdir) $(oldsrcdir) $(input-files2-name); \ >> 83 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(input-files3-name); \ >> 84 for F in $(wrapper-files); do \ >> 85 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ >> 86 done; \ >> 87 touch $@ 67 88 68 quiet_cmd_remove = REMOVE $(unwanted) 89 quiet_cmd_remove = REMOVE $(unwanted) 69 cmd_remove = rm -f $(unwanted) !! 90 cmd_remove = rm -f $(unwanted-file) 70 91 71 __headers: $(all-headers) !! 92 quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 72 ifneq ($(unwanted),) !! 93 # Headers list can be pretty long, xargs helps to avoid 73 $(call cmd,remove) !! 94 # the "Argument list too long" error. 74 endif !! 95 cmd_check = for f in $(all-files); do \ >> 96 echo "$(installdir)/$${f}"; done \ >> 97 | xargs \ >> 98 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ >> 99 touch $@ >> 100 >> 101 PHONY += __headersinst __headerscheck >> 102 >> 103 ifndef HDRCHECK >> 104 # Rules for installing headers >> 105 __headersinst: $(subdirs) $(install-file) 75 @: 106 @: 76 107 77 existing-headers := $(filter $(old-headers), $ !! 108 targets += $(install-file) >> 109 $(install-file): scripts/headers_install.sh $(input-files1) $(input-files2) $(input-files3) FORCE >> 110 $(if $(unwanted),$(call cmd,remove),) >> 111 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) >> 112 $(call if_changed,install) 78 113 79 -include $(foreach f,$(existing-headers),$(dir !! 114 else >> 115 __headerscheck: $(subdirs) $(check-file) >> 116 @: 80 117 81 PHONY += FORCE !! 118 targets += $(check-file) 82 FORCE: !! 119 $(check-file): scripts/headers_check.pl $(output-files) FORCE >> 120 $(call if_changed,check) >> 121 >> 122 endif >> 123 >> 124 # Recursion >> 125 hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj >> 126 .PHONY: $(subdirs) >> 127 $(subdirs): >> 128 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ >> 129 >> 130 targets := $(wildcard $(sort $(targets))) >> 131 cmd_files := $(wildcard \ >> 132 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) >> 133 >> 134 ifneq ($(cmd_files),) >> 135 include $(cmd_files) >> 136 endif 83 137 84 .PHONY: $(PHONY) 138 .PHONY: $(PHONY) >> 139 PHONY += FORCE >> 140 FORCE: ;
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.