1*4882a593Smuzhiyun# ========================================================================== 2*4882a593Smuzhiyun# Installing headers 3*4882a593Smuzhiyun# 4*4882a593Smuzhiyun# header-y - list files to be installed. They are preprocessed 5*4882a593Smuzhiyun# to remove __KERNEL__ section of the file 6*4882a593Smuzhiyun# genhdr-y - Same as header-y but in a generated/ directory 7*4882a593Smuzhiyun# 8*4882a593Smuzhiyun# ========================================================================== 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun# generated header directory 11*4882a593Smuzhiyungen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) 12*4882a593Smuzhiyun 13*4882a593Smuzhiyunkbuild-file := $(srctree)/$(obj)/Kbuild 14*4882a593Smuzhiyuninclude $(kbuild-file) 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun# called may set destination dir (when installing to asm/) 17*4882a593Smuzhiyun_dst := $(if $(destination-y),$(destination-y),$(if $(dst),$(dst),$(obj))) 18*4882a593Smuzhiyun 19*4882a593Smuzhiyunold-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild 20*4882a593Smuzhiyunifneq ($(wildcard $(old-kbuild-file)),) 21*4882a593Smuzhiyuninclude $(old-kbuild-file) 22*4882a593Smuzhiyunendif 23*4882a593Smuzhiyun 24*4882a593Smuzhiyuninclude scripts/Kbuild.include 25*4882a593Smuzhiyun 26*4882a593Smuzhiyuninstalldir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst)) 27*4882a593Smuzhiyun 28*4882a593Smuzhiyunheader-y := $(sort $(header-y)) 29*4882a593Smuzhiyunsubdirs := $(patsubst %/,%,$(filter %/, $(header-y))) 30*4882a593Smuzhiyunheader-y := $(filter-out %/, $(header-y)) 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun# files used to track state of install/check 33*4882a593Smuzhiyuninstall-file := $(installdir)/.install 34*4882a593Smuzhiyuncheck-file := $(installdir)/.check 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun# generic-y list all files an architecture uses from asm-generic 37*4882a593Smuzhiyun# Use this to build a list of headers which require a wrapper 38*4882a593Smuzhiyunwrapper-files := $(filter $(header-y), $(generic-y)) 39*4882a593Smuzhiyun 40*4882a593Smuzhiyunsrcdir := $(srctree)/$(obj) 41*4882a593Smuzhiyungendir := $(objtree)/$(gen) 42*4882a593Smuzhiyun 43*4882a593Smuzhiyunoldsrcdir := $(srctree)/$(subst /uapi,,$(obj)) 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun# all headers files for this dir 46*4882a593Smuzhiyunheader-y := $(filter-out $(generic-y), $(header-y)) 47*4882a593Smuzhiyunall-files := $(header-y) $(genhdr-y) $(wrapper-files) 48*4882a593Smuzhiyunoutput-files := $(addprefix $(installdir)/, $(all-files)) 49*4882a593Smuzhiyun 50*4882a593Smuzhiyuninput-files1 := $(foreach hdr, $(header-y), \ 51*4882a593Smuzhiyun $(if $(wildcard $(srcdir)/$(hdr)), \ 52*4882a593Smuzhiyun $(wildcard $(srcdir)/$(hdr))) \ 53*4882a593Smuzhiyun ) 54*4882a593Smuzhiyuninput-files1-name := $(notdir $(input-files1)) 55*4882a593Smuzhiyuninput-files2 := $(foreach hdr, $(header-y), \ 56*4882a593Smuzhiyun $(if $(wildcard $(srcdir)/$(hdr)),, \ 57*4882a593Smuzhiyun $(if $(wildcard $(oldsrcdir)/$(hdr)), \ 58*4882a593Smuzhiyun $(wildcard $(oldsrcdir)/$(hdr)), \ 59*4882a593Smuzhiyun $(error Missing UAPI file $(srcdir)/$(hdr))) \ 60*4882a593Smuzhiyun )) 61*4882a593Smuzhiyuninput-files2-name := $(notdir $(input-files2)) 62*4882a593Smuzhiyuninput-files3 := $(foreach hdr, $(genhdr-y), \ 63*4882a593Smuzhiyun $(if $(wildcard $(gendir)/$(hdr)), \ 64*4882a593Smuzhiyun $(wildcard $(gendir)/$(hdr)), \ 65*4882a593Smuzhiyun $(error Missing generated UAPI file $(gendir)/$(hdr)) \ 66*4882a593Smuzhiyun )) 67*4882a593Smuzhiyuninput-files3-name := $(notdir $(input-files3)) 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun# Work out what needs to be removed 70*4882a593Smuzhiyunoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 71*4882a593Smuzhiyununwanted := $(filter-out $(all-files),$(oldheaders)) 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 74*4882a593Smuzhiyununwanted-file := $(addprefix $(installdir)/, $(unwanted)) 75*4882a593Smuzhiyun 76*4882a593Smuzhiyunprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 77*4882a593Smuzhiyun 78*4882a593Smuzhiyunquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 79*4882a593Smuzhiyun file$(if $(word 2, $(all-files)),s)) 80*4882a593Smuzhiyun cmd_install = \ 81*4882a593Smuzhiyun $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(input-files1-name); \ 82*4882a593Smuzhiyun $(CONFIG_SHELL) $< $(installdir) $(oldsrcdir) $(input-files2-name); \ 83*4882a593Smuzhiyun $(CONFIG_SHELL) $< $(installdir) $(gendir) $(input-files3-name); \ 84*4882a593Smuzhiyun for F in $(wrapper-files); do \ 85*4882a593Smuzhiyun echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 86*4882a593Smuzhiyun done; \ 87*4882a593Smuzhiyun touch $@ 88*4882a593Smuzhiyun 89*4882a593Smuzhiyunquiet_cmd_remove = REMOVE $(unwanted) 90*4882a593Smuzhiyun cmd_remove = rm -f $(unwanted-file) 91*4882a593Smuzhiyun 92*4882a593Smuzhiyunquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 93*4882a593Smuzhiyun# Headers list can be pretty long, xargs helps to avoid 94*4882a593Smuzhiyun# the "Argument list too long" error. 95*4882a593Smuzhiyun cmd_check = for f in $(all-files); do \ 96*4882a593Smuzhiyun echo "$(installdir)/$${f}"; done \ 97*4882a593Smuzhiyun | xargs \ 98*4882a593Smuzhiyun $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 99*4882a593Smuzhiyun touch $@ 100*4882a593Smuzhiyun 101*4882a593SmuzhiyunPHONY += __headersinst __headerscheck 102*4882a593Smuzhiyun 103*4882a593Smuzhiyunifndef HDRCHECK 104*4882a593Smuzhiyun# Rules for installing headers 105*4882a593Smuzhiyun__headersinst: $(subdirs) $(install-file) 106*4882a593Smuzhiyun @: 107*4882a593Smuzhiyun 108*4882a593Smuzhiyuntargets += $(install-file) 109*4882a593Smuzhiyun$(install-file): scripts/headers_install.sh $(input-files1) $(input-files2) $(input-files3) FORCE 110*4882a593Smuzhiyun $(if $(unwanted),$(call cmd,remove),) 111*4882a593Smuzhiyun $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 112*4882a593Smuzhiyun $(call if_changed,install) 113*4882a593Smuzhiyun 114*4882a593Smuzhiyunelse 115*4882a593Smuzhiyun__headerscheck: $(subdirs) $(check-file) 116*4882a593Smuzhiyun @: 117*4882a593Smuzhiyun 118*4882a593Smuzhiyuntargets += $(check-file) 119*4882a593Smuzhiyun$(check-file): scripts/headers_check.pl $(output-files) FORCE 120*4882a593Smuzhiyun $(call if_changed,check) 121*4882a593Smuzhiyun 122*4882a593Smuzhiyunendif 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun# Recursion 125*4882a593Smuzhiyun.PHONY: $(subdirs) 126*4882a593Smuzhiyun$(subdirs): 127*4882a593Smuzhiyun $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 128*4882a593Smuzhiyun 129*4882a593Smuzhiyuntargets := $(wildcard $(sort $(targets))) 130*4882a593Smuzhiyuncmd_files := $(wildcard \ 131*4882a593Smuzhiyun $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 132*4882a593Smuzhiyun 133*4882a593Smuzhiyunifneq ($(cmd_files),) 134*4882a593Smuzhiyun include $(cmd_files) 135*4882a593Smuzhiyunendif 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun.PHONY: $(PHONY) 138*4882a593SmuzhiyunPHONY += FORCE 139*4882a593SmuzhiyunFORCE: ; 140