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 640f1d4c2SDavid Howells# genhdr-y - Same as header-y but in a generated/ directory 78d730cfbSDavid Woodhouse# 88d730cfbSDavid Woodhouse# ========================================================================== 98d730cfbSDavid Woodhouse 10cb97914bSH. Peter Anvin# generated header directory 11cb97914bSH. Peter Anvingen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) 12cb97914bSH. Peter Anvin 13283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild 14283039fbSSam Ravnborginclude $(kbuild-file) 15de789125SDavid Woodhouse 169b58b928SJesper Nilsson# called may set destination dir (when installing to asm/) 17*bd73a328SNicolas Dichtel_dst := $(if $(dst),$(dst),$(obj)) 189b58b928SJesper Nilsson 1910b63956SDavid Howellsold-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild 2010b63956SDavid Howellsifneq ($(wildcard $(old-kbuild-file)),) 2110b63956SDavid Howellsinclude $(old-kbuild-file) 2210b63956SDavid Howellsendif 23c7bb349eSSam Ravnborg 248d730cfbSDavid Woodhouseinclude scripts/Kbuild.include 258d730cfbSDavid Woodhouse 2610b63956SDavid Howellsinstalldir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst)) 2762284a37SSam Ravnborg 287cfddeefSSam Ravnborgheader-y := $(sort $(header-y)) 297712401aSSam Ravnborgsubdirs := $(patsubst %/,%,$(filter %/, $(header-y))) 308d730cfbSDavid Woodhouseheader-y := $(filter-out %/, $(header-y)) 318d730cfbSDavid Woodhouse 327712401aSSam Ravnborg# files used to track state of install/check 3310b63956SDavid Howellsinstall-file := $(installdir)/.install 3410b63956SDavid Howellscheck-file := $(installdir)/.check 357712401aSSam Ravnborg 36d8ecc5cdSSam Ravnborg# generic-y list all files an architecture uses from asm-generic 37d8ecc5cdSSam Ravnborg# Use this to build a list of headers which require a wrapper 38d8ecc5cdSSam Ravnborgwrapper-files := $(filter $(header-y), $(generic-y)) 39d8ecc5cdSSam Ravnborg 4010b63956SDavid Howellssrcdir := $(srctree)/$(obj) 4110b63956SDavid Howellsgendir := $(objtree)/$(gen) 4210b63956SDavid Howells 437712401aSSam Ravnborg# all headers files for this dir 44d8ecc5cdSSam Ravnborgheader-y := $(filter-out $(generic-y), $(header-y)) 4540f1d4c2SDavid Howellsall-files := $(header-y) $(genhdr-y) $(wrapper-files) 4610b63956SDavid Howellsoutput-files := $(addprefix $(installdir)/, $(all-files)) 4710b63956SDavid Howells 487c025b2aSNicolas Dichtel# Check that all expected files exist 497c025b2aSNicolas Dichtel$(foreach hdr, $(header-y), \ 50c0ff68f1SNicolas Dichtel $(if $(wildcard $(srcdir)/$(hdr)),, \ 517c025b2aSNicolas Dichtel $(error Missing UAPI file $(srcdir)/$(hdr)) \ 52c0ff68f1SNicolas Dichtel )) 537c025b2aSNicolas Dichtel$(foreach hdr, $(genhdr-y), \ 547c025b2aSNicolas Dichtel $(if $(wildcard $(gendir)/$(hdr)),, \ 5510b63956SDavid Howells $(error Missing generated UAPI file $(gendir)/$(hdr)) \ 5610b63956SDavid Howells )) 57de789125SDavid Woodhouse 58de789125SDavid Woodhouse# Work out what needs to be removed 5910b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 607712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 61de789125SDavid Woodhouse 627712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 6310b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 64de789125SDavid Woodhouse 657712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 66de789125SDavid Woodhouse 677712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 687712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 69db1bec4fSSam Ravnborg cmd_install = \ 707c025b2aSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-y); \ 717c025b2aSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-y); \ 72d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 7310b63956SDavid Howells echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 74d8ecc5cdSSam Ravnborg done; \ 757712401aSSam Ravnborg touch $@ 768d730cfbSDavid Woodhouse 777712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 787712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 798d730cfbSDavid Woodhouse 807712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 817211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 827211b8b9SSergei Poselenov# the "Argument list too long" error. 837211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 8410b63956SDavid Howells echo "$(installdir)/$${f}"; done \ 857211b8b9SSergei Poselenov | xargs \ 867211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 877712401aSSam Ravnborg touch $@ 8868475359SDavid Woodhouse 897712401aSSam RavnborgPHONY += __headersinst __headerscheck 908d730cfbSDavid Woodhouse 917712401aSSam Ravnborgifndef HDRCHECK 927712401aSSam Ravnborg# Rules for installing headers 937712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 947712401aSSam Ravnborg @: 95de789125SDavid Woodhouse 967712401aSSam Ravnborgtargets += $(install-file) 977c025b2aSNicolas Dichtel$(install-file): scripts/headers_install.sh \ 987c025b2aSNicolas Dichtel $(addprefix $(srcdir)/,$(header-y)) \ 997c025b2aSNicolas Dichtel $(addprefix $(gendir)/,$(genhdr-y)) FORCE 1007712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 1017712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 1027712401aSSam Ravnborg $(call if_changed,install) 103de789125SDavid Woodhouse 10468475359SDavid Woodhouseelse 1057712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 1067712401aSSam Ravnborg @: 1078d730cfbSDavid Woodhouse 1087712401aSSam Ravnborgtargets += $(check-file) 1097712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 1107712401aSSam Ravnborg $(call if_changed,check) 1114e420aa9SSam Ravnborg 1128d730cfbSDavid Woodhouseendif 1138d730cfbSDavid Woodhouse 1148d730cfbSDavid Woodhouse# Recursion 1157712401aSSam Ravnborg.PHONY: $(subdirs) 1167712401aSSam Ravnborg$(subdirs): 11762284a37SSam Ravnborg $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 1187712401aSSam Ravnborg 1197712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 1207712401aSSam Ravnborgcmd_files := $(wildcard \ 1217712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1227712401aSSam Ravnborg 1237712401aSSam Ravnborgifneq ($(cmd_files),) 1247712401aSSam Ravnborg include $(cmd_files) 1257712401aSSam Ravnborgendif 1267712401aSSam Ravnborg 1277712401aSSam Ravnborg.PHONY: $(PHONY) 1287712401aSSam RavnborgPHONY += FORCE 1297712401aSSam RavnborgFORCE: ; 130