18d730cfbSDavid Woodhouse# ========================================================================== 28d730cfbSDavid Woodhouse# Installing headers 38d730cfbSDavid Woodhouse# 4*7712401aSSam Ravnborg# header-y - list files to be installed. They are preprocessed 5*7712401aSSam Ravnborg# to remove __KERNEL__ section of the file 6*7712401aSSam Ravnborg# unifdef-y - Same as header-y. Obsolete 7*7712401aSSam Ravnborg# objhdr-y - Same as header-y but for generated files 88d730cfbSDavid Woodhouse# 98d730cfbSDavid Woodhouse# ========================================================================== 108d730cfbSDavid Woodhouse 11*7712401aSSam Ravnborg# called may set destination dir (when installing to asm/) 128d730cfbSDavid Woodhouse_dst := $(if $(dst),$(dst),$(obj)) 138d730cfbSDavid Woodhouse 14283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild 15283039fbSSam Ravnborginclude $(kbuild-file) 16de789125SDavid Woodhouse 178d730cfbSDavid Woodhouseinclude scripts/Kbuild.include 188d730cfbSDavid Woodhouse 1962284a37SSam Ravnborginstall := $(INSTALL_HDR_PATH)/$(_dst) 2062284a37SSam Ravnborg 214e420aa9SSam Ravnborgheader-y := $(sort $(header-y) $(unifdef-y)) 22*7712401aSSam Ravnborgsubdirs := $(patsubst %/,%,$(filter %/, $(header-y))) 238d730cfbSDavid Woodhouseheader-y := $(filter-out %/, $(header-y)) 248d730cfbSDavid Woodhouse 25*7712401aSSam Ravnborg# files used to track state of install/check 26*7712401aSSam Ravnborginstall-file := $(install)/.install 27*7712401aSSam Ravnborgcheck-file := $(install)/.check 28*7712401aSSam Ravnborg 29*7712401aSSam Ravnborg# all headers files for this dir 30*7712401aSSam Ravnborgall-files := $(header-y) $(objhdr-y) 31*7712401aSSam Ravnborginput-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \ 32*7712401aSSam Ravnborg $(addprefix $(objtree)/$(obj)/,$(objhdr-y)) 33*7712401aSSam Ravnborgoutput-files := $(addprefix $(install)/, $(all-files)) 34de789125SDavid Woodhouse 35de789125SDavid Woodhouse# Work out what needs to be removed 3662284a37SSam Ravnborgoldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) 37*7712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 38de789125SDavid Woodhouse 39*7712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 40*7712401aSSam Ravnborgunwanted-file := $(addprefix $(install)/, $(unwanted)) 41de789125SDavid Woodhouse 42*7712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 43de789125SDavid Woodhouse 44*7712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 45*7712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 46*7712401aSSam Ravnborg cmd_install = $(PERL) $< $(srctree)/$(obj) $(install) $(header-y); \ 47*7712401aSSam Ravnborg $(PERL) $< $(objtree)/$(obj) $(install) $(objhdr-y); \ 48*7712401aSSam Ravnborg touch $@ 498d730cfbSDavid Woodhouse 50*7712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 51*7712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 528d730cfbSDavid Woodhouse 53*7712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 54*7712401aSSam Ravnborg cmd_check = $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH) \ 55*7712401aSSam Ravnborg $(addprefix $(install)/, $(all-files)); \ 56*7712401aSSam Ravnborg touch $@ 5768475359SDavid Woodhouse 58*7712401aSSam RavnborgPHONY += __headersinst __headerscheck 598d730cfbSDavid Woodhouse 60*7712401aSSam Ravnborgifndef HDRCHECK 61*7712401aSSam Ravnborg# Rules for installing headers 62*7712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 63*7712401aSSam Ravnborg @: 64de789125SDavid Woodhouse 65*7712401aSSam Ravnborgtargets += $(install-file) 66*7712401aSSam Ravnborg$(install-file): scripts/headers_install.pl $(input-files) FORCE 67*7712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 68*7712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 69*7712401aSSam Ravnborg $(call if_changed,install) 70de789125SDavid Woodhouse 7168475359SDavid Woodhouseelse 72*7712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 73*7712401aSSam Ravnborg @: 748d730cfbSDavid Woodhouse 75*7712401aSSam Ravnborgtargets += $(check-file) 76*7712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 77*7712401aSSam Ravnborg $(call if_changed,check) 784e420aa9SSam Ravnborg 798d730cfbSDavid Woodhouseendif 808d730cfbSDavid Woodhouse 818d730cfbSDavid Woodhouse# Recursion 82*7712401aSSam Ravnborghdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 83*7712401aSSam Ravnborg.PHONY: $(subdirs) 84*7712401aSSam Ravnborg$(subdirs): 8562284a37SSam Ravnborg $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 86*7712401aSSam Ravnborg 87*7712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 88*7712401aSSam Ravnborgcmd_files := $(wildcard \ 89*7712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 90*7712401aSSam Ravnborg 91*7712401aSSam Ravnborgifneq ($(cmd_files),) 92*7712401aSSam Ravnborg include $(cmd_files) 93*7712401aSSam Ravnborgendif 94*7712401aSSam Ravnborg 95*7712401aSSam Ravnborg.PHONY: $(PHONY) 96*7712401aSSam RavnborgPHONY += FORCE 97*7712401aSSam RavnborgFORCE: ; 98