18d730cfbSDavid Woodhouse# ========================================================================== 28d730cfbSDavid Woodhouse# Installing headers 38d730cfbSDavid Woodhouse# 4*fcc8487dSNicolas Dichtel# All headers under include/uapi, include/generated/uapi, 5*fcc8487dSNicolas Dichtel# arch/<arch>/include/uapi/asm and arch/<arch>/include/generated/uapi/asm are 6*fcc8487dSNicolas Dichtel# exported. 7*fcc8487dSNicolas 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 14*fcc8487dSNicolas Dichtel# Kbuild file is optional 15283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild 16*fcc8487dSNicolas 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 30*fcc8487dSNicolas Dichtelsrcdir := $(srctree)/$(obj) 31*fcc8487dSNicolas Dichtelgendir := $(objtree)/$(gen) 32*fcc8487dSNicolas Dichtelsubdirs := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.)) 33*fcc8487dSNicolas Dichtelsubdirs += $(subdir-y) 34*fcc8487dSNicolas Dichtelheader-files := $(notdir $(wildcard $(srcdir)/*.h)) 35*fcc8487dSNicolas Dichtelheader-files += $(notdir $(wildcard $(srcdir)/*.agh)) 36*fcc8487dSNicolas Dichtelheader-files := $(filter-out $(no-export-headers), $(header-files)) 37*fcc8487dSNicolas Dichtelgenhdr-files := $(notdir $(wildcard $(gendir)/*.h)) 38*fcc8487dSNicolas Dichtelgenhdr-files := $(filter-out $(header-files), $(genhdr-files)) 398d730cfbSDavid Woodhouse 407712401aSSam Ravnborg# files used to track state of install/check 4110b63956SDavid Howellsinstall-file := $(installdir)/.install 4210b63956SDavid Howellscheck-file := $(installdir)/.check 437712401aSSam Ravnborg 44d8ecc5cdSSam Ravnborg# generic-y list all files an architecture uses from asm-generic 45d8ecc5cdSSam Ravnborg# Use this to build a list of headers which require a wrapper 46*fcc8487dSNicolas Dichtelgeneric-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h)) 47*fcc8487dSNicolas Dichtelwrapper-files := $(filter $(generic-files), $(generic-y)) 48*fcc8487dSNicolas Dichtelwrapper-files := $(filter-out $(header-files), $(wrapper-files)) 4910b63956SDavid Howells 507712401aSSam Ravnborg# all headers files for this dir 51*fcc8487dSNicolas Dichtelall-files := $(header-files) $(genhdr-files) $(wrapper-files) 5210b63956SDavid Howellsoutput-files := $(addprefix $(installdir)/, $(all-files)) 5310b63956SDavid Howells 54*fcc8487dSNicolas Dichtelifneq ($(mandatory-y),) 55*fcc8487dSNicolas Dichtelmissing := $(filter-out $(all-files),$(mandatory-y)) 56*fcc8487dSNicolas Dichtelifneq ($(missing),) 57*fcc8487dSNicolas Dichtel$(error Some mandatory headers ($(missing)) are missing in $(obj)) 58*fcc8487dSNicolas Dichtelendif 59*fcc8487dSNicolas Dichtelendif 60de789125SDavid Woodhouse 61de789125SDavid Woodhouse# Work out what needs to be removed 6210b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 637712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 64de789125SDavid Woodhouse 657712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 6610b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 67de789125SDavid Woodhouse 687712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 69de789125SDavid Woodhouse 707712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 717712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 72db1bec4fSSam Ravnborg cmd_install = \ 73*fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ 74*fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ 75d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 7610b63956SDavid 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 \ 8710b63956SDavid 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) 1007c025b2aSNicolas Dichtel$(install-file): scripts/headers_install.sh \ 101*fcc8487dSNicolas Dichtel $(addprefix $(srcdir)/,$(header-files)) \ 102*fcc8487dSNicolas Dichtel $(addprefix $(gendir)/,$(genhdr-files)) FORCE 1037712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 1047712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 1057712401aSSam Ravnborg $(call if_changed,install) 106de789125SDavid Woodhouse 10768475359SDavid Woodhouseelse 1087712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file) 1097712401aSSam Ravnborg @: 1108d730cfbSDavid Woodhouse 1117712401aSSam Ravnborgtargets += $(check-file) 1127712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 1137712401aSSam Ravnborg $(call if_changed,check) 1144e420aa9SSam Ravnborg 1158d730cfbSDavid Woodhouseendif 1168d730cfbSDavid Woodhouse 1178d730cfbSDavid Woodhouse# Recursion 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