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*c4619bc6SSam Ravnborg_dst := $(if $(destination-y),$(destination-y),$(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 4310b63956SDavid Howellsoldsrcdir := $(srctree)/$(subst /uapi,,$(obj)) 4410b63956SDavid 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) 4810b63956SDavid Howellsoutput-files := $(addprefix $(installdir)/, $(all-files)) 4910b63956SDavid Howells 5010b63956SDavid Howellsinput-files := $(foreach hdr, $(header-y), \ 51*c4619bc6SSam Ravnborg $(if $(wildcard $(srcdir)/$(hdr)), \ 5210b63956SDavid Howells $(wildcard $(srcdir)/$(hdr)), \ 53*c4619bc6SSam Ravnborg $(if $(wildcard $(oldsrcdir)/$(hdr)), \ 5410b63956SDavid Howells $(wildcard $(oldsrcdir)/$(hdr)), \ 55*c4619bc6SSam Ravnborg $(error Missing UAPI file $(srcdir)/$(hdr))) \ 5610b63956SDavid Howells )) \ 5710b63956SDavid Howells $(foreach hdr, $(genhdr-y), \ 58*c4619bc6SSam Ravnborg $(if $(wildcard $(gendir)/$(hdr)), \ 5910b63956SDavid Howells $(wildcard $(gendir)/$(hdr)), \ 6010b63956SDavid Howells $(error Missing generated UAPI file $(gendir)/$(hdr)) \ 6110b63956SDavid Howells )) 62de789125SDavid Woodhouse 63de789125SDavid Woodhouse# Work out what needs to be removed 6410b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 657712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 66de789125SDavid Woodhouse 677712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 6810b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 69de789125SDavid Woodhouse 707712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 71de789125SDavid Woodhouse 727712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 737712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 74db1bec4fSSam Ravnborg cmd_install = \ 7510b63956SDavid Howells $(PERL) $< $(installdir) $(SRCARCH) $(input-files); \ 76d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 7710b63956SDavid Howells echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 78d8ecc5cdSSam Ravnborg done; \ 797712401aSSam Ravnborg touch $@ 808d730cfbSDavid Woodhouse 817712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 827712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 838d730cfbSDavid Woodhouse 847712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 857211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 867211b8b9SSergei Poselenov# the "Argument list too long" error. 877211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 8810b63956SDavid Howells echo "$(installdir)/$${f}"; done \ 897211b8b9SSergei Poselenov | xargs \ 907211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 917712401aSSam Ravnborg touch $@ 9268475359SDavid Woodhouse 937712401aSSam RavnborgPHONY += __headersinst __headerscheck 948d730cfbSDavid Woodhouse 957712401aSSam Ravnborgifndef HDRCHECK 967712401aSSam Ravnborg# Rules for installing headers 977712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 987712401aSSam Ravnborg @: 99de789125SDavid Woodhouse 1007712401aSSam Ravnborgtargets += $(install-file) 1017712401aSSam Ravnborg$(install-file): scripts/headers_install.pl $(input-files) FORCE 1027712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 1037712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 1047712401aSSam Ravnborg $(call if_changed,install) 105de789125SDavid Woodhouse 10668475359SDavid Woodhouseelse 1077712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 1087712401aSSam Ravnborg @: 1098d730cfbSDavid Woodhouse 1107712401aSSam Ravnborgtargets += $(check-file) 1117712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 1127712401aSSam Ravnborg $(call if_changed,check) 1134e420aa9SSam Ravnborg 1148d730cfbSDavid Woodhouseendif 1158d730cfbSDavid Woodhouse 1168d730cfbSDavid Woodhouse# Recursion 1177712401aSSam Ravnborghdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 1187712401aSSam Ravnborg.PHONY: $(subdirs) 1197712401aSSam Ravnborg$(subdirs): 12062284a37SSam Ravnborg $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 1217712401aSSam Ravnborg 1227712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 1237712401aSSam Ravnborgcmd_files := $(wildcard \ 1247712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1257712401aSSam Ravnborg 1267712401aSSam Ravnborgifneq ($(cmd_files),) 1277712401aSSam Ravnborg include $(cmd_files) 1287712401aSSam Ravnborgendif 1297712401aSSam Ravnborg 1307712401aSSam Ravnborg.PHONY: $(PHONY) 1317712401aSSam RavnborgPHONY += FORCE 1327712401aSSam RavnborgFORCE: ; 133