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) 17*2f263d14SRichard Genoud 18*2f263d14SRichard Genoud# When make is run under a fakechroot environment, the function 19*2f263d14SRichard Genoud# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular 20*2f263d14SRichard Genoud# files. So, we are using a combination of sort/dir/wildcard which works 21*2f263d14SRichard Genoud# with fakechroot. 22*2f263d14SRichard Genoudsubdirs := $(patsubst $(srcdir)/%/,%,\ 23*2f263d14SRichard Genoud $(filter-out $(srcdir)/,\ 24*2f263d14SRichard Genoud $(sort $(dir $(wildcard $(srcdir)/*/))))) 25*2f263d14SRichard Genoud 2605d8cba4SMasahiro Yamada# caller may set destination dir (when installing to asm/) 2705d8cba4SMasahiro Yamada_dst := $(if $(dst),$(dst),$(obj)) 2805d8cba4SMasahiro Yamada 2905d8cba4SMasahiro Yamada# Recursion 3005d8cba4SMasahiro Yamada__headers: $(subdirs) 3105d8cba4SMasahiro Yamada 3205d8cba4SMasahiro Yamada.PHONY: $(subdirs) 3305d8cba4SMasahiro Yamada$(subdirs): 3405d8cba4SMasahiro Yamada $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ 3505d8cba4SMasahiro Yamada 3605d8cba4SMasahiro Yamada# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi. 3705d8cba4SMasahiro Yamada# We have only sub-directories there. 3805d8cba4SMasahiro Yamadaskip-inst := $(if $(filter %/uapi,$(obj)),1) 3905d8cba4SMasahiro Yamada 4005d8cba4SMasahiro Yamadaifeq ($(skip-inst),) 4105d8cba4SMasahiro Yamada 42cb97914bSH. Peter Anvin# generated header directory 43cb97914bSH. Peter Anvingen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) 44cb97914bSH. Peter Anvin 45fcc8487dSNicolas Dichtel# Kbuild file is optional 46283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild 47fcc8487dSNicolas Dichtel-include $(kbuild-file) 48de789125SDavid Woodhouse 4910b63956SDavid Howellsold-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild 5010b63956SDavid Howellsifneq ($(wildcard $(old-kbuild-file)),) 5110b63956SDavid Howellsinclude $(old-kbuild-file) 5210b63956SDavid Howellsendif 53c7bb349eSSam Ravnborg 5410b63956SDavid Howellsinstalldir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst)) 5562284a37SSam Ravnborg 56fcc8487dSNicolas Dichtelgendir := $(objtree)/$(gen) 57fcc8487dSNicolas Dichtelheader-files := $(notdir $(wildcard $(srcdir)/*.h)) 58fcc8487dSNicolas Dichtelheader-files += $(notdir $(wildcard $(srcdir)/*.agh)) 59fcc8487dSNicolas Dichtelheader-files := $(filter-out $(no-export-headers), $(header-files)) 60fcc8487dSNicolas Dichtelgenhdr-files := $(notdir $(wildcard $(gendir)/*.h)) 61fcc8487dSNicolas Dichtelgenhdr-files := $(filter-out $(header-files), $(genhdr-files)) 628d730cfbSDavid Woodhouse 637712401aSSam Ravnborg# files used to track state of install/check 6410b63956SDavid Howellsinstall-file := $(installdir)/.install 6510b63956SDavid Howellscheck-file := $(installdir)/.check 667712401aSSam Ravnborg 67d8ecc5cdSSam Ravnborg# generic-y list all files an architecture uses from asm-generic 68d8ecc5cdSSam Ravnborg# Use this to build a list of headers which require a wrapper 69fcc8487dSNicolas Dichtelgeneric-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h)) 70fcc8487dSNicolas Dichtelwrapper-files := $(filter $(generic-files), $(generic-y)) 71fcc8487dSNicolas Dichtelwrapper-files := $(filter-out $(header-files), $(wrapper-files)) 7210b63956SDavid Howells 737712401aSSam Ravnborg# all headers files for this dir 74fcc8487dSNicolas Dichtelall-files := $(header-files) $(genhdr-files) $(wrapper-files) 7510b63956SDavid Howellsoutput-files := $(addprefix $(installdir)/, $(all-files)) 7610b63956SDavid Howells 77fcc8487dSNicolas Dichtelifneq ($(mandatory-y),) 78fcc8487dSNicolas Dichtelmissing := $(filter-out $(all-files),$(mandatory-y)) 79fcc8487dSNicolas Dichtelifneq ($(missing),) 80fcc8487dSNicolas Dichtel$(error Some mandatory headers ($(missing)) are missing in $(obj)) 81fcc8487dSNicolas Dichtelendif 82fcc8487dSNicolas Dichtelendif 83de789125SDavid Woodhouse 84de789125SDavid Woodhouse# Work out what needs to be removed 8510b63956SDavid Howellsoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 867712401aSSam Ravnborgunwanted := $(filter-out $(all-files),$(oldheaders)) 87de789125SDavid Woodhouse 887712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 8910b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted)) 90de789125SDavid Woodhouse 917712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 92de789125SDavid Woodhouse 937712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 947712401aSSam Ravnborg file$(if $(word 2, $(all-files)),s)) 95db1bec4fSSam Ravnborg cmd_install = \ 96fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ 97fcc8487dSNicolas Dichtel $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ 98d8ecc5cdSSam Ravnborg for F in $(wrapper-files); do \ 9910b63956SDavid Howells echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 100d8ecc5cdSSam Ravnborg done; \ 1017712401aSSam Ravnborg touch $@ 1028d730cfbSDavid Woodhouse 1037712401aSSam Ravnborgquiet_cmd_remove = REMOVE $(unwanted) 1047712401aSSam Ravnborg cmd_remove = rm -f $(unwanted-file) 1058d730cfbSDavid Woodhouse 1067712401aSSam Ravnborgquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 1077211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid 1087211b8b9SSergei Poselenov# the "Argument list too long" error. 1097211b8b9SSergei Poselenov cmd_check = for f in $(all-files); do \ 11010b63956SDavid Howells echo "$(installdir)/$${f}"; done \ 1117211b8b9SSergei Poselenov | xargs \ 1127211b8b9SSergei Poselenov $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 1137712401aSSam Ravnborg touch $@ 11468475359SDavid Woodhouse 1157712401aSSam Ravnborgifndef HDRCHECK 1167712401aSSam Ravnborg# Rules for installing headers 11705d8cba4SMasahiro Yamada__headers: $(install-file) 1187712401aSSam Ravnborg @: 119de789125SDavid Woodhouse 1207712401aSSam Ravnborgtargets += $(install-file) 1217c025b2aSNicolas Dichtel$(install-file): scripts/headers_install.sh \ 122fcc8487dSNicolas Dichtel $(addprefix $(srcdir)/,$(header-files)) \ 123fcc8487dSNicolas Dichtel $(addprefix $(gendir)/,$(genhdr-files)) FORCE 1247712401aSSam Ravnborg $(if $(unwanted),$(call cmd,remove),) 1257712401aSSam Ravnborg $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 1267712401aSSam Ravnborg $(call if_changed,install) 127de789125SDavid Woodhouse 12868475359SDavid Woodhouseelse 12905d8cba4SMasahiro Yamada__headers: $(check-file) 1307712401aSSam Ravnborg @: 1318d730cfbSDavid Woodhouse 1327712401aSSam Ravnborgtargets += $(check-file) 1337712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE 1347712401aSSam Ravnborg $(call if_changed,check) 1354e420aa9SSam Ravnborg 1368d730cfbSDavid Woodhouseendif 1378d730cfbSDavid Woodhouse 1387712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets))) 1397712401aSSam Ravnborgcmd_files := $(wildcard \ 1407712401aSSam Ravnborg $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1417712401aSSam Ravnborg 1427712401aSSam Ravnborgifneq ($(cmd_files),) 1437712401aSSam Ravnborg include $(cmd_files) 1447712401aSSam Ravnborgendif 1457712401aSSam Ravnborg 14605d8cba4SMasahiro Yamadaendif # skip-inst 14705d8cba4SMasahiro Yamada 1487712401aSSam Ravnborg.PHONY: $(PHONY) 1497712401aSSam RavnborgPHONY += FORCE 1507712401aSSam RavnborgFORCE: ; 151