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# objhdr-y - Same as header-y but for generated files 78d730cfbSDavid Woodhouse# 88d730cfbSDavid Woodhouse# ========================================================================== 98d730cfbSDavid Woodhouse 107712401aSSam Ravnborg# called may set destination dir (when installing to asm/) 118d730cfbSDavid Woodhouse_dst := $(if $(dst),$(dst),$(obj)) 128d730cfbSDavid Woodhouse 13283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild 14283039fbSSam Ravnborginclude $(kbuild-file) 15de789125SDavid Woodhouse 16c7bb349eSSam Ravnborg_dst := $(if $(destination-y),$(destination-y),$(_dst)) 17c7bb349eSSam Ravnborg 188d730cfbSDavid Woodhouseinclude scripts/Kbuild.include 198d730cfbSDavid Woodhouse 2062284a37SSam Ravnborginstall := $(INSTALL_HDR_PATH)/$(_dst) 2162284a37SSam Ravnborg 22*7cfddeefSSam Ravnborgheader-y := $(sort $(header-y)) 237712401aSSam Ravnborgsubdirs := $(patsubst %/,%,$(filter %/, $(header-y))) 248d730cfbSDavid Woodhouseheader-y := $(filter-out %/, $(header-y)) 258d730cfbSDavid Woodhouse 267712401aSSam Ravnborg# files used to track state of install/check 277712401aSSam Ravnborginstall-file := $(install)/.install 287712401aSSam Ravnborgcheck-file := $(install)/.check 297712401aSSam Ravnborg 307712401aSSam Ravnborg# all headers files for this dir 317712401aSSam Ravnborgall-files := $(header-y) $(objhdr-y) 327712401aSSam Ravnborginput-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \ 337712401aSSam Ravnborg $(addprefix $(objtree)/$(obj)/,$(objhdr-y)) 347712401aSSam Ravnborgoutput-files := $(addprefix $(install)/, $(all-files)) 35de789125SDavid Woodhouse 36de789125SDavid Woodhouse# Work out what needs to be removed 3762284a37SSam Ravnborgoldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) 387712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 39de789125SDavid Woodhouse 407712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 417712401aSSam Ravnborgunwanted-file := $(addprefix $(install)/, $(unwanted)) 42de789125SDavid Woodhouse 437712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 44de789125SDavid Woodhouse 457712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 467712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 47db1bec4fSSam Ravnborg cmd_install = \ 48db1bec4fSSam Ravnborg $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \ 49db1bec4fSSam Ravnborg $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \ 507712401aSSam Ravnborg touch $@ 518d730cfbSDavid Woodhouse 527712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 537712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 548d730cfbSDavid Woodhouse 557712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 567211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 577211b8b9SSergei Poselenov# the "Argument list too long" error. 587211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 597211b8b9SSergei Poselenov echo "$(install)/$${f}"; done \ 607211b8b9SSergei Poselenov | xargs \ 617211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 627712401aSSam Ravnborg touch $@ 6368475359SDavid Woodhouse 647712401aSSam RavnborgPHONY += __headersinst __headerscheck 658d730cfbSDavid Woodhouse 667712401aSSam Ravnborgifndef HDRCHECK 677712401aSSam Ravnborg# Rules for installing headers 687712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 697712401aSSam Ravnborg @: 70de789125SDavid Woodhouse 717712401aSSam Ravnborgtargets += $(install-file) 727712401aSSam Ravnborg$(install-file): scripts/headers_install.pl $(input-files) FORCE 737712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 747712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 757712401aSSam Ravnborg $(call if_changed,install) 76de789125SDavid Woodhouse 7768475359SDavid Woodhouseelse 787712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 797712401aSSam Ravnborg @: 808d730cfbSDavid Woodhouse 817712401aSSam Ravnborgtargets += $(check-file) 827712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 837712401aSSam Ravnborg $(call if_changed,check) 844e420aa9SSam Ravnborg 858d730cfbSDavid Woodhouseendif 868d730cfbSDavid Woodhouse 878d730cfbSDavid Woodhouse# Recursion 887712401aSSam Ravnborghdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 897712401aSSam Ravnborg.PHONY: $(subdirs) 907712401aSSam Ravnborg$(subdirs): 9162284a37SSam Ravnborg $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 927712401aSSam Ravnborg 937712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 947712401aSSam Ravnborgcmd_files := $(wildcard \ 957712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 967712401aSSam Ravnborg 977712401aSSam Ravnborgifneq ($(cmd_files),) 987712401aSSam Ravnborg include $(cmd_files) 997712401aSSam Ravnborgendif 1007712401aSSam Ravnborg 1017712401aSSam Ravnborg.PHONY: $(PHONY) 1027712401aSSam RavnborgPHONY += FORCE 1037712401aSSam RavnborgFORCE: ; 104