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 1105d8cba4SMasahiro YamadaPHONY := __headers 1205d8cba4SMasahiro Yamada__headers: 1305d8cba4SMasahiro Yamada 1405d8cba4SMasahiro Yamadainclude scripts/Kbuild.include 1505d8cba4SMasahiro Yamada 1605d8cba4SMasahiro Yamadasrcdir := $(srctree)/$(obj) 172f263d14SRichard Genoud 182f263d14SRichard Genoud# When make is run under a fakechroot environment, the function 192f263d14SRichard Genoud# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular 202f263d14SRichard Genoud# files. So, we are using a combination of sort/dir/wildcard which works 212f263d14SRichard Genoud# with fakechroot. 222f263d14SRichard Genoudsubdirs := $(patsubst $(srcdir)/%/,%,\ 232f263d14SRichard Genoud $(filter-out $(srcdir)/,\ 242f263d14SRichard Genoud $(sort $(dir $(wildcard $(srcdir)/*/))))) 252f263d14SRichard Genoud 2605d8cba4SMasahiro Yamada# Recursion 2705d8cba4SMasahiro Yamada__headers: $(subdirs) 2805d8cba4SMasahiro Yamada 2905d8cba4SMasahiro Yamada.PHONY: $(subdirs) 3005d8cba4SMasahiro Yamada$(subdirs): 31a8ff49a1SMasahiro Yamada $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@ 3205d8cba4SMasahiro Yamada 3305d8cba4SMasahiro Yamada# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi. 3405d8cba4SMasahiro Yamada# We have only sub-directories there. 3505d8cba4SMasahiro Yamadaskip-inst := $(if $(filter %/uapi,$(obj)),1) 3605d8cba4SMasahiro Yamada 3705d8cba4SMasahiro Yamadaifeq ($(skip-inst),) 3805d8cba4SMasahiro Yamada 39fcc8487dSNicolas Dichtel# Kbuild file is optional 40283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild 41fcc8487dSNicolas Dichtel-include $(kbuild-file) 42de789125SDavid Woodhouse 43a8ff49a1SMasahiro Yamadainstalldir := $(INSTALL_HDR_PATH)/$(dst) 4487ebb94eSMasahiro Yamadagendir := $(objtree)/$(subst include/,include/generated/,$(obj)) 45fcc8487dSNicolas Dichtelheader-files := $(notdir $(wildcard $(srcdir)/*.h)) 46fcc8487dSNicolas Dichtelheader-files += $(notdir $(wildcard $(srcdir)/*.agh)) 47fcc8487dSNicolas Dichtelheader-files := $(filter-out $(no-export-headers), $(header-files)) 48fcc8487dSNicolas Dichtelgenhdr-files := $(notdir $(wildcard $(gendir)/*.h)) 49fcc8487dSNicolas Dichtelgenhdr-files := $(filter-out $(header-files), $(genhdr-files)) 508d730cfbSDavid Woodhouse 517712401aSSam Ravnborg# files used to track state of install/check 5210b63956SDavid Howellsinstall-file := $(installdir)/.install 5310b63956SDavid Howellscheck-file := $(installdir)/.check 547712401aSSam Ravnborg 557712401aSSam Ravnborg# all headers files for this dir 56*09c3776cSMasahiro Yamadaall-files := $(header-files) $(genhdr-files) 5710b63956SDavid Howellsoutput-files := $(addprefix $(installdir)/, $(all-files)) 5810b63956SDavid Howells 59fcc8487dSNicolas Dichtelifneq ($(mandatory-y),) 60fcc8487dSNicolas Dichtelmissing := $(filter-out $(all-files),$(mandatory-y)) 61fcc8487dSNicolas Dichtelifneq ($(missing),) 62fcc8487dSNicolas Dichtel$(error Some mandatory headers ($(missing)) are missing in $(obj)) 63fcc8487dSNicolas Dichtelendif 64fcc8487dSNicolas Dichtelendif 65de789125SDavid Woodhouse 66de789125SDavid Woodhouse# Work out what needs to be removed 6710b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 687712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 69de789125SDavid Woodhouse 707712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 7110b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 72de789125SDavid Woodhouse 737712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 74de789125SDavid Woodhouse 757712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 767712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 77db1bec4fSSam Ravnborg cmd_install = \ 78fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ 79fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ 807712401aSSam Ravnborg touch $@ 818d730cfbSDavid Woodhouse 827712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 837712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 848d730cfbSDavid Woodhouse 857712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 867211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 877211b8b9SSergei Poselenov# the "Argument list too long" error. 887211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 8910b63956SDavid Howells echo "$(installdir)/$${f}"; done \ 907211b8b9SSergei Poselenov | xargs \ 917211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 927712401aSSam Ravnborg touch $@ 9368475359SDavid Woodhouse 947712401aSSam Ravnborgifndef HDRCHECK 957712401aSSam Ravnborg# Rules for installing headers 9605d8cba4SMasahiro Yamada__headers: $(install-file) 977712401aSSam Ravnborg @: 98de789125SDavid Woodhouse 997712401aSSam Ravnborgtargets += $(install-file) 1007c025b2aSNicolas Dichtel$(install-file): scripts/headers_install.sh \ 101fcc8487dSNicolas Dichtel $(addprefix $(srcdir)/,$(header-files)) \ 102fcc8487dSNicolas 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 10805d8cba4SMasahiro Yamada__headers: $(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 1177712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 1187712401aSSam Ravnborgcmd_files := $(wildcard \ 1197712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1207712401aSSam Ravnborg 1217712401aSSam Ravnborgifneq ($(cmd_files),) 1227712401aSSam Ravnborg include $(cmd_files) 1237712401aSSam Ravnborgendif 1247712401aSSam Ravnborg 12505d8cba4SMasahiro Yamadaendif # skip-inst 12605d8cba4SMasahiro Yamada 1277712401aSSam Ravnborg.PHONY: $(PHONY) 1287712401aSSam RavnborgPHONY += FORCE 1297712401aSSam RavnborgFORCE: ; 130