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): 31*a8ff49a1SMasahiro 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 4310b63956SDavid Howellsold-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild 4410b63956SDavid Howellsifneq ($(wildcard $(old-kbuild-file)),) 4510b63956SDavid Howellsinclude $(old-kbuild-file) 4610b63956SDavid Howellsendif 47c7bb349eSSam Ravnborg 48*a8ff49a1SMasahiro Yamadainstalldir := $(INSTALL_HDR_PATH)/$(dst) 4987ebb94eSMasahiro Yamadagendir := $(objtree)/$(subst include/,include/generated/,$(obj)) 50fcc8487dSNicolas Dichtelheader-files := $(notdir $(wildcard $(srcdir)/*.h)) 51fcc8487dSNicolas Dichtelheader-files += $(notdir $(wildcard $(srcdir)/*.agh)) 52fcc8487dSNicolas Dichtelheader-files := $(filter-out $(no-export-headers), $(header-files)) 53fcc8487dSNicolas Dichtelgenhdr-files := $(notdir $(wildcard $(gendir)/*.h)) 54fcc8487dSNicolas Dichtelgenhdr-files := $(filter-out $(header-files), $(genhdr-files)) 558d730cfbSDavid Woodhouse 567712401aSSam Ravnborg# files used to track state of install/check 5710b63956SDavid Howellsinstall-file := $(installdir)/.install 5810b63956SDavid Howellscheck-file := $(installdir)/.check 597712401aSSam Ravnborg 60d8ecc5cdSSam Ravnborg# generic-y list all files an architecture uses from asm-generic 61d8ecc5cdSSam Ravnborg# Use this to build a list of headers which require a wrapper 62fcc8487dSNicolas Dichtelgeneric-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h)) 63fcc8487dSNicolas Dichtelwrapper-files := $(filter $(generic-files), $(generic-y)) 64fcc8487dSNicolas Dichtelwrapper-files := $(filter-out $(header-files), $(wrapper-files)) 6510b63956SDavid Howells 667712401aSSam Ravnborg# all headers files for this dir 67fcc8487dSNicolas Dichtelall-files := $(header-files) $(genhdr-files) $(wrapper-files) 6810b63956SDavid Howellsoutput-files := $(addprefix $(installdir)/, $(all-files)) 6910b63956SDavid Howells 70fcc8487dSNicolas Dichtelifneq ($(mandatory-y),) 71fcc8487dSNicolas Dichtelmissing := $(filter-out $(all-files),$(mandatory-y)) 72fcc8487dSNicolas Dichtelifneq ($(missing),) 73fcc8487dSNicolas Dichtel$(error Some mandatory headers ($(missing)) are missing in $(obj)) 74fcc8487dSNicolas Dichtelendif 75fcc8487dSNicolas Dichtelendif 76de789125SDavid Woodhouse 77de789125SDavid Woodhouse# Work out what needs to be removed 7810b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 797712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 80de789125SDavid Woodhouse 817712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 8210b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 83de789125SDavid Woodhouse 847712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 85de789125SDavid Woodhouse 867712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 877712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 88db1bec4fSSam Ravnborg cmd_install = \ 89fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ 90fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ 91d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 9210b63956SDavid Howells echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 93d8ecc5cdSSam Ravnborg done; \ 947712401aSSam Ravnborg touch $@ 958d730cfbSDavid Woodhouse 967712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 977712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 988d730cfbSDavid Woodhouse 997712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 1007211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 1017211b8b9SSergei Poselenov# the "Argument list too long" error. 1027211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 10310b63956SDavid Howells echo "$(installdir)/$${f}"; done \ 1047211b8b9SSergei Poselenov | xargs \ 1057211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 1067712401aSSam Ravnborg touch $@ 10768475359SDavid Woodhouse 1087712401aSSam Ravnborgifndef HDRCHECK 1097712401aSSam Ravnborg# Rules for installing headers 11005d8cba4SMasahiro Yamada__headers: $(install-file) 1117712401aSSam Ravnborg @: 112de789125SDavid Woodhouse 1137712401aSSam Ravnborgtargets += $(install-file) 1147c025b2aSNicolas Dichtel$(install-file): scripts/headers_install.sh \ 115fcc8487dSNicolas Dichtel $(addprefix $(srcdir)/,$(header-files)) \ 116fcc8487dSNicolas Dichtel $(addprefix $(gendir)/,$(genhdr-files)) FORCE 1177712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 1187712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 1197712401aSSam Ravnborg $(call if_changed,install) 120de789125SDavid Woodhouse 12168475359SDavid Woodhouseelse 12205d8cba4SMasahiro Yamada__headers: $(check-file) 1237712401aSSam Ravnborg @: 1248d730cfbSDavid Woodhouse 1257712401aSSam Ravnborgtargets += $(check-file) 1267712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 1277712401aSSam Ravnborg $(call if_changed,check) 1284e420aa9SSam Ravnborg 1298d730cfbSDavid Woodhouseendif 1308d730cfbSDavid Woodhouse 1317712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 1327712401aSSam Ravnborgcmd_files := $(wildcard \ 1337712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1347712401aSSam Ravnborg 1357712401aSSam Ravnborgifneq ($(cmd_files),) 1367712401aSSam Ravnborg include $(cmd_files) 1377712401aSSam Ravnborgendif 1387712401aSSam Ravnborg 13905d8cba4SMasahiro Yamadaendif # skip-inst 14005d8cba4SMasahiro Yamada 1417712401aSSam Ravnborg.PHONY: $(PHONY) 1427712401aSSam RavnborgPHONY += FORCE 1437712401aSSam RavnborgFORCE: ; 144