18d730cfbSDavid Woodhouse# ========================================================================== 28d730cfbSDavid Woodhouse# Installing headers 38d730cfbSDavid Woodhouse# 4fcc8487dSNicolas Dichtel# All headers under include/uapi, include/generated/uapi, 5*61562f98SNicolas Dichtel# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are 6fcc8487dSNicolas Dichtel# exported. 7fcc8487dSNicolas Dichtel# They are preprocessed to remove __KERNEL__ section of the file. 88d730cfbSDavid Woodhouse# 98d730cfbSDavid Woodhouse# ========================================================================== 108d730cfbSDavid Woodhouse 11cb97914bSH. Peter Anvin# generated header directory 12cb97914bSH. Peter Anvingen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) 13cb97914bSH. Peter Anvin 14fcc8487dSNicolas Dichtel# Kbuild file is optional 15283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild 16fcc8487dSNicolas Dichtel-include $(kbuild-file) 17de789125SDavid Woodhouse 189b58b928SJesper Nilsson# called may set destination dir (when installing to asm/) 19bd73a328SNicolas Dichtel_dst := $(if $(dst),$(dst),$(obj)) 209b58b928SJesper Nilsson 2110b63956SDavid Howellsold-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild 2210b63956SDavid Howellsifneq ($(wildcard $(old-kbuild-file)),) 2310b63956SDavid Howellsinclude $(old-kbuild-file) 2410b63956SDavid Howellsendif 25c7bb349eSSam Ravnborg 268d730cfbSDavid Woodhouseinclude scripts/Kbuild.include 278d730cfbSDavid Woodhouse 2810b63956SDavid Howellsinstalldir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst)) 2962284a37SSam Ravnborg 30fcc8487dSNicolas Dichtelsrcdir := $(srctree)/$(obj) 31fcc8487dSNicolas Dichtelgendir := $(objtree)/$(gen) 32fcc8487dSNicolas Dichtelsubdirs := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.)) 33fcc8487dSNicolas Dichtelheader-files := $(notdir $(wildcard $(srcdir)/*.h)) 34fcc8487dSNicolas Dichtelheader-files += $(notdir $(wildcard $(srcdir)/*.agh)) 35fcc8487dSNicolas Dichtelheader-files := $(filter-out $(no-export-headers), $(header-files)) 36fcc8487dSNicolas Dichtelgenhdr-files := $(notdir $(wildcard $(gendir)/*.h)) 37fcc8487dSNicolas Dichtelgenhdr-files := $(filter-out $(header-files), $(genhdr-files)) 388d730cfbSDavid Woodhouse 397712401aSSam Ravnborg# files used to track state of install/check 4010b63956SDavid Howellsinstall-file := $(installdir)/.install 4110b63956SDavid Howellscheck-file := $(installdir)/.check 427712401aSSam Ravnborg 43d8ecc5cdSSam Ravnborg# generic-y list all files an architecture uses from asm-generic 44d8ecc5cdSSam Ravnborg# Use this to build a list of headers which require a wrapper 45fcc8487dSNicolas Dichtelgeneric-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h)) 46fcc8487dSNicolas Dichtelwrapper-files := $(filter $(generic-files), $(generic-y)) 47fcc8487dSNicolas Dichtelwrapper-files := $(filter-out $(header-files), $(wrapper-files)) 4810b63956SDavid Howells 497712401aSSam Ravnborg# all headers files for this dir 50fcc8487dSNicolas Dichtelall-files := $(header-files) $(genhdr-files) $(wrapper-files) 5110b63956SDavid Howellsoutput-files := $(addprefix $(installdir)/, $(all-files)) 5210b63956SDavid Howells 53fcc8487dSNicolas Dichtelifneq ($(mandatory-y),) 54fcc8487dSNicolas Dichtelmissing := $(filter-out $(all-files),$(mandatory-y)) 55fcc8487dSNicolas Dichtelifneq ($(missing),) 56fcc8487dSNicolas Dichtel$(error Some mandatory headers ($(missing)) are missing in $(obj)) 57fcc8487dSNicolas Dichtelendif 58fcc8487dSNicolas Dichtelendif 59de789125SDavid Woodhouse 60de789125SDavid Woodhouse# Work out what needs to be removed 6110b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 627712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 63de789125SDavid Woodhouse 647712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 6510b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 66de789125SDavid Woodhouse 677712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 68de789125SDavid Woodhouse 697712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 707712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 71db1bec4fSSam Ravnborg cmd_install = \ 72fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ 73fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ 74d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 7510b63956SDavid Howells echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 76d8ecc5cdSSam Ravnborg done; \ 777712401aSSam Ravnborg touch $@ 788d730cfbSDavid Woodhouse 797712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 807712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 818d730cfbSDavid Woodhouse 827712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 837211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 847211b8b9SSergei Poselenov# the "Argument list too long" error. 857211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 8610b63956SDavid Howells echo "$(installdir)/$${f}"; done \ 877211b8b9SSergei Poselenov | xargs \ 887211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 897712401aSSam Ravnborg touch $@ 9068475359SDavid Woodhouse 917712401aSSam RavnborgPHONY += __headersinst __headerscheck 928d730cfbSDavid Woodhouse 937712401aSSam Ravnborgifndef HDRCHECK 947712401aSSam Ravnborg# Rules for installing headers 957712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file) 967712401aSSam Ravnborg @: 97de789125SDavid Woodhouse 987712401aSSam Ravnborgtargets += $(install-file) 997c025b2aSNicolas Dichtel$(install-file): scripts/headers_install.sh \ 100fcc8487dSNicolas Dichtel $(addprefix $(srcdir)/,$(header-files)) \ 101fcc8487dSNicolas Dichtel $(addprefix $(gendir)/,$(genhdr-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 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