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 107712401aSSam Ravnborg# called may set destination dir (when installing to asm/) 11*10b63956SDavid Howells_dst := $(or $(destination-y),$(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 19*10b63956SDavid Howellsold-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild 20*10b63956SDavid Howellsifneq ($(wildcard $(old-kbuild-file)),) 21*10b63956SDavid Howellsinclude $(old-kbuild-file) 22*10b63956SDavid Howellsendif 23c7bb349eSSam Ravnborg 248d730cfbSDavid Woodhouseinclude scripts/Kbuild.include 258d730cfbSDavid Woodhouse 26*10b63956SDavid 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 33*10b63956SDavid Howellsinstall-file := $(installdir)/.install 34*10b63956SDavid 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 40*10b63956SDavid Howellssrcdir := $(srctree)/$(obj) 41*10b63956SDavid Howellsgendir := $(objtree)/$(gen) 42*10b63956SDavid Howells 43*10b63956SDavid Howellsoldsrcdir := $(srctree)/$(subst /uapi,,$(obj)) 44*10b63956SDavid Howells 457712401aSSam Ravnborg# all headers files for this dir 46d8ecc5cdSSam Ravnborgheader-y := $(filter-out $(generic-y), $(header-y)) 4740f1d4c2SDavid Howellsall-files := $(header-y) $(genhdr-y) $(wrapper-files) 48*10b63956SDavid Howellsoutput-files := $(addprefix $(installdir)/, $(all-files)) 49*10b63956SDavid Howells 50*10b63956SDavid Howellsinput-files := $(foreach hdr, $(header-y), \ 51*10b63956SDavid Howells $(or \ 52*10b63956SDavid Howells $(wildcard $(srcdir)/$(hdr)), \ 53*10b63956SDavid Howells $(wildcard $(oldsrcdir)/$(hdr)), \ 54*10b63956SDavid Howells $(error Missing UAPI file $(srcdir)/$(hdr)) \ 55*10b63956SDavid Howells )) \ 56*10b63956SDavid Howells $(foreach hdr, $(genhdr-y), \ 57*10b63956SDavid Howells $(or \ 58*10b63956SDavid Howells $(wildcard $(gendir)/$(hdr)), \ 59*10b63956SDavid Howells $(error Missing generated UAPI file $(gendir)/$(hdr)) \ 60*10b63956SDavid Howells )) 61de789125SDavid Woodhouse 62de789125SDavid Woodhouse# Work out what needs to be removed 63*10b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 647712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 65de789125SDavid Woodhouse 667712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 67*10b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 68de789125SDavid Woodhouse 697712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 70de789125SDavid Woodhouse 717712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 727712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 73db1bec4fSSam Ravnborg cmd_install = \ 74*10b63956SDavid Howells $(PERL) $< $(installdir) $(SRCARCH) $(input-files); \ 75d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 76*10b63956SDavid Howells echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 77d8ecc5cdSSam Ravnborg done; \ 787712401aSSam Ravnborg touch $@ 798d730cfbSDavid Woodhouse 807712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 817712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 828d730cfbSDavid Woodhouse 837712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 847211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 857211b8b9SSergei Poselenov# the "Argument list too long" error. 867211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 87*10b63956SDavid Howells echo "$(installdir)/$${f}"; done \ 887211b8b9SSergei Poselenov | xargs \ 897211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 907712401aSSam Ravnborg touch $@ 9168475359SDavid Woodhouse 927712401aSSam RavnborgPHONY += __headersinst __headerscheck 938d730cfbSDavid Woodhouse 947712401aSSam Ravnborgifndef HDRCHECK 957712401aSSam Ravnborg# Rules for installing headers 967712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 977712401aSSam Ravnborg @: 98de789125SDavid Woodhouse 997712401aSSam Ravnborgtargets += $(install-file) 1007712401aSSam Ravnborg$(install-file): scripts/headers_install.pl $(input-files) FORCE 1017712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 1027712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 1037712401aSSam Ravnborg $(call if_changed,install) 104de789125SDavid Woodhouse 10568475359SDavid Woodhouseelse 1067712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 1077712401aSSam Ravnborg @: 1088d730cfbSDavid Woodhouse 1097712401aSSam Ravnborgtargets += $(check-file) 1107712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 1117712401aSSam Ravnborg $(call if_changed,check) 1124e420aa9SSam Ravnborg 1138d730cfbSDavid Woodhouseendif 1148d730cfbSDavid Woodhouse 1158d730cfbSDavid Woodhouse# Recursion 1167712401aSSam Ravnborghdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 1177712401aSSam Ravnborg.PHONY: $(subdirs) 1187712401aSSam Ravnborg$(subdirs): 11962284a37SSam Ravnborg $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 1207712401aSSam Ravnborg 1217712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 1227712401aSSam Ravnborgcmd_files := $(wildcard \ 1237712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1247712401aSSam Ravnborg 1257712401aSSam Ravnborgifneq ($(cmd_files),) 1267712401aSSam Ravnborg include $(cmd_files) 1277712401aSSam Ravnborgendif 1287712401aSSam Ravnborg 1297712401aSSam Ravnborg.PHONY: $(PHONY) 1307712401aSSam RavnborgPHONY += FORCE 1317712401aSSam RavnborgFORCE: ; 132