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 6*40f1d4c2SDavid Howells# genhdr-y - Same as header-y but in a generated/ directory 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 13cb97914bSH. Peter Anvin# generated header directory 14cb97914bSH. Peter Anvingen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) 15cb97914bSH. Peter Anvin 16283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild 17283039fbSSam Ravnborginclude $(kbuild-file) 18de789125SDavid Woodhouse 19c7bb349eSSam Ravnborg_dst := $(if $(destination-y),$(destination-y),$(_dst)) 20c7bb349eSSam Ravnborg 218d730cfbSDavid Woodhouseinclude scripts/Kbuild.include 228d730cfbSDavid Woodhouse 2362284a37SSam Ravnborginstall := $(INSTALL_HDR_PATH)/$(_dst) 2462284a37SSam Ravnborg 257cfddeefSSam Ravnborgheader-y := $(sort $(header-y)) 267712401aSSam Ravnborgsubdirs := $(patsubst %/,%,$(filter %/, $(header-y))) 278d730cfbSDavid Woodhouseheader-y := $(filter-out %/, $(header-y)) 288d730cfbSDavid Woodhouse 297712401aSSam Ravnborg# files used to track state of install/check 307712401aSSam Ravnborginstall-file := $(install)/.install 317712401aSSam Ravnborgcheck-file := $(install)/.check 327712401aSSam Ravnborg 33d8ecc5cdSSam Ravnborg# generic-y list all files an architecture uses from asm-generic 34d8ecc5cdSSam Ravnborg# Use this to build a list of headers which require a wrapper 35d8ecc5cdSSam Ravnborgwrapper-files := $(filter $(header-y), $(generic-y)) 36d8ecc5cdSSam Ravnborg 377712401aSSam Ravnborg# all headers files for this dir 38d8ecc5cdSSam Ravnborgheader-y := $(filter-out $(generic-y), $(header-y)) 39*40f1d4c2SDavid Howellsall-files := $(header-y) $(genhdr-y) $(wrapper-files) 407712401aSSam Ravnborginput-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \ 41cb97914bSH. Peter Anvin $(addprefix $(objtree)/$(gen)/,$(genhdr-y)) 427712401aSSam Ravnborgoutput-files := $(addprefix $(install)/, $(all-files)) 43de789125SDavid Woodhouse 44de789125SDavid Woodhouse# Work out what needs to be removed 4562284a37SSam Ravnborgoldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) 467712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 47de789125SDavid Woodhouse 487712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 497712401aSSam Ravnborgunwanted-file := $(addprefix $(install)/, $(unwanted)) 50de789125SDavid Woodhouse 517712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 52de789125SDavid Woodhouse 537712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 547712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 55db1bec4fSSam Ravnborg cmd_install = \ 56db1bec4fSSam Ravnborg $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \ 57cb97914bSH. Peter Anvin $(PERL) $< $(objtree)/$(gen) $(install) $(SRCARCH) $(genhdr-y); \ 58d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 59d8ecc5cdSSam Ravnborg echo "\#include <asm-generic/$$F>" > $(install)/$$F; \ 60d8ecc5cdSSam Ravnborg done; \ 617712401aSSam Ravnborg touch $@ 628d730cfbSDavid Woodhouse 637712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 647712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 658d730cfbSDavid Woodhouse 667712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 677211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 687211b8b9SSergei Poselenov# the "Argument list too long" error. 697211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 707211b8b9SSergei Poselenov echo "$(install)/$${f}"; done \ 717211b8b9SSergei Poselenov | xargs \ 727211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 737712401aSSam Ravnborg touch $@ 7468475359SDavid Woodhouse 757712401aSSam RavnborgPHONY += __headersinst __headerscheck 768d730cfbSDavid Woodhouse 777712401aSSam Ravnborgifndef HDRCHECK 787712401aSSam Ravnborg# Rules for installing headers 797712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 807712401aSSam Ravnborg @: 81de789125SDavid Woodhouse 827712401aSSam Ravnborgtargets += $(install-file) 837712401aSSam Ravnborg$(install-file): scripts/headers_install.pl $(input-files) FORCE 847712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 857712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 867712401aSSam Ravnborg $(call if_changed,install) 87de789125SDavid Woodhouse 8868475359SDavid Woodhouseelse 897712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 907712401aSSam Ravnborg @: 918d730cfbSDavid Woodhouse 927712401aSSam Ravnborgtargets += $(check-file) 937712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 947712401aSSam Ravnborg $(call if_changed,check) 954e420aa9SSam Ravnborg 968d730cfbSDavid Woodhouseendif 978d730cfbSDavid Woodhouse 988d730cfbSDavid Woodhouse# Recursion 997712401aSSam Ravnborghdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 1007712401aSSam Ravnborg.PHONY: $(subdirs) 1017712401aSSam Ravnborg$(subdirs): 10262284a37SSam Ravnborg $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 1037712401aSSam Ravnborg 1047712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 1057712401aSSam Ravnborgcmd_files := $(wildcard \ 1067712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1077712401aSSam Ravnborg 1087712401aSSam Ravnborgifneq ($(cmd_files),) 1097712401aSSam Ravnborg include $(cmd_files) 1107712401aSSam Ravnborgendif 1117712401aSSam Ravnborg 1127712401aSSam Ravnborg.PHONY: $(PHONY) 1137712401aSSam RavnborgPHONY += FORCE 1147712401aSSam RavnborgFORCE: ; 115