1# ========================================================================== 2# Installing headers 3# 4# header-y files will be installed verbatim 5# unifdef-y are the files where unifdef will be run before installing files 6# objhdr-y are generated files that will be installed verbatim 7# 8# ========================================================================== 9 10UNIFDEF := scripts/unifdef -U__KERNEL__ 11 12# Eliminate the contents of (and inclusions of) compiler.h 13HDRSED := sed -e "s/ inline / __inline__ /g" \ 14 -e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \ 15 -e "s/(__user[[:space:]]\{1,\}/ (/g" \ 16 -e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \ 17 -e "s/(__force[[:space:]]\{1,\}/ (/g" \ 18 -e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \ 19 -e "s/(__iomem[[:space:]]\{1,\}/ (/g" \ 20 -e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \ 21 -e "s/[[:space:]]__attribute_const__$$//" \ 22 -e "/^\#include <linux\/compiler.h>/d" 23 24_dst := $(if $(dst),$(dst),$(obj)) 25 26kbuild-file := $(srctree)/$(obj)/Kbuild 27include $(kbuild-file) 28 29include scripts/Kbuild.include 30 31install := $(INSTALL_HDR_PATH)/$(_dst) 32 33header-y := $(sort $(header-y) $(unifdef-y)) 34subdir-y := $(patsubst %/,%,$(filter %/, $(header-y))) 35header-y := $(filter-out %/, $(header-y)) 36 37# stamp files for header checks 38check-y := $(patsubst %,.check.%,$(header-y) $(objhdr-y)) 39 40# Work out what needs to be removed 41oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) 42unwanted := $(filter-out $(header-y) $(objhdr-y),$(oldheaders)) 43 44oldcheckstamps := $(patsubst $(install)/%,%,$(wildcard $(install)/.check.*.h)) 45unwanted += $(filter-out $(check-y),$(oldcheckstamps)) 46 47# Prefix them all with full paths to $(INSTALL_HDR_PATH) 48header-y := $(patsubst %,$(install)/%,$(header-y)) 49objhdr-y := $(patsubst %,$(install)/%,$(objhdr-y)) 50check-y := $(patsubst %,$(install)/%,$(check-y)) 51 52quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@) 53 cmd_o_hdr_install = cp $(patsubst $(install)/%,$(objtree)/$(obj)/%,$@) \ 54 $(install) 55 56quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@) 57 cmd_unifdef = $(UNIFDEF) $(patsubst $(install)/%,$(srctree)/$(obj)/%,$@)\ 58 | $(HDRSED) > $@ || : 59 60quiet_cmd_check = CHECK $(patsubst $(install)/.check.%,$(_dst)/%,$@) 61 cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \ 62 $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@ 63 64quiet_cmd_remove = REMOVE $(_dst)/$@ 65 cmd_remove = rm -f $(install)/$@ 66 67quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@) 68 cmd_mkdir = mkdir -p $@ 69 70.PHONY: __headersinst __headerscheck 71 72ifdef HDRCHECK 73__headerscheck: $(subdir-y) $(check-y) 74 @true 75 76$(check-y) : $(install)/.check.%.h : $(install)/%.h 77 $(call cmd,check) 78 79# Other dependencies for $(check-y) 80include /dev/null $(wildcard $(check-y)) 81 82# but leave $(check-y) as .PHONY for now until those 83# deps are actually correct. 84.PHONY: $(check-y) 85 86else 87# Rules for installing headers 88__headersinst: $(subdir-y) $(header-y) $(objhdr-y) 89 @true 90 91$(objhdr-y) $(subdir-y) $(header-y): | $(install) $(unwanted) 92 93$(install): 94 $(call cmd,mkdir) 95 96# Rules for removing unwanted header files 97.PHONY: $(unwanted) 98$(unwanted): 99 $(call cmd,remove) 100 101# Install generated files 102$(objhdr-y): $(install)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file) 103 $(call cmd,o_hdr_install) 104 105# Unifdef header files and install them 106$(header-y): $(install)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file) 107 $(call cmd,unifdef) 108 109endif 110 111hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 112 113# Recursion 114.PHONY: $(subdir-y) 115$(subdir-y): 116 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 117