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 227cfddeefSSam 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 30*d8ecc5cdSSam Ravnborg# generic-y list all files an architecture uses from asm-generic 31*d8ecc5cdSSam Ravnborg# Use this to build a list of headers which require a wrapper 32*d8ecc5cdSSam Ravnborgwrapper-files := $(filter $(header-y), $(generic-y)) 33*d8ecc5cdSSam Ravnborg 347712401aSSam Ravnborg# all headers files for this dir 35*d8ecc5cdSSam Ravnborgheader-y := $(filter-out $(generic-y), $(header-y)) 36*d8ecc5cdSSam Ravnborgall-files := $(header-y) $(objhdr-y) $(wrapper-files) 377712401aSSam Ravnborginput-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \ 387712401aSSam Ravnborg $(addprefix $(objtree)/$(obj)/,$(objhdr-y)) 397712401aSSam Ravnborgoutput-files := $(addprefix $(install)/, $(all-files)) 40de789125SDavid Woodhouse 41de789125SDavid Woodhouse# Work out what needs to be removed 4262284a37SSam Ravnborgoldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) 437712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 44de789125SDavid Woodhouse 457712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 467712401aSSam Ravnborgunwanted-file := $(addprefix $(install)/, $(unwanted)) 47de789125SDavid Woodhouse 487712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 49de789125SDavid Woodhouse 507712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 517712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 52db1bec4fSSam Ravnborg cmd_install = \ 53db1bec4fSSam Ravnborg $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \ 54db1bec4fSSam Ravnborg $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \ 55*d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 56*d8ecc5cdSSam Ravnborg echo "\#include <asm-generic/$$F>" > $(install)/$$F; \ 57*d8ecc5cdSSam Ravnborg done; \ 587712401aSSam Ravnborg touch $@ 598d730cfbSDavid Woodhouse 607712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 617712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 628d730cfbSDavid Woodhouse 637712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 647211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 657211b8b9SSergei Poselenov# the "Argument list too long" error. 667211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 677211b8b9SSergei Poselenov echo "$(install)/$${f}"; done \ 687211b8b9SSergei Poselenov | xargs \ 697211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 707712401aSSam Ravnborg touch $@ 7168475359SDavid Woodhouse 727712401aSSam RavnborgPHONY += __headersinst __headerscheck 738d730cfbSDavid Woodhouse 747712401aSSam Ravnborgifndef HDRCHECK 757712401aSSam Ravnborg# Rules for installing headers 767712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 777712401aSSam Ravnborg @: 78de789125SDavid Woodhouse 797712401aSSam Ravnborgtargets += $(install-file) 807712401aSSam Ravnborg$(install-file): scripts/headers_install.pl $(input-files) FORCE 817712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 827712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 837712401aSSam Ravnborg $(call if_changed,install) 84de789125SDavid Woodhouse 8568475359SDavid Woodhouseelse 867712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 877712401aSSam Ravnborg @: 888d730cfbSDavid Woodhouse 897712401aSSam Ravnborgtargets += $(check-file) 907712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 917712401aSSam Ravnborg $(call if_changed,check) 924e420aa9SSam Ravnborg 938d730cfbSDavid Woodhouseendif 948d730cfbSDavid Woodhouse 958d730cfbSDavid Woodhouse# Recursion 967712401aSSam Ravnborghdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 977712401aSSam Ravnborg.PHONY: $(subdirs) 987712401aSSam Ravnborg$(subdirs): 9962284a37SSam Ravnborg $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 1007712401aSSam Ravnborg 1017712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 1027712401aSSam Ravnborgcmd_files := $(wildcard \ 1037712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1047712401aSSam Ravnborg 1057712401aSSam Ravnborgifneq ($(cmd_files),) 1067712401aSSam Ravnborg include $(cmd_files) 1077712401aSSam Ravnborgendif 1087712401aSSam Ravnborg 1097712401aSSam Ravnborg.PHONY: $(PHONY) 1107712401aSSam RavnborgPHONY += FORCE 1117712401aSSam RavnborgFORCE: ; 112