18d730cfbSDavid Woodhouse# ========================================================================== 28d730cfbSDavid Woodhouse# Installing headers 38d730cfbSDavid Woodhouse# 4fcc8487dSNicolas Dichtel# All headers under include/uapi, include/generated/uapi, 561562f98SNicolas 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 11*05d8cba4SMasahiro YamadaPHONY := __headers 12*05d8cba4SMasahiro Yamada__headers: 13*05d8cba4SMasahiro Yamada 14*05d8cba4SMasahiro Yamadainclude scripts/Kbuild.include 15*05d8cba4SMasahiro Yamada 16*05d8cba4SMasahiro Yamadasrcdir := $(srctree)/$(obj) 17*05d8cba4SMasahiro Yamadasubdirs := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.)) 18*05d8cba4SMasahiro Yamada# caller may set destination dir (when installing to asm/) 19*05d8cba4SMasahiro Yamada_dst := $(if $(dst),$(dst),$(obj)) 20*05d8cba4SMasahiro Yamada 21*05d8cba4SMasahiro Yamada# Recursion 22*05d8cba4SMasahiro Yamada__headers: $(subdirs) 23*05d8cba4SMasahiro Yamada 24*05d8cba4SMasahiro Yamada.PHONY: $(subdirs) 25*05d8cba4SMasahiro Yamada$(subdirs): 26*05d8cba4SMasahiro Yamada $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 27*05d8cba4SMasahiro Yamada 28*05d8cba4SMasahiro Yamada# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi. 29*05d8cba4SMasahiro Yamada# We have only sub-directories there. 30*05d8cba4SMasahiro Yamadaskip-inst := $(if $(filter %/uapi,$(obj)),1) 31*05d8cba4SMasahiro Yamada 32*05d8cba4SMasahiro Yamadaifeq ($(skip-inst),) 33*05d8cba4SMasahiro Yamada 34cb97914bSH. Peter Anvin# generated header directory 35cb97914bSH. Peter Anvingen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) 36cb97914bSH. Peter Anvin 37fcc8487dSNicolas Dichtel# Kbuild file is optional 38283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild 39fcc8487dSNicolas Dichtel-include $(kbuild-file) 40de789125SDavid Woodhouse 4110b63956SDavid Howellsold-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild 4210b63956SDavid Howellsifneq ($(wildcard $(old-kbuild-file)),) 4310b63956SDavid Howellsinclude $(old-kbuild-file) 4410b63956SDavid Howellsendif 45c7bb349eSSam Ravnborg 4610b63956SDavid Howellsinstalldir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst)) 4762284a37SSam Ravnborg 48fcc8487dSNicolas Dichtelgendir := $(objtree)/$(gen) 49fcc8487dSNicolas Dichtelheader-files := $(notdir $(wildcard $(srcdir)/*.h)) 50fcc8487dSNicolas Dichtelheader-files += $(notdir $(wildcard $(srcdir)/*.agh)) 51fcc8487dSNicolas Dichtelheader-files := $(filter-out $(no-export-headers), $(header-files)) 52fcc8487dSNicolas Dichtelgenhdr-files := $(notdir $(wildcard $(gendir)/*.h)) 53fcc8487dSNicolas Dichtelgenhdr-files := $(filter-out $(header-files), $(genhdr-files)) 548d730cfbSDavid Woodhouse 557712401aSSam Ravnborg# files used to track state of install/check 5610b63956SDavid Howellsinstall-file := $(installdir)/.install 5710b63956SDavid Howellscheck-file := $(installdir)/.check 587712401aSSam Ravnborg 59d8ecc5cdSSam Ravnborg# generic-y list all files an architecture uses from asm-generic 60d8ecc5cdSSam Ravnborg# Use this to build a list of headers which require a wrapper 61fcc8487dSNicolas Dichtelgeneric-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h)) 62fcc8487dSNicolas Dichtelwrapper-files := $(filter $(generic-files), $(generic-y)) 63fcc8487dSNicolas Dichtelwrapper-files := $(filter-out $(header-files), $(wrapper-files)) 6410b63956SDavid Howells 657712401aSSam Ravnborg# all headers files for this dir 66fcc8487dSNicolas Dichtelall-files := $(header-files) $(genhdr-files) $(wrapper-files) 6710b63956SDavid Howellsoutput-files := $(addprefix $(installdir)/, $(all-files)) 6810b63956SDavid Howells 69fcc8487dSNicolas Dichtelifneq ($(mandatory-y),) 70fcc8487dSNicolas Dichtelmissing := $(filter-out $(all-files),$(mandatory-y)) 71fcc8487dSNicolas Dichtelifneq ($(missing),) 72fcc8487dSNicolas Dichtel$(error Some mandatory headers ($(missing)) are missing in $(obj)) 73fcc8487dSNicolas Dichtelendif 74fcc8487dSNicolas Dichtelendif 75de789125SDavid Woodhouse 76de789125SDavid Woodhouse# Work out what needs to be removed 7710b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 787712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 79de789125SDavid Woodhouse 807712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 8110b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 82de789125SDavid Woodhouse 837712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 84de789125SDavid Woodhouse 857712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 867712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 87db1bec4fSSam Ravnborg cmd_install = \ 88fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ 89fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ 90d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 9110b63956SDavid Howells echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 92d8ecc5cdSSam Ravnborg done; \ 937712401aSSam Ravnborg touch $@ 948d730cfbSDavid Woodhouse 957712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 967712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 978d730cfbSDavid Woodhouse 987712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 997211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 1007211b8b9SSergei Poselenov# the "Argument list too long" error. 1017211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 10210b63956SDavid Howells echo "$(installdir)/$${f}"; done \ 1037211b8b9SSergei Poselenov | xargs \ 1047211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 1057712401aSSam Ravnborg touch $@ 10668475359SDavid Woodhouse 1077712401aSSam Ravnborgifndef HDRCHECK 1087712401aSSam Ravnborg# Rules for installing headers 109*05d8cba4SMasahiro Yamada__headers: $(install-file) 1107712401aSSam Ravnborg @: 111de789125SDavid Woodhouse 1127712401aSSam Ravnborgtargets += $(install-file) 1137c025b2aSNicolas Dichtel$(install-file): scripts/headers_install.sh \ 114fcc8487dSNicolas Dichtel $(addprefix $(srcdir)/,$(header-files)) \ 115fcc8487dSNicolas Dichtel $(addprefix $(gendir)/,$(genhdr-files)) FORCE 1167712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 1177712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 1187712401aSSam Ravnborg $(call if_changed,install) 119de789125SDavid Woodhouse 12068475359SDavid Woodhouseelse 121*05d8cba4SMasahiro Yamada__headers: $(check-file) 1227712401aSSam Ravnborg @: 1238d730cfbSDavid Woodhouse 1247712401aSSam Ravnborgtargets += $(check-file) 1257712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 1267712401aSSam Ravnborg $(call if_changed,check) 1274e420aa9SSam Ravnborg 1288d730cfbSDavid Woodhouseendif 1298d730cfbSDavid Woodhouse 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 138*05d8cba4SMasahiro Yamadaendif # skip-inst 139*05d8cba4SMasahiro Yamada 1407712401aSSam Ravnborg.PHONY: $(PHONY) 1417712401aSSam RavnborgPHONY += FORCE 1427712401aSSam RavnborgFORCE: ; 143