18d730cfbSDavid Woodhouse# ========================================================================== 28d730cfbSDavid Woodhouse# Installing headers 38d730cfbSDavid Woodhouse# 47712401aSSam Ravnborg# header-y - list files to be installed. They are preprocessed 57712401aSSam Ravnborg# to remove __KERNEL__ section of the file 67712401aSSam Ravnborg# unifdef-y - Same as header-y. Obsolete 77712401aSSam Ravnborg# objhdr-y - Same as header-y but for generated files 88d730cfbSDavid Woodhouse# 98d730cfbSDavid Woodhouse# ========================================================================== 108d730cfbSDavid Woodhouse 117712401aSSam 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 17c7bb349eSSam Ravnborg_dst := $(if $(destination-y),$(destination-y),$(_dst)) 18c7bb349eSSam Ravnborg 198d730cfbSDavid Woodhouseinclude scripts/Kbuild.include 208d730cfbSDavid Woodhouse 2162284a37SSam Ravnborginstall := $(INSTALL_HDR_PATH)/$(_dst) 2262284a37SSam Ravnborg 234e420aa9SSam Ravnborgheader-y := $(sort $(header-y) $(unifdef-y)) 247712401aSSam Ravnborgsubdirs := $(patsubst %/,%,$(filter %/, $(header-y))) 258d730cfbSDavid Woodhouseheader-y := $(filter-out %/, $(header-y)) 268d730cfbSDavid Woodhouse 277712401aSSam Ravnborg# files used to track state of install/check 287712401aSSam Ravnborginstall-file := $(install)/.install 297712401aSSam Ravnborgcheck-file := $(install)/.check 307712401aSSam Ravnborg 317712401aSSam Ravnborg# all headers files for this dir 327712401aSSam Ravnborgall-files := $(header-y) $(objhdr-y) 337712401aSSam Ravnborginput-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \ 347712401aSSam Ravnborg $(addprefix $(objtree)/$(obj)/,$(objhdr-y)) 357712401aSSam Ravnborgoutput-files := $(addprefix $(install)/, $(all-files)) 36de789125SDavid Woodhouse 37de789125SDavid Woodhouse# Work out what needs to be removed 3862284a37SSam Ravnborgoldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) 397712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 40de789125SDavid Woodhouse 417712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 427712401aSSam Ravnborgunwanted-file := $(addprefix $(install)/, $(unwanted)) 43de789125SDavid Woodhouse 447712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 45de789125SDavid Woodhouse 467712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 477712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 48db1bec4fSSam Ravnborg cmd_install = \ 49db1bec4fSSam Ravnborg $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \ 50db1bec4fSSam Ravnborg $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \ 517712401aSSam Ravnborg touch $@ 528d730cfbSDavid Woodhouse 537712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 547712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 558d730cfbSDavid Woodhouse 567712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 57*7211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 58*7211b8b9SSergei Poselenov# the "Argument list too long" error. 59*7211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 60*7211b8b9SSergei Poselenov echo "$(install)/$${f}"; done \ 61*7211b8b9SSergei Poselenov | xargs \ 62*7211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 637712401aSSam Ravnborg touch $@ 6468475359SDavid Woodhouse 657712401aSSam RavnborgPHONY += __headersinst __headerscheck 668d730cfbSDavid Woodhouse 677712401aSSam Ravnborgifndef HDRCHECK 687712401aSSam Ravnborg# Rules for installing headers 697712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 707712401aSSam Ravnborg @: 71de789125SDavid Woodhouse 727712401aSSam Ravnborgtargets += $(install-file) 737712401aSSam Ravnborg$(install-file): scripts/headers_install.pl $(input-files) FORCE 747712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 757712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 767712401aSSam Ravnborg $(call if_changed,install) 77de789125SDavid Woodhouse 7868475359SDavid Woodhouseelse 797712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 807712401aSSam Ravnborg @: 818d730cfbSDavid Woodhouse 827712401aSSam Ravnborgtargets += $(check-file) 837712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 847712401aSSam Ravnborg $(call if_changed,check) 854e420aa9SSam Ravnborg 868d730cfbSDavid Woodhouseendif 878d730cfbSDavid Woodhouse 888d730cfbSDavid Woodhouse# Recursion 897712401aSSam Ravnborghdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 907712401aSSam Ravnborg.PHONY: $(subdirs) 917712401aSSam Ravnborg$(subdirs): 9262284a37SSam Ravnborg $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 937712401aSSam Ravnborg 947712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 957712401aSSam Ravnborgcmd_files := $(wildcard \ 967712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 977712401aSSam Ravnborg 987712401aSSam Ravnborgifneq ($(cmd_files),) 997712401aSSam Ravnborg include $(cmd_files) 1007712401aSSam Ravnborgendif 1017712401aSSam Ravnborg 1027712401aSSam Ravnborg.PHONY: $(PHONY) 1037712401aSSam RavnborgPHONY += FORCE 1047712401aSSam RavnborgFORCE: ; 105