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/) 17c4619bc6SSam 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 50*c0ff68f1SNicolas Dichtelinput-files1 := $(foreach hdr, $(header-y), \ 51c4619bc6SSam Ravnborg $(if $(wildcard $(srcdir)/$(hdr)), \ 52*c0ff68f1SNicolas Dichtel $(wildcard $(srcdir)/$(hdr))) \ 53*c0ff68f1SNicolas Dichtel ) 54*c0ff68f1SNicolas Dichtelinput-files1-name := $(notdir $(input-files1)) 55*c0ff68f1SNicolas Dichtelinput-files2 := $(foreach hdr, $(header-y), \ 56*c0ff68f1SNicolas Dichtel $(if $(wildcard $(srcdir)/$(hdr)),, \ 57c4619bc6SSam Ravnborg $(if $(wildcard $(oldsrcdir)/$(hdr)), \ 5810b63956SDavid Howells $(wildcard $(oldsrcdir)/$(hdr)), \ 59c4619bc6SSam Ravnborg $(error Missing UAPI file $(srcdir)/$(hdr))) \ 60*c0ff68f1SNicolas Dichtel )) 61*c0ff68f1SNicolas Dichtelinput-files2-name := $(notdir $(input-files2)) 62*c0ff68f1SNicolas Dichtelinput-files3 := $(foreach hdr, $(genhdr-y), \ 63c4619bc6SSam Ravnborg $(if $(wildcard $(gendir)/$(hdr)), \ 6410b63956SDavid Howells $(wildcard $(gendir)/$(hdr)), \ 6510b63956SDavid Howells $(error Missing generated UAPI file $(gendir)/$(hdr)) \ 6610b63956SDavid Howells )) 67*c0ff68f1SNicolas Dichtelinput-files3-name := $(notdir $(input-files3)) 68de789125SDavid Woodhouse 69de789125SDavid Woodhouse# Work out what needs to be removed 7010b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 717712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 72de789125SDavid Woodhouse 737712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 7410b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 75de789125SDavid Woodhouse 767712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 77de789125SDavid Woodhouse 787712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 797712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 80db1bec4fSSam Ravnborg cmd_install = \ 81*c0ff68f1SNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(input-files1-name); \ 82*c0ff68f1SNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(oldsrcdir) $(input-files2-name); \ 83*c0ff68f1SNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(gendir) $(input-files3-name); \ 84d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 8510b63956SDavid Howells echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 86d8ecc5cdSSam Ravnborg done; \ 877712401aSSam Ravnborg touch $@ 888d730cfbSDavid Woodhouse 897712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 907712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 918d730cfbSDavid Woodhouse 927712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 937211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 947211b8b9SSergei Poselenov# the "Argument list too long" error. 957211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 9610b63956SDavid Howells echo "$(installdir)/$${f}"; done \ 977211b8b9SSergei Poselenov | xargs \ 987211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 997712401aSSam Ravnborg touch $@ 10068475359SDavid Woodhouse 1017712401aSSam RavnborgPHONY += __headersinst __headerscheck 1028d730cfbSDavid Woodhouse 1037712401aSSam Ravnborgifndef HDRCHECK 1047712401aSSam Ravnborg# Rules for installing headers 1057712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 1067712401aSSam Ravnborg @: 107de789125SDavid Woodhouse 1087712401aSSam Ravnborgtargets += $(install-file) 109*c0ff68f1SNicolas Dichtel$(install-file): scripts/headers_install.sh $(input-files1) $(input-files2) $(input-files3) FORCE 1107712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 1117712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 1127712401aSSam Ravnborg $(call if_changed,install) 113de789125SDavid Woodhouse 11468475359SDavid Woodhouseelse 1157712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 1167712401aSSam Ravnborg @: 1178d730cfbSDavid Woodhouse 1187712401aSSam Ravnborgtargets += $(check-file) 1197712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 1207712401aSSam Ravnborg $(call if_changed,check) 1214e420aa9SSam Ravnborg 1228d730cfbSDavid Woodhouseendif 1238d730cfbSDavid Woodhouse 1248d730cfbSDavid Woodhouse# Recursion 1257712401aSSam Ravnborghdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 1267712401aSSam Ravnborg.PHONY: $(subdirs) 1277712401aSSam Ravnborg$(subdirs): 12862284a37SSam Ravnborg $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 1297712401aSSam Ravnborg 1307712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 1317712401aSSam Ravnborgcmd_files := $(wildcard \ 1327712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1337712401aSSam Ravnborg 1347712401aSSam Ravnborgifneq ($(cmd_files),) 1357712401aSSam Ravnborg include $(cmd_files) 1367712401aSSam Ravnborgendif 1377712401aSSam Ravnborg 1387712401aSSam Ravnborg.PHONY: $(PHONY) 1397712401aSSam RavnborgPHONY += FORCE 1407712401aSSam RavnborgFORCE: ; 141