1# ========================================================================== 2# Installing headers 3# 4# header-y - list files to be installed. They are preprocessed 5# to remove __KERNEL__ section of the file 6# genhdr-y - Same as header-y but in a generated/ directory 7# 8# ========================================================================== 9 10# called may set destination dir (when installing to asm/) 11_dst := $(if $(dst),$(dst),$(obj)) 12 13# generated header directory 14gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) 15 16kbuild-file := $(srctree)/$(obj)/Kbuild 17include $(kbuild-file) 18 19_dst := $(if $(destination-y),$(destination-y),$(_dst)) 20 21include scripts/Kbuild.include 22 23install := $(INSTALL_HDR_PATH)/$(_dst) 24 25header-y := $(sort $(header-y)) 26subdirs := $(patsubst %/,%,$(filter %/, $(header-y))) 27header-y := $(filter-out %/, $(header-y)) 28 29# files used to track state of install/check 30install-file := $(install)/.install 31check-file := $(install)/.check 32 33# generic-y list all files an architecture uses from asm-generic 34# Use this to build a list of headers which require a wrapper 35wrapper-files := $(filter $(header-y), $(generic-y)) 36 37# all headers files for this dir 38header-y := $(filter-out $(generic-y), $(header-y)) 39all-files := $(header-y) $(genhdr-y) $(wrapper-files) 40input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \ 41 $(addprefix $(objtree)/$(gen)/,$(genhdr-y)) 42output-files := $(addprefix $(install)/, $(all-files)) 43 44# Work out what needs to be removed 45oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) 46unwanted := $(filter-out $(all-files),$(oldheaders)) 47 48# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 49unwanted-file := $(addprefix $(install)/, $(unwanted)) 50 51printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 52 53quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 54 file$(if $(word 2, $(all-files)),s)) 55 cmd_install = \ 56 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \ 57 $(PERL) $< $(objtree)/$(gen) $(install) $(SRCARCH) $(genhdr-y); \ 58 for F in $(wrapper-files); do \ 59 echo "\#include <asm-generic/$$F>" > $(install)/$$F; \ 60 done; \ 61 touch $@ 62 63quiet_cmd_remove = REMOVE $(unwanted) 64 cmd_remove = rm -f $(unwanted-file) 65 66quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 67# Headers list can be pretty long, xargs helps to avoid 68# the "Argument list too long" error. 69 cmd_check = for f in $(all-files); do \ 70 echo "$(install)/$${f}"; done \ 71 | xargs \ 72 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 73 touch $@ 74 75PHONY += __headersinst __headerscheck 76 77ifndef HDRCHECK 78# Rules for installing headers 79__headersinst: $(subdirs) $(install-file) 80 @: 81 82targets += $(install-file) 83$(install-file): scripts/headers_install.pl $(input-files) FORCE 84 $(if $(unwanted),$(call cmd,remove),) 85 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 86 $(call if_changed,install) 87 88else 89__headerscheck: $(subdirs) $(check-file) 90 @: 91 92targets += $(check-file) 93$(check-file): scripts/headers_check.pl $(output-files) FORCE 94 $(call if_changed,check) 95 96endif 97 98# Recursion 99hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 100.PHONY: $(subdirs) 101$(subdirs): 102 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 103 104targets := $(wildcard $(sort $(targets))) 105cmd_files := $(wildcard \ 106 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 107 108ifneq ($(cmd_files),) 109 include $(cmd_files) 110endif 111 112.PHONY: $(PHONY) 113PHONY += FORCE 114FORCE: ; 115